Skip to content

Commit

Permalink
Merge pull request #180 from ageller/bugfix/numpy-2.0-support
Browse files Browse the repository at this point in the history
add import guard to import relocated AxisError as of numpy-2.0
  • Loading branch information
agurvich authored Oct 5, 2024
2 parents 512f899 + fdf8448 commit b38ea92
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ If you use Firefly, please cite our [ApJS paper](https://ui.adsabs.harvard.edu/a

Comprehensive documentation is available [here](https://firefly.rcs.northwestern.edu/docs).

*Note: currently Firefly requires numpy version<2.0. This may not be the default version of numpy installed via `pip install firefly`.*

## Contributors
### Primary Developers
* Aaron Geller
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

setuptools.setup(
name="firefly",
version="3.3.1",
version="3.3.2",
author = 'Alex Gurvich, Aaron Geller',
author_email = '[email protected], [email protected]',
author_email = '[email protected], [email protected]',
description="A browser-based particle visualization platform",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
21 changes: 13 additions & 8 deletions src/firefly/data_reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import numpy as np
import time

## numpy 1.X
try: AxisError = np.AxisError
## numpy 2.X
except: from numpy.exceptions import AxisError

from .settings import Settings,default_settings
from .tween import TweenParams
from .particlegroup import ParticleGroup
Expand Down Expand Up @@ -720,11 +725,11 @@ def __init__(
:type write_to_disk: bool, optional
:param loud: flag to print status information to the console, defaults to False
:type loud: bool, optional
:raises np.AxisError: if the coordinate data cannot be interpreted
:raises AxisError: if the coordinate data cannot be interpreted
:raises ValueError: if the number of particle groups does not match the number of
coordinate arrays
:raises np.AxisError: if the field data cannot be interpreted
:raises np.AxisError: if the field names cannot be interpreted
:raises AxisError: if the field data cannot be interpreted
:raises AxisError: if the field names cannot be interpreted
"""

super().__init__(**kwargs)
Expand All @@ -740,14 +745,14 @@ def __init__(
## passed a jagged array of different coordinates
pass
else:
raise np.AxisError("Uninterpretable coordinate array, either pass a single (N,3) array"+
raise AxisError("Uninterpretable coordinate array, either pass a single (N,3) array"+
" or a jagged list of 'shape' (M,N_m,3)")

ngroups = len(coordinates)
npartss = np.array([len(coords) for coords in coordinates])

## check fields and wrap a single field for a single particle group
fielderror = np.AxisError("Uninterpretable field array, either pass a single N array"
fielderror = AxisError("Uninterpretable field array, either pass a single N array"
" or a jagged list of 'shape' (M,N_fm,N_pm)")
if fields is not None:
## special case and want to allow convenient/inconsistent syntax,
Expand Down Expand Up @@ -784,7 +789,7 @@ def __init__(
nfieldss = [len(this_fields) for this_fields in fields]

## check field names and generate them if necessary
fieldnameerror = np.AxisError("Uninterpretable field array, either pass a single N array"+
fieldnameerror = AxisError("Uninterpretable field array, either pass a single N array"+
" or a jagged list of 'shape' (M,N_fm,N_pm)")

if field_names is not None:
Expand Down Expand Up @@ -1006,7 +1011,7 @@ def __getHDF5Coordinates(
:param coordinates: existing coordinate array that should be appended to, defaults to None
:type coordinates: np.ndarray, optional
:raises TypeError: if :code:`coordinates` is not of type :code:`np.ndarray`
:raises np.AxisError: if :code:`coordinates` does not have shape (N,3)
:raises AxisError: if :code:`coordinates` does not have shape (N,3)
:return: coordinates, the opened coordinate array from :code:`fname`
:rtype: np.ndarray
"""
Expand All @@ -1018,7 +1023,7 @@ def __getHDF5Coordinates(
elif type(coordinates)!= np.ndarray:
raise TypeError("Existing coordinate array must be of type np.ndarry")
if np.shape(coordinates)[-1] != 3:
raise np.AxisError("Last axis of existing coordinate array must be of size 3")
raise AxisError("Last axis of existing coordinate array must be of size 3")

## open the hdf5 group
if particle_group is not None:
Expand Down
13 changes: 9 additions & 4 deletions src/firefly/data_reader/tween.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import numpy as np

## numpy 1.X
try: AxisError = np.AxisError
## numpy 2.X
except: from numpy.exceptions import AxisError

import os

from .json_utils import write_to_json
Expand Down Expand Up @@ -73,16 +78,16 @@ def addKeyframe(
* [d1,d2,...] multiple durations (corresponding to number of keyframes or
raises an error)
:type duration: float/list of float
:raises np.AxisError: if len of coords is not divisible by 3
:raises np.AxisError: if len of durations does not match len of coords
:raises AxisError: if len of coords is not divisible by 3
:raises AxisError: if len of durations does not match len of coords
"""

try:
## cast to numpy array and reorder coords at the same time for
## convenient input
coords = np.array(coords).reshape(-1,3)
except:
raise np.AxisError("coords should either be a 2d Nx3 numpy array or"+
raise AxisError("coords should either be a 2d Nx3 numpy array or"+
"a 3N list/array.")

## convert duration to a 1d numpy array, however it was passed
Expand All @@ -92,7 +97,7 @@ def addKeyframe(
## ensure there is a duration per keyframe transition
## TODO: shouldn't durations be 1 less than coordss?
if duration.shape[0]!=coords.shape[0]:
raise np.AxisError(
raise AxisError(
"Mismatching coords and duration shape (%d,%d)"%(
coords.shape[0],
duration.shape[0]))
Expand Down

0 comments on commit b38ea92

Please sign in to comment.