esm-tools / pymorize

A Python based Tool to CMORize NetCDF Data
https://pymorize.readthedocs.io
MIT License
2 stars 1 forks source link

Rule Inheritance #39

Closed pgierz closed 1 month ago

pgierz commented 1 month ago

This allows for inheritance of global attributes to Rule objects.

For example:

  # ... other configuration
  inherit:
    frequency: mon
  # ... other configuration

  rules:
    - name: my_rule
      cmor_variable: tas
      patterns:
        - 'tas_*.nc'
      pipelines:
        - my_pipeline

This would give a Rule object like so:

>>> rule = Rule(...)
>>> rule.frequency
'mon'

It also ensures that an attribute specifically set on the rule will be used instead of the global setting (local version wins):

  # ... other configuration
  inherit:
    frequency: mon
    my_attr: foo
  # ... other configuration

  rules:
    - name: my_rule
      cmor_variable: tas
      my_attr: not_foo
      patterns:
        - 'tas_*.nc'
      pipelines:
        - my_pipeline

Gives:

>>> rule = Rule(...)
>>> rule.my_attr
'not_foo'
pgierz commented 1 month ago

This pull request introduces a new inheritance feature to the pymorize CLI, allowing rules to inherit global values from a new inherit section in the configuration file. The most important changes include updates to the documentation, the addition of an inheritance configuration section, and modifications to the Rule class to support this feature.

Documentation Updates:

Codebase Enhancements: