Commit 3950e2b6 authored by LUSTIG Peter's avatar LUSTIG Peter

end of the day...

parent 3a77a79f
......@@ -3,27 +3,8 @@ from astropy.io.fits import PrimaryHDU, BinTableHDU, HDUList, open
from pathlib import Path
import astropy.units as u
import numpy as np
import os
import sys
print(os.getcwd())
def CombineMeasurements(sourceslist, fakesourceslist):
fake_sources = Table()
sources = Table()
for _fake, _detected in zip(fakesourceslist, sourceslist):
n_fake = len(fake_sources)
n_detected = len(sources)
if _detected is not None:
_detected['ID'] = _detected['ID'] + n_detected
_detected['fake_sources'] = _detected['fake_sources'] + n_fake
sources = vstack([sources, _detected])
_fake['ID'] = _fake['ID'] + n_fake
_fake['find_peak'] = _fake['find_peak'] + n_detected
fake_sources = vstack([fake_sources, _fake])
return sources, fake_sources
from utils import CombineMeasurements
def LoadSingleFile(fname):
......
......@@ -181,6 +181,14 @@ class PCEvaluation:
return completness, purity, norm_comp, norm_pur
def InterpolateCompletnessThreshold(self, threshold, completness=None):
if completness is None:
completness = self.completness
nextidx = np.argsort(np.absolute(completness - threshold))[:2]
nextidx = np.sort(nextidx)
## np.interp(???) maybe even sorting not necessary
def PlotBin(self, data, title='', flux=None, thresh=None,
nfluxlabels=None, nthreshlabels=None, **kwargs):
tickfs = 20
......@@ -352,12 +360,15 @@ class PCAreaEvaluation:
sources = AddXYCoordinatesTo(sources, wcs)
realsources = AddXYCoordinatesTo(realsources, wcs)
fake_sources = AddXYCoordinatesTo(fake_sources, wcs)
self.sources = sources
#import ipdb; ipdb.set_trace()
# %%
if mask is not None:
assert wcs is not None, 'Need wcs to find sources in mask.'
self.sources = GetInsideSources(sources, self.mask)
if realsources is not None:
realsources = GetInsideSources(realsources, self.mask)
self.RealSources = realsources
_, self.absolute_detections = Purity1D(self.sources,
......@@ -486,7 +497,7 @@ def AddXYCoordinatesTo(sources, wcs):
def GetInsideSources(sources, mask):
pos = np.array([sources['xmean'], sources['ymean']]).T
pos = np.array([sources['ymean'], sources['xmean']]).T
pos, sources = pos_in_mask(pos, mask=mask, extra=sources)
return sources
......@@ -540,6 +551,8 @@ if __name__ == '__main__':
'sourcemap/180418_141500_sourcemap_thresh2.fits')
rsfname = ('/home/peter/Dokumente/Uni/Paris/Stage/FirstSteps/Completness/'
'sourcemap/180419_183430_sourcemap_thresh2.fits')
addmaskname = ('/home/peter/Dokumente/Uni/Paris/Stage/FirstSteps/'
'Completness/hlsmask.fits')
hdul = fits.open(fname)
......@@ -549,14 +562,19 @@ if __name__ == '__main__':
wcs = WCS(hdul[0].header)
nsim = hdul[0].header['NSIM']
aa = PCAreaEvaluation(mask=mask, sources=sources, wcs=wcs, nsim=nsim,
addmask = fits.open(addmaskname)['hlsmask'].data
globmask = np.array(addmask | mask, dtype=bool)
# sys.exit()
aa = PCAreaEvaluation(mask=globmask, sources=sources, wcs=wcs, nsim=nsim,
realsources=realsources, threshold_range=(2.5, 10),
threshold_bins=50)
if(1): # plot mask
if(1): # plot mask
fig = plt.figure()
ax, img = aa.PlotMask(sources=True, realsources=True)
plt.show(block=True)
ax, img = aa.PlotMask(sources=True, realsources=False)
#plt.show()
if(1):
plt.figure()
......
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