-
Notifications
You must be signed in to change notification settings - Fork 12
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-39842: Convert MeasureApCorr to new exceptions #364
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,16 +153,18 @@ def testTooFewSources(self): | |
""" If there are too few sources, check that an exception is raised.""" | ||
# Create an empty catalog with no sources to process. | ||
catalog = afwTable.SourceCatalog(self.schema) | ||
with self.assertLogs(level=logging.WARNING) as cm: | ||
with self.assertRaisesRegex(measureApCorr.MeasureApCorrError, "failed on required algorithm"): | ||
self.meas_apCorr_task.run(catalog=catalog, exposure=self.exposure) | ||
self.assertIn("Unable to measure aperture correction for required algorithm", cm.output[0]) | ||
with self.assertRaisesRegex(measureApCorr.MeasureApCorrError, | ||
"Unable to measure aperture correction for 'test1Ap'"): | ||
self.meas_apCorr_task.run(catalog=catalog, exposure=self.exposure) | ||
|
||
# We now try again after declaring that the aperture correction is | ||
# allowed to fail. This should run cleanly without raising an exception. | ||
# allowed to fail. This should run without raising an exception, but | ||
# will log a warning. | ||
Comment on lines
160
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a really nice example of the utility of this new exception handling option! However, it's not clear to me how a user would set this at runtime, do you have an example for how to do that available somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is specifically for the aperture correction algorithm: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I know this is a specific situation where you now use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, |
||
for name in self.names: | ||
self.meas_apCorr_task.config.allowFailure.append(name + self.apNameStr) | ||
self.meas_apCorr_task.run(catalog=catalog, exposure=self.exposure) | ||
with self.assertLogs(level=logging.WARNING) as cm: | ||
self.meas_apCorr_task.run(catalog=catalog, exposure=self.exposure) | ||
self.assertIn("Unable to measure aperture correction for 'test1Ap'", cm.output[0]) | ||
|
||
def testSourceNotUsed(self): | ||
""" Check that a source outside the bounding box is flagged as not used (False).""" | ||
|
@@ -247,10 +249,9 @@ def testTooFewSourcesAfterFiltering(self): | |
nameAp = name + self.apNameStr | ||
sourceCat[nameAp + "_instFlux"][0] = 100.0 | ||
|
||
with self.assertLogs(level=logging.WARNING) as cm: | ||
with self.assertRaisesRegex(measureApCorr.MeasureApCorrError, "Aperture correction failed"): | ||
self.meas_apCorr_task.run(catalog=sourceCat, exposure=self.exposure) | ||
self.assertIn("only 4 sources remain", cm.output[0]) | ||
with self.assertRaisesRegex(measureApCorr.MeasureApCorrError, | ||
f"Unable to measure aperture correction for '{nameAp}'"): | ||
self.meas_apCorr_task.run(catalog=sourceCat, exposure=self.exposure) | ||
|
||
# We now try again after declaring that the aperture correction is | ||
# allowed to fail. This should run cleanly without raising an exception. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
is not None
part needed here? I feel like flake8 has yelled at me in the past for not just doing, e.g.,if thing
instead ofif thing is not None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're thinking of
if thing == None
, which is not good (None
is a singleton). In this case, the check is explicitly "is this None", not any other "falsey" value.