-
Notifications
You must be signed in to change notification settings - Fork 153
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
HDU Header for components #1723
Conversation
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 working on this! This is looking good so far, just a few minor comments. In addition, could you add a test?
@@ -28,6 +44,8 @@ def fits_writer(filename, data, components=None): | |||
else: | |||
mask = None | |||
|
|||
data_header = data.coords.header if hasattr(data.coords, "header") else 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.
A more robust way here would be to check if data.coords
is an instance of glue.core.coordinates. WCSCoordinates
(rather than just checking whether header
exists).
glue/core/data_factories/fits.py
Outdated
@@ -114,14 +114,16 @@ def new_data(suffix=True): | |||
if is_image_hdu(hdu): | |||
shape = hdu.data.shape | |||
coords = coordinates_from_header(hdu.header) | |||
units = hdu.header["BUNIT"] if "BUNIT" in hdu.header else 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.
I think you can write this as hdu.header.get('BUNIT')
as that will return None
if the key doesn't exist.
glue/core/data_factories/fits.py
Outdated
@@ -205,7 +207,9 @@ def casalike_cube(filename, **kwargs): | |||
header = hdulist[0].header | |||
result.coords = coordinates_from_header(header) | |||
for i in range(array.shape[0]): | |||
result.add_component(array[[i]], label='STOKES %i' % i) | |||
units = header["BUNIT"] if "BUNIT" in header else 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.
Same comment as above regarding using .get
expected to come from Data.coords.header by default. | ||
:param component: glue Component | ||
:param header: astropy.io.fits.header.Header | ||
:return: |
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.
I'm currently trying to switch over to the Numpydoc format (the same one used by astropy), so could you update this docstring accordingly?
glue/core/data_factories/fits.py
Outdated
@@ -114,7 +114,7 @@ def new_data(suffix=True): | |||
if is_image_hdu(hdu): | |||
shape = hdu.data.shape | |||
coords = coordinates_from_header(hdu.header) | |||
units = hdu.header["BUNIT"] if "BUNIT" in hdu.header else None | |||
units = hdu.header.get('BUNIT')if "BUNIT" in hdu.header else 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.
Just to clarify, you can just do:
units = hdu.header.get('BUNIT')
and you don't need the if statement part.
Ok thanks. Fixing now |
Before I merge this, could you add a test? Thanks! |
@astrofrog I have added some tests |
@robelgeda - thanks! is the |
It is needed, it is a small 1D fits file with |
This will introduce header files from
Data.coords.header
into theFITS (1 component/HDU)
data exporter. It also adds a functionmake_component_header
that fills in component specific information into the header.