Skip to content

Commit

Permalink
wcs->jointcal_wcs and photoCalib->jointcal_photoCalib
Browse files Browse the repository at this point in the history
jointcal_wcs is no longer stored in an empty Exposure!
  • Loading branch information
parejkoj committed Feb 16, 2018
1 parent 746c5c5 commit c26b4d7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
6 changes: 3 additions & 3 deletions bin.src/plot_photoCalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
matplotlib.rcParams['figure.dpi'] = 300


def getValidDataIds(butler, tract, dataset_type='photoCalib'):
def getValidDataIds(butler, tract, dataset_type='jointcal_photoCalib'):
"""Return a list of all dataIds that exist in this butler.
This exists here because the butler doesn't provide this functionality.
Expand Down Expand Up @@ -125,7 +125,7 @@ def makePhotoCalibImages(visit, butler, step=8, chips=[], tract=None,
if verbose:
print('calib ccd %s: %s' % (ccd, calibScaling))

photoCalib = butler.get('photoCalib', dataId=dict(visit=int(visit), ccd=int(ccd), tract=0))
photoCalib = butler.get('jointcal_photoCalib', dataId=dict(visit=int(visit), ccd=int(ccd), tract=0))
if verbose:
print("photoCalib mean ccd %s: %s" % (ccd, photoCalib.getCalibrationMean()))
scaled = photoCalib.computeScaledCalibration()
Expand Down Expand Up @@ -243,7 +243,7 @@ def main():
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("repo", metavar="repo",
help="Directory to butler repository containing `photoCalib` datasets.")
help="Directory to butler repository containing `jointcal_photoCalib` datasets.")
parser.add_argument("--step", default=8, type=int,
help="Steps between samples per image (i.e. larger number = coarser image).")
parser.add_argument("--tract", default=0, type=int,
Expand Down
12 changes: 5 additions & 7 deletions python/lsst/jointcal/jointcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def _iterate_fit(self, fit, model, max_steps, name, whatToFit):

def _write_astrometry_results(self, associations, model, visit_ccd_to_dataRef):
"""
Write the fitted astrometric results to a new 'wcs' dataRef.
Write the fitted astrometric results to a new 'jointcal_wcs' dataRef.
Parameters
----------
Expand All @@ -691,20 +691,18 @@ def _write_astrometry_results(self, associations, model, visit_ccd_to_dataRef):
ccd = ccdImage.ccdId
visit = ccdImage.visit
dataRef = visit_ccd_to_dataRef[(visit, ccd)]
exp = afwImage.ExposureI(0, 0)
self.log.info("Updating WCS for visit: %d, ccd: %d", visit, ccd)
tanSip = model.produceSipWcs(ccdImage)
tanWcs = lsst.jointcal.gtransfoToTanWcs(tanSip, ccdImage.imageFrame, False)
exp.setWcs(tanWcs)
wcs = lsst.jointcal.gtransfoToTanWcs(tanSip, ccdImage.imageFrame, False)
try:
dataRef.put(exp, 'wcs')
dataRef.put(wcs, 'jointcal_wcs')
except pexExceptions.Exception as e:
self.log.fatal('Failed to write updated Wcs: %s', str(e))
raise e

def _write_photometry_results(self, associations, model, visit_ccd_to_dataRef):
"""
Write the fitted photometric results to a new 'photoCalib' dataRef.
Write the fitted photometric results to a new 'jointcal_photoCalib' dataRef.
Parameters
----------
Expand All @@ -725,7 +723,7 @@ def _write_photometry_results(self, associations, model, visit_ccd_to_dataRef):
self.log.info("Updating PhotoCalib for visit: %d, ccd: %d", visit, ccd)
photoCalib = model.toPhotoCalib(ccdImage)
try:
dataRef.put(photoCalib, 'photoCalib')
dataRef.put(photoCalib, 'jointcal_photoCalib')
except pexExceptions.Exception as e:
self.log.fatal('Failed to write updated PhotoCalib: %s', str(e))
raise e
4 changes: 2 additions & 2 deletions python/lsst/jointcal/jointcalCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def applyJointcalResultsExposure(self, dataRef, calexp=None):
if calexp is None:
calexp = dataRef.get("calexp")

wcsCont = dataRef.get("wcs")
calexp.setWcs(wcsCont.getWcs())
wcsCont = dataRef.get("jointcal_wcs")
calexp.setWcs(wcsCont)

return Struct(exposure=calexp)
12 changes: 6 additions & 6 deletions python/lsst/jointcal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def compute(catalogs, photoCalibs):
new_cats = [ref.get('src') for ref in data_refs]
new_wcss = []
if self.do_astrometry:
new_wcss = [ref.get('wcs') for ref in data_refs]
new_wcss = [ref.get('jointcal_wcs') for ref in data_refs]
new_calibs = []
if self.do_photometry:
new_calibs = [ref.get('photoCalib') for ref in data_refs]
new_calibs = [ref.get('jointcal_photoCalib') for ref in data_refs]
if self.do_astrometry:
for wcs, cat in zip(new_wcss, new_cats):
# update in-place the object coordinates based on the new wcs
lsst.afw.table.updateSourceCoords(wcs.getWcs(), cat)
lsst.afw.table.updateSourceCoords(wcs, cat)

self.new_dist, self.new_flux, self.new_ref_flux, self.new_source = compute(new_cats, new_calibs)

Expand Down Expand Up @@ -499,7 +499,7 @@ def plot_all_wcs_deltas(plt, data_refs, visits, old_wcs_list, per_ccd_plot=False
for i, ref in enumerate(data_refs):
md = ref.get('calexp_md')
dims = lsst.afw.image.bboxFromMetadata(md).getDimensions()
plot_wcs(plt, old_wcs_list[i], ref.get('wcs').getWcs(),
plot_wcs(plt, old_wcs_list[i], ref.get('jointcal_wcs'),
dims.getX(), dims.getY(),
center=(md.get('CRVAL1'), md.get('CRVAL2')), name='dataRef %d'%i,
outdir=outdir)
Expand Down Expand Up @@ -555,7 +555,7 @@ def plot_all_wcs_quivers(plt, data_refs, visits, old_wcs_list, name, outdir='.pl
continue
md = ref.get('calexp_md')
dims = lsst.afw.image.bboxFromMetadata(md).getDimensions()
Q = plot_wcs_quivers(ax, old_wcs, ref.get('wcs').getWcs(),
Q = plot_wcs_quivers(ax, old_wcs, ref.get('jointcal_wcs'),
dims.getX(), dims.getY())
# TODO: add CCD bounding boxes to plot once DM-5503 is finished.
# TODO: add a circle for the full focal plane.
Expand Down Expand Up @@ -625,7 +625,7 @@ def plot_wcs_magnitude(plt, data_refs, visits, old_wcs_list, name, outdir='.plot
md = ref.get('calexp_md')
dims = lsst.afw.image.bboxFromMetadata(md).getDimensions()
x1, y1, x2, y2 = make_xy_wcs_grid(dims.getX(), dims.getY(),
old_wcs, ref.get('wcs').getWcs())
old_wcs, ref.get('jointcal_wcs'))
uu = x2 - x1
vv = y2 - y1
extent = (x1[0, 0], x1[-1, -1], y1[0, 0], y1[-1, -1])
Expand Down
7 changes: 3 additions & 4 deletions tests/test_jointcal_hsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def testJointcalTask_2_visits_no_astrometry(self):

for data_ref in data_refs:
with self.assertRaises(lsst.daf.persistence.butlerExceptions.NoResults):
data_ref.get('wcs').getWcs()
data_ref.get('jointcal_wcs')

def testJointcalTask_2_visits_no_photometry(self):
"""Test turning off fitting photometry."""
Expand Down Expand Up @@ -169,9 +169,8 @@ def testJointcalTask_2_visits_no_photometry(self):
self.assertIsNone(rms_result.pa1)

for data_ref in data_refs:
calib = data_ref.get('wcs').getCalib()
blank_calib = lsst.afw.image.Calib()
self.assertEqual(calib, blank_calib)
with self.assertRaises(lsst.daf.persistence.butlerExceptions.NoResults):
data_ref.get('jointcal_photoCalib')

def test_jointcalTask_2_visits_gaia_refcat(self):
self.config = lsst.jointcal.jointcal.JointcalConfig()
Expand Down
9 changes: 4 additions & 5 deletions tests/test_jointcal_lsstSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def testJointcalTask_2_visits_no_astrometry(self):
self.assertLess(rms_result.pa1, pa1)

for data_ref in data_refs:
wcs = data_ref.get('wcs').getWcs()
self.assertIsNone(wcs)
with self.assertRaises(lsst.daf.persistence.butlerExceptions.NoResults):
data_ref.get('jointcal_wcs')

def testJointcalTask_2_visits_no_photometry(self):
"""Test turning off fitting photometry."""
Expand Down Expand Up @@ -193,9 +193,8 @@ def testJointcalTask_2_visits_no_photometry(self):
self.assertIsNone(rms_result.pa1)

for data_ref in data_refs:
calib = data_ref.get('wcs').getCalib()
blank_calib = lsst.afw.image.Calib()
self.assertEqual(calib, blank_calib)
with self.assertRaises(lsst.daf.persistence.butlerExceptions.NoResults):
data_ref.get('jointcal_photoCalib')


class MemoryTester(lsst.utils.tests.MemoryTestCase):
Expand Down

0 comments on commit c26b4d7

Please sign in to comment.