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

Grid cell area calculation breaks with CF-Python version 3.14.0 and above #98

Closed mattjbr123 closed 3 weeks ago

mattjbr123 commented 3 weeks ago

The refactor of the CF-Python regridding code for dask implementation in v3.14.0 (https://github.com/NCAS-CMS/cf-python/pull/438) causes the calculation of grid cell area to fail for unifhy.space grids with spherical coordinates. The _compute_cell_area function in unifhy.space uses the ESMF.Regrid operator calculated as part of a regridding operation initiated through CF-Python.

In CF-Python v3.13.1 (the version immediately prior to v3.14.0) the return_operator kwarg to the cf-python.field.regrids function returns a cf.RegridOperator object via the regrid_create_operator function in cf-python/regrid/utils. The cf.RegridOperator object has a 'regrid' attribute which is the ESMF.Regrid operator object associated with the regrid requested.

This behaviour changes in v3.14.0. cf-python.regrids and regridc now call the regrid worker function in a new regrid/regrid file and the cf.RegridOperator object returned by it no longer has a regridattribute from which to access the ESMF.Regrid operator object. Instead, this functionality is separated out from thecf.RegridOperator object and incorporated into the regrid worker function/subfunctions, which will return the ESMF.Regrid operator if a return_esmpy_regrid_operator=True kwarg is passed to it. However, neither regrids or regridc define this kwarg, so the only way to access the ESMF.Regrid operator is by calling the regrid worker function directly, which is probably not good practice, but might be a necessary workaround for now to get UnifHy working again.

mattjbr123 commented 3 weeks ago

I'm currently unsure why this only occurs for spherical grids and not cartesian grids... Will investigate.

Because a different method is used to calculate area of cartesian grids: https://github.com/unifhy-org/unifhy/blob/0e16755d40ec4dd7da7212b0579ff1172faf6364/unifhy/space.py#L4782

mattjbr123 commented 3 weeks ago

This will be fixed in CF-Python v3.16.2, and I have made changes to unifhy to accomodate the slight change in syntax required, hence the requirement for CF-Python for unifhy is now v3.16.2.