Commit 08fe2210 authored by LUSTIG Peter's avatar LUSTIG Peter

current status

parent ee74c132
......@@ -108,8 +108,8 @@ directory = 'montecarlo_results/700/'
directory = ('/home/peter/Dokumente/Uni/Paris/Stage/FirstSteps/Completness/'
'montecarlo_results/photometry/thresh4')
outname = 'allresults_phot_thresh4.fits'
key = '*.fits'
outname = 'allresults_phot_thresh4_Parity0.fits'
key = '*ParityAll*'
Combine(directory, key, outname)
......
......@@ -401,6 +401,7 @@ class PCAreaEvaluation:
threshold_bins)
self.nsim = nsim
self.real_sources = realsources
self.wcs = wcs
sources = MakeListFrom(sources)
fake_sources = MakeListFrom(fake_sources)
......@@ -435,27 +436,30 @@ class PCAreaEvaluation:
self.sourcelocmask.append(_sourceslocmask)
self.fsourceslocmask.append(_fsourceslocmask)
''' calculate purity and absolute detections'''
_purity, _norm_pur = Purity1D(_sources,
self.threshold_range,
self.threshold_bins,
sourceslocmask=_sourceslocmask
)
if _purity is not None:
_purity /= _norm_pur
(self.purity[iflux],
self.absolute_detections[iflux]) = _purity, _norm_pur
if 'snr' in _sources.keys():
''' calculate purity and absolute detections'''
''' testtest '''
_purity, _norm_pur = Purity1D(_sources,
self.threshold_range,
self.threshold_bins,
sourceslocmask=_sourceslocmask
)
if _purity is not None:
_purity /= _norm_pur
''' calculate completness '''
_completness, _norm_comp = Completness1D(
_sources, _fake_sources,
self.threshold_range,
self.threshold_bins,
fakesourcelocmask=_fsourceslocmask)
(self.purity[iflux],
self.absolute_detections[iflux]) = _purity, _norm_pur
if _completness is not None and _norm_comp is not None:
self.completness[iflux] = _completness / _norm_comp
''' calculate completness '''
_completness, _norm_comp = Completness1D(
_sources, _fake_sources,
self.threshold_range,
self.threshold_bins,
fakesourcelocmask=_fsourceslocmask)
if _completness is not None and _norm_comp is not None:
self.completness[iflux] = _completness / _norm_comp
self.sources.append(_sources)
......@@ -495,21 +499,34 @@ class PCAreaEvaluation:
return np.nanpercentile(flux[~totmask], percentiles)
def PlotPercentiles(self, percentiles=None, influx=None):
def PlotPercentiles(self, percentiles=None, influx=None, ax=None):
if percentiles is None:
percentiles = self.fluxpercentiles
if influx is None:
influx = self.flux
percentiles = np.copy(percentiles).T
medidx = int(percentiles.shape[0] / 2)
if ax is None:
fig = plt.figure(figsize=(7, 6))
ax = fig.add_subplot(111)
plt.plot(influx, percentiles[medidx]/influx)
colorarr = ['red', 'yellow']
for iperc in range(1, medidx+1):
plt.plot(influx, percentiles[medidx]/influx, linewidth=3,
label='Median')
colorarr = ['orange', 'yellow']
for iperc in range(medidx, 0, -1):
plt.fill_between(influx,
percentiles[medidx-iperc]/influx,
percentiles[medidx+iperc]/influx,
alpha=.5, facecolor=colorarr[iperc-1])
alpha=1, facecolor=colorarr[iperc-1],
label=r'${{{}}}\sigma$'.format(iperc))
plt.axhline(1, color='k')
plt.title('Flux Resolution', y=1.02, fontsize=25)
plt.xlabel('Injected Flux [mJy]', fontsize=20)
plt.ylabel(r'F$_{\mathrm{out}}$ / F$_{\mathrm{in}}$', fontsize=20)
plt.legend(fontsize=20, loc='upper right')
ax.set_yscale('log')
plt.xticks(fontsize=15)
plt.yticks(fontsize=15)
def GetNormedDetections(self, absolute_detections=None, norm=None):
if absolute_detections is None:
......@@ -531,22 +548,46 @@ class PCAreaEvaluation:
detection_thresholds[::-1])
return thresh
def PlotMask(self, mask=None, sources=False, sourcecat=None,
realsources=False, realsourcecat=None, **kwargs):
if mask is None:
mask = self.mask
if sources and sourcecat is None:
sourcecat = self.sources[0]
def PlotMask(self, sourcecat=None,
realsources=False, realsourcecat=None,
fluxdev=False, sources=False, **kwargs):
mask = self.mask
if sourcecat is not None:
if type(sourcecat) is int:
idx = sourcecat
sourcecat = self.sources[idx]
if 'find_peak' in sourcecat.keys():
fpmask = sourcecat['find_peak'].mask
# print(type(fpmask))
smask = np.array(fpmask | self.sourcelocmask[idx],
dtype=bool)
else:
smask = self.sourcelocmask[idx]
sourcecat = sourcecat[~smask]
if realsources and realsourcecat is None:
sourcecat = self.RealSources
realsourcecat = self.RealSources
wcs = self.wcs
ax, img = Plot2D(np.array(mask, dtype=int), **kwargs)
ax, img = Plot2D(np.array(mask, dtype=int), wcs=wcs, xlabel='Ra',
ylabel='Dec', **kwargs)
print(type(sourcecat))
if sourcecat is not None:
plt.scatter(sourcecat['xmean'], sourcecat['ymean'], marker='.')
if not fluxdev:
plt.scatter(sourcecat['xmean'], sourcecat['ymean'], marker='.',
label='Sources')
else:
dev = (Quantity(sourcecat['flux_psf'] - sourcecat['amplitude'])
.to_value(u.mJy)) # ** 2
plt.scatter(sourcecat['xmean'], sourcecat['ymean'], marker='.',
c=dev, label='Sources')
if realsourcecat is not None:
plt.scatter(realsourcecat['xmean'], realsourcecat['ymean'],
marker='.', color='r')
marker='.', color='r', label='Real Sources')
return ax, img
def PlotCounts(self, data=None, fluxbin=None, normalize=1):
......@@ -701,13 +742,23 @@ def Plot1D(x, y, title='', xlabel='', ylabel='', **kwargs):
return ax
def Plot2D(img, title='', xlabel='', ylabel='', **kwargs):
ax = plt.subplot(111)
def Plot2D(img, title='', xlabel='', ylabel='', wcs=None, **kwargs):
if wcs is not None:
ax = plt.subplot(111, projection=wcs)
ra = ax.coords[0]
dec = ax.coords[1]
ra.set_axislabel(xlabel, minpad=0.4, fontsize=25)
ra.set_ticklabel(fontsize=20)
dec.set_axislabel(ylabel, minpad=-0.5, fontsize=25)
dec.set_ticklabel(fontsize=20)
else:
ax = plt.subplot(111)
ax.set_xlabel(xlabel, fontsize=25)
ax.set_ylabel(ylabel, fontsize=25)
ax.tick_params(axis='both', labelsize=20)
img = ax.imshow(img, origin='lower', **kwargs)
ax.set_title(title, fontsize=30, y=1.02)
ax.set_xlabel(xlabel, fontsize=25)
ax.set_ylabel(ylabel, fontsize=25)
ax.tick_params(axis='both', labelsize=20)
return ax, img
......@@ -782,6 +833,7 @@ if __name__ == '__main__':
#bb = PCAreaEvaluation(mask=globmask, sources=sources, wcs=wcs, nsim=nsim,
# realsources=realsources, flux=pflux, fake_sources=None,
# threshold_range=(2.5, 10), threshold_bins=50)
'''
# %%
# % matplotlib tk
plt.figure(figsize=(8, 7))
......@@ -790,7 +842,13 @@ if __name__ == '__main__':
plt.ylim(ymin=0.08)
# fig = plt.gcf()
plt.subplots_adjust(left=0.15, bottom=0.12, right=0.97, top=0.92)
# plt.figure()
'''
# %%
# % matplotlib tk
bb.PlotPercentiles()
plt.show(block=True)
# %%
#bb.FitFluxResolution(10*u.mJy)
#bb.FitFluxResolution(5*u.mJy)
#bb.FitFluxResolution(1*u.mJy)
......
......@@ -166,7 +166,7 @@ filenamecomment = 'NewRealisation_'
# DATA_DIR_SERVER = Path("/data/NIKA/Reduced/"
# "HLS091828_common_mode_one_block/v_1")
DATA_DIR_SERVER = Path("/data/NIKA/Reduced/May2018/"
"HLS091828_common_mode_one_block/v_1/")
"HLS091828_common_mode_one_block/v_1/")
DATA_DIR_MYPC = Path("/home/peter/Dokumente/Uni/Paris/Stage/data/v_1")
......
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