From 40956835c488b4df05b9e168670c7041bfb01e58 Mon Sep 17 00:00:00 2001 From: thurber Date: Thu, 3 Feb 2022 08:22:02 -0800 Subject: [PATCH] force int64 wherever ints are used to address windows inconsistencies --- mosartwmpy/_version.py | 2 +- mosartwmpy/grid/grid.py | 14 +++++++------- mosartwmpy/model.py | 2 +- mosartwmpy/state/state.py | 8 ++++---- mosartwmpy/utilities/create_grand_parameters.py | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mosartwmpy/_version.py b/mosartwmpy/_version.py index 01ef120..6cd38b7 100644 --- a/mosartwmpy/_version.py +++ b/mosartwmpy/_version.py @@ -1 +1 @@ -__version__ = "0.2.6" +__version__ = "0.2.7" diff --git a/mosartwmpy/grid/grid.py b/mosartwmpy/grid/grid.py index 11c23f7..4071e2d 100644 --- a/mosartwmpy/grid/grid.py +++ b/mosartwmpy/grid/grid.py @@ -159,7 +159,7 @@ def __init__(self, config: Benedict = None, parameters: Parameters = None, empty 3, 2 ) - ) + ).astype(np.int64) # TODO this is basically the same as the above... should consolidate code to just use one of these masks # mosart ocean/land mask @@ -179,7 +179,7 @@ def __init__(self, config: Benedict = None, parameters: Parameters = None, empty 0 ) ) - ) + ).astype(np.int64) # determine final downstream outlet of each cell # this essentially slices up the grid into discrete basins @@ -188,15 +188,15 @@ def __init__(self, config: Benedict = None, parameters: Parameters = None, empty for i, _id in enumerate(self.id): id_hashmap[int(_id)] = int(i) # convert downstream ids into downstream indices - self.downstream_id = np.array([id_hashmap[int(i)] if int(i) in id_hashmap else -1 for i in self.downstream_id], dtype=int) + self.downstream_id = np.array([id_hashmap[int(i)] if int(i) in id_hashmap else -1 for i in self.downstream_id], dtype=np.int64) # update the id to be zero-indexed (note this makes them one less than fortran mosart ids) - self.id = np.arange(self.id.size) + self.id = np.arange(self.id.size).astype(np.int64) # follow each cell downstream to compute outlet id size = self.downstream_id.size - self.outlet_id = np.full(size, -1) - self.upstream_id = np.full(size, -1) - self.upstream_cell_count = np.full(size, 0) + self.outlet_id = np.full(size, -1, dtype=np.int64) + self.upstream_id = np.full(size, -1, dtype=np.int64) + self.upstream_cell_count = np.full(size, 0, dtype=np.int64) for i in np.arange(size): if self.downstream_id[i] >= 0: # mark as upstream cell of downstream cell diff --git a/mosartwmpy/model.py b/mosartwmpy/model.py index 64979da..b792f80 100644 --- a/mosartwmpy/model.py +++ b/mosartwmpy/model.py @@ -362,7 +362,7 @@ def get_grid_rank(self, grid: int = 0) -> int: def get_grid_size(self, grid: int = 0) -> int: return self.grid.cell_count - def get_grid_shape(self, grid: int = 0, shape: np.ndarray = np.empty(2, dtype=int)) -> np.ndarray: + def get_grid_shape(self, grid: int = 0, shape: np.ndarray = np.empty(2, dtype=np.int64)) -> np.ndarray: shape[0] = self.grid.unique_latitudes.size shape[1] = self.grid.unique_longitudes.size return shape diff --git a/mosartwmpy/state/state.py b/mosartwmpy/state/state.py index bb25fec..5b107e8 100644 --- a/mosartwmpy/state/state.py +++ b/mosartwmpy/state/state.py @@ -198,7 +198,7 @@ def __init__(self, grid: Grid = None, config: Benedict = None, parameters: Param # tracer, i.e. liquid or ice - TODO ice not implemented yet self.tracer: np.ndarray = np.empty(0) # euler mask - which cells to perform the euler calculation on - self.euler_mask: np.ndarray = np.empty(0) + self.euler_mask: np.ndarray = np.empty(0, dtype=np.int64) # a column of always all zeros, to use as a utility self.zeros: np.ndarray = np.empty(0) @@ -209,11 +209,11 @@ def __init__(self, grid: Grid = None, config: Benedict = None, parameters: Param # storage [m3] self.reservoir_storage: np.ndarray = np.empty(0) # MthStOp, - self.reservoir_month_start_operations: np.ndarray = np.empty(0) + self.reservoir_month_start_operations: np.ndarray = np.empty(0, dtype=np.int64) # MthStFC - self.reservoir_month_flood_control_start: np.ndarray = np.empty(0) + self.reservoir_month_flood_control_start: np.ndarray = np.empty(0, dtype=np.int64) # MthNdFC - self.reservoir_month_flood_control_end: np.ndarray = np.empty(0) + self.reservoir_month_flood_control_end: np.ndarray = np.empty(0, dtype=np.int64) # release [m3/s] self.reservoir_release: np.ndarray = np.empty(0) # supply [m3/s] diff --git a/mosartwmpy/utilities/create_grand_parameters.py b/mosartwmpy/utilities/create_grand_parameters.py index debe296..b3dba65 100644 --- a/mosartwmpy/utilities/create_grand_parameters.py +++ b/mosartwmpy/utilities/create_grand_parameters.py @@ -199,7 +199,7 @@ def create_grand_parameters( latitude = latitude.flatten() grid = gpd.GeoDataFrame(geometry=gpd.points_from_xy(longitude, latitude)) grid['GRID_CELL_INDEX'] = grid.index - grid['DOWNSTREAM_INDEX'] = domain[grid_downstream_key].values.flatten().astype(int) - 1 + grid['DOWNSTREAM_INDEX'] = domain[grid_downstream_key].values.flatten().astype(np.int64) - 1 grid['DRAINAGE_AREA'] = domain[grid_drainage_area_key].values.flatten() / 1000000 # create a dam geometry point column @@ -432,7 +432,7 @@ def move_dam(dam, error_threshold=1.0, improvement_threshold=0.5): dependent_cells = dependent_cells[dependent_cells['ELEVATION'] <= dam_cell['ELEVATION']] dependent_cells = dependent_cells[dependent_cells['OUTLET_INDEX'] == dam_cell['OUTLET_INDEX']] dependent_cells = dependent_cells.index.values - dependent_cell_indices.append(dependent_cells[~np.isnan(dependent_cells)].astype(int)) + dependent_cell_indices.append(dependent_cells[~np.isnan(dependent_cells)].astype(np.int64)) filtered['DEPENDENT_CELL_INDICES'] = dependent_cell_indices filtered.index = filtered.GRAND_ID.values