Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix copy keywords for numpy 2 compatibility #30

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 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,9 @@ 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 +306,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 +317,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 +364,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 +379,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 +447,15 @@ 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
Loading