Skip to content

Commit

Permalink
fix copy keywords for numpy 2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
aelanman authored and aelanman committed Jun 26, 2024
1 parent 2602f35 commit add0918
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
27 changes: 14 additions & 13 deletions lunarsky/moon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CartesianRepresentation,
)
from astropy.coordinates.attributes import Attribute
from astropy.utils.compat import COPY_IF_NEEDED

from .spice_utils import remove_topo

Expand Down Expand Up @@ -134,7 +135,7 @@ def new_like(self, cols, length, metadata_conflicts="warn", name=None):
# selenodetic coordinates.
shape = (length,) + attrs.pop("shape")
data = u.Quantity(
np.zeros(shape=shape, dtype=cols[0].dtype), unit=cols[0].unit, copy=False
np.zeros(shape=shape, dtype=cols[0].dtype), unit=cols[0].unit, copy=COPY_IF_NEEDED
)
# Get arguments needed to reconstruct class
map = {
Expand Down Expand Up @@ -303,9 +304,9 @@ def from_selenocentric(cls, x, y, z, unit=None):
)

try:
x = u.Quantity(x, unit, copy=False)
y = u.Quantity(y, unit, copy=False)
z = u.Quantity(z, unit, copy=False)
x = u.Quantity(x, unit, copy=COPY_IF_NEEDED)
y = u.Quantity(y, unit, copy=COPY_IF_NEEDED)
z = u.Quantity(z, unit, copy=COPY_IF_NEEDED)
except u.UnitsError:
raise u.UnitsError(
"Selenocentric coordinate units should all be " "consistent."
Expand All @@ -314,7 +315,7 @@ def from_selenocentric(cls, x, y, z, unit=None):
x, y, z = np.broadcast_arrays(x, y, z)
struc = np.empty(x.shape, cls._location_dtype)
struc["x"], struc["y"], struc["z"] = x, y, z
inst = super().__new__(cls, struc, unit, copy=False)
inst = super().__new__(cls, struc, unit, copy=COPY_IF_NEEDED)

return inst

Expand Down Expand Up @@ -361,11 +362,11 @@ def from_selenodetic(cls, lon, lat, height=0.0, ellipsoid=None):
"""
ellipsoid = _check_ellipsoid(ellipsoid, default=cls._ellipsoid)
lon = Longitude(lon, u.degree, copy=False).wrap_at(180 * u.degree)
lat = Latitude(lat, u.degree, copy=False)
lon = Longitude(lon, u.degree, copy=COPY_IF_NEEDED).wrap_at(180 * u.degree)
lat = Latitude(lat, u.degree, copy=COPY_IF_NEEDED)
# don't convert to m by default, so we can use the height unit below.
if not isinstance(height, u.Quantity):
height = u.Quantity(height, u.m, copy=False)
height = u.Quantity(height, u.m, copy=COPY_IF_NEEDED)

if not lon.shape == lat.shape:
raise ValueError(
Expand All @@ -376,7 +377,7 @@ def from_selenodetic(cls, lon, lat, height=0.0, ellipsoid=None):

# get selenocentric coordinates. Have to give one-dimensional array.

selenodetic = SELENOIDS[ellipsoid](lon, lat, height, copy=False)
selenodetic = SELENOIDS[ellipsoid](lon, lat, height, copy=COPY_IF_NEEDED)
xyz = selenodetic.to_cartesian().get_xyz(xyz_axis=-1) << height.unit
self = xyz.view(cls._location_dtype, cls).reshape(selenodetic.shape)
self.ellipsoid = ellipsoid
Expand Down Expand Up @@ -444,13 +445,13 @@ def to_selenodetic(self, ellipsoid=None):
"""
ellipsoid = _check_ellipsoid(ellipsoid, default=self.ellipsoid)
xyz = self.view(self._array_dtype, u.Quantity)
llh = CartesianRepresentation(xyz, xyz_axis=-1, copy=False).represent_as(
llh = CartesianRepresentation(xyz, xyz_axis=-1, copy=COPY_IF_NEEDED).represent_as(
SELENOIDS[ellipsoid],
)
return SelenodeticLocation(
Longitude(llh.lon, u.degree, wrap_angle=180.0 * u.degree, copy=False),
Latitude(llh.lat, u.degree, copy=False),
u.Quantity(llh.height, self.unit, copy=False),
Longitude(llh.lon, u.degree, wrap_angle=180.0 * u.degree, copy=COPY_IF_NEEDED),
Latitude(llh.lat, u.degree, copy=COPY_IF_NEEDED),
u.Quantity(llh.height, self.unit, copy=COPY_IF_NEEDED),
)

@property
Expand Down
3 changes: 2 additions & 1 deletion lunarsky/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import astropy
from astropy import version
from astropy.utils.compat import COPY_IF_NEEDED
from astropy.coordinates import EarthLocation, Longitude

from .moon import MoonLocation
Expand Down Expand Up @@ -30,7 +31,7 @@ def __init__(
in_subfmt=None,
out_subfmt=None,
location=None,
copy=False,
copy=COPY_IF_NEEDED,
):

super_loc = None
Expand Down

0 comments on commit add0918

Please sign in to comment.