Skip to content

Commit

Permalink
Added ignoring ndarrays in L2 Metadata Muxing.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHuwe committed Jan 29, 2024
1 parent 853e477 commit a547611
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/roman_datamodels/datamodels/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from the schema manifest defined by RAD.
"""

import asdf
import numpy as np
from astropy.table import QTable

Expand Down Expand Up @@ -80,24 +81,39 @@ def append_individual_image_meta(self, meta):
# Keys that are themselves Dnodes (subdirectories)
# neccessitate a new table
if isinstance(value, stnode.DNode):
# Collect key names
subtable_cols = meta_dict[key].keys()

# Collect values (lists converted to strings)
# Storage for keys and values
subtable_cols = []
subtable_vals = []
for value in meta_dict[key].values():
if isinstance(value, list):
subtable_vals.append([str(value)])

# Loop over items within the node
for subkey, subvalue in meta_dict[key].items():
# Skip ndarrays
if isinstance(subvalue, asdf.tags.core.ndarray.NDArrayType):
continue

Check warning on line 92 in src/roman_datamodels/datamodels/_datamodels.py

View check run for this annotation

Codecov / codecov/patch

src/roman_datamodels/datamodels/_datamodels.py#L92

Added line #L92 was not covered by tests

subtable_cols.append(subkey)

if isinstance(subvalue, list):
subtable_vals.append([str(subvalue)])
else:
subtable_vals.append([value])
subtable_vals.append([subvalue])

# Skip this Table if it would be empty
if len(subtable_vals) == 0:
continue

Check warning on line 103 in src/roman_datamodels/datamodels/_datamodels.py

View check run for this annotation

Codecov / codecov/patch

src/roman_datamodels/datamodels/_datamodels.py#L103

Added line #L103 was not covered by tests

# Make new Keyword Table if needed
if self.meta.individual_image_meta[key].colnames == ["dummy"]:
if ((key not in self.meta.individual_image_meta) or
(self.meta.individual_image_meta[key].colnames == ["dummy"])):
self.meta.individual_image_meta[key] = QTable(names=subtable_cols, data=subtable_vals)
else:
# Append to existing table
self.meta.individual_image_meta[key].add_row(subtable_vals)
else:
# Skip ndarrays
if isinstance(value.strip(), asdf.tags.core.ndarray.NDArrayType):
continue

Check warning on line 115 in src/roman_datamodels/datamodels/_datamodels.py

View check run for this annotation

Codecov / codecov/patch

src/roman_datamodels/datamodels/_datamodels.py#L115

Added line #L115 was not covered by tests

# Store Basic keyword
basic_cols.append(key)

Expand Down

0 comments on commit a547611

Please sign in to comment.