Skip to content

Commit

Permalink
fix streams not computed (#188)
Browse files Browse the repository at this point in the history
* fix streams not computed
* rename reachfid -> surfacestate
  • Loading branch information
pesekon2 authored Jun 19, 2023
1 parent 1f65d9b commit 71ceed0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmd_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
python-version:
- "2.7"
# - "2.7"
- "3.8"
- "3.11.2"

Expand Down
16 changes: 13 additions & 3 deletions smoderp2d/core/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def __init__(self):

self.mat_stream_reach = Gl.mat_stream_reach

self.state = self.mat_stream_reach
self.arr.state = ma.where(
self.mat_stream_reach > Gl.streams_flow_inc,
self.mat_stream_reach,
0
)

self.STREAM_RATIO = Gl.STREAM_RATIO

Expand All @@ -124,7 +128,13 @@ def reset_inflows(self):
# @param fid feature id
def reach_inflows(self, fid, inflows, indices):
try:
self.reach[fid].V_in_from_field += ma.where(indices, inflows, 0)
# TODO: Would be nice to avoid the loop
for fid_cur in self.reach.keys():
self.reach[fid_cur].V_in_from_field += ma.sum(
ma.where(
ma.logical_and(indices, fid == fid_cur), inflows, 0
)
)
except KeyError:
raise ProviderError(
"Unable to reach inflow. Feature id {} not found in {}".format(
Expand Down Expand Up @@ -172,7 +182,7 @@ def stream_cumulative(self, time):
r.h_max = ma.maximum(r.h, r.h_max)

def return_stream_str_vals(self, i, j, sep, dt, extraOut):
fid = int(self.state[i, j] - Gl.streams_flow_inc)
fid = int(self.arr.state[i, j] - Gl.streams_flow_inc)
# Time; V_runoff ; Q ; V_from_field ; V_rests_in_stream
# print fid, self.reach[fid].Q_out, str(self.reach[fid].V_out)
r = self.reach[fid]
Expand Down
9 changes: 5 additions & 4 deletions smoderp2d/providers/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def postprocessing(self, cumulative, surface_array, stream):

self.storage.write_raster(self._make_mask(totalBil), 'massbalance', 'control')
self.storage.write_raster(self._make_mask(vRest), 'volrest_m3', 'control')
self.storage.write_raster(self._make_mask(finState), 'reachfid', 'control')
self.storage.write_raster(self._make_mask(finState), 'surfacestate', 'control')

# store stream reaches results to a table
# if stream is calculated
Expand Down Expand Up @@ -554,9 +554,10 @@ def postprocessing(self, cumulative, surface_array, stream):
outputtable[i][5] = ma.unique(stream[fid[i]].V_out_cum)[0]
outputtable[i][6] = ma.unique(stream[fid[i]].Q_max)[0]

path_ = os.path.join(
Globals.outdir, 'temp', 'stream.csv'
)
temp_dir = os.path.join(Globals.outdir, 'temp')
if not os.path.isdir(temp_dir):
os.makedirs(temp_dir)
path_ = os.path.join(temp_dir, 'stream.csv')
np.savetxt(path_, outputtable, delimiter=';',fmt = '%.3e',
header='FID{sep}b_m{sep}m__{sep}rough_s_m1_3{sep}q365_m3_s{sep}V_out_cum_m3{sep}Q_max_m3_s'.format(sep=';'))

Expand Down
5 changes: 4 additions & 1 deletion smoderp2d/time_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def do_flow(self, surface, subsurface, delta_t, flow_control, courant):
delta_t, mat_efect_cont
)
if ma.any(cond_state_flow):
fc.ratio = 0
fc.ratio = ma.masked_array(
np.zeros((GridGlobals.r, GridGlobals.c)),
mask=GridGlobals.masks
)
else:
# TODO: Better way to make it just a number
fc.ratio = runoff_return[4]
Expand Down

0 comments on commit 71ceed0

Please sign in to comment.