hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.4k stars 471 forks source link

Request: implement support for geographical coordinates #1828

Open jkaumanns opened 1 year ago

jkaumanns commented 1 year ago

Handling of geographical coordinates is currently poorly implemented. I propose the following changes:

-(1) Add units 'degree_west' and 'degree_south', such that the cardinal directions point in opposite directions, e.g. x degrees_north = -x degrees_south and y degrees_east = -y degrees_west -(2) Following this change, cardinal directions should not be able to be able to converted into each other, e.g. degrees_north cannot be turned into degrees_east, since cardinal directions are only ever used to define positions on a spherical surface. -(3) When converting to radians, as is usually necessary for trigonometric functions, this behavior should be mirrored, e.g pint.Quantity(x, units='degrees_south').to('radians') = pint.Quantity(-x, units='degrees_north').to('radians'). It may be reasonable to introduce a new type of radian unit to ensure proposed point (2) -(4) To transform regular angles to cardinal directions, I propose a new function. Default transformation to degrees_north could be [0°, 360°] -> [-180°N, 180°N], default transformation to degrees_south could be [0°, 180°] -> [-90N°, 90N°]. Ideally, we would introduce a prime meridian like origin for the new coordinate systems.

jules-ch commented 1 year ago

See https://github.com/hgrecco/pint/issues/1650 and https://github.com/hgrecco/pint/issues/1344

We made the decisions to keep angles units calculations out of those kind of consideration. That said, I don't know if we can implement context transformation for this kind of calculations. See https://pint.readthedocs.io/en/0.10.1/contexts.html

I know that Metpy does define alias for degree_north and degree_east https://github.com/Unidata/MetPy/blob/325b053b1294f4b5f93d60c4aca710a80d11b445/src/metpy/units.py#L76 just to properly define them as degree.