Skip to content

Commit

Permalink
Merge pull request #80 from IMMM-SFA/hotfix/integer-64
Browse files Browse the repository at this point in the history
force int64 wherever ints are used to address windows inconsistencies
  • Loading branch information
thurber authored Feb 3, 2022
2 parents 1bdfa0e + 4095683 commit 4792a84
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mosartwmpy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.6"
__version__ = "0.2.7"
14 changes: 7 additions & 7 deletions mosartwmpy/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mosartwmpy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions mosartwmpy/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions mosartwmpy/utilities/create_grand_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4792a84

Please sign in to comment.