Exemple #1
0
    def testKnown(self):
        """!Test a few known values
        """
        numAmps = (2, 2)
        bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(4, 4))
        # make a 4x4 image with 4 identical 2x2 subregions that flatten to -1, 0, 1, 2
        im = afwImage.ImageF(bbox)
        imArr = im.getArray()
        imArr[:, :] = np.array(
            ((-1, 0, -1, 0), (1, 2, 1, 2), (-1, 0, -1, 0), (1, 2, 1, 2)),
            dtype=imArr.dtype)

        sqCoeffs = np.array(((0, 0.11), (-0.15, -12)))
        detector = self.makeDetector(bbox=bbox,
                                     numAmps=numAmps,
                                     sqCoeffs=sqCoeffs)
        ampInfoCat = detector.getAmpInfoCatalog()

        linSq = LinearizeSquared()
        linSq(im, detector=detector)

        # amp 0 has 0 squared coefficient and so makes no correction
        imArr0 = im.Factory(im, ampInfoCat[0].getBBox()).getArray()
        linCoeff0 = ampInfoCat[0].getLinearityCoeffs()[0]
        self.assertEqual(0, linCoeff0)
        self.assertFloatsAlmostEqual(imArr0.flatten(), (-1, 0, 1, 2))

        # test all amps
        for ampInfo in ampInfoCat:
            imArr = im.Factory(im, ampInfo.getBBox()).getArray()
            linCoeff = ampInfo.getLinearityCoeffs()[0]
            expect = np.array(
                (-1 + linCoeff, 0, 1 + linCoeff, 2 + 4 * linCoeff),
                dtype=imArr.dtype)
            self.assertFloatsAlmostEqual(imArr.flatten(), expect)
Exemple #2
0
    def testBasics(self):
        """!Test basic functionality of LinearizeSquared
        """
        for imageClass in (afwImage.ImageF, afwImage.ImageD):
            inImage = makeRampImage(bbox=self.bbox,
                                    start=-5,
                                    stop=2500,
                                    imageClass=imageClass)

            measImage = inImage.Factory(inImage, True)
            linSq = LinearizeSquared()
            linRes = linSq(image=measImage, detector=self.detector)
            desNumLinearized = np.sum(self.sqCoeffs.flatten() > 0)
            self.assertEqual(linRes.numLinearized, desNumLinearized)
            self.assertEqual(linRes.numAmps,
                             len(self.detector.getAmpInfoCatalog()))

            refImage = inImage.Factory(inImage, True)
            refLinearizeSquared(image=refImage, detector=self.detector)

            self.assertImagesAlmostEqual(refImage, measImage)

            # make sure logging is accepted
            log = Log.getLogger("ip.isr.LinearizeSquared")
            linRes = linSq(image=measImage, detector=self.detector, log=log)
Exemple #3
0
    def __init__(self, *args, **kwargs):
        super(SuprimecamMapperBase, self).__init__(*args, **kwargs)

        self._linearize = LinearizeSquared()

        # Ensure each dataset type of interest knows about the full range of keys available from the registry
        keys = {'field': str,
                'visit': int,
                'filter': str,
                'ccd': int,
                'dateObs': str,
                'taiObs': str,
                'expTime': float,
                'pointing': int,
                }
        for name in ("raw",
                     # processCcd outputs
                     "postISRCCD", "calexp", "postISRCCD", "src", "icSrc", "icMatch",
                     "srcMatch",
                     # processCcd QA
                     "ossThumb", "flattenedThumb", "calexpThumb", "plotMagHist", "plotSeeingRough",
                     "plotSeeingRobust", "plotSeeingMap", "plotEllipseMap", "plotEllipticityMap",
                     "plotFwhmGrid", "plotEllipseGrid", "plotEllipticityGrid", "plotPsfSrcGrid",
                     "plotPsfModelGrid", "fitsFwhmGrid", "fitsEllipticityGrid", "fitsEllPaGrid",
                     "fitsPsfSrcGrid", "fitsPsfModelGrid", "tableSeeingMap", "tableSeeingGrid",
                     # forcedPhot outputs
                     "forced_src",
                     ):
            self.mappings[name].keyDict.update(keys)
