Exemplo n.º 1
0
    def testCompressedSinglePlaneExposureFitsReader(self):
        """Test that a compressed single plane image can be read as exposure.
        """
        uncompressed_file = os.path.join(TESTDIR, "data", "ticketdm26260.fits")
        compressed_file = os.path.join(TESTDIR, "data",
                                       "ticketdm26260.fits.fz")
        uncompressed = ExposureFitsReader(uncompressed_file).read()
        compressed = ExposureFitsReader(compressed_file).read()

        self.assertMaskedImagesEqual(uncompressed.maskedImage,
                                     compressed.maskedImage)
Exemplo n.º 2
0
    def testPersistence(self):
        """Test persisting an exposure with an attached Blob.
        """
        im = ExposureF(10, 10)
        # Extra components must be ALL CAPS for fits storage.
        im.getInfo().setComponent("BLOB", self.blob)
        with lsst.utils.tests.getTempFilePath(".fits") as tmpFile:
            im.writeFits(tmpFile)

            newIm = ExposureF(tmpFile)
            self.assertEqual(newIm.getInfo().getComponent("BLOB"), self.blob)

            reader = ExposureFitsReader(tmpFile)
            newBlob = reader.readComponent("BLOB")
            self.assertEqual(newBlob, self.blob)
Exemplo n.º 3
0
    def checkExposureFitsReader(self, exposureIn, fileName, dtypesOut):
        """Test ExposureFitsReader.

        Parameters
        ----------
        exposureIn : `Exposure`
            Object originally saved, to compare against.
        fileName : `str`
            Name of the file the reader is reading.
        dtypesOut : sequence of `numpy.dype`
            Compatible image pixel types to try to read in.
        """
        reader = ExposureFitsReader(fileName)
        self.assertIn('EXPINFO_V',
                      reader.readMetadata().toDict(),
                      "metadata is automatically versioned")
        reader.readMetadata().remove('EXPINFO_V')
        self.assertGreaterEqual(reader.readSerializationVersion(), 0)
        self.assertEqual(exposureIn.getMetadata().toDict(),
                         reader.readMetadata().toDict())
        self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(),
                                          reader.readWcs(),
                                          self.bbox,
                                          maxDiffPix=0,
                                          maxDiffSky=0 * degrees)
        self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(),
                                          reader.readComponent(
                                              ExposureInfo.KEY_WCS),
                                          self.bbox,
                                          maxDiffPix=0,
                                          maxDiffSky=0 * degrees)
        self.assertEqual(exposureIn.getFilter(), reader.readFilter())
        self.assertEqual(exposureIn.getFilterLabel(), reader.readFilterLabel())
        self.assertEqual(exposureIn.getFilterLabel(),
                         reader.readComponent(ExposureInfo.KEY_FILTER))
        self.assertEqual(exposureIn.getPhotoCalib(), reader.readPhotoCalib())
        self.assertEqual(exposureIn.getPhotoCalib(),
                         reader.readComponent(ExposureInfo.KEY_PHOTO_CALIB))
        self.assertImagesEqual(exposureIn.getPsf().computeImage(),
                               reader.readPsf().computeImage())
        self.assertImagesEqual(exposureIn.getPsf().computeImage(),
                               reader.readComponent('PSF').computeImage())
        self.assertEqual(exposureIn.getInfo().getValidPolygon(),
                         reader.readValidPolygon())
        self.assertEqual(exposureIn.getInfo().getValidPolygon(),
                         reader.readComponent(ExposureInfo.KEY_VALID_POLYGON))
        self.assertCountEqual(exposureIn.getInfo().getApCorrMap(),
                              reader.readApCorrMap())
        self.assertCountEqual(
            exposureIn.getInfo().getApCorrMap(),
            reader.readComponent(ExposureInfo.KEY_AP_CORR_MAP))
        self.assertEqual(exposureIn.getInfo().getVisitInfo().getExposureTime(),
                         reader.readVisitInfo().getExposureTime())
        point = Point2D(2.3, 3.1)
        wavelengths = np.linspace(4000, 5000, 5)
        self.assertFloatsEqual(
            exposureIn.getInfo().getTransmissionCurve().sampleAt(
                point, wavelengths),
            reader.readTransmissionCurve().sampleAt(point, wavelengths))
        # Note: readComponent(ExposureInfo.KEY_TRANSMISSION_CURVE) returns a generic Storable
        # rather than a TransmissionCurve object.

        # Because we persisted the same instances, we should get back the same
        # instances for *archive* components, and hence equality comparisons
        # should work even if it just amounts to C++ pointer equality.
        record = reader.readCoaddInputs().ccds[0]
        self.assertEqual(record.getWcs(), reader.readWcs())
        self.assertEqual(record.getPsf(), reader.readPsf())
        self.assertEqual(record.getValidPolygon(), reader.readValidPolygon())
        self.assertEqual(record.getApCorrMap(), reader.readApCorrMap())
        self.assertEqual(record.getPhotoCalib(), reader.readPhotoCalib())
        self.assertEqual(record.getDetector(), reader.readDetector())
        self.checkMultiPlaneReader(
            reader,
            exposureIn,
            fileName,
            dtypesOut,
            compare=lambda a, b: self.assertMaskedImagesEqual(
                a.maskedImage, b.maskedImage))
Exemplo n.º 4
0
    def checkExposureFitsReader(self, exposureIn, fileName, dtypesOut):
        """Test ExposureFitsReader.

        Parameters
        ----------
        exposureIn : `Exposure`
            Object originally saved, to compare against.
        fileName : `str`
            Name of the file the reader is reading.
        dtypesOut : sequence of `numpy.dype`
            Compatible image pixel types to try to read in.
        """
        reader = ExposureFitsReader(fileName)
        self.assertEqual(exposureIn.getMetadata().toDict(),
                         reader.readMetadata().toDict())
        self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(),
                                          reader.readWcs(),
                                          self.bbox,
                                          maxDiffPix=0,
                                          maxDiffSky=0 * degrees)
        self.assertEqual(exposureIn.getFilter(), reader.readFilter())
        self.assertEqual(exposureIn.getCalib(), reader.readCalib())
        self.assertImagesEqual(exposureIn.getPsf().computeImage(),
                               reader.readPsf().computeImage())
        self.assertEqual(exposureIn.getInfo().getValidPolygon(),
                         reader.readValidPolygon())
        self.assertCountEqual(exposureIn.getInfo().getApCorrMap(),
                              reader.readApCorrMap())
        self.assertEqual(exposureIn.getInfo().getVisitInfo().getExposureTime(),
                         reader.readVisitInfo().getExposureTime())
        point = Point2D(2.3, 3.1)
        wavelengths = np.linspace(4000, 5000, 5)
        self.assertFloatsEqual(
            exposureIn.getInfo().getTransmissionCurve().sampleAt(
                point, wavelengths),
            reader.readTransmissionCurve().sampleAt(point, wavelengths))
        # Because we persisted the same instances, we should get back the same
        # instances for *archive* components, and hence equality comparisons
        # should work even if it just amounts to C++ pointer equality.
        record = reader.readCoaddInputs().ccds[0]
        self.assertEqual(record.getWcs(), reader.readWcs())
        self.assertEqual(record.getPsf(), reader.readPsf())
        self.assertEqual(record.getValidPolygon(), reader.readValidPolygon())
        self.assertEqual(record.getApCorrMap(), reader.readApCorrMap())
        self.assertEqual(record.getCalib(), reader.readCalib())
        self.assertEqual(record.getDetector(), reader.readDetector())
        self.checkMultiPlaneReader(
            reader,
            exposureIn,
            fileName,
            dtypesOut,
            compare=lambda a, b: self.assertMaskedImagesEqual(
                a.maskedImage, b.maskedImage))
Exemplo n.º 5
0
    def checkExposureFitsReader(self, exposureIn, fileName, dtypesOut):
        """Test ExposureFitsReader.

        Parameters
        ----------
        exposureIn : `Exposure`
            Object originally saved, to compare against.
        fileName : `str`
            Name of the file the reader is reading.
        dtypesOut : sequence of `numpy.dype`
            Compatible image pixel types to try to read in.
        """
        reader = ExposureFitsReader(fileName)
        self.assertIn('EXPINFO_V', reader.readMetadata().toDict(), "metadata is automatically versioned")
        reader.readMetadata().remove('EXPINFO_V')
        self.assertEqual(exposureIn.getMetadata().toDict(), reader.readMetadata().toDict())
        self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(), reader.readWcs(), self.bbox,
                                          maxDiffPix=0, maxDiffSky=0*degrees)
        self.assertEqual(exposureIn.getFilter(), reader.readFilter())
        self.assertEqual(exposureIn.getPhotoCalib(), reader.readPhotoCalib())
        self.assertImagesEqual(exposureIn.getPsf().computeImage(), reader.readPsf().computeImage())
        self.assertEqual(exposureIn.getInfo().getValidPolygon(), reader.readValidPolygon())
        self.assertCountEqual(exposureIn.getInfo().getApCorrMap(), reader.readApCorrMap())
        self.assertEqual(exposureIn.getInfo().getVisitInfo().getExposureTime(),
                         reader.readVisitInfo().getExposureTime())
        point = Point2D(2.3, 3.1)
        wavelengths = np.linspace(4000, 5000, 5)
        self.assertFloatsEqual(exposureIn.getInfo().getTransmissionCurve().sampleAt(point, wavelengths),
                               reader.readTransmissionCurve().sampleAt(point, wavelengths))
        # Because we persisted the same instances, we should get back the same
        # instances for *archive* components, and hence equality comparisons
        # should work even if it just amounts to C++ pointer equality.
        record = reader.readCoaddInputs().ccds[0]
        self.assertEqual(record.getWcs(), reader.readWcs())
        self.assertEqual(record.getPsf(), reader.readPsf())
        self.assertEqual(record.getValidPolygon(), reader.readValidPolygon())
        self.assertEqual(record.getApCorrMap(), reader.readApCorrMap())
        self.assertEqual(record.getPhotoCalib(), reader.readPhotoCalib())
        self.assertEqual(record.getDetector(), reader.readDetector())
        self.checkMultiPlaneReader(
            reader, exposureIn, fileName, dtypesOut,
            compare=lambda a, b: self.assertMaskedImagesEqual(a.maskedImage, b.maskedImage)
        )
Exemplo n.º 6
0
    def checkExposureFitsReader(self, exposureIn, fileName, dtypesOut):
        """Test ExposureFitsReader.

        Parameters
        ----------
        exposureIn : `Exposure`
            Object originally saved, to compare against.
        fileName : `str`
            Name of the file the reader is reading.
        dtypesOut : sequence of `numpy.dype`
            Compatible image pixel types to try to read in.
        """
        reader = ExposureFitsReader(fileName)
        self.assertIn('EXPINFO_V',
                      reader.readMetadata().toDict(),
                      "metadata is automatically versioned")
        reader.readMetadata().remove('EXPINFO_V')
        # ensure EXTNAMEs can be read and make sense
        extnames = set(('PRIMARY', 'IMAGE', 'MASK', 'VARIANCE',
                        'ARCHIVE_INDEX', 'Detector', 'TransformMap',
                        'TransformPoint2ToPoint2', 'FilterLabel', 'SkyWcs',
                        'ApCorrMap', 'PhotoCalib', 'ChebyshevBoundedField',
                        'CoaddInputs', 'GaussianPsf', 'Polygon', 'VisitInfo'))
        with astropy.io.fits.open(fileName) as astropyReadFile:
            for hdu in astropyReadFile:
                self.assertIn(hdu.name, extnames)
        self.assertIn('EXTNAME',
                      reader.readMetadata().toDict(),
                      "EXTNAME is added upon writing")
        reader.readMetadata().remove('EXTNAME')
        self.assertGreaterEqual(reader.readSerializationVersion(), 0)
        self.assertEqual(exposureIn.info.id, reader.readExposureId())
        self.assertEqual(exposureIn.getMetadata().toDict(),
                         reader.readMetadata().toDict())
        self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(),
                                          reader.readWcs(),
                                          self.bbox,
                                          maxDiffPix=0,
                                          maxDiffSky=0 * degrees)
        self.assertWcsAlmostEqualOverBBox(exposureIn.getWcs(),
                                          reader.readComponent(
                                              ExposureInfo.KEY_WCS),
                                          self.bbox,
                                          maxDiffPix=0,
                                          maxDiffSky=0 * degrees)
        self.assertEqual(exposureIn.getFilter(), reader.readFilter())
        self.assertEqual(exposureIn.getFilter(),
                         reader.readComponent(ExposureInfo.KEY_FILTER))
        with self.assertWarns(FutureWarning):
            self.assertEqual(exposureIn.getFilterLabel(),
                             reader.readFilterLabel())
            self.assertEqual(exposureIn.getFilterLabel(),
                             reader.readComponent(ExposureInfo.KEY_FILTER))
        self.assertEqual(exposureIn.getPhotoCalib(), reader.readPhotoCalib())
        self.assertEqual(exposureIn.getPhotoCalib(),
                         reader.readComponent(ExposureInfo.KEY_PHOTO_CALIB))
        center = exposureIn.getBBox().getCenter()
        self.assertImagesEqual(exposureIn.getPsf().computeImage(center),
                               reader.readPsf().computeImage(center))
        self.assertImagesEqual(
            exposureIn.getPsf().computeImage(center),
            reader.readComponent('PSF').computeImage(center))
        self.assertEqual(exposureIn.getInfo().getValidPolygon(),
                         reader.readValidPolygon())
        self.assertEqual(exposureIn.getInfo().getValidPolygon(),
                         reader.readComponent(ExposureInfo.KEY_VALID_POLYGON))
        self.assertCountEqual(exposureIn.getInfo().getApCorrMap(),
                              reader.readApCorrMap())
        self.assertCountEqual(
            exposureIn.getInfo().getApCorrMap(),
            reader.readComponent(ExposureInfo.KEY_AP_CORR_MAP))
        self.assertEqual(exposureIn.getInfo().getVisitInfo().getExposureTime(),
                         reader.readVisitInfo().getExposureTime())
        point = Point2D(2.3, 3.1)
        wavelengths = np.linspace(4000, 5000, 5)
        self.assertFloatsEqual(
            exposureIn.getInfo().getTransmissionCurve().sampleAt(
                point, wavelengths),
            reader.readTransmissionCurve().sampleAt(point, wavelengths))
        # Note: readComponent(ExposureInfo.KEY_TRANSMISSION_CURVE) returns a generic Storable
        # rather than a TransmissionCurve object.

        # Because we persisted the same instances, we should get back the same
        # instances for *archive* components, and hence equality comparisons
        # should work even if it just amounts to C++ pointer equality.
        record = reader.readCoaddInputs().ccds[0]
        self.assertEqual(record.getWcs(), reader.readWcs())
        self.assertEqual(record.getPsf(), reader.readPsf())
        self.assertEqual(record.getValidPolygon(), reader.readValidPolygon())
        self.assertEqual(record.getApCorrMap(), reader.readApCorrMap())
        self.assertEqual(record.getPhotoCalib(), reader.readPhotoCalib())
        self.assertEqual(record.getDetector(), reader.readDetector())
        self.checkMultiPlaneReader(
            reader,
            exposureIn,
            fileName,
            dtypesOut,
            compare=lambda a, b: self.assertMaskedImagesEqual(
                a.maskedImage, b.maskedImage))