GEOS-ESM / MAPL

MAPL is a foundation layer of the GEOS architecture, whose original purpose is to supplement the Earth System Modeling Framework (ESMF)
https://geos-esm.github.io/MAPL/
Apache License 2.0
26 stars 17 forks source link

Unit testing of vertical regridding code #2253

Open bena-nasa opened 1 year ago

bena-nasa commented 1 year ago

Just making a note here that we do need to think about some unit testing for the vertical regridding code, both for MAPL3 and just so that if people do want to clean/optimize we don't break it.

I do think that we at least need to have some realistic inputs for the unit tests, if synthetic they need be somewhat realistic. The whole point of the main event in this code is given a level(s), say 1000mb, 950mb, and a variable that defines the column edge pressures interpolate another variable defined on those column edges or centers of each column level to those output levels(s).

It would be non-sense to generate say a synthetic PLE for a column that was not not monotonic increasing or decreasing set of numbers, so if you are going to generate synthetic inputs, it at least better be physically reasonable.

I would argue let's just capture several representative columns of edge pressures as inputs for a unit test and be done with it. Or write some code to generate physically reasonable synthetic pressure columns.

tclune commented 1 year ago

I'll try to dig up an old presentation where I used interpolation (1D) as an example for demonstrating test driven development. In general, unit testing is quite friendly to this type of layer, but the interfaces may need to be modified to be more well-suited, and we may have to factor out more helper procedures than is typically the case.

The basic approach is to break the problem into 3 distinct issues:

  1. For a given x, find the bracket that contains x
  2. For a given x within a bracket b, compute the weight(s).
    • subtests should include point on each node, point in the middle, etc.
  3. Iterate over x's

Testing the latter is a bit less valuable of course.

Now if vectorization is unfriendly to such small procedures with narrow interfaces, you use the well-tested procedures as the "expected" result for the fully fused/integrated interfaces. Might have to allow for roundoff depending.

The variant here is the use of a reference pressure. That will add a bit of complexity, but I doubt it will substantially change the approach.

Synthetic values are used everywhere ...

bena-nasa commented 1 year ago

I'll have to refresh my memory about the interface (probably needs to be trashed and cleaned up, I just pulled the code out of History that I assume Larry wrote and put it in a module without really looking into what it did in detail) and what this code actually does before we go too far into how to test this or having a discussion about the details.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. If there are no updates within 7 days, it will be closed. You can add the "long term" tag to prevent the Stale bot from closing this issue.