Commit a2c391a9 authored by LUSTIG Peter's avatar LUSTIG Peter

Created Object that shifts positions from catalog to map area

parent fae88fa6
from nikamap import NikaMap
from astropy.table import Table
import numpy as np
import astropy.units as u
def GetInRange(array, low=None, high=None, extra=None):
lmask = np.zeros(len(array), dtype=bool)
hmask = np.zeros(len(array), dtype=bool)
if low is not None:
lmask = array < low
if high is not None:
hmask = array > high
tmask = lmask | hmask
if extra is not None:
return array[~tmask], extra[~tmask]
else:
return array[~tmask]
def uniform(a, b, size=None):
return (b - a) * np.random.random_sample(size) + a
def rel_to_coord(a, b, relcoord):
return (b - a) * relcoord + a
'''
def Shift(biglimits, smalllimits, relcoord):
shiftrange = np.sort(biglimits-smalllimits)
shift = rel_to_coord(*shiftrange)
return shift
'''
def Shift(shiftrange, relcoord):
shift = rel_to_coord(*shiftrange, relcoord)
return shift
class CatalogShifter:
def __init__(self, catalog, mapshape, wcs):
maplimits = wcs.wcs_pix2world(*(np.array(((0, 0), mapshape)).T), 0)
ra, dec = catalog['ra'], catalog['dec']
sourcelimits = np.array([[np.amax(ra), np.amin(ra)],
[np.amin(dec), np.amax(dec)]])
shiftlimits = maplimits - sourcelimits
self.catalog = catalog
self._maplmits = maplimits
self._shiftlimits = shiftlimits
def __call__(self, relra=None, reldec=None):
ra_shiftlimits, dec_shiftlimits = self._shiftlimits
maplimits = self._maplmits
outcat = self.catalog # this should create a copy
if relra is None:
relra = np.random.random_sample()
if reldec is None:
reldec = np.random.random_sample()
rashift = Shift(np.sort(ra_shiftlimits), relra)
decshift = Shift(np.sort(dec_shiftlimits), reldec)
outcat['ra'] = outcat['ra'] + rashift
outcat['dec'] = outcat['dec'] + decshift
_, outcat = GetInRange(outcat['ra'], *np.sort(maplimits[0]), outcat)
_, outcat = GetInRange(outcat['dec'], *np.sort(maplimits[1]), outcat)
return outcat
if __name__ == "__main__":
nmfile = "/home/peter/Dokumente/Uni/Paris/Stage/data/map.fits"
tablefile = "/home/peter/Dokumente/Uni/Paris/Stage/N2CLS/SIDES_NIKA.fits"
nm = NikaMap.read(nmfile)
wcs = nm.wcs
shape = nm.shape
catalog = Table.read(tablefile)
catalog.keys()
sh = CatalogShifter(catalog, shape, wcs)
sh()
# %matplotlib tk
nm.plot()
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