Commit 45d45ee6 authored by LUSTIG Peter's avatar LUSTIG Peter

Added flux percentile evaluation

parent c5968bb1
......@@ -411,6 +411,7 @@ class PCAreaEvaluation:
self.absolute_detections = np.zeros((len(sources), threshold_bins))
self.sourcelocmask = []
self.fsourceslocmask = []
self.fluxpercentiles = np.zeros((len(sources), 5))
for iflux in range(len(sources)):
print('loop {}'.format(iflux))
......@@ -458,6 +459,11 @@ class PCAreaEvaluation:
self.sources.append(_sources)
if 'flux_psf' in _sources.keys():
self.fluxpercentiles[iflux] = self.FluxPercentiles(
_sources['flux_psf'],
_sourceslocmask)
self.normed_detections = self.GetNormedDetections(
self.absolute_detections,
self.nsim)
......@@ -480,6 +486,15 @@ class PCAreaEvaluation:
self.threshold_bins,
sourceslocmask=self.realsourcelocmask)
def FluxPercentiles(self, flux, locmask=None,
percentiles=np.array([2.3, 15.9, 50., 84.1, 97.7])):
if locmask is None:
totmask = flux.mask
else:
totmask = np.array(flux.mask | locmask, dtype=bool)
return np.nanpercentile(flux[~totmask], percentiles)
def GetNormedDetections(self, absolute_detections=None, norm=None):
if absolute_detections is None:
absolute_detections = self.absolute_detections
......@@ -500,7 +515,6 @@ 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:
......@@ -631,9 +645,9 @@ def Purity1D(sources, threshold_range, nbins, sourceslocmask=None):
else:
purity = None
print('snrlength in purity', len(sources_snr))
print('mask in purity', sourceslocmask)
print('masklength in purity', len(sourceslocmask))
# print('snrlength in purity', len(sources_snr))
# print('mask in purity', sourceslocmask)
# print('masklength in purity', len(sourceslocmask))
norm_pur, _ = np.histogram(sources_snr, bins=bin_edges,
weights=(~sourceslocmask).astype(int))
norm_pur = np.cumsum(norm_pur[::-1], dtype=float)[::-1]
......@@ -745,14 +759,14 @@ if __name__ == '__main__':
#plt.show(block=True)
#bb = PCAreaEvaluation(mask=globmask, sources=psources, wcs=wcs, nsim=nsim,
# realsources=realsources, flux=pflux, fake_sources=pfsources,
# threshold_range=(4, 10), threshold_bins=5)
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)
bb = PCAreaEvaluation(mask=globmask, sources=psources, wcs=wcs, nsim=nsim,
realsources=realsources, flux=pflux, fake_sources=pfsources,
threshold_range=(4, 10), threshold_bins=5)
#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
# % matplotlib tk
plt.figure(figsize=(8, 7))
bb.PlotCounts()
plt.xlim(xmin=2.5, xmax=5)
......
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