Skip to content

Instantly share code, notes, and snippets.

@wadawson
Created March 8, 2016 23:26
Show Gist options
  • Save wadawson/043f6a9d17aea661157c to your computer and use it in GitHub Desktop.
Save wadawson/043f6a9d17aea661157c to your computer and use it in GitHub Desktop.
The DM incantation used to process a GalSim grid of blended pairs of objects.
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2015 AURA/LSST
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
import argparse
import glob
import math
import sys
import os.path
import numpy
import pyfits
import lsst.meas.base as measBase
import lsst.afw.geom as afwGeom
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.afw.image as afwImage
import lsst.meas.algorithms as measAlg
from lsst.pipe.tasks.processCcd import ProcessCcdTask
"""
"""
def runProcess(fitsFile):
exposure = afwImage.ExposureF.readFits(fitsFile)
kernel = afwMath.FixedKernel(afwImage.ImageD.readFits("psf_fixed.fits"))
exposure.setPsf(measAlg.KernelPsf(kernel))
CD = numpy.array([[5.55E-5, 0.0], [0.0, 5.55E-5]])
crpix = afwGeom.Point2D(0.0,0.0)
crval = afwGeom.Point2D(0.0,0.0)
exposure.setWcs(afwImage.Wcs(crval, crpix, CD))
exposure.getMaskedImage().getVariance().set(100)
config = ProcessCcdTask.ConfigClass()
config.doCalibrate = False
config.doDetection = True
config.doDeblend = True
config.doMeasurement = True
config.doWriteCalibrate = False
config.persistBackgroundModel = False
config.doWriteCalibrateMatches = False
config.doWriteSources = False
config.doWriteSourceMatches = False
config.doWriteHeavyFootprintsInSources = False
config.measurement.slots.centroid = "base_GaussianCentroid"
config.measurement.slots.shape = None
config.measurement.slots.psfFlux = "base_PsfFlux"
config.measurement.slots.apFlux = None
config.measurement.slots.instFlux = None
config.measurement.slots.modelFlux = None
config.measurement.doReplaceWithNoise = False
config.measurement.doApplyApCorr = "no"
config.measurement.plugins.names = ["base_GaussianCentroid", "base_PsfFlux"]
processTask = ProcessCcdTask(name="xyzzy", config=config)
result = processTask.process(None, exposure)
result.sources.writeFits("sources.fits")
result.exposure.writeFits("exposure.fits")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("fitsFile", type=str, help="Name of file to process", default=None)
args = parser.parse_args()
runProcess(args.fitsFile)
@wadawson
Copy link
Author

wadawson commented Mar 8, 2016

It was pointed out the config.measurement.doReplaceWithNoise = False should be changed to:

config.measurement.doReplaceWithNoise = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment