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-40652: Raise error when data is insufficient #38

Merged
merged 1 commit into from Dec 9, 2023

Conversation

cmsaunders
Copy link
Collaborator

No description provided.

@@ -436,6 +436,11 @@ def run(
``outputCatalog`` : `pyarrow.Table`
Catalog with fit residuals of all sources used.
"""
if (len(inputVisitSummaries) == 1) and (self.config.deviceModel and self.config.exposureModel):
raise RuntimeError(
"More than one exposure is necessary to break the degeneracy between the"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"More than one exposure is necessary to break the degeneracy between the"
"More than one exposure is necessary to break the degeneracy between the "

if (len(inputVisitSummaries) == 1) and (self.config.deviceModel and self.config.exposureModel):
raise RuntimeError(
"More than one exposure is necessary to break the degeneracy between the"
" device model and the exposure model."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
" device model and the exposure model."
"device model and the exposure model."

@@ -436,6 +436,11 @@ def run(
``outputCatalog`` : `pyarrow.Table`
Catalog with fit residuals of all sources used.
"""
if (len(inputVisitSummaries) == 1) and (self.config.deviceModel and self.config.exposureModel):
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, I was thinking about self.config.deviceModel and self.config.exposureModel going together, but I realize it's logically the same without parentheses.

# free parameters in the per-visit mapping. Set minFitExposures to be
# the number of free parameters, so that visits with fewer visits are
# dropped.
nCoeffVisitModel = int(((2 * self.config.exposurePolyOrder + 3) ** 2 - 1) / 8)
Copy link
Member

Choose a reason for hiding this comment

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

Could you briefly comment on how this calculation comes about? Even better would be to make this a utility function and comment it as a docstring, since you use this calculation at least twice in this code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I decided to make utility functions for this and for the inverse operation.

visitMap = wcsf.mapCollection.orderAtoms(f"{visit}")[0]
visitMapType = wcsf.mapCollection.getMapType(visitMap)
if (visitMap not in mapParams) and (visitMapType != "Identity"):
self.log.warning(f"Visit {visit} was dropped because of an insufficient number of sources.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.log.warning(f"Visit {visit} was dropped because of an insufficient number of sources.")
self.log.warning("Visit %d was dropped because of an insufficient number of sources.", visit)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you explain this suggestion? Is there an issue with f-strings in logging, or are you otherwise concerned about formatting of visit?

Copy link
Member

Choose a reason for hiding this comment

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

f-strings in loggers are frowned upon and non-standard where deferred formatting is the norm. For warnings it doesn't really matter because we can be very sure that the warning will always be issued (whereas for debugs you definitely don't want to use f-strings).

Copy link
Member

Choose a reason for hiding this comment

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

What Tim said.

@@ -948,6 +962,47 @@ class `wcsfit.FoFClass`, associating them into matches as you go.

return sourceIndices, columns

def _check_degeneracies(self, associations, extensionInfo):
Copy link
Member

Choose a reason for hiding this comment

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

It looks like you could decorate it as a staticmethod as it doesn't use self in the body.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does use a config parameter actually, so I need self.

if unconstrainedDetectors:
raise RuntimeError(
"The model is not constrained. The following detectors do not have enough "
f"sources ({nCoeffDetectorModel} required): " + ", ".join(unconstrainedDetectors)
Copy link
Member

Choose a reason for hiding this comment

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

Because this is within parenthesis, you could drop the + and the strings would concatenate anyway.

@cmsaunders cmsaunders force-pushed the tickets/DM-40652 branch 2 times, most recently from 84cb7b3 to 23368fb Compare December 8, 2023 20:40
nCoeffs : `int`
Number of coefficients for the polynomial in question.
"""
nCoeffs = int(((2 * degree + 3) ** 2 - 1) / 8)
Copy link
Member

Choose a reason for hiding this comment

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

This formula wasn't obvious but makes sense now after reading the docstring. Why not just (degree+2)*(degree+1)/2 though? It doesn't seem like the simplest form of the quantity you want to compute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I don't remember why I didn't simplify this when I first implemented it. I think my idea was to preserve the structure of the formula, but I don't think it's necessary.

@cmsaunders cmsaunders merged commit 1f21874 into main Dec 9, 2023
3 checks passed
@cmsaunders cmsaunders deleted the tickets/DM-40652 branch December 9, 2023 01:43
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.

None yet

3 participants