Skip to content

Commit c627cee

Browse files
BurgholzerBurgholzer
authored andcommitted
apply ruff to changed files
1 parent 009d61b commit c627cee

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

src/hsp2/hsp2/om_special_action.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def hdf5_load_all(hdf_source):
208208
# - alternative: save the integer timestamp or timestep of the start, and if step/stamp > value, enable
209209
# @tbd: add number of repeats, and save the value of repeats in a register
210210
"""
211+
212+
211213
@njit(cache=True)
212214
def step_special_action(op, state_ix, dict_ix, step):
213215
ix = op[1] # ID of this op

src/hsp2/hsp2/sedtrn_step.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,56 @@
44
from numba.types import List
55

66
# the following imports added to handle special actions
7-
from hsp2.hsp2.state import sedtrn_get_ix, sedtrn_init_ix, get_domain_state, set_domain_state
7+
from hsp2.hsp2.state import (
8+
sedtrn_get_ix,
9+
sedtrn_init_ix,
10+
get_domain_state,
11+
set_domain_state,
12+
)
813
from hsp2.hsp2.om import pre_step_model, step_model, model_domain_dependencies
914
from numba.typed import Dict
1015

16+
1117
@njit
12-
def step_sedtrn(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list, step, ep_list):
18+
def step_sedtrn(
19+
domain,
20+
state_paths,
21+
state_ix,
22+
dict_ix,
23+
ts_ix,
24+
op_tokens,
25+
model_exec_list,
26+
step,
27+
ep_list,
28+
):
1329
# model_exec_list: a list of elements (specl etc.) that influence these SEDTRN end points
1430
# ep_list = np.asarray(["RSED1", "RSED2", "RSED3", "RSED4", "RSED5", "RSED6"], dtype='U')
1531
# NOTE: this could be cached in dict_ix
1632
# call related specl/ops pre-steps, such as loading timeseries values
1733
pre_step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)
1834
# call related specl/ops steps
19-
step_model( model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)
35+
step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)
2036
# get state value at beginning of timestep - python experts will no doubt have a more code efficient method than this
21-
sand_rsed1, silt_rsed2, clay_rsed3, sand_wt_rsed4, silt_wt_rsed5, clay_wt_rsed6 = get_domain_state(state_paths, state_ix, domain, ep_list)
22-
37+
sand_rsed1, silt_rsed2, clay_rsed3, sand_wt_rsed4, silt_wt_rsed5, clay_wt_rsed6 = (
38+
get_domain_state(state_paths, state_ix, domain, ep_list)
39+
)
40+
2341
# now, do sedtrn (simplified for demo purposes)
2442
tsed1 = sand_rsed1 + silt_rsed2 + clay_rsed3
2543
tsed2 = sand_wt_rsed4 + silt_wt_rsed5 + clay_wt_rsed6
26-
sand_t_rsed7 = sand_rsed1 + sand_wt_rsed4
44+
sand_t_rsed7 = sand_rsed1 + sand_wt_rsed4
2745
silt_t_rsed8 = silt_rsed2 + silt_wt_rsed5
2846
clay_t_rsed9 = clay_rsed3 + clay_wt_rsed6
2947
tsed3 = sand_t_rsed7 + silt_t_rsed8 + clay_t_rsed9
30-
48+
3149
# pass values back to state
32-
state_vals = [sand_rsed1, silt_rsed2, clay_rsed3, sand_wt_rsed4, silt_wt_rsed5, clay_wt_rsed6]
50+
state_vals = [
51+
sand_rsed1,
52+
silt_rsed2,
53+
clay_rsed3,
54+
sand_wt_rsed4,
55+
silt_wt_rsed5,
56+
clay_wt_rsed6,
57+
]
3358
set_domain_state(state_paths, state_ix, domain, ep_list, state_vals)
3459
return

src/hsp2/hsp2/state.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ def state_load_dynamics_hsp2(state, io_manager, siminfo):
192192
def get_domain_state(state_paths, state_ix, domain, varkeys):
193193
# get values for a set of variables in a domain
194194
# will not check for the index in state_ix, and will fail if a non-scalar value is needed (like from dict_ix)
195-
# if varkeys = False, assume that we want all the variables
195+
# if varkeys = False, assume that we want all the variables
196196
# from the domain, that are predetermined ahead of time, and should save performance
197197
ret_vals = np.zeros(len(varkeys))
198198
j = 0
199199
for i in varkeys:
200200
# var_path = f'{domain}/{i}'
201201
var_path = domain + "/" + i
202-
#print(var_path)
202+
# print(var_path)
203203
ix = state_paths[var_path]
204-
#print("ix",ix)
204+
# print("ix",ix)
205205
ret_vals[j] = state_ix[ix]
206206
j += 1
207207
return ret_vals
@@ -211,18 +211,19 @@ def get_domain_state(state_paths, state_ix, domain, varkeys):
211211
def set_domain_state(state_paths, state_ix, domain, varkeys, state_vals):
212212
# get values for a set of variables in a domain
213213
# will not check for the index in state_ix, and will fail if a non-scalar value is needed (like from dict_ix)
214-
# if varkeys = False, assume that we want all the variables
214+
# if varkeys = False, assume that we want all the variables
215215
# from the domain, that are predetermined ahead of time, and should save performance
216216
j = 0
217217
for i in varkeys:
218218
# var_path = f'{domain}/{i}'
219219
var_path = domain + "/" + i
220-
#print(var_path)
220+
# print(var_path)
221221
ix = state_paths[var_path]
222222
state_ix[ix] = state_vals[j]
223223
j += 1
224224
return True
225225

226+
226227
def hydr_state_vars():
227228
return [
228229
"DEP",

0 commit comments

Comments
 (0)