iris icon indicating copy to clipboard operation
iris copied to clipboard

2D guess bounds

Open stephenworsley opened this issue 1 year ago • 4 comments

✨ Feature Request

Adopt a method for guessing the bounds of 2D coordinates.

Motivation

The guess_bounds method is currently only available for 1D coordinates. There are cases where only the 2D coordinates exist and it is not possible to determine the coordinate system of the 1D coordinates from which they derive. In this case, it would be useful to be able to guess the bounds so that functions wich require such bounds can be used.

Additional context

Guessing bounds becomes significantly more complex in 2 dimensions, especially when taking into account spherical geometry. A naive approach whish treats coordinates as if they existed in flat space could be easier to program, but it may lead to unusual behaviour near the pole. There is not (at least to me) an obvious algorithm to use to guess these bounds or an obvious answer as to which is the correct bound to guess. We would have to resolve the following questions:

  • Is it acceptible to treat coordinates as if they were flat?
  • Should there be special behaviour at the poles to ensure sensible choices of points?
  • Should behaviour of guess_bounds be invariant in different rotational frames?
  • Is there a sensible method for guessing bounds which lie on the edge of the grid?
  • Should "degenerate bounds" be specifically avoided? (e.g. in the case where two cell centers on the edge of the grid are on or are very close to a pole)
  • Is it reasonable to expect that, for 2D coordinates generated from 1d coords with a rotated pole coordinate system, their guessed bounds should match?

Ping @nhsavage

stephenworsley avatar Jul 29 '24 15:07 stephenworsley

Some downstream code that might need to change:

https://github.com/SciTools/iris/blob/5c18504eaecfd92651c3e408ce14c1cba9caf47a/lib/iris/mesh/components.py#L2896-L2904

trexfeathers avatar Aug 05 '24 09:08 trexfeathers

There is a bit of code in ESMValCore for guessing bounds of 2D coordinates here, but I have some doubts about how well that works because the results of area weighted regridding with these guessed bounds do not look so good https://github.com/ESMValGroup/ESMValCore/issues/2405#issuecomment-2121968753.

bouweandela avatar Aug 08 '24 12:08 bouweandela

There is a bit of code in ESMValCore for guessing bounds of 2D coordinates here, but I have some doubts about how well that works because the results of area weighted regridding with these guessed bounds do not look so good ESMValGroup/ESMValCore#2405 (comment).

@bouweandela correct me if I'm misreading, but it looks like this code requires there to be existing DimCoords on the cube to derive from. It looks like what's required here is a way to guess 2D bounds without refering to the 1D bounds.

stephenworsley avatar Aug 14 '24 12:08 stephenworsley

If the DimCoords are missing they get added here.

bouweandela avatar Aug 14 '24 16:08 bouweandela