Commit b3fa9b4b authored by LUSTIG Peter's avatar LUSTIG Peter

some corrections and plot improvements

parent 995bafe5
......@@ -29,18 +29,6 @@ from utils import completness_purity_wcs, completness_worker, purity_worker
from utils import find_nearest
import os
os.getcwd()
'''
%load_ext autoreload
%autoreload 2
%matplotlib tk
'''
plt.ion()
class PCEvaluation:
def __init__(self, sources, fake_sources, shape, wcs, flux=None,
mapbins=19, threshold_bins=5, threshold_range=(3, 5)):
......@@ -78,8 +66,17 @@ class PCEvaluation:
- threshold_edges) < 1e-15)
self.completness, self.purity, self.hitmap = self.GetCP()
def GetCompletnessBin(self, xbin, ybin):
return self.completness[:, ybin, xbin, :]
def GetPurityBin(self, xbin, ybin):
return self.purity[:, ybin, xbin, :]
def GetHitsBin(self, xbin, ybin):
return self.purity[:, ybin, xbin]
def GetCP(self, sources=None, fake_sources=None, wcs=None, shape=None,
pool=None):
pool=None):
if sources is None:
sources = self.sources
if fake_sources is None:
......@@ -143,7 +140,7 @@ class PCEvaluation:
if flux is None:
flux = self.flux.to_value(u.mJy)
if thresh is None:
thresh = self.threshold
thresh = self.thresholds
if nfluxlabels is not None:
_label_flux = np.geomspace(flux[0], flux[-1], nfluxlabels)
......@@ -179,11 +176,13 @@ class PCEvaluation:
cbar.ax.tick_params(labelsize=tickfs)
def PlotFixedThreshold(self, data, thresholds, nfluxlabels=None,
hlines=None):
hlines=None, ylabel=''):
linestyles = ['-', '--', '-.', ':']
real_thresholds = find_nearest(self.thresholds, thresholds)
_x = self.flux.to_value(u.mJy)
plt.figure()
for i in range(len(real_thresholds)):
_y = data[:, real_thresholds[i]]
plt.plot(_x, _y, linestyle=linestyles[i],
......@@ -194,7 +193,7 @@ class PCEvaluation:
plt.axhline(val, color='r')
plt.title('Fixed Threshold', fontsize=30, y=1.02)
plt.xlabel('Source Flux [mJy]', fontsize=25)
plt.ylabel('Completness', fontsize=25)
plt.ylabel(ylabel, fontsize=25)
plt.yticks(fontsize=20)
plt.xticks(fontsize=20)
plt.subplots_adjust(left=0.12)
......@@ -204,10 +203,9 @@ class PCEvaluation:
legend = plt.legend(fontsize=25, title='SNR', loc='upper left',
framealpha=1)
plt.setp(legend.get_title(), fontsize=25)
plt.show(block=True)
def PlotOverview(self, completness=None, purity=None, threshold=None,
flux=None):
def PlotOverview(self, flux=None, completness=None, purity=None,
threshold=None):
if completness is None:
completness = self.completness
if purity is None:
......@@ -224,7 +222,6 @@ class PCEvaluation:
sharex=True, sharey=True)
for i in range(threshold_bins):
print(i)
axes[0, i].imshow(_completness[:, :, i], vmin=0, vmax=1)
im = axes[1, i].imshow(_purity[:, :, i], vmin=0, vmax=1)
axes[1, i].set_xlabel("thresh={:.2f}".format(threshold[i]))
......@@ -240,40 +237,61 @@ class PCEvaluation:
axes[0, 0].set_ylabel("completness")
axes[1, 0].set_ylabel("purity")
DATA_DIR = "/home/peter/Dokumente/Uni/Paris/Stage/data/v_1"
data = NikaMap.read(Path(DATA_DIR) / '..' / 'map.fits')
sh = data.data.shape
wcs = data.wcs
hdul = fits.HDUList(fits.open('/home/peter/Dokumente/Uni/Paris/Stage/'
'FirstSteps/Completness/'
'combined_tables_long.fits'))
nfluxes = hdul[0].header['NFLUXES']
print('{} different fluxes found'.format(nfluxes))
FLUX = []
SOURCE = []
FSOURCE = []
# for isimu in range(nfluxes):
for isimu in range(nfluxes):
FLUX.append(u.Quantity(hdul[0].header['flux{}'.format(isimu)]))
SOURCE.append(Table.read(hdul['DETECTED_SOURCES{}'
.format(FLUX[isimu])]))
FSOURCE.append(Table.read(hdul['FAKE_SOURCES{}'
.format(FLUX[isimu])]))
xx = PCEvaluation(SOURCE, FSOURCE, sh, wcs, u.Quantity(FLUX))
# %% testfunctions
dd = xx.completness
print('comp shape', dd.shape)
# xx.PlotBin(xx.completness[:, 9, 9, :])
# xx.PlotFixedThreshold(xx.completness[:, 9, 9, :], np.array([3, 5]))
xx.PlotOverview(flux=5*u.mJy)
plt.show(block=True)
sys.exit('Done')
def PlotHitmap(self, flux=None, **kwargs):
fluxidx = find_nearest(self.flux.to_value(u.mJy), flux.to_value(u.mJy))
for iidx in fluxidx:
plt.figure()
plt.imshow(self.hitmap[iidx], origin='lower', **kwargs)
plt.title('Hitmap {:.1f}'.format(flux), fontsize=30, y=1.02)
def UglyLoader(filename):
hdul = fits.HDUList(fits.open(filename))
nfluxes = hdul[0].header['NFLUXES']
print('{} different fluxes found'.format(nfluxes))
FLUX = []
SOURCE = []
FSOURCE = []
# for isimu in range(nfluxes):
for isimu in range(nfluxes):
FLUX.append(u.Quantity(hdul[0].header['flux{}'.format(isimu)]))
SOURCE.append(Table.read(hdul['DETECTED_SOURCES{}'
.format(FLUX[isimu])]))
FSOURCE.append(Table.read(hdul['FAKE_SOURCES{}'
.format(FLUX[isimu])]))
return u.Quantity(FLUX), SOURCE, FSOURCE
if __name__ == '__main__':
DATA_DIR = "/home/peter/Dokumente/Uni/Paris/Stage/data/v_1"
data = NikaMap.read(Path(DATA_DIR) / '..' / 'map.fits')
sh = data.data.shape
wcs = data.wcs
fname = ('/home/peter/Dokumente/Uni/Paris/Stage/'
'FirstSteps/Completness/combined_tables_long.fits')
FLUX, SOURCE, FSOURCE = UglyLoader(fname)
xx = PCEvaluation(SOURCE, FSOURCE, sh, wcs, FLUX, mapbins=19,
threshold_bins=6, threshold_range=(2.5, 5))
xx.PlotBin(xx.GetCompletnessBin(9, 9), nfluxlabels=10, title='Completness')
xx.PlotBin(xx.GetPurityBin(9, 9), nfluxlabels=10, title='Purity')
xx.PlotFixedThreshold(xx.GetCompletnessBin(9, 9), np.array([3, 5]),
ylabel='Completness')
xx.PlotFixedThreshold(xx.GetPurityBin(9, 9), np.array([3, 5]),
ylabel='Purity')
xx.PlotOverview(flux=5*u.mJy)
xx.PlotHitmap(flux=5*u.mJy)
yy = PCEvaluation(SOURCE, FSOURCE, sh, wcs, FLUX, mapbins=9,
threshold_bins=6, threshold_range=(2.5, 5))
yy.PlotFixedThreshold(yy.GetCompletnessBin(4, 4), np.array([3, 5]),
ylabel='Completness')
yy.PlotFixedThreshold(yy.GetPurityBin(4, 4), np.array([3, 5]),
ylabel='Purity')
plt.show(block=True)
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