Skip to content

2D guess bounds #6097

@stephenworsley

Description

@stephenworsley

✨ 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

Proposal

We treat each point as if it lies on the surface of a perfect sphere. We assume that our array of points has dimesnions of size at least 2 and raise an error if it does not.

  1. For bounds contained between 4 points, take the centroid of those 4 points in 3-space (xyz coordinates). Then project this average onto its equivalent on the surface on the sphere. In the edge case where this average is at the origin, raise an error.

  2. For bounds on the edge which belong to precisely 2 points, take the neighbouring bound (this will be, precisely, the only bound which also belongs to the same 2 points), and take the midpoint between these two points. Take the shortest great circle arc which connects this bound to this midpoint and extend it (traveling in the direction from the bound to the midpoint) until the same distance is traveled. The endpoint of this extended great circle will be our (projected) bound.

  3. For bounds on the corner of the grid which belong to precisely 1 point, take this point and take the neighbouring bound (the unique bound which shares that point). In the same way as described in 2), extend the great circle from that bound, through that point to get the (projected) bound.

Image

There may be a case for adding in special behaviour for ensuring the projected bounds at the edges to not intersect with each other, which may prove necessary when dealing with poles, though this may be added in future and controlled via a keyword in guess_bounds and may not be considered minimal for the time being.

Metadata

Metadata

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions