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

Updating tests to handle nutrient Components #93

Closed mattjbr123 closed 3 months ago

mattjbr123 commented 8 months ago

Sub-task of #14

As part of #14 the unit tests for UNIFHY need to be updated to expect nutrient components before any development on UNIFHY to add these components takes place.

mattjbr123 commented 8 months ago

There is some question on whether or not to make the nutrient components mandatory or not for the tests (and thus for the user).

As UNIFHY allows NullComponents, which essentially remove the component from the Model, I think for now we will require all 6 components be provided for a Model, as the user will have the option of making the nutrient components NullComponents if they do not wish to model nutrients. Therefore the tests will be set up similarly, to expect 6 components for a given Model, and failing otherwise.

mattjbr123 commented 8 months ago

The following changes need to be made to the tests for them to require 6 components instead of 3:

test_model.py:

test_component.py

test_clock.py

test_record.py

Dummy component files

Dummy data files

There also needs to be:

mattjbr123 commented 7 months ago

Regarding the structure of the new dummy components. I have settled upon the setup shown in the diagram below. The key features are:

The two transfers added are:

To accommodate these transfers the following edits were made to the WaterEnergy Components:

The Nutrient Components are copies of the WaterEnergy components with only the transfer names changed as shown in the diagram below. The edits then made to accommodate the two new transfers added are:

Further to this the new setup will require replication of the files that are used as input to the WaterEnergy Components, as noted in 'Dummy data files' in https://github.com/unifhy-org/unifhy/issues/93#issuecomment-1717762320. The expected records in test_record.py may also need to be changed to reflect the additional calculations as a result of the additional transfers.

Scratch - page 5

ThibHlln commented 7 months ago

Hi Matt,

For the dummy files, you may find these scripts useful (I hope): https://github.com/hydro-jules/data-generators

As you will have noticed, I tried to keep the "equations" in the dummy components as simple as possible while using each input/transfer/parameter/state/constant at least once. This meant that the time series the components were producing were mostly made of integers or at least rational numbers (see https://github.com/unifhy-org/unifhy/blob/4105932ed7dfec34d428c1f2d2f85ec25ea522ed/tests/tests/test_utils/test_record.py#L10-L59 and https://github.com/hydro-jules/data-generators/blob/a4667021f7f0e4c9edf32eacd40f0d3394ce71c9/generate_dummy_cf_substitute_data.py#L35-L66). This was to avoid having to deal with floating point precision when comparing what was produced by the components vs. what I was expecting on paper. Since you are necessarily adding transfers between WaterEnergy and Nutrient, you will have to increase the "complexity" of these "equations", so you may not be able to avoid ending up with irrational numbers, but I guess it is not too bad.

mattjbr123 commented 7 months ago

Thanks Thibault :) I was aware of this issue of possible irrational numbers, so I tried to keep the extra calculations as simple as possible but didn't actually check what the records would now come out as. That's my next job xD

It looks like I don't have access to the data-generators repo - I'm just getting a 404

mattjbr123 commented 4 months ago

Adding in the expected records for the 3 nutrient Components for the same_t and diff_t tests to test_record.py took a long time due to the need to calculate 16 model timesteps by hand, with 6 components.

To ease this process for future development I created a script that users can trust to calculate these values for them once they input their dummy components. See issue #95

mattjbr123 commented 3 months ago

Test updates (finally!) complete. Next step is to analyse which of these changes will result in the errors when the full framework is run and make changes to the framework to allow the tests to pass.