Exemplo n.º 1
0
    def bypass_defects(self, datasetType, pythonType, butlerLocation, dataId):
        """Return a defect based on the butler location returned by map_defects

        Parameters
        ----------
        butlerLocation : `lsst.daf.persistence.ButlerLocation`
            locationList = path to defects FITS file
        dataId : `dict`
            Butler data ID; "ccd" must be set.

        Note: the name "bypass_XXX" means the butler makes no attempt to
        convert the ButlerLocation into an object, which is what we want for
        now, since that conversion is a bit tricky.
        """
        detectorName = self._extractDetectorName(dataId)
        defectsFitsPath = butlerLocation.locationList[0]

        with fits.open(defectsFitsPath) as hduList:
            for hdu in hduList[1:]:
                if hdu.header["name"] != detectorName:
                    continue

                defectList = Defects()
                for data in hdu.data:
                    bbox = geom.Box2I(
                        geom.Point2I(int(data['x0']), int(data['y0'])),
                        geom.Extent2I(int(data['width']), int(data['height'])),
                    )
                    defectList.append(bbox)
                return defectList

        raise RuntimeError("No defects for ccd %s in %s" % (detectorName, defectsFitsPath))
Exemplo n.º 2
0
def read_defects_one_chip(root, chip_name, chip_id):
    """Read defects for a particular sensor from the standard format at a particular root.

    Parameters
    ----------
    root : str
        Path to the top level of the defects tree.  This is expected to hold directories
        named after the sensor names.  They are expected to be lower case.
    chip_name : str
        The name of the sensor for which to read defects.
    chip_id : int
        The identifier for the sensor in question.

    Returns
    -------
    dict
        A dictionary of `lsst.meas.algorithms.Defects`.
        The key is the validity start time as a `datetime` object.
    """
    files = glob.glob(os.path.join(root, chip_name, '*.ecsv'))
    parts = os.path.split(root)
    instrument = os.path.split(
        parts[0])[1]  # convention is that these reside at <instrument>/defects
    defect_dict = {}
    for f in files:
        date_str = os.path.splitext(os.path.basename(f))[0]
        valid_start = dateutil.parser.parse(date_str)
        defect_dict[valid_start] = Defects.readText(f)
        check_metadata(defect_dict[valid_start], valid_start, instrument,
                       chip_id, f)
    return defect_dict
Exemplo n.º 3
0
    def makeDefectList(self):
        """Generate a simple single-entry defect list.

        Returns
        -------
        defectList : `lsst.meas.algorithms.Defects`
            Simulated defect list
        """
        return Defects([lsst.geom.Box2I(lsst.geom.Point2I(0, 0),
                                        lsst.geom.Extent2I(40, 50))])
Exemplo n.º 4
0
detectorName = "0"
"""Detector name."""
detectorSerial = "0000011"
"""Detector serial code"""


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description=f"""Construct a defects file from the mask plane of a test camera bias frame.
To use this command you must setup ip_isr and astropy.
Output is written to the current directory as file {DefectsPath}, which must not already exist.
"""
    )
    parser.add_argument("bias", help="path to bias image for the test camera")
    args = parser.parse_args()

    biasMI = afwImage.MaskedImageF(args.bias)
    defectList = Defects.fromMask(biasMI, "BAD")
    valid_start = dateutil.parser.parse('19700101T000000')
    md = defectList.getMetadata()
    md['INSTRUME'] = 'test'
    md['DETECTOR'] = detectorName
    md['CALIBDATE'] = valid_start.isoformat()
    md['FILTER'] = None
    defect_file = defectList.writeText(DefectsPath)
    print("wrote defects file %r" % (DefectsPath,))

    test2defectList = Defects.readText(defect_file)
    assert defectList == test2defectList
    print("verified that defects file %r round trips correctly" % (DefectsPath,))