unifhy-org / unifhy

A Unified Framework for Hydrology
https://unifhy-org.github.io/unifhy
BSD 3-Clause "New" or "Revised" License
11 stars 5 forks source link

Metadata for OpenWaterComponent _inwards_info attribute incorrect for some variables in the temporary_with_nutrients branch #89

Closed mattjbr123 closed 1 year ago

mattjbr123 commented 1 year ago

For 'mass_flux_of_nitrogen_as_ammonium_from_atmosphere_to_surface_due_to_deposition', 'mass_flux_of_nitrogen_as_nitrate_from_atmosphere_to_surface_due_to_deposition', 'mass_flux_of_sulfur_as_sulfate_from_atmosphere_to_surface_due_to_deposition' and 'mass_concentration_of_carbon_dioxide_in_air' 'from' is set to 'surface' in the _inwards_info attribute of the OpenWaterComponent class, when it should be 'surfacelayer' as for e.g. 'water_evaporation_flux_from_open_water' https://github.com/unifhy-org/unifhy/blob/b49fef0d8ae258e45ca7f8b930dc99bb4b8491fb/unifhy/component.py#L1759

This causes the following error when building a Model:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [19], in <cell line: 1>()
----> 1 model = unifhy.Model(
      2     identifier='test',
      3     config_directory='/home/users/mattjbr/unifhy/unifhy_outputs',
      4     saving_directory='/home/users/mattjbr/unifhy/unifhy_outputs',
      5     surfacelayer=surf_comp,
      6     subsurface=subsurf_comp,
      7     openwater=ow_comp
      8 )

File ~/anaconda3/envs/unifhy/lib/python3.9/site-packages/unifhy/model.py:63, in Model.__init__(self, identifier, config_directory, saving_directory, surfacelayer, subsurface, openwater, _to_yaml)
     59 #: Return the open water component of the model.
     60 self.openwater = self._process_component_type(
     61     openwater, OpenWaterComponent)
---> 63 self._check_components_plugging()
     65 # assign identifier
     66 self.identifier = identifier

File ~/anaconda3/envs/unifhy/lib/python3.9/site-packages/unifhy/model.py:121, in Model._check_components_plugging(self)
    119 for trf, info in dst.inwards_info.items():
    120     print(trf, info)
--> 121     src = getattr(self, info['from'])
    122     print(src)
    123     print(src.outwards_info)

AttributeError: 'Model' object has no attribute 'surface'

as when checking the inwards & outwards are correct, the Model cannot find a 'surface' attribute of itself, because the surface attribute is actually called 'surfacelayer'.

Should be an easy fix, just need to change the offending 'surface's to 'surfacelayer's. Will try and submit a pull request for this.