Commit f2b534e4 authored by LUSTIG Peter's avatar LUSTIG Peter

new transformation, hopefully the right one

parent 05c62339
......@@ -5,9 +5,10 @@ import astropy.units as u
from nikamap.utils import pos_cat
import matplotlib.pyplot as plt
from astropy.wcs import WCS
#%load_ext autoreload
#%matplotlib tk
from astropy.coordinates import SkyCoord
%load_ext autoreload
%autoreload 2
%matplotlib tk
def GetInRange(array, low=None, high=None, extra=None):
......@@ -47,7 +48,7 @@ def Shift(shiftrange, relcoord):
return shift
class CatalogShifter:
class OldCatalogShifter:
def __init__(self, catalog, mapshape, wcs, coverage=1):
'''
Class that takes sources catalog and shifts source positions to area
......@@ -165,6 +166,41 @@ def test_catalogshifter():
#print(sh(0,0, coverage=1))
class CatalogShifter(object):
def __init__(self, catalog, mapshape, mapwcs):
# create centerframe
centerpixel = (np.array(nm.shape)/2).astype(int)
centerworld = nm.wcs.wcs_pix2world(*nmcenterpixel, 0)
centerframe = SkyCoord(*(nmcenterworld*u.deg)).skyoffset_frame()
catcoords = SkyCoord(catalog['ra'], catalog['dec'], unit=u.deg)
self.catalog = catalog
self.catcoords = catcoords
self.centerframe = centerframe
def __call__(self, coord_in_center, rotation=0*u.deg):
catalog = self.catalog
catcoords = self.catcoords
centerframe = self.centerframe
# create new frame with new center and transform soucres into
sourcecenterframe = coord_in_center.skyoffset_frame(rotation=rotation)
sourcecoordinates = catcoords.transform_to(newcenterframe)
# change variable in center with variable in mapcenter
relativecoordinates = SkyCoord(newcoordinates.lon.deg * u.deg,
newcoordinates.lat.deg * u.deg,
frame=centerframe)
absolutecoordinates = relativecoordinates.transform_to('icrs')
# write in table copy
ra, dec = newnew.ra.deg, newnew.dec.deg
catalog['ra'] = ra
catalog['dec'] = dec
return catalog
if __name__ == "__main__":
# test_catalogshifter()
......@@ -176,14 +212,46 @@ if __name__ == "__main__":
wcs = nm.wcs
shape = nm.shape
catalog = Table.read(tablefile)
catalog.keys()
catalog = catalog[catalog['SNIKA1200'] > 1E-3]
sh = NewCatalogShifter(catalog, (501, 501), nm.wcs)
t = sh(SkyCoord(1.4*u.deg, 1.4*u.deg))
print(t)
print('done')
#%%
'''
nmcenterpixel = (np.array(nm.shape)/2).astype(int)
nmcenterworld = nm.wcs.wcs_pix2world(*nmcenterpixel, 0)
nmcenterframe = SkyCoord(*(nmcenterworld*u.deg)).skyoffset_frame()
catcoords = SkyCoord(catalog['ra']*u.deg, catalog['dec']*u.deg)
# coord_to_center = catcoords[0]
rotation=45*u.deg
coord_in_center = SkyCoord(1.3*u.deg, 1.4*u.deg)
newcenterframe = coord_in_center.skyoffset_frame(rotation=rotation)
newcoordinates = catcoords.transform_to(newcenterframe)
newcoordinates
newnew = SkyCoord(newcoordinates.lon.deg * u.deg,
newcoordinates.lat.deg * u.deg, frame=nmcenterframe)
newnew = newnew.transform_to('icrs')
ra, dec = newnew.ra.deg, newnew.dec.deg
catalog['_ra'] = ra
catalog['_dec'] = dec
cat = catalog
cat = CatalogFor_pos_cat(catalog, fluxkey='SNIKA1200',
fluxunit=u.Jy, minflux=1*u.mJy)
nm.add_gaussian_sources(cat_gen=pos_cat, catalog=cat, wcs=nm.wcs)
nm.plot()
'''
'''
sh = CatalogShifter(catalog, shape, wcs, coverage=.5)
cat = CatalogFor_pos_cat(sh(1, 1), fluxkey='SNIKA1200',
fluxunit=u.Jy, minflux=1*u.mJy)
print(np.amin(cat['_ra']))
nm.add_gaussian_sources(cat_gen=pos_cat, catalog=cat, wcs=nm.wcs)
'''
# %matplotlib tk
nm.plot()
plt.show(block=True)
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