Skip to content

Commit 35108a6

Browse files
author
Cinzia Mazzetti
committed
running on catchment with single gridcell
1 parent a64d1f1 commit 35108a6

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/lisflood/hydrological_modules/kinematic_wave_parallel.py

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def _setRoutingOrders(self):
154154
self.pixels_ordered = self.pixels_ordered.sort_values(["order", "pixels"]).set_index("order").squeeze()
155155
except: # FOR COMPATIBILITY WITH OLDER PANDAS VERSIONS
156156
self.pixels_ordered = self.pixels_ordered.sort(["order", "pixels"]).set_index("order").squeeze()
157+
# Ensure output is always a Series, even if only one element
158+
if not isinstance(self.pixels_ordered, pd.DataFrame):
159+
self.pixels_ordered = pd.Series(self.pixels_ordered)
160+
157161
order_counts = self.pixels_ordered.groupby(self.pixels_ordered.index).count()
158162
stop = order_counts.cumsum()
159163
self.order_start_stop = np.column_stack((np.append(0, stop[:-1]), stop)).astype(int)

src/lisflood/hydrological_modules/routing.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -1148,9 +1148,16 @@ def MCTRoutingLoop(self,ChanQMCTOutStart,ChanQMCTInStart,ChanQKinOut,SideflowCha
11481148
### calling MCT function for single cell
11491149
q11[idpix], V11[idpix], Cm0[idpix], Dm0[idpix] = self.MCTRouting_single(q10[idpix], q01[idpix], q00[idpix], ql[idpix], Cm0[idpix], Dm0[idpix],
11501150
dt, xpix[idpix], s0[idpix], Balv[idpix], ANalv[idpix], Nalv[idpix])
1151-
# debug
1152-
# q11[idpix] = q01[idpix]
1153-
# Set outflow to be the same as inflow in MCT grid cells ('tanto entra tanto esce')
1151+
1152+
# # cmcheck - tanto entra tanto esce
1153+
# # debug
1154+
# q11[idpix] = q01[idpix] + ql[idpix]
1155+
# # Set outflow to be the same as inflow in MCT grid cells ('tanto entra tanto esce')
1156+
# V11[idpix] = ChanM3MCT0[idpix]
1157+
# # Set end volume to be the same as initial volume in MCT grid cells ('tanto entra tanto esce')
1158+
1159+
1160+
11541161

11551162
# Update contribution from upstream pixels at time t+1 (dim=all pixels) using the newly calculated q11
11561163
# I want to update q01 (inflow at t+1) for cells downstream of idpix using the newly calculated q11
@@ -1288,10 +1295,10 @@ def MCTRouting_single(self, q10, q01, q00, ql, Cm0, Dm0, dt, xpix, s0, Balv, ANa
12881295
#### end of for loop
12891296

12901297

1291-
# cmcheck
1292-
calc_t = xpix / ck1
1293-
if calc_t < dt:
1294-
print('xpix/ck1 < dt')
1298+
# # cmcheck
1299+
# calc_t = xpix / ck1
1300+
# if calc_t < dt:
1301+
# print('xpix/ck1 < dt')
12951302

12961303

12971304
k1 = dt / Cm1
@@ -1556,12 +1563,10 @@ def _setMCTRoutingOrders(self):
15561563
self.pixels_ordered = self.pixels_ordered.sort_values(["order", "pixels"]).set_index("order").squeeze()
15571564
except: # FOR COMPATIBILITY WITH OLDER PANDAS VERSIONS
15581565
self.pixels_ordered = self.pixels_ordered.sort(["order", "pixels"]).set_index("order").squeeze()
1559-
# Output of pd.DataFrame.squeeze() is not a DataFrame and not a Series.
1566+
# Ensure output is always a Series, even if only one element
15601567
if not isinstance(self.pixels_ordered, pd.Series):
1561-
# self.pixels_ordered = pd.DataFrame({'order': [0], 'pixel': self.pixels_ordered})
1562-
# self.pixels_ordered.set_index('order', inplace=True)
15631568
self.pixels_ordered = pd.Series(self.pixels_ordered)
1564-
self.pixels_ordered.rename_axis("order")
1569+
15651570
order_counts = self.pixels_ordered.groupby(self.pixels_ordered.index).count()
15661571
stop = order_counts.cumsum()
15671572
self.order_start_stop = np.column_stack((np.append(0, stop[:-1]), stop)).astype(int) # astype for cython import in windows (see above)

0 commit comments

Comments
 (0)