def testDeleteBasicWcsMetadata(self): wcsName = "Q" # arbitrary metadata = createTrivialWcsMetadata(wcsName=wcsName, xy0=lsst.geom.Point2I(0, 0)) # add the other keywords that will be deleted for i in range(2): for j in range(2): metadata.set("CD%d_%d%s" % (i+1, j+1, wcsName), 0.2) # arbitrary nonzero value metadata.set("WCSAXES%s" % (wcsName,), 2) # add a keyword that will not be deleted metadata.set("NAXIS1", 100) self.assertEqual(len(metadata.names(True)), 14) # deleting data for a different WCS will delete nothing deleteBasicWcsMetadata(metadata=metadata, wcsName="B") self.assertEqual(len(metadata.names(True)), 14) # deleting data for the right WCS deletes all but one keyword deleteBasicWcsMetadata(metadata=metadata, wcsName=wcsName) self.assertEqual(len(metadata.names(True)), 1) self.assertEqual(metadata.getScalar("NAXIS1"), 100) # try with a smattering of keywords (should silently ignore the missing ones) metadata.set("WCSAXES%s" % (wcsName,), 2) metadata.set("CD1_2%s" % (wcsName,), 0.5) metadata.set("CRPIX2%s" % (wcsName,), 5) metadata.set("CRVAL1%s" % (wcsName,), 55) deleteBasicWcsMetadata(metadata=metadata, wcsName=wcsName) self.assertEqual(len(metadata.names(True)), 1) self.assertEqual(metadata.getScalar("NAXIS1"), 100)
def testDeleteBasicWcsMetadata(self): wcsName = "Q" # arbitrary metadata = createTrivialWcsMetadata(wcsName=wcsName, xy0=lsst.geom.Point2I(0, 0)) # add the other keywords that will be deleted for i in range(2): for j in range(2): metadata.set("CD%d_%d%s" % (i + 1, j + 1, wcsName), 0.2) # arbitrary nonzero value metadata.set("WCSAXES%s" % (wcsName, ), 2) # add a keyword that will not be deleted metadata.set("NAXIS1", 100) self.assertEqual(len(metadata.names(True)), 14) # deleting data for a different WCS will delete nothing deleteBasicWcsMetadata(metadata=metadata, wcsName="B") self.assertEqual(len(metadata.names(True)), 14) # deleting data for the right WCS deletes all but one keyword deleteBasicWcsMetadata(metadata=metadata, wcsName=wcsName) self.assertEqual(len(metadata.names(True)), 1) self.assertEqual(metadata.getScalar("NAXIS1"), 100) # try with a smattering of keywords (should silently ignore the missing ones) metadata.set("WCSAXES%s" % (wcsName, ), 2) metadata.set("CD1_2%s" % (wcsName, ), 0.5) metadata.set("CRPIX2%s" % (wcsName, ), 5) metadata.set("CRVAL1%s" % (wcsName, ), 55) deleteBasicWcsMetadata(metadata=metadata, wcsName=wcsName) self.assertEqual(len(metadata.names(True)), 1) self.assertEqual(metadata.getScalar("NAXIS1"), 100)
def testGetImageXY0FromMetadata(self): wcsName = "Z" # arbitrary xy0 = lsst.geom.Point2I( 47, -200) # arbitrary with a negative value to check rounding metadata = createTrivialWcsMetadata(wcsName=wcsName, xy0=xy0) # reading the wrong wcsName should be treated as no data available xy0WrongWcsName = getImageXY0FromMetadata(metadata=metadata, wcsName="X", strip=True) self.assertEqual(xy0WrongWcsName, lsst.geom.Point2I(0, 0)) self.assertEqual(len(metadata.names(True)), 8) # deleting one of the required keywords should be treated as no data available for namePrefixToRemove in ("CRPIX1", "CRPIX2", "CRVAL1", "CRVAL2"): nameToRemove = namePrefixToRemove + wcsName removedValue = metadata.getScalar(nameToRemove) metadata.remove(nameToRemove) xy0MissingWcsKey = getImageXY0FromMetadata(metadata=metadata, wcsName=wcsName, strip=True) self.assertEqual(xy0MissingWcsKey, lsst.geom.Point2I(0, 0)) self.assertEqual(len(metadata.names(True)), 7) # restore removed item metadata.set(nameToRemove, removedValue) self.assertEqual(len(metadata.names(True)), 8) # setting CRPIX1, 2 to something other than 1 should be treated as no data available for i in (1, 2): nameToChange = "CRPIX%d%s" % (i, wcsName) metadata.set(nameToChange, 1.1) xy0WrongWcsName = getImageXY0FromMetadata(metadata=metadata, wcsName=wcsName, strip=True) self.assertEqual(xy0WrongWcsName, lsst.geom.Point2I(0, 0)) self.assertEqual(len(metadata.names(True)), 8) # restore altered CRPIX value metadata.set(nameToChange, 1.0) self.assertEqual(len(metadata.names(True)), 8) # use the correct WCS name but don't strip xy0RightWcsName = getImageXY0FromMetadata(metadata, wcsName, strip=False) self.assertEqual(xy0RightWcsName, xy0) self.assertEqual(len(metadata.names(True)), 8) # use the correct WCS and strip usable metadata xy0RightWcsName = getImageXY0FromMetadata(metadata, wcsName, strip=True) self.assertEqual(xy0RightWcsName, xy0) self.assertEqual(len(metadata.names(True)), 0)
def testCreateTrivialWcsAsPropertySet(self): wcsName = "Z" # arbitrary xy0 = lsst.geom.Point2I(47, -200) # arbitrary metadata = createTrivialWcsMetadata(wcsName=wcsName, xy0=xy0) desiredNameValueList = ( # names are missing wcsName suffix ("CRPIX1", 1.0), ("CRPIX2", 1.0), ("CRVAL1", xy0[0]), ("CRVAL2", xy0[1]), ("CTYPE1", "LINEAR"), ("CTYPE2", "LINEAR"), ("CUNIT1", "PIXEL"), ("CUNIT2", "PIXEL"), ) self.assertEqual(len(metadata.names(True)), len(desiredNameValueList)) for name, value in desiredNameValueList: self.assertEqual(metadata.getScalar(name + wcsName), value)
def testCreateTrivialWcsAsPropertySet(self): wcsName = "Z" # arbitrary xy0 = lsst.geom.Point2I(47, -200) # arbitrary metadata = createTrivialWcsMetadata(wcsName=wcsName, xy0=xy0) desiredNameValueList = ( # names are missing wcsName suffix ("CRPIX1", 1.0), ("CRPIX2", 1.0), ("CRVAL1", xy0[0]), ("CRVAL2", xy0[1]), ("CTYPE1", "LINEAR"), ("CTYPE2", "LINEAR"), ("CUNIT1", "PIXEL"), ("CUNIT2", "PIXEL"), ) self.assertEqual(len(metadata.names(True)), len(desiredNameValueList)) for name, value in desiredNameValueList: self.assertEqual(metadata.getScalar(name + wcsName), value)
def testGetImageXY0FromMetadata(self): wcsName = "Z" # arbitrary xy0 = lsst.geom.Point2I(47, -200) # arbitrary with a negative value to check rounding metadata = createTrivialWcsMetadata(wcsName=wcsName, xy0=xy0) # reading the wrong wcsName should be treated as no data available xy0WrongWcsName = getImageXY0FromMetadata(metadata=metadata, wcsName="X", strip=True) self.assertEqual(xy0WrongWcsName, lsst.geom.Point2I(0, 0)) self.assertEqual(len(metadata.names(True)), 8) # deleting one of the required keywords should be treated as no data available for namePrefixToRemove in ("CRPIX1", "CRPIX2", "CRVAL1", "CRVAL2"): nameToRemove = namePrefixToRemove + wcsName removedValue = metadata.getScalar(nameToRemove) metadata.remove(nameToRemove) xy0MissingWcsKey = getImageXY0FromMetadata(metadata=metadata, wcsName=wcsName, strip=True) self.assertEqual(xy0MissingWcsKey, lsst.geom.Point2I(0, 0)) self.assertEqual(len(metadata.names(True)), 7) # restore removed item metadata.set(nameToRemove, removedValue) self.assertEqual(len(metadata.names(True)), 8) # setting CRPIX1, 2 to something other than 1 should be treated as no data available for i in (1, 2): nameToChange = "CRPIX%d%s" % (i, wcsName) metadata.set(nameToChange, 1.1) xy0WrongWcsName = getImageXY0FromMetadata(metadata=metadata, wcsName=wcsName, strip=True) self.assertEqual(xy0WrongWcsName, lsst.geom.Point2I(0, 0)) self.assertEqual(len(metadata.names(True)), 8) # restore altered CRPIX value metadata.set(nameToChange, 1.0) self.assertEqual(len(metadata.names(True)), 8) # use the correct WCS name but don't strip xy0RightWcsName = getImageXY0FromMetadata(metadata, wcsName, strip=False) self.assertEqual(xy0RightWcsName, xy0) self.assertEqual(len(metadata.names(True)), 8) # use the correct WCS and strip usable metadata xy0RightWcsName = getImageXY0FromMetadata(metadata, wcsName, strip=True) self.assertEqual(xy0RightWcsName, xy0) self.assertEqual(len(metadata.names(True)), 0)