Skip to content

Commit

Permalink
don't raise a warning for identical units
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 10, 2025
1 parent ff61ead commit 3499fdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions py/desiutil/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ def annotate_fits(filename, extension, output, units=None, comments=None,
for colname in column_index:
ttype = f"TTYPE{column_index[colname]:d}"
if colname in column_comments:
if hdu.header.comments[ttype].strip():
if hdu.header.comments[ttype].strip() and column_comments[colname] != hdu.header.comments[ttype].strip():
log.warning("Overriding comment on column '%s': '%s' -> '%s'.",
colname, hdu.header.comments[ttype].strip(), column_comments[colname])
hdu.header[ttype] = (colname, column_comments[colname])
log.debug('Set %s comment to "%s"', colname, column_comments[colname])
if colname in column_units:
tunit = f"TUNIT{column_index[colname]:d}"
if tunit in hdu.header and hdu.header[tunit].strip():
if tunit in hdu.header and hdu.header[tunit].strip() and column_units[colname] != hdu.header[tunit].strip():
log.warning("Overriding units for column '%s': '%s' -> '%s'.",
colname, hdu.header[tunit].strip(), column_units[colname])
hdu.header[tunit] = (column_units[colname], colname+' units')
Expand Down
10 changes: 10 additions & 0 deletions py/desiutil/test/test_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ def test_annotate_fits(self, mock_log):
self.assertEqual(new_hdulist[2].header['TUNIT2'], 'deg')
self.assertEqual(new_hdulist[2].header['TUNIT3'], 'deg')
new_hdulist_name = os.path.join(self.TMP, 'test_annotate_update2.fits')
#
# Changing the unit to the same unit should not raise a warning.
#
new_hdulist = annotate_fits(self.fits_file, 2, new_hdulist_name, units={'MAG': 'mag'}, overwrite=True)
self.assertIn('TUNIT4', new_hdulist[2].header)
self.assertEqual(new_hdulist[2].header['TUNIT4'], 'mag')
mock_log().warning.assert_not_called()
#
# Actually change the units.
#
new_hdulist = annotate_fits(self.fits_file, 2, new_hdulist_name, units={'MAG': 'nJy'}, overwrite=True)
self.assertIn('TUNIT4', new_hdulist[2].header)
self.assertEqual(new_hdulist[2].header['TUNIT4'], 'nJy')
Expand Down

0 comments on commit 3499fdf

Please sign in to comment.