Skip to content

Commit

Permalink
adds processing provenance to an HDU table
Browse files Browse the repository at this point in the history
  • Loading branch information
lowderchris committed Nov 26, 2024
1 parent f2716ec commit a9a0d23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions punchbowl/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ def write_ndcube_to_fits(cube: NDCube,
header=full_header,
name="Uncertainty array",
quantize_level=uncertainty_quantize_level)
hdu_provenance = fits.BInTableHDU.from_columns(fits.ColDefs([fits.Column(
name="provenance", format="A40", array=np.char.array(cube.meta.provenance))]))

hdul = cube.wcs.to_fits()
hdul[0] = fits.PrimaryHDU()
hdul.insert(1, hdu_data)
hdul.insert(2, hdu_uncertainty)
hdul.insert(3, hdu_provenance)
hdul.writeto(filename, overwrite=overwrite, checksum=True)
hdul.close()
if write_hash:
Expand Down Expand Up @@ -162,6 +165,7 @@ def load_ndcube_from_fits(path: str | Path, key: str = " ") -> NDCube:
header["CHECKSUM"] = ""
header["DATASUM"] = ""
meta = NormalizedMetadata.from_fits_header(header)
meta.provenance = hdul[-1].data["provenance"]
wcs = WCS(header, hdul, key=key)
unit = u.ct

Expand Down
9 changes: 9 additions & 0 deletions punchbowl/data/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def __init__(
self,
contents: t.OrderedDict[str, t.OrderedDict[str, MetaField]],
history: History | None = None,
provenance: list[str] | None = None,
wcs_section_name: str = "World Coordinate System",
) -> None:
"""
Expand All @@ -219,12 +220,15 @@ def __init__(
contents of the meta information
history: History
history contents for this meta field
provenance: list[str]
list of files used in the generation of this product
wcs_section_name: str
the section title for the WCS section to specially fill
"""
self._contents = contents
self._history = history if history is not None else History()
self._provenance = provenance if history is not None else []
self._wcs_section_name = wcs_section_name

def __iter__(self) -> t.Iterator[t.Any]:
Expand Down Expand Up @@ -616,6 +620,11 @@ def history(self) -> History:
def history(self, history: History) -> None:
self._history = history

@property
def provenance(self) -> list[str]:
"""Returns file provenance."""
return self._provenance

@staticmethod
def _validate_key_is_str(key: str) -> None:
"""
Expand Down

0 comments on commit a9a0d23

Please sign in to comment.