Skip to content

Conversation

@aglavic
Copy link
Collaborator

@aglavic aglavic commented Jul 30, 2025

As pointed out by @andyfaff in #143 it can be hard to validate the Orso header data and find out which attributes are missing/wrong. This adds a check_valid method to each Header derived class that can be used to check a dictionary for correctness and get detailed information on the issues if it is invalid.

The returned class includes a list of any missing or invalid attributes as well as sub-attribute details. with ORSOValidationResult.get_report() the results are summarized so users of the API can quickly fix what is missing.

Examples:

from orsopy.fileio import *
print(
    Person.check_valid({'name': 'Test User', 'affiliacion': 'Test'}).get_report()
)
> Dictionary was invalid for Person!
>    Reasons for classification:
>    User parameters not part of specification
>      affiliacion
>    Required parameters not provided
>      affiliation

print(
    InstrumentSettings.check_valid({
        'incident_angle': {'magnitude': 4.0, 'unit': 'deg'}, 
        'wavelength': {'min': 2.0, 'max': 12.0, 'unit': 12}, 
        'polarization': 'unpolarized'}).get_report()
)
>  Dictionary was invalid for InstrumentSettings!
>    Reasons for classification:
>    Parameters with invalid type or attributes
>      wavelength
>      ORSO parameter wavelength extra information:
>        Dictionary was invalid for ValueRange!
>          Reasons for classification:
>          Parameters with invalid type or attributes

This should work arbitrarily deep, as illustrated by putting the previous result into a DataSource:

Dictionary was invalid for DataSource!
  Reasons for classification:
  Parameters with invalid type or attributes
    measurement
    ORSO parameter measurement extra information:
      Dictionary was invalid for Measurement!
        Reasons for classification:
        Parameters with invalid type or attributes
          instrument_settings
          ORSO parameter instrument_settings extra information:
            Dictionary was invalid for InstrumentSettings!
              Reasons for classification:
              Parameters with invalid type or attributes
                wavelength
                ORSO parameter wavelength extra information:
                  Dictionary was invalid for ValueRange!
                    Reasons for classification:
                    Parameters with invalid type or attributes
                      unit

@aglavic aglavic requested review from andyfaff and arm61 July 30, 2025 16:32
@andyfaff
Copy link
Contributor

We've had the capability of validating against the schema for a while, via fileio.base._read_header_data. I guess this adds validation to each type of Header?

@aglavic
Copy link
Collaborator Author

aglavic commented Aug 20, 2025

Yes, this is the idea and also to have better feedback. There also was no public API for that header validation and it did not seem to work in all cases that I tried using the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants