Skip to content

Commit

Permalink
remove assignment validation from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Nov 18, 2024
1 parent 2489046 commit a4bf38a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 51 deletions.
3 changes: 2 additions & 1 deletion docs/roman_datamodels/datamodels/general_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ ref_optical_element-1.0.0::
...

If one tries to modify the datamodel contents with a value inconsistent with
what a schema requires, validation will raise an error.
what a schema requires, validation will raise an error when the datamodel is
validated.

Level 1 Example
...............
Expand Down
44 changes: 2 additions & 42 deletions docs/roman_datamodels/datamodels/stnode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ The specific stnode objects will be subclasses of the
`~roman_datamodels.stnode.TaggedObjectNode` or
`~roman_datamodels.stnode.TaggedListNode` classes. These classes are extensions
of the `~roman_datamodels.stnode.DNode` and `~roman_datamodels.stnode.LNode`
classes which have extensions to handle looking up the schema information for on
the fly data validation. In particular, they will track the ``tag`` information
classes which have extensions to handle looking up the schema information.
In particular, they will track the ``tag`` information
contained within the manifest from RAD.

These "tagged-nodes" are then turned into specific stnode objects via the
Expand Down Expand Up @@ -126,46 +126,6 @@ is reorganized, then scalar node concept can be removed from the codebase.
dictionary.


Validation
----------

The stnode objects are designed to attempt to validate the data they contain or
have set in them against the schema information in RAD. This is typically done
on the fly when the data is set via the ``.`` interface; however, ASDF by
default will validate the data stored in the node against its schema during both
serialization and de-serialization.

In order to avoid the overhead of re-validating all of the data in a node when
one thing is updated (this can induce a lot of overhead), the stnode objects
will attempt to parse a given "tagged-node's" schema down so that it is only
validating the field being updated. It performs the validation by attempting to
construct in-memory an ASDF-schema representing just the portion of the schema
it needs to validate just that single field against. It then passes that schema
into the ASDF validation routines to check the data. Unfortunately, this is not
a perfect process nor is it particularly robust. It is possible for a schema to
have fields that the parse down process cannot handle, or use JSON-schema
constructs which the parser is unaware of. In these cases, validation might
raise an error or pass invalid data.

.. warning::

The only validation process that is guaranteed to validate the data
correctly is the full ASDF validation process. This is because ASDF will be
using the full schema and be checking everything against it. The on-the-fly
validation's parsing may create unreliable validation scenarios.

.. note::

In order to avoid the "on-the-fly" validation process, one can set values in
a node/datamodel via the dictionary, ``[]``, interface instead of the ``.``
interface. This is because the ``[]`` purposely bypasses the on-the-fly
validation process. Thus in general it is recommend that one uses the ``.``
interface for setting values in a node/datamodel, and only using the ``[]``
when one needs to store temporary invalid data in a node/datamodel. The use
``[]`` runs the risk of placing the node/datamodel in a state where it
cannot be serialized to ASDF.


ASDF
----

Expand Down
32 changes: 24 additions & 8 deletions docs/roman_datamodels/datamodels/using_datamodels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ page::
print(dm.meta.exposure.start_time_mjd)
60000.0

# Try to assign invalid type
# Assign invalid type

>>> d.meta.exposure.start_time_mjd = "hello"
>>> d.validate()

# Last part of resulting traceback

Expand Down Expand Up @@ -72,13 +73,28 @@ page::

# Try to assign wrong kind of node

>>> dm.meta.observation = dm.meta.exposure
Failed validating 'tag' in schema:
{'$schema': 'http://stsci.edu/schemas/asdf-schema/0.1.0/asdf-schema',
'tag': 'asdf://stsci.edu/datamodels/roman/tags/observation-1.0.0'}

On instance:
{'groupgap': 0, 'ma_table_name': 'High Latitude Spec. Survey', 'ma_table_number': 1, 'nframes': 8, 'ngroups': 6, 'p_exptype': 'WFI_IMAGE|', 'type': 'WFI_IMAGE'}
>>> dm.meta.exposure = dm.meta.observation
>>> dm.validate()

ValidationError: mismatched tags, wanted 'asdf://stsci.edu/datamodels/roman/tags/exposure-1.0.0', got 'asdf://stsci.edu/datamodels/roman/tags/observation-1.0.0'

Failed validating 'tag' in schema['properties']['meta']['allOf'][0]['allOf'][1]['properties']['exposure']:
{'tag': 'asdf://stsci.edu/datamodels/roman/tags/exposure-1.0.0',
'title': 'Exposure Information'}

On instance['meta']['exposure']:
{'execution_plan': 1,
'exposure': 1,
'observation': 1,
'observation_id': '?',
'pass': 1,
'program': 1,
'segment': 1,
'visit': 1,
'visit_file_activity': '01',
'visit_file_group': 1,
'visit_file_sequence': 1,
'visit_id': '?'}

# Show and then change pixel value in data

Expand Down

0 comments on commit a4bf38a

Please sign in to comment.