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
Fix for Astropy Header not behaving dict-like. #53
Conversation
I gave it a shot: astropy/astropy#11729; but in the end I think they are right. The primary difference is that a I've left the check in I think that this test there is an overkill though. I think that a "better" fix for this might be wrap the
but I don't know if you would like that, and like this it's double-checked that when Astropy fixes Headers nothing gets lost in translation either. |
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.
Looks okay. I'd like the main logic for porting dict to Header to be tweaked. If we keep the method name the same the diff will be much smaller. Please make sure Jenkins passes.
# Header can not parse multi-line header keys as lists | ||
for key, val in header.items(): | ||
if isinstance(val, list): | ||
header[key] = "".join(val) |
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.
This can't be right. By definition FITS headers can have multiple entries for the same key so this should convert as multiple repeat keys. If you want to be pedantic about it you should handle blank lines and comments/history explicitly with add_comment
etc methods.
I think it would be more accurate to do something like:
header = Header()
for key, val in header.items():
if key in ("COMMENT", "HISTORY", ""):
# comment cards are not relevant for header translation
continue
values = val if isinstance(val, list) else [val]
for v in values:
header.append((key, val))
I haven't tested this but I hope it gives you the idea.
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.
Thanks, this was very helpful. What we can't do is
Header({"SIMPLE": True, "EXTEND": True, "COMMENT": ["A ", "list"]})
so as long as we unravel the list into individual elements Astropy will handle insertions for us (including special treatment for special keywords like COMMENT, HIERARCH, blank etc.) I just got too stuck into typing the incoming object that I didn't simplify.
d372ffc
to
7ba19c6
Compare
7ba19c6
to
401be08
Compare
d2ad6d9
to
23e2b76
Compare
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.
Thanks for reorganizing. Looks great.
Astropy Header overrides the
in
operator functionality, effect of which is that anValueError
error is raised when comparison value is not anstr
, anint
or atuple
like(str, int)
.This breaks
Translator.is_keyword_defined
functionality for DECam.Added tests explicitly testing behavior of
ObservationInfo
when instantiated fromHeader
objects for all translators.