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

DM-11571 fixes for jointcal/meas_mosaic comparison output #65

Merged
merged 8 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 27 additions & 27 deletions etc/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ AM1:
- level: design
value: 10.0
unit: marcsec
filter_names: [z, r, i, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, with the verify port, this file has gone away, so we will need to port any changes here to verify_metrics. That doesn't need to be done here, but we will need to do it at some point.

- level: minimum
value: 20.0
unit: marcsec
filter_names: [z, r, i, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
- level: stretch
value: 5.0
unit: marcsec
filter_names: [z, r, i, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]

AM2:
reference:
Expand All @@ -150,15 +150,15 @@ AM2:
- level: design
value: 10.0
unit: marcsec
filter_names: [z, r, i, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
- level: minimum
value: 20.0
unit: marcsec
filter_names: [z, r, i, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
- level: stretch
value: 5.0
unit: marcsec
filter_names: [z, r, i, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]

AM3:
reference:
Expand All @@ -176,15 +176,15 @@ AM3:
- level: design
value: 15.0
unit: marcsec
filter_names: [r, i, z, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
- level: minimum
value: 30.0
unit: marcsec
filter_names: [r, i, z, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
- level: stretch
value: 10.0
unit: marcsec
filter_names: [r, i, z, HSC-R, HSC-I]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]

AF1:
reference:
Expand All @@ -202,19 +202,19 @@ AF1:
- level: design
value: 10.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD1
- level: minimum
value: 20.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD1
- level: stretch
value: 5.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD1

Expand All @@ -234,19 +234,19 @@ AF2:
- level: design
value: 10.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD2
- level: minimum
value: 20.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD2
- level: stretch
value: 5.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD2

Expand All @@ -266,19 +266,19 @@ AF3:
- level: design
value: 10.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD3
- level: minimum
value: 20.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD3
- level: stretch
value: 5.0
unit: ''
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AD3

Expand All @@ -298,19 +298,19 @@ AD1:
- level: design
value: 20.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF1
- level: minimum
value: 40.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF1
- level: stretch
value: 10.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF1

Expand All @@ -330,19 +330,19 @@ AD2:
- level: design
value: 20.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF2
- level: minimum
value: 40.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF2
- level: stretch
value: 10.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF2

Expand All @@ -362,19 +362,19 @@ AD3:
- level: design
value: 30.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF3
- level: minimum
value: 50.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF3
- level: stretch
value: 20.0
unit: milliarcsecond
filter_names: [r, i, z, HSC-R, HSC-I, HSC-Y]
filter_names: [u, g, r, i, z, y, HSC-U, HSC-G, HSC-R, HSC-I, HSC-Z, HSC-Y]
dependencies:
- AF3

Expand Down
12 changes: 11 additions & 1 deletion python/lsst/validate/drp/matchedVisitMetricsTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class MatchedVisitMetricsConfig(Config):
dtype=bool, default=False,
doc="Whether to use jointcal (or meas_mosaic) to calibrate measurements"
)
skipTEx = Field(
dtype=bool, default=False,
doc="Skip TEx calculations (useful for older catalogs that don't have PsfShape measurements)."
)
verbose = Field(
dtype=bool, default=False,
doc="More verbose output during validate calculations."
)


class MatchedVisitMetricsTask(CmdLineTask):
Expand Down Expand Up @@ -120,7 +128,9 @@ def run(self, butler, filterName, output, dataIds):
makeJson=self.config.makeJson,
filterName=filterName,
outputPrefix=outputPrefix,
useJointCal=self.config.useJointCal)
useJointCal=self.config.useJointCal,
skipTEx=self.config.skipTEx,
verbose=self.config.verbose)
if self.config.makePlots:
plot_metrics(job, filterName, outputPrefix=outputPrefix)

Expand Down
48 changes: 25 additions & 23 deletions python/lsst/validate/drp/matchreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import numpy as np
import astropy.units as u
from sqlalchemy.exc import OperationalError

import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
import lsst.daf.persistence as dafPersist
from lsst.afw.table import (SourceCatalog, SchemaMapper, Field,
Expand Down Expand Up @@ -60,6 +60,11 @@ class MatchedMultiVisitDataset(BlobBase):
Radius for matching. Default is 1 arcsecond.
safeSnr : `float`, optional
Minimum median SNR for a match to be considered "safe".
useJointCal : bool, optional
Use jointcal/meas_mosaic outputs to calibrate positions and fluxes.
skipTEx : bool, optional
Skip TEx calculations (useful for older catalogs that don't have
PsfShape measurements).
verbose : `bool`, optional
Output additional information on the analysis steps.

Expand Down Expand Up @@ -106,10 +111,11 @@ class MatchedMultiVisitDataset(BlobBase):
name = 'MatchedMultiVisitDataset'

def __init__(self, repo, dataIds, matchRadius=None, safeSnr=50.,
useJointCal=False, verbose=False):
useJointCal=False, skipTEx=False, verbose=False):
BlobBase.__init__(self)

self.verbose = verbose
self.skipTEx = skipTEx
if not matchRadius:
matchRadius = afwGeom.Angle(1, afwGeom.arcseconds)

Expand Down Expand Up @@ -173,6 +179,8 @@ def _loadAndMatchCatalogs(self, repo, dataIds, matchRadius,
calibration.
matchRadius : afwGeom.Angle(), optional
Radius for matching. Default is 1 arcsecond.
useJointCal : bool, optional
Use jointcal/meas_mosaic outputs to calibrate positions and fluxes.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to document skipTEx as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, per your later comment, the argument is going away since we're going to use the class member.


Returns
-------
Expand Down Expand Up @@ -233,23 +241,22 @@ def _loadAndMatchCatalogs(self, repo, dataIds, matchRadius,
except (FitsError, dafPersist.NoResults) as e:
print(e)
print("Could not open photometric calibration for ", vId)
print("Skipping %s " % repr(vId))
print("Skipping this dataId.")
continue
try:
md = butler.get("wcs_md", vId)
wcs = afwImage.makeWcs(md)
wcs = butler.get("wcs", vId).getWcs()
except (FitsError, dafPersist.NoResults) as e:
print(e)
print("Could not open updated WCS for ", vId)
print("Skipping %s " % repr(vId))
print("Skipping this dataId.")
continue
else:
try:
calexpMetadata = butler.get("calexp_md", vId)
calib = butler.get("calexp_calib", vId)
except (FitsError, dafPersist.NoResults) as e:
print(e)
print("Could not open calibrated image file for ", vId)
print("Skipping %s " % repr(vId))
print("Skipping this dataId.")
continue
except TypeError as te:
# DECam images that haven't been properly reformatted
Expand All @@ -262,24 +269,18 @@ def _loadAndMatchCatalogs(self, repo, dataIds, matchRadius,
# See, e.g., DM-2957 for details.
print(te)
print("Calibration image header information malformed.")
print("Skipping %s " % repr(vId))
print("Skipping this dataId.")
continue

calib = afwImage.Calib(calexpMetadata)

# We don't want to put this above the first "if useJointCal block"
# because we need to use the first `butler.get` above to quickly
# catch data IDs with no usable outputs.
try:
# HSC supports these flags, which dramatically improve I/O
# performance; support for other cameras is DM-6927.
# performance; TODO: support for other cameras is DM-6927.
oldSrc = butler.get('src', vId, flags=SOURCE_IO_NO_FOOTPRINTS)
calexp = butler.get("calexp", vId, flags=SOURCE_IO_NO_FOOTPRINTS)
except:
except OperationalError:
oldSrc = butler.get('src', vId)
calexp = butler.get("calexp", vId)

psf = calexp.getPsf()

print(len(oldSrc), "sources in ccd %s visit %s" %
(vId[ccdKeyName], vId["visit"]))
Expand All @@ -301,12 +302,13 @@ def _loadAndMatchCatalogs(self, repo, dataIds, matchRadius,
tmpCat['base_PsfFlux_mag'][:] = _[0]
tmpCat['base_PsfFlux_magErr'][:] = _[1]

_, psf_e1, psf_e2 = ellipticity_from_cat(oldSrc, slot_shape='slot_PsfShape')
_, star_e1, star_e2 = ellipticity_from_cat(oldSrc, slot_shape='slot_Shape')
tmpCat['e1'][:] = star_e1
tmpCat['e2'][:] = star_e2
tmpCat['psf_e1'][:] = psf_e1
tmpCat['psf_e2'][:] = psf_e2
if not self.skipTEx:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps I'm missing something, but you are accessing the skipTEx attribute on self which is set in the constructor. However, it is also legal to send a skipTEx parameter to this method. The two don't seem to be reconciled, which seems dangerous. I think you should just use either the attribute on self or pass it through.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Good catch. Since this is an internal method that's called by __init__, I'm just going to use the class member and cleanup the method signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

_, psf_e1, psf_e2 = ellipticity_from_cat(oldSrc, slot_shape='slot_PsfShape')
_, star_e1, star_e2 = ellipticity_from_cat(oldSrc, slot_shape='slot_Shape')
tmpCat['e1'][:] = star_e1
tmpCat['e2'][:] = star_e2
tmpCat['psf_e1'][:] = psf_e1
tmpCat['psf_e2'][:] = psf_e2

srcVis.extend(tmpCat, False)
mmatch.add(catalog=tmpCat, dataId=vId)
Expand Down
5 changes: 5 additions & 0 deletions python/lsst/validate/drp/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def plotAstrometryErrorModel(dataset, astromModel, outputPrefix=''):
plotPath = makeFilename(outputPrefix, pathFormat, name="check_astrometry", ext=ext)
plt.savefig(plotPath, format=ext)
plt.close(fig)
print("Wrote plot:", plotPath)


def plotAstromErrModelFit(snr, dist, model,
Expand Down Expand Up @@ -413,6 +414,7 @@ def plotPhotometryErrorModel(dataset, photomModel,
plotPath = makeFilename(outputPrefix, pathFormat, name="check_photometry", ext=ext)
plt.savefig(plotPath, format=ext)
plt.close(fig)
print("Wrote plot:", plotPath)


def plotPA1(pa1, outputPrefix=""):
Expand Down Expand Up @@ -471,6 +473,7 @@ def plotPA1(pa1, outputPrefix=""):
plotPath = makeFilename(outputPrefix, pathFormat, name="PA1", ext=ext)
plt.savefig(plotPath, format=ext)
plt.close(fig)
print("Wrote plot:", plotPath)


def plotAMx(amx, afx, filterName, amxSpecName='design', outputPrefix=""):
Expand Down Expand Up @@ -566,6 +569,7 @@ def plotAMx(amx, afx, filterName, amxSpecName='design', outputPrefix=""):
plt.tight_layout() # fix padding
plt.savefig(plotPath, dpi=300, format=ext)
plt.close(fig)
print("Wrote plot:", plotPath)


def plotTEx(tex, filterName, texSpecName='design', outputPrefix=''):
Expand Down Expand Up @@ -646,3 +650,4 @@ def plotTEx(tex, filterName, texSpecName='design', outputPrefix=''):
plt.tight_layout() # fix padding
plt.savefig(plotPath, dpi=300, ext=ext)
plt.close(fig)
print("Wrote plot:", plotPath)