Skip to content

Commit

Permalink
Preallocate numpy arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Sep 6, 2024
1 parent 82df240 commit a69a48d
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,22 +993,17 @@ def filter_stations(self, stations: dict[str, Station]) -> dict[str, Station]:
if self._topography is None:
return stations

filtered_stations = dict()

names: list[str] = []
lats: list[float] = []
lons: list[float] = []
alts: list[float] = []
for name, station in stations.items():
names.append(name)
lats.append(station["latitude"])
lons.append(station["longitude"])
alts.append(station["altitude"])

names = np.array(names)
lats = np.array(lats)
lons = np.array(lons)
alts = np.array(alts)
names = np.ndarray(len(stations), dtype=np.dtypes.StrDType)
lats = np.ndarray(len(stations), dtype=np.float64)
lons = np.ndarray(len(stations), dtype=np.float64)
alts = np.ndarray(len(stations), dtype=np.float64)

for i, name in enumerate(stations):
station = stations[name]
names[i] = name
lats[i] = station["latitude"]
lons[i] = station["longitude"]
alts[i] = station["altitude"]

out_of_bounds_mask = np.logical_or(np.logical_or(lons < self._boundary_west, lons > self._boundary_east), np.logical_or(lats < self._boundary_south, lats > self._boundary_north))
if np.sum(out_of_bounds_mask) > 0:
Expand Down

0 comments on commit a69a48d

Please sign in to comment.