SciTools / iris

A powerful, format-agnostic, and community-driven Python package for analysing and visualising Earth science data
https://scitools-iris.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
635 stars 283 forks source link

Why can we define a `HybridPressureFactory` without surface air pressure #6072

Open schlunma opened 3 months ago

schlunma commented 3 months ago

📰 Custom Issue

Iris allows defining a HybridPressureFactory without specifying a surface air pressure coordinate. The coordinate will be treated as 0 in this case.

I encountered this problem in a file with an invalid formula_terms: ap: ap b: ap ps: ps where ps does not exist in the cube. This will lead to the warning IrisCfMissingVarWarning: Missing CF-netCDF formula term variable 'ps', referenced by netCDF variable 'lev', but apart from that the cube is loaded and a wrong air pressure coordinate is created.

What's the reasoning behind this to allow that? I would have expected an error similar to the one that is raised for the AtmosphereSigmaFactory.

A similar problem happens for the HybridHeightFactory, which can also be created without orography.

stephenworsley commented 3 months ago

@SciTools/peloton I believe this is due to generic code which will replace missing dependencies with 0. It seems like this effectively leads to nonsense in the case of HyridPressureFactory, though for HybridHeightFactory makes more sense, since it effectively describes a default of a spherical earth. There may be a case for adding logic which declines to build a coordinate (and raises a warning) when doing so would be nonsensical. How important do you consider it to be to avoid creating such invalid pressure coordinates?

schlunma commented 3 months ago

Thanks for the answer @stephenworsley!

It's not super critical to me, but I think it would be helpful if iris would not create the factory if one of the formula terms is invalid instead of building a (potentially) wrong coordinate. I know that there is a warning, but it's super easy to ignore that, especially if the derived coordinate is present in the cube.

pp-mo commented 2 months ago

From @SciTools/peloton we think this is a good idea, but we're currently very resource-limited, so it's hard to see when this can get done. So we think we'll have to leave this unresolved for now. If you want to propose new code, that might be a way forward, but it still needs attention from the team, and it's unclear when we will get around to it.