Skip to content

Commit

Permalink
replacement for ndarray.newbyteorder, removed in numpy 2.x (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jornbr authored Jun 19, 2024
1 parent 9ebd005 commit e635f0a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/pyfabm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ def value(self):
shape = self.model.interior_domain_shape
else:
shape = self.model.horizontal_domain.shape
return np.ctypeslib.as_array(pdata, shape).newbyteorder("=")
arr = np.ctypeslib.as_array(pdata, shape)
return arr.view(dtype=self.model.fabm.numpy_dtype)


class NamedObjectList(Sequence):
Expand Down Expand Up @@ -1575,22 +1576,18 @@ def process_dependencies(dependencies):
return False
for i, variable in enumerate(self.interior_diagnostic_variables):
pdata = self.fabm.get_interior_diagnostic_data(self.pmodel, i + 1)
variable.data = (
None
if not pdata
else np.ctypeslib.as_array(
pdata, self.interior_domain_shape
).newbyteorder("=")
)
if pdata:
arr = np.ctypeslib.as_array(pdata, self.interior_domain_shape)
variable.data = arr.view(dtype=self.fabm.numpy_dtype)
else:
variable.data = None
for i, variable in enumerate(self.horizontal_diagnostic_variables):
pdata = self.fabm.get_horizontal_diagnostic_data(self.pmodel, i + 1)
variable.data = (
None
if not pdata
else np.ctypeslib.as_array(
pdata, self.horizontal_domain_shape
).newbyteorder("=")
)
if pdata:
arr = np.ctypeslib.as_array(pdata, self.horizontal_domain_shape)
variable.data = arr.view(dtype=self.fabm.numpy_dtype)
else:
variable.data = None
return ready

checkReady = start
Expand Down

0 comments on commit e635f0a

Please sign in to comment.