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-46966: Make calibrating pixel values optional in CalibrateImageTask #996

Merged
merged 6 commits into from
Nov 6, 2024

Conversation

TallJimbo
Copy link
Member

No description provided.

@TallJimbo TallJimbo force-pushed the tickets/DM-46966 branch 2 times, most recently from a337ece to 8b8725f Compare October 20, 2024 12:26
default=True,
doc=(
"If True, apply the photometric calibration to the image pixels "
"and background model, and attach an identify PhotoCalib to "
Copy link
Contributor

Choose a reason for hiding this comment

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

Identity not identify

----------
exposure : `lsst.afw.image.Exposure`
Exposure with the target `lsst.afw.image.PhotoCalib` attached.
On return, pixel values will be calibrated and an identify
Copy link
Contributor

Choose a reason for hiding this comment

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

Identity

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

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

Should setting this new config to False also require changing the exposure output name to something other than initial_pvi, so that we can keep track of which ones were calibrated and which not? That's my main worry here, since right now the only way to know is to check whether the attached PhotoCalib is ==1.

doc=(
"If True, apply the photometric calibration to the image pixels "
"and background model, and attach an identity PhotoCalib to "
"the output image to reflect this."
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add something like "Otherwise, leave the image and background uncalibrated and attach the PhotoCalib that would calibrate them."

Comment on lines 589 to 591

This is `None` if ``config.do_calibrate_pixels`` is `False`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a newline allowed here? I've never done that before.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, but it doesn't really do any harm to drop it, and I'll do that since apparently package-docs build is messed up somehow for me locally and I don't want to wade into that.

Comment on lines 914 to 915
background : `lsst.afw.math.BackgroundList`
Background model to convert to nanojansky units in place.
Copy link
Contributor

Choose a reason for hiding this comment

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

You got rid of this parameter, no?


Returns
-------
calibrated_stars : `lsst.afw.table.SourceCatalog`
Star catalog with flux/magnitude columns computed from the fitted
photoCalib.
photoCalib (instFlux columns are retained as well).
matches : `list` [`lsst.afw.table.ReferenceMatch`]
Reference/stars matches used in the fit.
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we need to also add matchMeta to this output list, too. Sorry I'd neglected that.

background : `lsst.afw.math.BackgroundList`
Background model to convert to nanojansky units in place.
"""
photo_calib = exposure.getPhotoCalib()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use exposure.photoCalib below, instead of assigning it? Doesn't really matter, I just don't like proliferating the getX when we don't have to.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because I was going to need this as a local variable anyway later in the method, after exposure.photoCalib has been set to the identity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right, good point.

# TODO investigation: because this takes the photoCalib from the
# exposure, photometric summary values may be "incorrect" (i.e. they
# will reflect the ==1 nJy calibration on the exposure, not the
# applied calibration). This needs to be checked.
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, at least I'd left a TODO to reflect this that can be retired!

self.assertEqual(result.exposure.getPhotoCalib().getCalibrationMean(), 1.0)
else:
self.assertIsNone(result.applied_photo_calib)
photo_calib = result.exposure.getPhotoCalib()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
photo_calib = result.exposure.getPhotoCalib()
photo_calib = result.exposure.photoCalib

# Fit photoCalib should be the applied value if we calibrated
# pixels, not the ==1 one on the exposure.
photo_calib = result.applied_photo_calib
self.assertEqual(result.exposure.getPhotoCalib().getCalibrationMean(), 1.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual(result.exposure.getPhotoCalib().getCalibrationMean(), 1.0)
self.assertEqual(result.exposure.photoCalib.getCalibrationMean(), 1.0)

Comment on lines 240 to 241
"""Test that run() returns reasonable values to be butler put when
do_calibrate_pixels=False.
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this came from my original wording, but this is much clearer.

Suggested change
"""Test that run() returns reasonable values to be butler put when
do_calibrate_pixels=False.
"""Test that run() returns reasonable values when
``do_calibrate_pixels=False``.

@@ -595,6 +616,36 @@ def test_runQuantum_no_optional_outputs(self):
# Restore the one we removed for the next test.
connections[optional] = temp

def test_runQuantum_no_calibrate_pixels(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should note in the test docstring that this is testing that the applied_photo_calib output has been removed.

@TallJimbo
Copy link
Member Author

Should setting this new config to False also require changing the exposure output name to something other than initial_pvi, so that we can keep track of which ones were calibrated and which not? That's my main worry here, since right now the only way to know is to check whether the attached PhotoCalib is ==1.

I'm a little worried about this, but I think putting constraints on the dataset type name might be the kind of fix that's worse than the problem, especially with the names still somewhat in flux.

To get at the root issue, what do you think about setting BUNIT in the FITS header? That's not as nice as some afw object that maps to and from the FITS header, but it's a very established external standard, and arguably all we really need for external users.

@@ -949,6 +949,7 @@ def _apply_photometry(self, exposure, background):
photo_calib.getCalibrationErr(),
bbox=exposure.getBBox())
exposure.setPhotoCalib(identity)
exposure.metadata["BUNIT"] = "nJy"
Copy link
Contributor

Choose a reason for hiding this comment

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

Although I'd much rather have this done within PhotoCalib itself, I guess it's not the worst thing to do it here, even better if we also do it in reprocessVisitImage, and the diffim and coadd code.

@parejkoj
Copy link
Contributor

parejkoj commented Nov 5, 2024

You don't have to do it on this ticket, but please file a ticket about setting BUNIT everywhere we're writing an nJy image, and/or getting PhotoCalib to do it automatically if possible.

@TallJimbo
Copy link
Member Author

TallJimbo commented Nov 5, 2024

As you might have seen, I've already added BUNIT to CalibrateImageTask here, and I've created DM-47408 for the rest.

This resolves a TODO comment wondering whether computing summary stats
after applying the photometric calibration would be a problem, because
it is - at least for DRP, where FGCM depends on some quantities being
in instrumental units.  I'm guessing AP doesn't care, but this needs
to be verified.
@TallJimbo TallJimbo merged commit b51dc15 into main Nov 6, 2024
2 checks passed
@TallJimbo TallJimbo deleted the tickets/DM-46966 branch November 6, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants