Skip to content

Commit

Permalink
Fix inverse linearity for CRDS and add uri/filename consistency check…
Browse files Browse the repository at this point in the history
…s. (#296)
  • Loading branch information
WilliamJamieson authored Jul 20, 2023
2 parents 8276e6c + 23645e0 commit c46d5a1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Update the steps listed in ``cal_step`` with the ``resample`` step. [#295]

- Fix the URIs for ``inverselinearity`` and add consistency checks for names/uris. [#296]

0.16.0 (2023-06-26)
-------------------

Expand Down
4 changes: 2 additions & 2 deletions src/rad/resources/manifests/datamodels-1.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ tags:
title: Gain reference schema
description: |-
Gain reference schema
- tag_uri: asdf://stsci.edu/datamodels/roman/tags/reference_files/inverse_linearity-1.0.0
schema_uri: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverse_linearity-1.0.0
- tag_uri: asdf://stsci.edu/datamodels/roman/tags/reference_files/inverselinearity-1.0.0
schema_uri: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverselinearity-1.0.0
title: Inverse linearity correction reference schema
description: |-
Inverse linearity correction reference schema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
%YAML 1.1
---
$schema: asdf://stsci.edu/datamodels/roman/schemas/rad_schema-1.0.0
id: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverse_linearity-1.0.0
id: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverselinearity-1.0.0

title: Inverse linearity correction reference schema

datamodel_name: InverseLinearityRefModel
datamodel_name: InverselinearityRefModel

type: object
properties:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ def test_schema_integration(schema_path):
schema = yaml.safe_load(content)
asdf_content = asdf.get_config().resource_manager[schema["id"]]
assert asdf_content == content


@pytest.mark.parametrize("schema_path", (importlib_resources.files(resources) / "schemas").glob("**/*.yaml"))
def test_schema_filename(schema_path):
"""
Check the filename pattern aligns with the schema ID.
"""
schema = yaml.safe_load(schema_path.read_bytes())
id_suffix = str(schema_path.with_suffix("")).split(str(importlib_resources.files(resources)))[-1]
assert schema["id"].endswith(id_suffix)
26 changes: 18 additions & 8 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
to schemas that exist.
"""
import asdf
import pytest

from .conftest import MANIFEST


def test_manifest_valid(manifest):
Expand All @@ -13,11 +16,18 @@ def test_manifest_valid(manifest):
assert "title" in manifest
assert "description" in manifest

for tag in manifest["tags"]:
# Check that the schema exists:
assert tag["schema_uri"] in asdf.get_config().resource_manager
# These are not required by the manifest schema but we're holding ourselves
# to a higher standard:
assert "title" in tag
assert "description" in tag
assert tag["tag_uri"].startswith("asdf://stsci.edu/datamodels/roman/tags/")

@pytest.mark.parametrize("entry", MANIFEST["tags"])
def test_manifest_entries(entry):
# Check that the schema exists:
assert entry["schema_uri"] in asdf.get_config().resource_manager
# These are not required by the manifest schema but we're holding ourselves
# to a higher standard:
assert "title" in entry
assert "description" in entry

# Check the URIs
assert entry["tag_uri"].startswith("asdf://stsci.edu/datamodels/roman/tags/")
uri_suffix = entry["tag_uri"].split("asdf://stsci.edu/datamodels/roman/tags/")[-1]
assert entry["schema_uri"].endswith(uri_suffix)
assert entry["schema_uri"].startswith("asdf://stsci.edu/datamodels/roman/schemas/")
36 changes: 36 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def ref_file_schema(request):
return yaml.safe_load(asdf.get_config().resource_manager[request.param])


@pytest.fixture(scope="session", params=[entry for entry in MANIFEST["tags"] if "/reference_files/" in entry["schema_uri"]])
def ref_file_uris(request):
return request.param["tag_uri"], request.param["schema_uri"]


@pytest.fixture(scope="session")
def valid_tag_uris(manifest):
uris = {t["tag_uri"] for t in manifest["tags"]}
Expand Down Expand Up @@ -139,6 +144,23 @@ def callback(node):
asdf.treeutil.walk(schema, callback)


def _model_name_from_schema_uri(schema_uri):
schema_name = schema_uri.split("/")[-1].split("-")[0]
class_name = "".join([p.capitalize() for p in schema_name.split("_")])
if schema_uri.startswith("asdf://stsci.edu/datamodels/roman/schemas/reference_files/"):
class_name += "Ref"

if class_name.startswith("Wfi") and "Ref" not in class_name:
class_name = class_name.split("Wfi")[-1]

return f"{class_name}Model"


def test_datamodel_name(schema):
if "datamodel_name" in schema:
assert _model_name_from_schema_uri(schema["id"]) == schema["datamodel_name"]


# Confirm that the optical_element filter in wfi_img_photom.yml matches WFI_OPTICAL_ELEMENTS
def test_matched_optical_element_entries():
phot_table_keys = list(
Expand Down Expand Up @@ -178,3 +200,17 @@ def test_reftype(ref_file_schema):
"""
reftype = _get_reftype(ref_file_schema)
assert is_crds_name(f"roman_wfi_{reftype.lower()}_0000.asdf")


def test_reftype_tag(ref_file_uris):
"""
Check that the URIs match the reftype for a valid CRDS check
"""
tag_uri = ref_file_uris[0]
schema_uri = ref_file_uris[1]

schema = yaml.safe_load(asdf.get_config().resource_manager[schema_uri])
reftype = _get_reftype(schema).lower()

assert asdf.util.uri_match(f"asdf://stsci.edu/datamodels/roman/tags/reference_files/*{reftype}-*", tag_uri)
assert asdf.util.uri_match(f"asdf://stsci.edu/datamodels/roman/schemas/reference_files/*{reftype}-*", schema_uri)

0 comments on commit c46d5a1

Please sign in to comment.