John Parejko and had a few chats about how to fit the final WCS that includes only a shift/rotation and possibly a small stretch. Thankfully most of the functions we need to create everything are exposed in python through ast-shim.
The plan we came up with is to postpend a fitted 2D matrix transform to the already existing transform between the ast Frame just before the "IWC" frame to take care of any rotation and possible "squish". In addition to this we will fit the crvals on the "Sky" frame. The fitting would be done a total of 6 variables and would minimize the distance between reference positions on the sky to the predicted source locations on sky. This leaves every part of the WCS produced by Parejko's createInitialWcs function intact save for the initial crvals.
The steps to fit would be:
get frameDict from inital WCS
|
copy all frames from frameDict
|
for iteration in number of fit steps:
|
create new rotation matrix and post-pend to the mapping of "DOMAIN_BEFORE_IWC" -> "IWC"
|
update crval in SkyFrame copy
|
create new SkyWcs from copied/updated frames
|
predict source sky locations
|
compare to matched reference locations
|
return final WCS
|
Parejko was also helpful enough to write a small example of getting the frames and creating a new WCS
# solution for now (until DM-20315 is fixed)
|
frameDict = skyWcs.getFrameDict()
|
mapping = frameDict.getMapping("PIXELS", "IWC")
|
newMap = mapping.then(astshim.MatrixMap(someMatrix))
|
# maybe remapFrame would work, if we could trust it
|
pixels = frameDict.getFrame("PIXELS")
|
iwc = frameDict.getFrame("IWC")
|
sky = frameDict.getFrame("SKY")
|
iwcMap = frameDict.getMapping("IWC", "SKY")
|
newFrameDict = frameDict(pixels)
|
newFrameDict.addFrame("PIXELS", newMap, iwc)
|
newFrameDict.addFrame("IWC", iwcMap, sky)
|
newSkyWcs = SkyWcs(newFrameDict)
|
John Parejko and had a few chats about how to fit the final WCS that includes only a shift/rotation and possibly a small stretch. Thankfully most of the functions we need to create everything are exposed in python through ast-shim.
The plan we came up with is to postpend a fitted 2D matrix transform to the already existing transform between the ast Frame just before the "IWC" frame to take care of any rotation and possible "squish". In addition to this we will fit the crvals on the "Sky" frame. The fitting would be done a total of 6 variables and would minimize the distance between reference positions on the sky to the predicted source locations on sky. This leaves every part of the WCS produced by Parejko's createInitialWcs function intact save for the initial crvals.
The steps to fit would be:
get frameDict from inital WCS
copy all frames from frameDict
for iteration in number of fit steps:
create new rotation matrix and post-pend to the mapping of "DOMAIN_BEFORE_IWC" -> "IWC"
update crval in SkyFrame copy
create new SkyWcs from copied/updated frames
predict source sky locations
compare to matched reference locations
return final WCS
Parejko was also helpful enough to write a small example of getting the frames and creating a new WCS
# solution for now (until DM-20315 is fixed)
frameDict = skyWcs.getFrameDict()
mapping = frameDict.getMapping("PIXELS", "IWC")
newMap = mapping.then(astshim.MatrixMap(someMatrix))
# maybe remapFrame would work, if we could trust it
pixels = frameDict.getFrame("PIXELS")
iwc = frameDict.getFrame("IWC")
sky = frameDict.getFrame("SKY")
iwcMap = frameDict.getMapping("IWC", "SKY")
newFrameDict = frameDict(pixels)
newFrameDict.addFrame("PIXELS", newMap, iwc)
newFrameDict.addFrame("IWC", iwcMap, sky)
newSkyWcs = SkyWcs(newFrameDict)