Commit 05886a0a authored by LUSTIG Peter's avatar LUSTIG Peter

deleted old files

parent 02bb0e88
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import dill as pickle
import matplotlib.pyplot as plt
import numpy as np
import astropy.units as u
from nikamap import NikaMap
#from completness import *
import myfunctions as mfct
from time import clock
from multiprocess import Pool
from functools import partial
import sys
from astropy.table import vstack
#import sys
import completness as cp
import os
import matplotlib.pyplot as plt
flux_bins = 2
flux_range = [0.1, 10]
threshold_bins = 5
threshold_range = [2, 10]
#threshold_range = [3, 5]
nsim = 10
flux = 10 * u.mJy
noisefile = "../../N2CLS/ForMarseille/HLS091828_common_mode_kids_out/map_JK.fits"
outfile = None
outdir = "results/"
ncore = 4
import argparse
desc = "Place false sources with a defined flux on Jackknife maps, detect sources and calculate the purity and completness of the detection."
parser = argparse.ArgumentParser(description=desc)
#parser.add_argument("-n", "--noisefile", action="store",
# dest="noisefile",
# help="Name of the Noise Containing Input File")
help="Name of the Noise Containing Input File")
parser.add_argument("-s", "--simulations", action="store",
dest="nsim", type=int, default=10,
help="Number of Simulations")
parser.add_argument("-f", "--flux", action="store",
dest="flux", type=float, default=10.,
help="Flux of the Created Sources in mJy")
parser.add_argument("-m", "--method", action="store",
dest="method", default="unknown",
help="Name of the Reduction Method for Outfile Header")
parser.add_argument("-o", "--outfile", action="store",
dest="outfile", default=None,
help="Output File Name. If not specified: completness-method-flux_[flux]-nsim_[nsim].fits")
parser.add_argument("-d", "--outdir", action="store",
dest="outdir", default="",
help="Output directory. Default: This folder.")
nsim = args.nsim
flux = args.flux * u.mJy
noisefile = args.noisefile
outfile = args.outfile
outdir = args.outdir
#flux bins
#flux range
#threshold bins
#threshold range
############### Begin Calculation #############
sim_per_core = mfct.Distribute_Njobs(ncore, nsim)
data =
fluxes = np.logspace(np.log10(flux_range[0]), np.log10(flux_range[1]), flux_bins)*u.mJy
fluxes_edges = np.logspace(np.log10(flux_range[0]), np.log10(flux_range[1]), flux_bins + 1)*u.mJy
threshold = np.linspace(threshold_range[0], threshold_range[1], threshold_bins)
threshold_edges = np.linspace(threshold_range[0], threshold_range[1], threshold_bins+1)
# Create 4D wcs
shape_4D, wcs_4D = cp.completness_purity_wcs(data.shape, data.wcs, bins=20,
flux_range=flux_range, flux_bins=flux_bins, flux_log=True,
threshold_range=threshold_range, threshold_bins=threshold_bins)
# Testing the lower edges
wcs_threshold = wcs_4D.sub([3])
assert np.all(np.abs(wcs_threshold.all_pix2world(np.arange(threshold_bins+1)-0.5, 0) - threshold_edges) < 1e-15)
wcs_flux = wcs_4D.sub([4])
assert np.all(np.abs(wcs_flux.all_pix2world(np.arange(flux_bins+1)-0.5, 0) - fluxes_edges.value) < 1e-13)
T0 = clock()
helpfunc = partial(cp.completness_purity_2, flux, **{"nsources":8**2, "within":(0, 1),
"wcs":wcs_4D.sub([1, 2, 3]), "jk_map":data})
pool = Pool(ncore)
tmpres =, sim_per_core)
tmpres = list(zip(*tmpres))
all_comp = np.sum(tmpres[0], axis=0)
all_comp_n = np.sum(tmpres[1], axis=0)
all_pur = np.sum(tmpres[2], axis=0)
all_pur_n = np.sum(tmpres[3], axis=0)
sourceresult = vstack(tmpres[4])
with np.errstate(divide='ignore', invalid='ignore'):
completness = all_comp / all_comp_n[..., np.newaxis]
purity = all_pur / all_pur_n
if (method == "unknown" and "/" in noisefile):
method = noisefile.split("/")[-2]
if outfile is None:
outfile = "completness-" + method + "-flux_{:04.0f}-nsim_{:03}.fits".format(flux.value, nsim)
if outdir != "":
if outdir[-1] != "/":
outdir = outdir + "/"
if not os.path.exists(outdir):
outfile = outdir + outfile
mfct.WriteResult(outfile, threshold, completness, purity, nsim, wcs_4D, method, flux, sourceresult)
cp.Plot_CompPur(completness, purity, threshold, nsim=nsim, savename=outfile[0:-5]+"-plot.png")
T = clock()-T0
print('Total calculation time: {:.0f}s'.format(T))
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment