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

try fibermap header if (TARGT)RA isn't in primary header #934

Merged
merged 2 commits into from Mar 27, 2020
Merged

Conversation

sbailey
Copy link
Contributor

@sbailey sbailey commented Mar 26, 2020

This PR fixes the crash in PR #896 by trying the fibermap header if it can't find RA or TARGTRA in the primary HDU (as was the case in early commissioning data) for the purposes of barycentric corrections.

Tested on the command originally reported in #896 (20200122/00043028), and also on 20200315/00055611 (new data)

@sbailey sbailey requested a review from akremin March 26, 2020 23:51
@sbailey sbailey added this to In progress in Data Release 20.4 via automation Mar 26, 2020
Copy link
Member

@akremin akremin left a comment

Choose a reason for hiding this comment

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

I won't make this a formal "request changes" as this is a perfectly good solution. But I am interested in hearing a bit more rationale for whatever you decide on.

@@ -170,7 +170,12 @@ def main(args):
dw = 0.7

if args.barycentric_correction :
barycentric_correction_factor = barycentric_correction_multiplicative_factor(img.meta)
try:
Copy link
Member

@akremin akremin Mar 27, 2020

Choose a reason for hiding this comment

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

Personally I'd prefer an "if" statement here. If the key is in img.meta use that, else use fibermap.meta. Better yet, check both with if-elif-else where we return a more informative error in the else case where neither has it.

Try's are great for robustness but since we know the failure point here I think it's more efficient/readable to address it directly.

In thinking more this was probably done because we'd want to check for both RA and DEC keywords as well as the TARGETXX varieties, and the function could possibly fail because of other keywords (which this try statement would catch).

Even so, I think I lean toward an "if" statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally used try/except because it was fewer lines of code, but agree that if/else is clearer code, and that is valuable. I switched it.

@@ -334,7 +339,12 @@ def main_mpi(args, comm=None, timing=None):
dw = 0.7

if args.barycentric_correction :
barycentric_correction_factor = barycentric_correction_multiplicative_factor(img.meta)
try:
Copy link
Member

Choose a reason for hiding this comment

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

The same comment as above. Assuming these are the only two places this is done I think it's fine that they're copy-pasted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a ton of replicated code in extract.main vs. extract.main_mpi which is indeed a maintenance risk; issue #827 is about resolving that overall but in the meantime we continue to accrete more copied code. Related: I'm working with @lastephey and @ziyaointl on an extraction refactor to make it easier to port to GPUs, and that's where we'll reconcile this MPI vs. non-MPI code duplication.

Copy link
Member

@akremin akremin left a comment

Choose a reason for hiding this comment

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

This looks good. I think it's ready to merge

@akremin akremin merged commit 8faf2de into master Mar 27, 2020
Data Release 20.4 automation moved this from In progress to Done Mar 27, 2020
@akremin akremin deleted the barycorr branch March 27, 2020 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants