BlendingToolKit
BlendingToolKit copied to clipboard
Handle WCS with galsim instead of Astropy
We discussed about using Galsim WCS instead of Astropy, here is a simple function I have (from this code) to create CelestialWCS with Galsim (no optical distortion here):
def get_wcs(world_position= (0,0), pixel_scale=0.187, img_shape=(51,51)):
""" Get WCS
Give basic WCS as galsim object.
Parameters
----------
world_position: tuple
World position at the center of the postage stamp (ra, dec) in degrees.
pixel_scale: float
Pixel scale of the image in arcsec/pixel.
img_shape: tuple
Final size of the postage stamp (nx, ny).
Returns
-------
wcs: galsim.fitswcs.GSFitsWCS
WCS for the postage stamp.
"""
tot_origin = galsim.PositionD(img_shape[0]/2, img_shape[1]/2)
tot_world_origin = galsim.CelestialCoord(world_position[0]*galsim.degrees,
world_position[1]*galsim.degrees)
affine = galsim.AffineTransform(pixel_scale, 0, 0, pixel_scale, origin=tot_origin)
wcs = galsim.TanWCS(affine, world_origin=tot_world_origin)
return wcs
The reason why it is done this way and not using PixelScale or ShearWCS is to have a celestial projection which might preferable in some cases.. This should give you the equivalent of what you get with astropy.
I think the point of implementing WCS feature in BTK was to be able to manage the celestial projection if needed ; using a simple pixel scale is not much work anyway and do not really require a WCS. I do not use the feature myself so I do not know how important it is though ; I suppose it would be important if one where to draw blends from real blends in the catalog for instance.
I notice that you use TanWCS which corresponds to the TAN projection ; the astropy WCS supports a bunch of other projections https://docs.astropy.org/en/stable/wcs/supported_projections.html (which the user should be able to specify but I am not sure if this is the case right now) ; are those useful to anyone ?
Otherwise using the galsim feature seems fair to me ; anyway we definitely need to take a look at the feature to check if it is working correctly with all the updates BTK had in the meantime.