Commit 04feb4f8 authored by LUSTIG Peter's avatar LUSTIG Peter

save changes...

parent bb0b205a
......@@ -76,37 +76,83 @@ def AddXYCoordinatesTo(sources, wcs):
sources['xmean'], sources['ymean'] = pos[:, 0], pos[:, 1]
return sources
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)
return ax, img
class BasicEvaluation:
def __init__(self, sources, fake_sources, shape, wcs, mask=None):
def __init__(self, sources, shape, wcs, mask=None):
self.sources = sources
self.fake_sources = fake_sources
self.sourceslocmask = np.zeros(len(sources))
self.fake_sources = None
self.shape = shape
self.wcs = wcs
self.ChangeMask(mask)
def ChangeMask(self, mask):
fake_sourceslocmask = np.zeros(len(fake_sources), dtype=bool)
sourceslocmask = np.zeros(len(sources), dtype=bool)
if mask is not None:
shape = self.shape
#
fake_sourceslocmask = GetLocationMask(fake_sources, mask)
# should check if corresponding fake_source is in mask or not
# sourceslocmask = fakesourceslocmask[sources['fake_sources']] ?
sourceslocmask = GetInsideMask(sources, shape)
sourceslocmask = GetLocationMask(sources, mask,
addmask=sourceslocmask)
self.sourceslocmask = sourceslocmask
self.fake_sourceslocmask = fake_sourceslocmask
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:
realsourcecat = self.RealSources
wcs = self.wcs
ax, img = Plot2D(np.array(mask, dtype=int), wcs=wcs, xlabel='Ra',
ylabel='Dec', **kwargs)
print(type(sourcecat))
if sourcecat is not None:
if not fluxdev:
plt.scatter(sourcecat['xmean'], sourcecat['ymean'], marker='.',
label='Sources')
else:
dev = (u.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', label='Real Sources')
return ax, img
class CompletnessArea(BasicEvaluation):
def __init__(self, sources, fake_sources=None,
shape=None, wcs=None, threshold_edges=None, flux_edges=None,
flux_centers=None,
mask=None):
flux_centers=None, mask=None):
sources = AddXYCoordinatesTo(sources, wcs)
fake_sources = AddXYCoordinatesTo(fake_sources, wcs)
......@@ -312,6 +358,44 @@ class CountsAreaEvaluation(BasicEvaluation):
return ax
class FluxArea(CompletnessArea):
def __init__(self, sources, fake_sources=None, shape=None, wcs=None,
threshold_edges=None, flux_edges=None, flux_centers=None,
mask=None):
super().__init__(sources, fake_sources, shape, wcs, threshold_edges,
flux_edges, flux_centers, mask)
def FluxPercentiles(self, flux, snrbins=None,
percentiles=np.array([2.3, 15.9, 50., 84.1, 97.7])):
fake_sources = self.fake_sources
sources = self.sources
locmask = self.fake_sourceslocmask
bins = self.flux_edges.to_value(u.mJy)
xval = u.Quantity(fake_sources['amplitude']).to_value(u.mJy)
if snrbins is not None:
bins = snrbins
xval = np.ma.array(sources[fake_sources['find_peak']]['SNR'],
mask=fake_sources['find_peak'].mask)
xval[xval > bins[-1]] = bins[-1]
binidx = np.digitize(xval, bins, right=True)
percentiles = np.zeros((len(bins)-1, len(percentiles)))
outflux = sources[fake_sources['find_peak']]['flux_psf']
influx = fake_sources['amplitude']
fluxdeviation = np.ma.array(
(outflux - influx) / influx,
mask=fake_sources['find_peak'].mask)
for i in range(len(bins)-1):
binmask = binidx != i
totmask = binmask | fake_sources['find_peak'].mask | locmask
percentiles[i] = np.nanpercentile(fluxdeviation[~totmask],
percentiles)
return percentiles
def Plot1D(x, y, title='', xlabel='', ylabel='', ax=None, **kwargs):
if ax is None:
fig = plt.figure(figsize=(7, 6))
......
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