Skip to content

Commit

Permalink
handle ndim>2 in maker utils
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Feb 22, 2024
1 parent 6f464a7 commit cdbaa77
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/roman_datamodels/maker_utils/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ def mk_source_catalog(*, filepath=None, **kwargs):
source_catalog = stnode.SourceCatalog()

source_catalog["source_catalog"] = kwargs.get("source_catalog", Table([range(3), range(3)], names=["a", "b"]))
source_catalog["meta"] = mk_common_meta()
source_catalog["meta"].update(kwargs.get("meta", dict(segmentation_map='')))

return save_node(source_catalog, filepath=filepath)

Expand All @@ -470,11 +468,17 @@ def mk_segmentation_map(*, filepath=None, shape=(4096, 4096), **kwargs):
-------
roman_datamodels.stnode.SegmentationMap
"""
segmentation_map = stnode.SegmentationMap()
if len(shape) > 2:
shape = shape[1:3]

warnings.warn(
f"{MESSAGE} assuming the first entry is n_groups followed by y, x. The remaining is thrown out!", UserWarning
)

segmentation_map = stnode.SegmentationMap()
segmentation_map["data"] = kwargs.get("data", np.zeros(shape, dtype=np.uint32))
segmentation_map["meta"] = mk_common_meta()
segmentation_map["meta"].update(kwargs.get("meta", dict(filename='')))
segmentation_map["meta"].update(kwargs.get("meta", {}))

return save_node(segmentation_map, filepath=filepath)

7 changes: 7 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,13 @@ def test_make_source_catalog():
assert isinstance(source_catalog_model.source_catalog, Table)


def test_make_segmentation_map():
segmentation_map = utils.mk_segmentation_map()
segmentation_map_model = datamodels.SegmentationMapModel(segmentation_map)

assert isinstance(segmentation_map_model.data, np.ndarray)


def test_datamodel_info_search(capsys):
wfi_science_raw = utils.mk_level1_science_raw(shape=(2, 8, 8))
af = asdf.AsdfFile()
Expand Down
3 changes: 0 additions & 3 deletions tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ def test_node_round_trip(tmp_path, node_class):
@pytest.mark.filterwarnings("ignore:This function assumes shape is 2D")
@pytest.mark.filterwarnings("ignore:Input shape must be 5D")
def test_opening_model(tmp_path, node_class):
if node_class == stnode.SourceCatalog:
pytest.xfail("SourceCatalog does not have a meta attribute yet")

file_path = tmp_path / "test.asdf"

# Create a node and write it to disk
Expand Down

0 comments on commit cdbaa77

Please sign in to comment.