Skip to content

Commit ff0f471

Browse files
create an interpretation of partial opening of DCC as monthly fraction
1 parent 26d48d2 commit ff0f471

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

bdschism/bdschism/port_boundary.py

+27
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ def clean_df(in_df):
126126
return out_df
127127

128128

129+
def set_gate_fraction(dts, op_var="height", ubound=10, lbound=0):
130+
# Filter rows where height is not 10 or 0
131+
fraction_mask = (dts[op_var] != ubound) & (dts[op_var] != lbound)
132+
133+
# Apply the mask to filter the DataFrame
134+
filtered_dts = dts[fraction_mask]
135+
136+
# Group the filtered DataFrame by month
137+
for month, group in filtered_dts.groupby(filtered_dts.index.to_period("M")):
138+
# Calculate the fraction
139+
fraction = group[op_var].iloc[0] / ubound
140+
141+
# Get the first fraction of the month
142+
fraction_point = int(len(group) * fraction)
143+
first_indices = group.index[:fraction_point]
144+
second_indices = group.index[fraction_point:]
145+
146+
# Set the first half to lbound and the second half to ubound
147+
dts.loc[first_indices, op_var] = lbound
148+
dts.loc[second_indices, op_var] = ubound
149+
150+
return dts
151+
152+
129153
@click.command()
130154
@click.argument("config_yaml", type=click.Path(exists=True))
131155
@click.option(
@@ -271,6 +295,9 @@ def create_schism_bc(config_yaml, kwargs={}):
271295
source_file, v, name, dt, p=p, interp=interp
272296
)
273297
dts = eval(formula).to_frame(name).reindex(df_rng)
298+
if boundary_kind == "dcc_gate":
299+
# Need to make any Percentage between 0 and 100 and convert them to days of month open
300+
dts = set_gate_fraction(dts.ffill(), "height")
274301
if interp:
275302
dfi = ts_gaussian_filter(dts, sigma=100)
276303
else:

0 commit comments

Comments
 (0)