forked from UMEP-dev/SUEWS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_sample_output.py
33 lines (27 loc) · 1.22 KB
/
gen_sample_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from datetime import datetime
from pathlib import Path
import supy as sp
# Get the test data directory from the environment variable
test_data_dir = Path(__file__).parent / "supy"/'test' / "data_test"
# test_data_dir = os.environ.get('TEST_DATA_DIR', Path(__file__).parent / 'data_test')
# Construct the file path for the data file
p_df_sample = Path(test_data_dir) / "sample_output.pkl"
# if file exists, rename it with a timestamp
if p_df_sample.exists():
# generate a timestamp as of now
dt_stamp = datetime.now()
str_stamp = dt_stamp.strftime("%Y%m%d_%H%M%S")
# rename the file
print(f"Renaming existing file: {p_df_sample.as_posix()}")
p_df_sample_save=p_df_sample.with_suffix(f".{str_stamp}.pkl")
p_df_sample.rename(p_df_sample_save)
print(f"Renamed to: {p_df_sample_save.as_posix()}")
print("\n========================================")
print("Generating sample output for testing")
df_state_init, df_forcing_tstep = sp.load_SampleData()
df_forcing_part = df_forcing_tstep.iloc[: 288 * 365]
# single-step results
df_output_s, df_state_s = sp.run_supy(df_forcing_part, df_state_init)
# generate pickle file
print(f"Saving sample output to: {p_df_sample.as_posix()}")
df_output_s.SUEWS.to_pickle(p_df_sample)