Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions adforce/ani.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .mesh import bbox_mesh, xr_loader
from .fort22datatree import read_fort22
from .constants import NO_BBOX, NEW_ORLEANS
from .config import load_config
from .fort22 import create_fort22

# from sithom.xr import plot_units

Expand Down Expand Up @@ -145,6 +147,7 @@ def ani_heights_and_winds(
x_pos (float, optional): relative x position of quiver label.
y_pos (float, optional): relative y position of quiver label.
"""
regenerate_fort22_if_does_not_exist(path_in)
plot_defaults()
img_folder = os.path.join(path_in, "img", "height_and_wind")
gif_folder = os.path.join(path_in, "gif", "height_and_wind")
Expand Down Expand Up @@ -421,6 +424,8 @@ def single_wind_and_height_step(
"""
plot_defaults()

regenerate_fort22_if_does_not_exist(path_in)

img_folder = os.path.join(path_in, "img")
os.makedirs(img_folder, exist_ok=True)
if bbox is not None:
Expand Down Expand Up @@ -564,6 +569,24 @@ def single_wind_and_height_step(
plt.clf()


def regenerate_fort22_if_does_not_exist(path: str) -> None:
"""
Regenerate fort.22 if it does not exist.

Args:
path (str): path to fort.22.nc.
"""
if not os.path.exists(os.path.join(path, "fort.22.nc")) and os.path.exists(
os.path.join(path, "config.yaml")
):
print("Regenerating fort.22.nc")
cfg = load_config(os.path.join(path, "config.yaml"))
create_fort22(path, cfg.grid, cfg.tc)
print("fort.22.nc regenerated")
else:
print("fort.22.nc already exists or config.yaml not found")


if __name__ == "__main__":
# python -m adforce.ani
run_animation()
Expand Down
27 changes: 26 additions & 1 deletion adforce/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,37 @@
ChavasCollision: A dataclass to store the impact location of the Chavas Lin and Emanuel (2015) profile collision on a straight track.
"""

import os
from dataclasses import dataclass
import hydra
from omegaconf import DictConfig
from omegaconf import OmegaConf


@dataclass
class ChavasCollision:
impact_lon: float
impact_lat: float


def save_config(cfg: DictConfig) -> None:
"""Save the configuration file for a wrapped ADCIRC run.

Args:
cfg (DictConfig): configuration.
"""
with open(os.path.join(cfg.files.run_folder, "config.yaml"), "w") as fp:
OmegaConf.save(config=cfg, f=fp.name)


def load_config(path: str) -> DictConfig:
"""Load the configuration file for a wrapped ADCIRC run.

Args:
path (str): path to the config file.

Returns:
DictConfig: loaded configuration.
"""
with open(path, "r") as fp:
cfg = OmegaConf.load(fp.name)
return cfg
11 changes: 1 addition & 10 deletions adforce/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .slurm import setoff_slurm_job_and_wait
from .subprocess import setoff_subprocess_job_and_wait
from .mesh import xr_loader
from .config import save_config


def observe_max_point(cfg: DictConfig) -> float:
Expand Down Expand Up @@ -39,16 +40,6 @@ def observe_max_point(cfg: DictConfig) -> float:
return maxele


def save_config(cfg: DictConfig) -> None:
"""Save the configuration file.

Args:
cfg (DictConfig): configuration.
"""
with open(os.path.join(cfg.files.run_folder, "config.yaml"), "w") as fp:
OmegaConf.save(config=cfg, f=fp.name)


@timeit
def idealized_tc_observe(cfg: DictConfig) -> float:
"""Wrap the adcirc call.
Expand Down