Skip to content

Commit

Permalink
fixed compute_surge_comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsail committed Mar 13, 2024
1 parent b8a8ae2 commit 955b9b7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
42 changes: 30 additions & 12 deletions auto_reports/data_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,15 @@ def compute_stats(obs: pd.DataFrame, sim: pd.DataFrame) -> pd.DataFrame:
def compare_one_seaset(
station: str,
lat: float,
obs_root: str,
obs_folder: str,
model_folder: str,
surge_folder: str,
opts: dict,
t_rsp: int = 30,
ext: str = ".csv",
) -> pd.DataFrame:
obs_data = read_df(os.path.join(obs_root, "clean", f"{station}.parquet"))
sim = read_df(os.path.join(obs_root, "model", f"{station}.parquet"))
obs_data = read_df(os.path.join(obs_folder, f"{station}{ext}"))
sim = read_df(os.path.join(model_folder, f"{station}{ext}"))
sim = sim.iloc[:, 0] # take only the first column, whatever its name
local_opts = opts.copy()
local_opts["lat"] = lat
Expand All @@ -325,9 +327,7 @@ def compare_one_seaset(
obs = detide(h_rsmp, **local_opts)
stats = compute_stats(obs, sim)
if len(obs) > 0:
write_df(
obs.to_frame(), os.path.join(obs_root, "surge", f"{station}.parquet")
)
write_df(obs.to_frame(), os.path.join(surge_folder, f"{station}{ext}"))
# add sensor info
stats["sensor"] = sensor
return pd.DataFrame(
Expand All @@ -336,13 +336,26 @@ def compare_one_seaset(


def generate_ioc_comparison_inputs(
stations: pd.DataFrame, obs_folder: str, opts: dict, ext: str = ".csv"
stations: pd.DataFrame,
obs_folder: str,
model_folder: str,
surge_folder: str,
opts: dict,
ext: str = ".csv",
) -> List[dict]:
inputs = []
for i_s, station in enumerate(stations.ioc_code):
lat = stations.iloc[i_s].latitude
inputs.append(
dict(station=station, lat=lat, obs_root=obs_folder, opts=opts, ext=ext)
dict(
station=station,
lat=lat,
obs_root=obs_folder,
model_folder=model_folder,
surge_folder=surge_folder,
opts=opts,
ext=ext,
)
)
return inputs

Expand Down Expand Up @@ -381,11 +394,15 @@ def extract_from_ds(
def compute_surge_comparison(
stations: pd.DataFrame,
obs_folder: str,
model_folder: str,
surge_folder: str,
opts: dict = OPTS,
ext: str = ".csv",
):
logging.info("Computing model vs obs surge comparison..")
inputs = generate_ioc_comparison_inputs(stations, obs_folder, opts, ext)
inputs = generate_ioc_comparison_inputs(
stations, obs_folder, model_folder, surge_folder, opts, ext
)
# the line equation:
results = multiprocess(
compare_one_seaset,
Expand All @@ -402,13 +419,14 @@ def compute_surge_comparison(
def compute_surge_comparison_serial(
stations: pd.DataFrame,
obs_folder: str,
model_folder: str,
surge_folder: str,
opts: dict = OPTS,
ext: str = ".csv",
):
logging.info("Computing model vs obs surge comparison.. (sequential execution)")
inputs = generate_ioc_comparison_inputs(
stations,
obs_folder,
opts,
stations, obs_folder, model_folder, surge_folder, opts, ext
)
# the line equation:
res = pd.DataFrame()
Expand Down
6 changes: 4 additions & 2 deletions auto_reports/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,13 @@ def create_subsequent_pages(
return fig


def create_storm_surge_report(start, end, regions, storm_name, wdir):
def create_storm_surge_report(start, end, regions, storm_name, wdir=None):
if wdir is None:
wdir = os.path.join(os.getcwd())
tmin = start.strftime("%Y-%m-%d")
tmax = end.strftime("%Y-%m-%d")
obs_root = os.path.join(wdir, f"obs/{tmin}_{tmax}")
dirs = ["raw", "clean", "surge"]
dirs = ["raw", "clean", "surge", "model"]

for d in dirs:
ensure_directory(os.path.join(obs_root, d))
Expand Down
Binary file modified model/oper/202310_2D.nc
Binary file not shown.

0 comments on commit 955b9b7

Please sign in to comment.