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

standardize getting NIGHT from raw data headers #1083

Merged
merged 5 commits into from Jan 6, 2021
Merged

standardize getting NIGHT from raw data headers #1083

merged 5 commits into from Jan 6, 2021

Conversation

sbailey
Copy link
Contributor

@sbailey sbailey commented Jan 6, 2021

This PR provides desispec.util.header2night which standardizes how to get the YEARMMDD NIGHT from the raw data fits headers, including handling real-world problems that have come up:

  • NIGHT keyword is completely missing
  • NIGHT keyword is present but blank (i.e. None)
  • NIGHT keyword is present but not an integer (e.g. ' ')
    in these cases it falls back to using DATE-OBS, and then falls back to MJD-OBS, including handling the definition of "NIGHT" rolling over at noon MST (KPNO local time).

dateobs2night and mjd2night are also added as utility functions used by header2night. These might be useful by other code too, but if you are deriving a YEARMMDD from a header, please use header2night(header) to handle the various bogus-header cases.

I have tested this with desi_proc, desi_qproc (via nightwatch), and the unit tests, but I have not updated the desi_daily_proc_manager bookkeeping code.

@akremin please add the necessary fixes to this branch for the nightly processing bookkeeping to work too. Thanks.

#- update header as needed so the correction propagates downstream
try:
night = int(primary_header['NIGHT'])
except (KeyError, ValueError, TypeError):
Copy link
Member

Choose a reason for hiding this comment

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

If this fails, I don't think the variable "night" gets defined using this try statement.

Also, is there a motivation for using try rather than just checking that the key exists and value isn't None? I appreciate that the net result is equivalent, so I'm fine with this.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't use the variable night, I think your function call already has this logic, so it might be redundant as well. You could just call it for everything and it will return without assigning anything of the header keyword is valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point here is to test if the keyword "NIGHT" exists and whether it can be converted into an int, and if not replace it with a valid NIGHT. Although "and if not None" logic would work for the problem last night (20210105), on 20190626 the keyword existed, wasn't None, but was a blank string instead. Rather than try to individually test for each way it could be wrong in the past and future, I opted for try/except for whether you can succeed to hopefully be robust to new and novel ways in which that keyword could be wrong in the future...

You make a good point about night not being set if the try fails. I didn't actually need that variable but the meaningful name implied that maybe you could rely upon it, so I renamed it to tmp instead.

pass

raise ValueError('Unable to derive YEARMMDD from header NIGHT,DATE-OBS,MJD')

Copy link
Member

Choose a reason for hiding this comment

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

Same comment here as before about try's vs if's. Fine either way

@sbailey
Copy link
Contributor Author

sbailey commented Jan 6, 2021

Thanks for updating offline pipeline code. Merging now.

@sbailey sbailey merged commit ccbfce9 into master Jan 6, 2021
@sbailey sbailey deleted the nonight branch January 6, 2021 22:35
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

2 participants