Skip to content

Commit

Permalink
Optimize RAM usage by converting data to float32.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnrgomes committed Dec 15, 2023
1 parent e4d79fa commit 394859c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lisfloodutilities/gridding/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ def __init__(self, dem_map: Path, quiet_mode: bool = False):
reader = NetCDFReader(self._dem_map)
self.nrows = reader._rows
self.ncols = reader._cols
self.mv = reader.mv
self.values = reader.values
self.mv = reader.mv.astype(np.float32)
self.values = reader.values.astype(np.float32)
self.lats, self.lons = reader.get_lat_lon_values()
self.lats = self.lats.astype(np.float32)
self.lons = self.lons.astype(np.float32)
self.lat_values = reader.get_lat_values()
self.lon_values = reader.get_lon_values()
self.cell_size_x = reader._pxlW
Expand Down Expand Up @@ -185,7 +187,7 @@ def __init__(self, config_filename: str, start_date: datetime = None, end_date:
def __setup_interpolation_parameters(self):
self.scipy_modes_nnear = Config.INTERPOLATION_MODES
self.grid_details = {'gridType': 'NOT rotated', 'Nj': 1, 'radius': 6367470.0}
self.min_upper_bound = 100000000 # max search distance in meters
self.min_upper_bound = 100000000.0 # max search distance in meters
cdd_map_path = Path(self.config_path).joinpath(f'CDDmap_{self.var_code}.nc')
self.cdd_map = f'{cdd_map_path}'
if self.interpolation_mode == 'cdd' and not os.path.isfile(self.cdd_map):
Expand Down Expand Up @@ -411,9 +413,9 @@ def generate_grid(self, filename: Path) -> np.ndarray:
x = df[self.conf.COLUMN_LON].values
y = df[self.conf.COLUMN_LAT].values
z = df[self.conf.COLUMN_VALUE].values
xp = np.array(x)
yp = np.array(y)
values = np.array(z)
xp = np.array(x).astype(np.float32)
yp = np.array(y).astype(np.float32)
values = np.array(z).astype(np.float32)
df = None
if self.conf.interpolation_mode == 'cdd':
scipy_interpolation = ScipyInterpolation(xp, yp, self.conf.grid_details, values,
Expand Down

0 comments on commit 394859c

Please sign in to comment.