ortk95 / planetmapper

PlanetMapper: An open source Python package for visualising, navigating and mapping Solar System observations
https://planetmapper.readthedocs.io
MIT License
10 stars 1 forks source link

Allow passing arrays to coordinate transformation methods #370

Closed ortk95 closed 2 months ago

ortk95 commented 2 months ago

Array transformation methods (e.g. radec2lonlat) can now transform arrays of coordinates, in addition to coordinates for a single point.

If the input coordinates are both floats, then the method will return a tuple of floats (i.e. the existing behaviour). If either of the input coordinates are arrays, then the inputs will be broadcast together, and a tuple of NumPy arrays will be returned. There are no restrictions on the shape and number of dimensions of the input arrays - the only requirement is that the input arrays can be broadcast together.

For example:

body = planetmapper.Body('Jupiter', utc='2005-01-01T00:00:00')

print(body.lonlat2radec(180, 0))
# (196.3742463154229, -5.566702383405959)
print(body.lonlat2radec(np.arange(360), np.zeros(360)))
# (array([196.36993081, ..., 196.37000169]), array([-5.5652366 , ..., -5.56527024]))
print(body.lonlat2radec(np.array([1,2]), np.array([[1,2],[3,4]])))
# (array([[196.36989221, 196.36985491], [196.3699572, 196.36992117]]), array([[-5.56513378, -5.56503142], [-5.56499563, -5.5648938 ]]))

Closes #358

Pull request checklist

See CONTRIBUTING.md for more details.

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 9564560155

Details


Totals Coverage Status
Change from base Build 9547931142: 0.005%
Covered Lines: 3101
Relevant Lines: 3113

💛 - Coveralls