Exemple #4
0
    def testPickle(self):
        """!Test that a LinearizeSquared can be pickled and unpickled
        """
        inImage = makeRampImage(bbox=self.bbox, start=-5, stop=2500)
        linSq = LinearizeSquared()

        refImage = inImage.Factory(inImage, True)
        refNumOutOfRange = linSq(refImage, self.detector)

        pickledStr = pickle.dumps(linSq)
        restoredLlt = pickle.loads(pickledStr)

        measImage = inImage.Factory(inImage, True)
        measNumOutOfRange = restoredLlt(measImage, self.detector)

        self.assertEqual(refNumOutOfRange, measNumOutOfRange)
        self.assertImagesAlmostEqual(refImage, measImage)
Exemple #5
0
    def __init__(self, **kwargs):
        policyFile = Policy.defaultPolicyFile("obs_subaru", "HscMapper.yaml",
                                              "policy")
        policy = Policy(policyFile)
        if not kwargs.get('root', None):
            try:
                kwargs['root'] = os.path.join(
                    os.environ.get('SUPRIME_DATA_DIR'), 'HSC')
            except:
                raise RuntimeError(
                    "Either $SUPRIME_DATA_DIR or root= must be specified")
        if not kwargs.get('calibRoot', None):
            calibSearch = [os.path.join(kwargs['root'], 'CALIB')]
            if "repositoryCfg" in kwargs:
                calibSearch += [
                    os.path.join(cfg.root, 'CALIB')
                    for cfg in kwargs["repositoryCfg"].parents
                    if hasattr(cfg, "root")
                ]
                calibSearch += [
                    cfg.root for cfg in kwargs["repositoryCfg"].parents
                    if hasattr(cfg, "root")
                ]
            for calibRoot in calibSearch:
                if os.path.exists(
                        os.path.join(calibRoot, "calibRegistry.sqlite3")):
                    kwargs['calibRoot'] = calibRoot
                    break
            if not kwargs.get('calibRoot', None):
                lsst.log.Log.getLogger("HscMapper").warn(
                    "Unable to find calib root directory")

        super(HscMapper, self).__init__(policy, os.path.dirname(policyFile),
                                        **kwargs)

        self._linearize = LinearizeSquared()

        # Ensure each dataset type of interest knows about the full range of keys available from the registry
        keys = {
            'field': str,
            'visit': int,
            'filter': str,
            'ccd': int,
            'dateObs': str,
            'taiObs': str,
            'expTime': float,
            'pointing': int,
        }
        for name in (
                "raw",
                # processCcd outputs
                "postISRCCD",
                "calexp",
                "postISRCCD",
                "src",
                "icSrc",
                "icMatch",
                "srcMatch",
                # mosaic outputs
                "wcs",
                "fcr",
                # processCcd QA
                "ossThumb",
                "flattenedThumb",
                "calexpThumb",
                "plotMagHist",
                "plotSeeingRough",
                "plotSeeingRobust",
                "plotSeeingMap",
                "plotEllipseMap",
                "plotEllipticityMap",
                "plotFwhmGrid",
                "plotEllipseGrid",
                "plotEllipticityGrid",
                "plotPsfSrcGrid",
                "plotPsfModelGrid",
                "fitsFwhmGrid",
                "fitsEllipticityGrid",
                "fitsEllPaGrid",
                "fitsPsfSrcGrid",
                "fitsPsfModelGrid",
                "tableSeeingMap",
                "tableSeeingGrid",
                # forcedPhot outputs
                "forced_src",
        ):
            self.mappings[name].keyDict.update(keys)

        # SDSS g': http://www.naoj.org/Observing/Instruments/SCam/txt/g.txt
        # SDSS r': http://www.naoj.org/Observing/Instruments/SCam/txt/r.txt
        # SDSS i': http://www.naoj.org/Observing/Instruments/SCam/txt/i.txt
        # SDSS z': http://www.naoj.org/Observing/Instruments/SCam/txt/z.txt
        # y-band: Shimasaku et al., 2005, PASJ, 57, 447

        # The order of these defineFilter commands matters as their IDs are used to generate at least some
        # object IDs (e.g. on coadds) and changing the order will invalidate old objIDs

        afwImageUtils.resetFilters()
        afwImageUtils.defineFilter(name="UNRECOGNISED",
                                   lambdaEff=0,
                                   alias=[
                                       "NONE",
                                       "None",
                                       "Unrecognised",
                                       "UNRECOGNISED",
                                       "Unrecognized",
                                       "UNRECOGNIZED",
                                       "NOTSET",
                                   ])
        afwImageUtils.defineFilter(name='g',
                                   lambdaEff=477,
                                   alias=['W-S-G+', 'HSC-G'])
        afwImageUtils.defineFilter(name='r',
                                   lambdaEff=623,
                                   alias=['W-S-R+', 'HSC-R'])
        afwImageUtils.defineFilter(name='r1',
                                   lambdaEff=623,
                                   alias=['109', 'ENG-R1'])
        afwImageUtils.defineFilter(name='i',
                                   lambdaEff=775,
                                   alias=['W-S-I+', 'HSC-I'])
        afwImageUtils.defineFilter(name='z',
                                   lambdaEff=925,
                                   alias=['W-S-Z+', 'HSC-Z'])
        afwImageUtils.defineFilter(name='y',
                                   lambdaEff=990,
                                   alias=['W-S-ZR', 'HSC-Y'])
        afwImageUtils.defineFilter(name='N387',
                                   lambdaEff=387,
                                   alias=['NB0387'])
        afwImageUtils.defineFilter(name='N515',
                                   lambdaEff=515,
                                   alias=['NB0515'])
        afwImageUtils.defineFilter(name='N656',
                                   lambdaEff=656,
                                   alias=['NB0656'])
        afwImageUtils.defineFilter(name='N816',
                                   lambdaEff=816,
                                   alias=['NB0816'])
        afwImageUtils.defineFilter(name='N921',
                                   lambdaEff=921,
                                   alias=['NB0921'])
        afwImageUtils.defineFilter(name='N1010',
                                   lambdaEff=1010,
                                   alias=['NB1010'])
        afwImageUtils.defineFilter(name='SH', lambdaEff=0, alias=[
            'SH',
        ])
        afwImageUtils.defineFilter(name='PH', lambdaEff=0, alias=[
            'PH',
        ])
        afwImageUtils.defineFilter(name='N527',
                                   lambdaEff=527,
                                   alias=['NB0527'])
        afwImageUtils.defineFilter(name='N718',
                                   lambdaEff=718,
                                   alias=['NB0718'])
        afwImageUtils.defineFilter(name='I945',
                                   lambdaEff=945,
                                   alias=['IB0945'])
        afwImageUtils.defineFilter(name='N973',
                                   lambdaEff=973,
                                   alias=['NB0973'])
        afwImageUtils.defineFilter(name='i2', lambdaEff=775, alias=['HSC-I2'])
        afwImageUtils.defineFilter(name='r2', lambdaEff=623, alias=['HSC-R2'])
        afwImageUtils.defineFilter(name='N468',
                                   lambdaEff=468,
                                   alias=['NB0468'])
        afwImageUtils.defineFilter(name='N926',
                                   lambdaEff=926,
                                   alias=['NB0926'])
        #
        # self.filters is used elsewhere, and for now we'll set it
        #
        # It's a bit hard to initialise self.filters properly until #2113 is resolved,
        # including the part that makes it possible to get all aliases
        #
        self.filters = {}
        for f in [
                "HSC-G", "HSC-R", "HSC-R2", "HSC-I", "HSC-I2", "HSC-Z",
                "HSC-Y", "ENG-R1", "NB0387", "NB0468", "NB0515", "NB0527",
                "NB0656", "NB0718", "NB0816", "NB0921", "NB0926", "IB0945",
                "NB0973", "NB1010", "SH", "PH", "NONE", "UNRECOGNISED"
        ]:
            self.filters[f] = afwImage.Filter(f).getCanonicalName()
        self.defaultFilterName = "UNRECOGNISED"

        #
        # The number of bits allocated for fields in object IDs, appropriate for
        # the default-configured Rings skymap.
        #
        # This shouldn't be the mapper's job at all; see #2797.

        HscMapper._nbit_tract = 16
        HscMapper._nbit_patch = 5
        HscMapper._nbit_filter = 6

        HscMapper._nbit_id = 64 - (HscMapper._nbit_tract +
                                   2 * HscMapper._nbit_patch +
                                   HscMapper._nbit_filter)

        if len(afwImage.Filter.getNames()) >= 2**HscMapper._nbit_filter:
            raise RuntimeError(
                "You have more filters defined than fit into the %d bits allocated"
                % HscMapper._nbit_filter)
