SOLARNETSchema

class solarnet_metadata.schema.SOLARNETSchema(schema_layers: list[Path] | None = None, use_defaults: bool | None = True)[source]

Bases: object

Class representing a schema for SOLARNET requirements for solar observations.

The SOLARNET Keyword information is loaded from YAML (dict-like) files in the following format:

attribute_key:
    attribute_name:
        data_type: <string> # A string representing the data type of the attribute
        default: <Any> | null # A default value for the attribute of the given data type
        description: >
            Include a meaningful description of the attribute and context needed to understand its values.
        human_readable: <string> # A human-readable version of the attribute name
        required: <bool> # Whether the attribute is required
        valid_values: optional[list] # A list of valid values for the attribute in the given data type
conditional_requirements:
    - condition_type: <string> # The type of condition that must be met.
      condition_key: <string> # The keyword that the condition requirement is based on
      condition_value: optional[string] # The value that the condition requirement is based on.
      required_attributes: <list> # A list of keyword names that are required if the condition is met.
Parameters:
  • schema_layers (Optional[list[Path]]) – Absolute file paths to attribute schema files. These schema files are layered on top of one another in a latest-priority ordering. That is, the latest file that modifies a common schema attribute will take precedence over earlier values for a given attribute.

  • use_defaults (Optional[bool]) – Whether or not to load the default attribute schema files. These default schema files contain only the requirements for SOLARNET validation.

Examples

>>> from solarnet_metadata.schema import SOLARNETSchema
>>> schema = SOLARNETSchema(use_defaults=True)
>>> # Get Information about the AUTHOR Attriube
>>> my_info = schema.attribute_info(attribute_name="AUTHOR")
>>> # Get the template for required attributes
>>> attribute_template = schema.attribute_template()

Attributes Summary

attribute_key

(dict) The attribute_key section of the schema.

attribute_schema

(dict) Schema for attributes of the file.

default_attributes

(fits.Header) Default Attributes applied for all Data Files

Methods Summary

attribute_info([attribute_name])

Function to generate an astropy.table.Table of information about each metadata attribute.

attribute_template([primary, obs, ...])

Function to generate a template of required attributes that must be set for a valid data file.

get_comment(attribute_name)

Function to get the comment/description for a given attribute.

get_optional_keywords()

Function to get a list of optional keywords.

get_required_keywords([primary, obs])

Function to get a list of required keywords based on whether the HDU is an observation HDU or not.

load_default_attributes()

Function to load the default attributes for a SOLARNET-compliant data file.

Attributes Documentation

attribute_key

(dict) The attribute_key section of the schema.

attribute_schema

(dict) Schema for attributes of the file.

default_attributes

(fits.Header) Default Attributes applied for all Data Files

Methods Documentation

attribute_info(attribute_name: str | None = None)[source]

Function to generate an astropy.table.Table of information about each metadata attribute. The Table contains all information in the SOLARNET attribute schema including:

  • attribute: (str) The name of the attribute

  • data_type: (str) The data type of the attribute

  • default: (str) The default value used if none is provided

  • description: (str) A description of the attribute and its context

  • human_readable: (str) A human-readable version of the attribute name

  • required: (str) Indicates the requirement level for the attribute. Possible values are:
    • ‘all’: required for all data

    • ‘primary’: required for primary data

    • ‘obs’: required for observational data

    • ‘optional’: not required, optional attribute

  • origin: (str) The origin of the attribute

  • valid_values: (list) A list of valid values for the attribute

  • pattern: (str) A regex pattern that the attribute value must match

Parameters:

attribute_name (str, optional, default None) – The name of the attribute to get specific information for.

Returns:

info – A table of information about the SOLARNET keywords

Return type:

astropy.table.Table

Raises:

KeyError – If attribute_name is not a recognized attribute.:

attribute_template(primary: bool | None = False, obs: bool | None = False, observatory_type: str | None = None, instrument_type: str | None = None) Header[source]

Function to generate a template of required attributes that must be set for a valid data file.

Parameters:
  • primary (bool, optional, default False) – Whether or not the template is being generated for a primary HDU. If True, the template will include attributes required for primary HDUs.]

  • obs (bool, optional, default False) – Whether or not the template is being generated for an observation HDU. If True, the template will include attributes required for observation HDUs.

  • observatory_type (str, optional, default None) – This details whether the observatory is ground-based, earth-orbiting or deep-space and can be used to determine the required metadata attributes for the observatory.

  • instrument_type (str, optional, default None) – This details whether the instrument is Imager or Spectrograph and can be used to determine the required metadata attributes for the instrument.

Returns:

template – A template for required attributes that must be provided.

Return type:

fits.Header

get_comment(attribute_name: str) str | None[source]

Function to get the comment/description for a given attribute.

Parameters:

attribute_name (str) – The name of the attribute to get the comment for.

Returns:

comment – The comment/human-readable description for the attribute, or None if not found.

Return type:

str | None

get_optional_keywords() Dict[str, Dict[str, Any]][source]

Function to get a list of optional keywords.

Returns:

optional_keywords – A dictionary of optional keywords and their associated information.

Return type:

Dict[str, Dict[str, Any]]

get_required_keywords(primary: bool | None = False, obs: bool | None = False) Dict[str, Dict[str, Any]][source]

Function to get a list of required keywords based on whether the HDU is an observation HDU or not.

Parameters:
  • primary (bool, optional, default False) – Whether or not the HDU is a primary HDU. If True, the function will return keywords required for primary HDUs.

  • obs (bool, optional, default False) – Whether or not the HDU is an observation HDU. If True, the function will return keywords required for observation HDUs.

Returns:

required_keywords – A dictionary of required keywords and their associated information.

Return type:

Dict[str, Dict[str, Any]]

load_default_attributes() Header[source]

Function to load the default attributes for a SOLARNET-compliant data file.

Returns:

header – A FITS header containing the default attributes.

Return type:

fits.Header