Skip to content

Commit

Permalink
Merge pull request #83 from m-fehr/feature/NumpyFix
Browse files Browse the repository at this point in the history
Fix deprecated np.math calls
  • Loading branch information
m-fehr authored Aug 30, 2024
2 parents 26921a2 + 5c8918f commit 3deee21
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
17 changes: 9 additions & 8 deletions fdsreader/bndf/obstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing_extensions import Literal
import numpy as np


from fdsreader.utils import Extent, Quantity, Dimension
import fdsreader.utils.fortran_data as fdtype
from fdsreader import settings
Expand Down Expand Up @@ -164,8 +165,8 @@ def get_nearest_timestep(self, time: float) -> int:
"""Calculates the nearest timestep for which data has been output for this obstruction.
"""
idx = np.searchsorted(self.times, time, side="left")
if time > 0 and (idx == len(self.times) or np.math.fabs(
time - self.times[idx - 1]) < np.math.fabs(time - self.times[idx])):
if time > 0 and (idx == len(self.times) or math.fabs(
time - self.times[idx - 1]) < math.fabs(time - self.times[idx])):
return idx - 1
else:
return idx
Expand Down Expand Up @@ -275,7 +276,7 @@ def get_nearest_index(self, dimension: Literal['x', 'y', 'z'], orientation: int,
if self.has_boundary_data:
coords = self.get_coordinates()[orientation][dimension]
idx = np.searchsorted(coords, value, side="left")
if idx > 0 and (idx == coords.size or np.math.fabs(value - coords[idx - 1]) < np.math.fabs(
if idx > 0 and (idx == coords.size or math.fabs(value - coords[idx - 1]) < math.fabs(
value - coords[idx])):
return idx - 1
else:
Expand Down Expand Up @@ -485,8 +486,8 @@ def get_coordinates(self, ignore_cell_centered: bool = False) -> Dict[
mesh = subobst.mesh
mesh_coords = mesh.coordinates[dim]
idx = np.searchsorted(mesh_coords, single_coordinate, side="left")
if idx > 0 and (idx == mesh_coords.size or np.math.fabs(
single_coordinate - mesh_coords[idx - 1]) < np.math.fabs(
if idx > 0 and (idx == mesh_coords.size or math.fabs(
single_coordinate - mesh_coords[idx - 1]) < math.fabs(
single_coordinate - mesh_coords[idx])):
idx = idx + 1
if mesh_coords[idx] - single_coordinate < nearest_coordinate - single_coordinate:
Expand All @@ -503,7 +504,7 @@ def get_nearest_index(self, dimension: Literal['x', 'y', 'z'], orientation: int,
if self.has_boundary_data:
coords = self.get_coordinates()[orientation][dimension]
idx = np.searchsorted(coords, value, side="left")
if idx > 0 and (idx == coords.size or np.math.fabs(value - coords[idx - 1]) < np.math.fabs(
if idx > 0 and (idx == coords.size or math.fabs(value - coords[idx - 1]) < math.fabs(
value - coords[idx])):
return idx - 1
else:
Expand Down Expand Up @@ -560,8 +561,8 @@ def get_nearest_timestep(self, time: float, visible_only: bool = False) -> int:
if self.has_boundary_data:
times = self.get_visible_times(self.times) if visible_only else self.times
idx = np.searchsorted(times, time, side="left")
if time > 0 and (idx == len(times) or np.math.fabs(
time - times[idx - 1]) < np.math.fabs(time - times[idx])):
if time > 0 and (idx == len(times) or math.fabs(
time - times[idx - 1]) < math.fabs(time - times[idx])):
return idx - 1
else:
return idx
Expand Down
3 changes: 2 additions & 1 deletion fdsreader/fds_classes/mesh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, Tuple, Sequence, List, Union
from typing_extensions import Literal
import numpy as np
import math

from fdsreader import settings
from fdsreader.utils import Dimension, Extent, Quantity
Expand Down Expand Up @@ -101,7 +102,7 @@ def coordinate_to_index(self, coordinate: Tuple[float, ...],
if cell_centered:
coords = coords[:-1] + (coords[1] - coords[0]) / 2
idx = np.searchsorted(coords, co, side="left")
if co > 0 and (idx == len(coords) or np.math.fabs(co - coords[idx - 1]) < np.math.fabs(
if co > 0 and (idx == len(coords) or math.fabs(co - coords[idx - 1]) < math.fabs(
co - coords[idx])):
ret.append(idx - 1)
else:
Expand Down
5 changes: 3 additions & 2 deletions fdsreader/isof/isosurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import BinaryIO, Dict, Union, List, Tuple, Optional

import numpy as np
import math

from fdsreader.fds_classes import Mesh
from fdsreader.utils import Quantity
Expand Down Expand Up @@ -337,8 +338,8 @@ def get_nearest_timestep(self, time: float) -> int:
"""Calculates the nearest timestep for which data has been output for this isosurface.
"""
idx = np.searchsorted(self.times, time, side="left")
if time > 0 and (idx == len(self.times) or np.math.fabs(
time - self.times[idx - 1]) < np.math.fabs(time - self.times[idx])):
if time > 0 and (idx == len(self.times) or math.fabs(
time - self.times[idx - 1]) < math.fabs(time - self.times[idx])):
return idx - 1
else:
return idx
Expand Down
5 changes: 3 additions & 2 deletions fdsreader/slcf/geomslice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import os
from copy import deepcopy

Expand Down Expand Up @@ -285,8 +286,8 @@ def get_nearest_timestep(self, time: float) -> int:
"""Calculates the nearest timestep for which data has been output for this geomslice.
"""
idx = np.searchsorted(self.times, time, side="left")
if time > 0 and (idx == len(self.times) or np.math.fabs(
time - self.times[idx - 1]) < np.math.fabs(time - self.times[idx])):
if time > 0 and (idx == len(self.times) or math.fabs(
time - self.times[idx - 1]) < math.fabs(time - self.times[idx])):
return idx - 1
else:
return idx
Expand Down
10 changes: 5 additions & 5 deletions fdsreader/slcf/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ def get_nearest_timestep(self, time: float) -> int:
"""Calculates the nearest timestep for which data has been output for this slice.
"""
idx = np.searchsorted(self.times, time, side="left")
if time > 0 and (idx == len(self.times) or np.math.fabs(
time - self.times[idx - 1]) < np.math.fabs(time - self.times[idx])):
if time > 0 and (idx == len(self.times) or math.fabs(
time - self.times[idx - 1]) < math.fabs(time - self.times[idx])):
return idx - 1
else:
return idx
Expand All @@ -322,7 +322,7 @@ def get_nearest_index(self, dimension: Literal['x', 'y', 'z'], value: float) ->
"""
coords = self.get_coordinates()[dimension]
idx = np.searchsorted(coords, value, side="left")
if idx > 0 and (idx == coords.size or np.math.fabs(value - coords[idx - 1]) < np.math.fabs(
if idx > 0 and (idx == coords.size or math.fabs(value - coords[idx - 1]) < math.fabs(
value - coords[idx])):
return idx - 1
else:
Expand Down Expand Up @@ -365,8 +365,8 @@ def get_coordinates(self, ignore_cell_centered: bool = False) -> Dict[
for mesh in self._subslices.keys():
mesh_coords = mesh.coordinates[dim]
idx = np.searchsorted(mesh_coords, slice_coordinate, side="left")
if idx > 0 and (idx == mesh_coords.size or np.math.fabs(
slice_coordinate - mesh_coords[idx - 1]) < np.math.fabs(
if idx > 0 and (idx == mesh_coords.size or math.fabs(
slice_coordinate - mesh_coords[idx - 1]) < math.fabs(
slice_coordinate - mesh_coords[idx])):
idx = idx + 1
if mesh_coords[idx] - slice_coordinate < nearest_coordinate - slice_coordinate:
Expand Down

0 comments on commit 3deee21

Please sign in to comment.