Exemple #6
0
    def __init__(self, **kwargs):
        policyFile = Policy.defaultPolicyFile("obs_subaru", "HscMapper.yaml", "policy")
        policy = Policy(policyFile)
        if not kwargs.get('root', None):
            try:
                kwargs['root'] = os.path.join(os.environ.get('SUPRIME_DATA_DIR'), 'HSC')
            except Exception:
                raise RuntimeError("Either $SUPRIME_DATA_DIR or root= must be specified")
        if not kwargs.get('calibRoot', None):
            calibSearch = [os.path.join(kwargs['root'], 'CALIB')]
            if "repositoryCfg" in kwargs:
                calibSearch += [os.path.join(cfg.root, 'CALIB') for cfg in kwargs["repositoryCfg"].parents if
                                hasattr(cfg, "root")]
                calibSearch += [cfg.root for cfg in kwargs["repositoryCfg"].parents if hasattr(cfg, "root")]
            for calibRoot in calibSearch:
                if os.path.exists(os.path.join(calibRoot, "calibRegistry.sqlite3")):
                    kwargs['calibRoot'] = calibRoot
                    break
            if not kwargs.get('calibRoot', None):
                lsst.log.Log.getLogger("HscMapper").warn("Unable to find calib root directory")

        super(HscMapper, self).__init__(policy, os.path.dirname(policyFile), **kwargs)

        self._linearize = LinearizeSquared()

        # Ensure each dataset type of interest knows about the full range of keys available from the registry
        keys = {'field': str,
                'visit': int,
                'filter': str,
                'ccd': int,
                'dateObs': str,
                'taiObs': str,
                'expTime': float,
                'pointing': int,
                }
        for name in ("raw",
                     # processCcd outputs
                     "postISRCCD", "calexp", "postISRCCD", "src", "icSrc", "icMatch",
                     "srcMatch",
                     # mosaic outputs
                     "wcs", "fcr",
                     # processCcd QA
                     "ossThumb", "flattenedThumb", "calexpThumb", "plotMagHist", "plotSeeingRough",
                     "plotSeeingRobust", "plotSeeingMap", "plotEllipseMap", "plotEllipticityMap",
                     "plotFwhmGrid", "plotEllipseGrid", "plotEllipticityGrid", "plotPsfSrcGrid",
                     "plotPsfModelGrid", "fitsFwhmGrid", "fitsEllipticityGrid", "fitsEllPaGrid",
                     "fitsPsfSrcGrid", "fitsPsfModelGrid", "tableSeeingMap", "tableSeeingGrid",
                     # forcedPhot outputs
                     "forced_src",
                     ):
            self.mappings[name].keyDict.update(keys)

        self.addFilters()

        self.filters = {}
        for filt in HSC_FILTER_DEFINITIONS:
            self.filters[filt.physical_filter] = afwImage.Filter(filt.physical_filter).getCanonicalName()
        self.defaultFilterName = "UNRECOGNISED"

        #
        # The number of bits allocated for fields in object IDs, appropriate for
        # the default-configured Rings skymap.
        #
        # This shouldn't be the mapper's job at all; see #2797.

        HscMapper._nbit_tract = 16
        HscMapper._nbit_patch = 5
        HscMapper._nbit_filter = 6

        HscMapper._nbit_id = 64 - (HscMapper._nbit_tract + 2*HscMapper._nbit_patch + HscMapper._nbit_filter)

        if len(afwImage.Filter.getNames()) >= 2**HscMapper._nbit_filter:
            raise RuntimeError("You have more filters defined than fit into the %d bits allocated" %
                               HscMapper._nbit_filter)