Skip to content

Commit

Permalink
Merge pull request #7454 from wtbarnes/header-helper-units-string
Browse files Browse the repository at this point in the history
Allow units to be passed as strings to header helper
  • Loading branch information
dstansby committed Feb 23, 2024
2 parents 8349d7f + 2ff5d8a commit bf6eb58
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/7454.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow units to be passed to `~sunpy.map.header_helper.make_fitswcs_header` as strings.
2 changes: 1 addition & 1 deletion sunpy/map/header_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _set_instrument_meta(meta_wcs, instrument, telescope, observatory, detector,
if exposure is not None:
meta_wcs['exptime'] = exposure.to_value(u.s)
if unit is not None:
meta_wcs['bunit'] = unit.to_string("fits")
meta_wcs['bunit'] = u.Unit(unit).to_string("fits")

return meta_wcs

Expand Down
7 changes: 7 additions & 0 deletions sunpy/map/tests/test_header_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ def test_quantity_input(map_data, hpc_coord):
assert header['bunit'] == override_unit.to_string('fits')


def test_unit_as_string(map_data, hpc_coord):
# Test that unit can be passed in as a string
map_unit = u.Unit('ct / (pix s)')
header = make_fitswcs_header(map_data, hpc_coord, unit=map_unit.to_string())
assert header['bunit'] == map_unit.to_string('fits')


def test_invalid_inputs(map_data, hcc_coord, hpc_coord_notime, hpc_coord):
# Raise the HCC error
with pytest.raises(ValueError):
Expand Down

0 comments on commit bf6eb58

Please sign in to comment.