Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review for DM-2674: Make meas_mosaic work on LSST. #1

Merged
merged 44 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8c319f9
Use LSST exception names.
jdswinbank Jul 1, 2015
70f1d62
cameraGeom::Ccd::Ptr -> PTR(cameraGeom::Detector)
jdswinbank Jul 1, 2015
53fc296
Replace calls to Detector::get{Cos,Sin}Yaw().
jdswinbank Jul 1, 2015
a76fac9
Convert fluxfit.cc to new cameraGeom.
jdswinbank Jul 3, 2015
6cc9af5
Convert mosaicfit.cc to new cameraGeom.
jdswinbank Jul 8, 2015
189183b
Correct location of PerTractCcdDataIdContainer.
jdswinbank Aug 11, 2015
751b6ff
Adapt to new meas_astrom.
jdswinbank Aug 13, 2015
e31fc2c
Adapt to new colorterm system.
jdswinbank Aug 13, 2015
c069ccb
Make photometry catalog name a config parameter.
jdswinbank Aug 12, 2015
c700ef9
Use meas_base-style field names.
jdswinbank Aug 13, 2015
da21d15
Adapt MosaicTask to new cameraGeom.
jdswinbank Aug 13, 2015
f36d3fd
Adapt CheckMosaicTask to new MosaicRunner.
jdswinbank Aug 12, 2015
33a48ea
Make use of LaTeX in figure captions optional.
jdswinbank Aug 13, 2015
a32f6bf
Add wrappers to map to the old cameraGeom API.
jdswinbank Aug 18, 2015
6994ed3
Adapt existing code to use cameraGeom shim.
jdswinbank Aug 19, 2015
98984e4
Remove unused & broken test.
jdswinbank Aug 20, 2015
1c27fa9
Adapt to running on OSX/SIP.
jdswinbank Feb 15, 2016
94f3c00
Correct include file name.
jdswinbank Feb 15, 2016
a627301
Reword source loading for LSST.
jdswinbank Feb 17, 2016
f961819
Make it possible to correct flux only.
jdswinbank Feb 19, 2016
a644076
Specify coadd type in MosaicTaskConfig.
jdswinbank Feb 19, 2016
8c67389
Account for astrometry catalogs being read in Jy.
laurenam Jun 30, 2016
a08f7d2
Make it possible to correct Wcs only.
jdswinbank Feb 19, 2016
1ce11a3
Update to match recent Butler API changes.
jdswinbank Apr 14, 2016
6907577
Update to match new ProcessCcdTask.
jdswinbank Apr 14, 2016
626bf5d
Fix reference flux key name for colorterm
laurenam Apr 20, 2016
2e2038b
Adjust formatting & clean up.
laurenam Apr 20, 2016
3ef9dcb
De-boostification
laurenam May 18, 2016
d5a7939
Add function name to print statements
laurenam May 18, 2016
f6b1ce5
Account for catalogs read in janskys: fluxSigmas
laurenam May 27, 2016
056f48e
Update diagnostics output.
laurenam Jun 7, 2016
927de8c
Rotate catalog centroids to meas_mosaic coords
laurenam Jun 30, 2016
6bc2ac5
Account for w<-->h for oddly rotated CCDs
laurenam Jun 14, 2016
59d2d7d
Accommodate running on HSC stack products
laurenam Jun 14, 2016
47a3aba
Add options to select against objects for mosaic fit
laurenam Jun 14, 2016
72d414f
Use full pivoting when using Eigen
laurenam Jun 14, 2016
6fe95ec
Force use of Eigen over MKL
laurenam Jun 14, 2016
536471f
Move appropriate functions to utils.py.
laurenam Jun 27, 2016
ea73947
Make minor plot updates: labels and font size
laurenam Jun 27, 2016
1a1a0cd
Make minor style and formatting updates
laurenam Jun 27, 2016
009cb28
Update applyMosaicResultsCatalog
laurenam Jun 27, 2016
f86d34b
Update getFluxKeys in updateExposure.py
laurenam Jun 27, 2016
3804a84
Update applyCalib in updateExposure.py
laurenam Jun 27, 2016
d5f1045
Drop dependencies on MKL and OpenBLAS
jdswinbank Jun 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config.log
*.o
*.os
*.so
*.dylib
*.cfgc
*.pyc
*_wrap.cc
Expand All @@ -12,5 +13,10 @@ doc/html
doc/*.tag
doc/*.inc
doc/doxygen.conf
tests/.cache
tests/.tests
version.py
bin/calibrateCatalog.py
bin/calibrateExposure.py
bin/checkMosaic.py
bin/mosaic.py
3 changes: 3 additions & 0 deletions bin.src/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.shebang()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions include/lsst/meas/mosaic/fluxfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace lsst {

class FluxFitParams {
public:
typedef boost::shared_ptr<FluxFitParams> Ptr;
typedef std::shared_ptr<FluxFitParams> Ptr;

int order;
bool chebyshev;
Expand Down Expand Up @@ -58,23 +58,23 @@ namespace lsst {

FluxFitParams::Ptr
convertFluxFitParams(FluxFitParams::Ptr& ffp,
lsst::afw::cameraGeom::Ccd::Ptr& ccd,
PTR(lsst::afw::cameraGeom::Detector)& ccd,
double x0=0.0, double y0=0.0);

lsst::daf::base::PropertySet::Ptr
metadataFromFluxFitParams(FluxFitParams::Ptr& ffp);

lsst::afw::image::Image<float>::Ptr
getFCorImg(FluxFitParams::Ptr& p,
lsst::afw::cameraGeom::Ccd::Ptr& ccd,
PTR(lsst::afw::cameraGeom::Detector)& ccd,
Coeff::Ptr& coeff);

lsst::afw::image::Image<float>::Ptr
getFCorImg(FluxFitParams::Ptr& p, int width, int height);

lsst::afw::image::Image<float>::Ptr
getFCorImg(FluxFitParams::Ptr& p,
lsst::afw::cameraGeom::Ccd::Ptr& ccd);
PTR(lsst::afw::cameraGeom::Detector)& ccd);

#include "chebyshev.h"
}
Expand Down
33 changes: 16 additions & 17 deletions include/lsst/meas/mosaic/mosaicfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#if !defined(HSC_MEAS_MOSAIC_H)
#define HSC_MEAS_MOSAIC_H

#include <cmath>
#include <memory>
#include <vector>
#include "lsst/pex/exceptions.h"
#include "lsst/afw/image.h"
#include "lsst/afw/geom.h"
#include "lsst/afw/cameraGeom.h"
#include "lsst/afw/table.h"
#include "lsst/utils/ieee.h"
#include "boost/enable_shared_from_this.hpp"

namespace lsst {
namespace meas {
Expand All @@ -33,11 +33,11 @@ namespace lsst {
_err(std::numeric_limits<double>::quiet_NaN()),
_xerr(std::numeric_limits<double>::quiet_NaN()),
_yerr(std::numeric_limits<double>::quiet_NaN()),
_astromBad(!lsst::utils::isfinite(_flux))
_astromBad(!std::isfinite(_flux))
{
try {
_err = record.get(record.getSchema().find<double>("flux.err").key);
} catch (pex::exceptions::NotFoundException const&) {
_err = record.get(record.getSchema().find<double>("fluxSigma").key);
} catch (pex::exceptions::NotFoundError const&) {
// flux.err is not availabe. sqrt of flux will be used
// 1.E-08 is a scaling factor to make mag_err ~ 0.1mag for 15 mag
// This is a good approximation for 2MASS J-band
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace lsst {

class Poly {
public:
typedef boost::shared_ptr<Poly> Ptr;
typedef std::shared_ptr<Poly> Ptr;

int order;
int ncoeff;
Expand All @@ -128,7 +128,7 @@ namespace lsst {

class Coeff {
public:
typedef boost::shared_ptr<Coeff> Ptr;
typedef std::shared_ptr<Coeff> Ptr;

Poly::Ptr p;
int iexp;
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace lsst {

class Obs {
public:
typedef boost::shared_ptr<Obs> Ptr;
typedef std::shared_ptr<Obs> Ptr;

double ra, dec;
double xi, eta;
Expand Down Expand Up @@ -217,20 +217,20 @@ namespace lsst {

Obs(int id, double ra, double dec, double x, double y, int ichip, int iexp);
Obs(int id, double ra, double dec, int ichip, int iexp);
void setUV(lsst::afw::cameraGeom::Ccd::Ptr const &ccd, double x0=0, double y0=0);
void setUV(PTR(lsst::afw::cameraGeom::Detector) &ccd, double x0=0, double y0=0);
void setXiEta(double ra_c, double dec_c);
void setFitVal(Coeff::Ptr& c, Poly::Ptr p);
void setFitVal2(Coeff::Ptr& c, Poly::Ptr p);
};

class KDTree
#if !defined(SWIG)
: public boost::enable_shared_from_this<KDTree>
: public std::enable_shared_from_this<KDTree>
#endif
{
public:
typedef boost::shared_ptr<KDTree> Ptr;
typedef boost::shared_ptr<const KDTree> ConstPtr;
typedef std::shared_ptr<KDTree> Ptr;
typedef std::shared_ptr<const KDTree> ConstPtr;

int depth;
int axis;
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace lsst {
void _initializeMatches(SourceMatchSet& m, int depth);
};

typedef std::map<int, lsst::afw::cameraGeom::Ccd::Ptr> CcdSet;
typedef std::map<int, PTR(lsst::afw::cameraGeom::Detector)> CcdSet;
typedef std::map<int, Coeff::Ptr> CoeffSet;
typedef std::vector<Obs::Ptr> ObsVec;

Expand Down Expand Up @@ -314,23 +314,23 @@ namespace lsst {
std::string const & snapshotDir = ".");

Coeff::Ptr convertCoeff(Coeff::Ptr& coeff,
lsst::afw::cameraGeom::Ccd::Ptr& ccd);
PTR(lsst::afw::cameraGeom::Detector)& ccd);

lsst::afw::image::TanWcs::Ptr wcsFromCoeff(Coeff::Ptr& coeff);

Coeff::Ptr coeffFromTanWcs(lsst::afw::image::Wcs::Ptr& wcs);

lsst::afw::image::Image<float>::Ptr
getJImg(Coeff::Ptr& coeff,
lsst::afw::cameraGeom::Ccd::Ptr& ccd);
PTR(lsst::afw::cameraGeom::Detector)& ccd);

lsst::afw::image::Image<float>::Ptr
getJImg(lsst::afw::image::Wcs::Ptr& wcs,
int width, int height);

lsst::afw::image::Image<float>::Ptr
getJImg(lsst::afw::image::Wcs::Ptr& wcs,
lsst::afw::cameraGeom::Ccd::Ptr& ccd);
PTR(lsst::afw::cameraGeom::Detector)& ccd);

//{
// Calculate Jacobian correction
Expand All @@ -353,7 +353,6 @@ namespace lsst {
ndarray::Array<double const, 1> const& y ///< y positions for correction
);
//}

}
}
}
Expand Down
50 changes: 50 additions & 0 deletions include/lsst/meas/mosaic/shimCameraGeom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// -*- lsst-c++ -*-
#ifndef LSST_MEAS_MOSAIC_SHIM_CAMERAGEOM_H
#define LSST_MEAS_MOSAIC_SHIM_CAMERAGEOM_H

#include "lsst/afw/geom.h"
#include "lsst/afw/cameraGeom.h"

namespace lsst {
namespace meas {
namespace mosaic {

// Get the number of quarter rotations of the detector.
int getNQuarter(CONST_PTR(afw::cameraGeom::Detector));

// Get the detector yaw.
afw::geom::Angle getYaw(CONST_PTR(afw::cameraGeom::Detector));

// Return a linear transform which scales from dimensions in mm to dimensions
// in pixels.
afw::geom::LinearTransform makeScalingMmToPx(afw::geom::Extent2D const pSize);

// Return the position of the center of the detector in pixels on the focal plane.
// Mimics HSC's camGeom: ccd.getCenter().getPixels(ccd.getPixelSize())
afw::geom::Point2D getCenterInFpPixels(CONST_PTR(afw::cameraGeom::Detector));

// Return the position of the center of the detector in pixels on the
// detector.
// Mimics HSC's camGeom: ccd.getCenterPixel()
afw::geom::Point2D getCenterInDetectorPixels(CONST_PTR(afw::cameraGeom::Detector));

// Return the width of the detector in pixels.
int getWidth(CONST_PTR(afw::cameraGeom::Detector));

// Return the height of the detector in pixels.
int getHeight(CONST_PTR(afw::cameraGeom::Detector));

// Convert a pixel position on a given detector to a pixel position on the focal plane.
afw::geom::Point2D detPxToFpPx(CONST_PTR(afw::cameraGeom::Detector), afw::geom::Point2D const);

// Convert a pixel position on a given detector to a pixel position on the focal plane
// accounting for yaw rotation.
// Mimics HSC's camGeom: ccd.getPositionFromPixel(point).getPixels(ccd.getPixelSize())
afw::geom::Point2D detPxToFpPxRot(CONST_PTR(afw::cameraGeom::Detector), afw::geom::Point2D const);

// Compute new position of lower left corner in Focal Plane pixels: X0, Y0
afw::geom::Point2D computeX0Y0(CONST_PTR(afw::cameraGeom::Detector), double, double);

}}} // lsst::meas::mosaic

#endif
4 changes: 2 additions & 2 deletions include/lsst/meas/mosaic/spatialCellSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace lsst {

class SpatialCellSource : public lsst::afw::math::SpatialCellCandidate {
public:
typedef boost::shared_ptr<SpatialCellSource> Ptr;
typedef boost::shared_ptr<const SpatialCellSource> ConstPtr;
typedef std::shared_ptr<SpatialCellSource> Ptr;
typedef std::shared_ptr<const SpatialCellSource> ConstPtr;

SpatialCellSource(float const xCenter,
float const yCenter,
Expand Down
21 changes: 18 additions & 3 deletions python/lsst/meas/mosaic/calibrate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from lsst.pipe.base import CmdLineTask, ArgumentParser
from lsst.pex.config import Config, Field
from lsst.pex.config import Config, Field, DictField
from .updateExposure import applyMosaicResultsExposure, applyMosaicResultsCatalog, applyCalib
from lsst.pipe.tasks.dataIds import PerTractCcdDataIdContainer
from lsst.meas.base.forcedPhotCcd import PerTractCcdDataIdContainer
from . import utils as mosaicUtils

class CalibrateCatalogConfig(Config):
doApplyCalib = Field(dtype=bool, default=True, doc="Calibrate fluxes to magnitudes?")
srcSchemaMap = DictField(
doc="Mapping between different stack (e.g. HSC vs. LSST) schema names",
keytype=str,
itemtype=str,
default=None,
optional=True)

class CalibrateCatalogTask(CmdLineTask):
ConfigClass = CalibrateCatalogConfig
Expand All @@ -19,10 +26,18 @@ def _makeArgumentParser(cls):

def run(self, dataRef):
catalog = dataRef.get("src", immediate=True)
calexp_md = dataRef.get('calexp_md', immediate=True)
# Check if we are looking at HSC stack outputs
hscRun = mosaicUtils.checkHscStack(calexp_md)
# Set the aliap map for the source catalog
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias

if self.config.srcSchemaMap is not None and hscRun is not None:
aliasMap = catalog.schema.getAliasMap()
for lsstName, otherName in self.config.srcSchemaMap.iteritems():
aliasMap.set(lsstName, otherName)
results = applyMosaicResultsCatalog(dataRef, catalog)
catalog = results.catalog
if self.config.doApplyCalib:
catalog = applyCalib(catalog, results.ffp.calib)
catalog = applyCalib(catalog, results.ffp.calib, hscRun=hscRun)
dataRef.put(catalog, "calibrated_src")

def writeConfig(self, *args, **kwargs):
Expand Down
59 changes: 38 additions & 21 deletions python/lsst/meas/mosaic/checkMosaicTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
from lsst.meas.mosaic.mosaicTask import MosaicConfig
from lsst.meas.mosaic.mosaicTask import MosaicRunner
import lsst.meas.mosaic.mosaicLib as measMosaic
import lsst.meas.astrom.astrom as measAstrom
import lsst.meas.algorithms as measAlg
import lsst.meas.astrom as measAstrom
import lsst.afw.image as afwImage
import lsst.afw.geom as afwGeom
import lsst.afw.table as afwTable

from lsst.meas.photocal.colorterms import ColortermLibraryConfig
from lsst.pipe.tasks.colorterms import ColortermLibrary

class CheckMosaicConfig(MosaicConfig):
maxMag = pexConfig.Field(
Expand Down Expand Up @@ -424,7 +425,7 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):

sourceSet = measMosaic.SourceGroup()
matchList = measMosaic.SourceMatchGroup()
astrom = measAstrom.Astrometry(self.config.astrom)
astrom = measAstrom.ANetBasicAstrometryTask(self.config.astrom)
ssVisit = dict()
mlVisit = dict()
dataRefListUsed = list()
Expand Down Expand Up @@ -467,25 +468,41 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):
flags=afwTable.SOURCE_IO_NO_FOOTPRINTS,
immediate=True)
packedMatches = dataRef.get('icMatch')
matches = astrom.joinMatchListWithCatalog(packedMatches, icSrces, True)
matches = astrom.joinMatchListWithCatalog(packedMatches, icSrces)

matches = [m for m in matches if m.first != None]
if ct != None and len(matches) != 0:

if matches:
refSchema = matches[0].first.schema
key_p = refSchema.find(ct.primary).key
key_s = refSchema.find(ct.secondary).key
key_f = refSchema.find("flux").key
for m in matches:
refFlux1 = m.first.get(key_p)
refFlux2 = m.first.get(key_s)
refMag1 = -2.5*math.log10(refFlux1)
refMag2 = -2.5*math.log10(refFlux2)
if ct:
# Add a "flux" field to the match records which contains the
# colorterm-corrected reference flux. The field name is hard-coded in
# lsst::meas::mosaic::Source.
mapper = afwTable.SchemaMapper(refSchema)
for key, field in refSchema:
mapper.addMapping(key)
key_f = mapper.editOutputSchema().addField("flux", type=float, doc="Reference flux")
table = afwTable.SimpleTable.make(mapper.getOutputSchema())
table.preallocate(len(matches))
for match in matches:
newMatch = table.makeRecord()
newMatch.assign(match.first, mapper)
match.first = newMatch

key_p = refSchema.find(refSchema.join(ct.primary, "flux")).key
key_s = refSchema.find(refSchema.join(ct.secondary, "flux")).key
refFlux1 = numpy.array([m.first.get(key_p) for m in matches])
refFlux2 = numpy.array([m.first.get(key_s) for m in matches])
refMag1 = -2.5*numpy.log10(refFlux1)
refMag2 = -2.5*numpy.log10(refFlux2)
refMag = ct.transformMags(refMag1, refMag2)
refFlux = math.pow(10.0, -0.4*refMag)
if refFlux == refFlux:
m.first.set(key_f, refFlux)
else:
m.first = None
refFlux = numpy.power(10.0, -0.4*refMag)
matches = [setCatFlux(m, f, key_f) for m, f in zip(matches, refFlux) if f == f]
else:
# No colorterm; we can get away with aliasing the reference flux.
refFluxField = measAlg.getRefFluxField(refSchema, filterName)
refSchema.getAliasMap().set("flux", refFluxField)

sources = self.selectStars(sources)
matches = self.selectStars(matches, True)
except Exception, e:
Expand Down Expand Up @@ -528,9 +545,9 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):
self.plotPosAsMag(m0_s, dx_s, dy_s)
self.writeCatalog(allSource, wcsDic, calibDic, ffpDic)

def run(self, camera, butler, dataRefList, debug):
def run(self, camera, butler, tract, dataRefList, debug):

colorterms = ColortermLibraryConfig()
colorterms = ColortermLibrary()
name = os.path.join(os.environ["OBS_SUBARU_DIR"], "config", camera, "colorterms.py")
if os.path.exists(name):
colorterms.load(name)
Expand All @@ -544,7 +561,7 @@ def run(self, camera, butler, dataRefList, debug):
self.log.fatal("There are %d filters in input frames" % len(filters))
return None

ct = colorterms.selectColorTerm(butler.mapper.filters[filters[0]])
ct = colorterms.getColorterm(butler.mapper.filters[filters[0]], self.config.photoCatName)

return self.check(dataRefList, ct, debug)

Expand Down