Skip to content

Commit

Permalink
numpy 2.0 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-lieck committed Oct 14, 2024
1 parent 8846ec2 commit cbea85a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions musicflower/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

def rgba(*args):
if len(args) == 1:
rgba = np.asfarray(args[0])
rgba = np.asarray(args[0], dtype=float)
else:
rgba = np.asfarray(args)
rgba = np.asarray(args, dtype=float)
if len(rgba) not in [3, 4]:
raise ValueError("rgba values have to be specified as (an array of) 3 or 4 values")
if np.any(rgba > 1) or np.any(rgba < 0):
Expand All @@ -40,8 +40,8 @@ def rgba(*args):


def rgba_mix(colors, weights, normalise=True):
colors = np.asfarray(colors)
weights = np.asfarray(weights)
colors = np.asarray(colors, dtype=float)
weights = np.asarray(weights, dtype=float)
if np.any(weights < 0):
raise ValueError("'weights' must be positive")
if normalise:
Expand Down Expand Up @@ -447,7 +447,7 @@ def make_parallels(n_levels=5,
def plot_pcd_marker(pcd, labels,
name=None, groupname=None, group=None, r=None,
parallels_kwargs=(), meridians_kwargs=(), label_kwargs=()):
pcd = np.asfarray(pcd)
pcd = np.asarray(pcd, dtype=float)
amplitude, phase = get_fourier_component(pcds=pcd[None], fourier_component=5)
x, y, z = remap_to_xyz(amplitude=amplitude, phase=phase)
altitude = np.arctan2(z, np.sqrt(x ** 2 + y ** 2))[0]
Expand Down Expand Up @@ -491,10 +491,10 @@ def add_key_markers(fig, **kwargs):


def ellipse_coords(r1, r2, centre=(0, 0, 0), n=100, plane=None):
centre = np.asfarray(centre)
centre = np.asarray(centre, dtype=float)
if plane is None:
r1 = np.asfarray(r1)
r2 = np.asfarray(r2)
r1 = np.asarray(r1, dtype=float)
r2 = np.asarray(r2, dtype=float)
elif plane == 'xy':
r1 = r1 * np.array([1, 0, 0])
r2 = r2 * np.array([0, 1, 0])
Expand Down
2 changes: 1 addition & 1 deletion musicflower/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_fourier_component(pcds: np.ndarray, fourier_component: int = None) -> np
:return: array of shape (2, ..., n//2 + 1) with amplitude and phase along the first dimension and the different
Fourier components along the last dimension
"""
pcds = np.asfarray(pcds)
pcds = np.asarray(pcds, dtype=float)
pcds /= pcds.sum(axis=-1, keepdims=True)
ft = np.fft.rfft(pcds, axis=-1)
if fourier_component is not None:
Expand Down
2 changes: 1 addition & 1 deletion musicflower/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def check_features(cls, features, n=1, asfarray=True):
if len(features) != n:
raise ValueError(f"expected {n} features but got {len(features)}")
if asfarray:
features = [np.asfarray(f) for f in features]
features = [np.asarray(f, dtype=float) for f in features]
if n == 1:
features = features[0]
return features
Expand Down

0 comments on commit cbea85a

Please sign in to comment.