Skip to content

Commit

Permalink
Merge pull request #46 from oceanmodeling/bugfix/minor
Browse files Browse the repository at this point in the history
Bugfixes and cleanup
  • Loading branch information
SorooshMani-NOAA committed Mar 6, 2024
2 parents 269f744 + 69a1a00 commit d48c0cb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 34 deletions.
6 changes: 4 additions & 2 deletions singularity/info/files/hurricane_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def main(args):
else:
event = StormEvent(name_or_code, year)
nhc_code = event.nhc_code
storm_name = event.name
logger.info("Fetching a-deck track info...")

prescribed = None
Expand Down Expand Up @@ -137,7 +138,7 @@ def main(args):
gdf_track
))
df_dt['date_time'] = (
track.start_date, track.end_date, forecast_start
forecast_start - timedelta(days=2), track.end_date, forecast_start
)


Expand Down Expand Up @@ -174,6 +175,7 @@ def main(args):
# NOTE: Fake best track AFTER perturbation
# gdf_track.advisory = 'BEST'
# gdf_track.forecast_hours = 0
gdf_track['name'] = storm_name
track = VortexTrack(storm=gdf_track, file_deck='a', advisories=[advisory])

windswath_dict = track.wind_swaths(wind_speed=34)
Expand Down Expand Up @@ -251,7 +253,7 @@ def main(args):
geometry=gs, data={'RADII': len(gs) * [34]}, crs="EPSG:4326"
)
gdf_windswath.to_file(swath_out)
if coops_ssh is not None:
if coops_ssh is not None and len(coops_ssh) > 0:
coops_ssh.to_netcdf(sta_dat_out, 'w')
coops_ssh[['x', 'y']].to_dataframe().drop(columns=['nws_id']).to_csv(
sta_loc_out, header=False, index=False)
Expand Down
2 changes: 1 addition & 1 deletion singularity/info/info.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ From: continuumio/miniconda3:23.3.1-0-alpine
mamba clean --all --yes

conda run -n info --no-capture-output \
pip install stormevents==2.2.0
pip install stormevents==2.2.1


conda clean --all
Expand Down
2 changes: 1 addition & 1 deletion singularity/prep/files/setup_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def main(args):
# spinup too instead of spinup trying to download!
forcing_configurations.append(
BestTrackForcingJSON(
nhc_code=f'{args.name}{args.year}',
nhc_code=orig_track.nhc_code,
interval_seconds=3600,
nws=20,
fort22_filename=workdir / 'track_files' / 'original.22',
Expand Down
93 changes: 63 additions & 30 deletions singularity/prep/files/setup_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from pyschism import dates
from pyschism.enums import NWSType
from pyschism.driver import ModelConfig
from pyschism.forcing.bctides import iettype, ifltype
from pyschism.forcing.bctides.tides import Tides, TidalDatabase
from pyschism.forcing.bctides.tpxo import TPXO_ELEVATION
from pyschism.forcing.bctides.tpxo import TPXO_VELOCITY
from pyschism.forcing.nws import GFS, HRRR, ERA5, BestTrackForcing
from pyschism.forcing.nws.nws2 import hrrr3
from pyschism.forcing.source_sink import NWM
Expand Down Expand Up @@ -146,17 +148,20 @@ def copy_meteo_cache(sflux_dir, meteo_cache_path):


def setup_schism_model(
mesh_path,
domain_bbox_path,
date_range_path,
station_info_path,
out_dir,
main_cache_path,
parametric_wind=False,
nhc_track_file=None,
storm_id=None,
use_wwm=False,
):
mesh_path,
domain_bbox_path,
date_range_path,
station_info_path,
out_dir,
main_cache_path,
parametric_wind=False,
nhc_track_file=None,
storm_id=None,
use_wwm=False,
tpxo_dir=None,
with_hydrology=False,
):


domain_box = gpd.read_file(domain_bbox_path)
atm_bbox = Bbox(domain_box.to_crs('EPSG:4326').total_bounds.reshape(2, 2))
Expand All @@ -173,9 +178,12 @@ def setup_schism_model(
# measurement days +7 days of simulation: 3 ramp, 2 prior
# & 2 after the measurement dates
dt_data = pd.read_csv(date_range_path, delimiter=',')
date_1, date_2 = pd.to_datetime(dt_data.date_time).dt.strftime('%Y%m%d%H').values
date_1 = datetime.strptime(date_1, '%Y%m%d%H')
date_2 = datetime.strptime(date_2, '%Y%m%d%H')
date_1, date_2, date_3 = pd.to_datetime(dt_data.date_time).dt.strftime(
"%Y%m%d%H").values
date_1 = datetime.strptime(date_1, "%Y%m%d%H")
date_2 = datetime.strptime(date_2, "%Y%m%d%H")
# date_3 = datetime.strptime(date_3, "%Y%m%d%H")


# If there are no observation data, it's hindcast mode
hindcast_mode = (station_info_path).is_file()
Expand Down Expand Up @@ -239,15 +247,26 @@ def setup_schism_model(
# hrrr3.HRRR combination are supported by nws2 mechanism
pass

logger.info('Creating model configuration ...')

tidal_flags = [3, 3, 0, 0]
logger.info("Creating model configuration ...")
src_sink = None
if with_hydrology:
src_sink = NWM()
config = ModelConfig(
hgrid=hgrid,
fgrid=fgrid,
iettype=iettype.Iettype3(database='tpxo'),
ifltype=ifltype.Ifltype3(database='tpxo'),
flags=[tidal_flags for _ in hgrid.boundaries.open.itertuples()],
constituents=[], # we're overwriting Tides obj
database='tpxo', # we're overwriting Tides obj
nws=atmospheric,
source_sink=NWM(),
source_sink=src_sink,
)
tide_db = TidalDatabase.TPXO.value(
h_file=tpxo_dir / TPXO_ELEVATION, u_file=tpxo_dir / TPXO_VELOCITY,
)
tides = Tides(tidal_database=tide_db, constituents='all')
config.bctides.tides = tides

if config.forcings.nws and getattr(config.forcings.nws, 'sflux_2', None):
config.forcings.nws.sflux_2.inventory.file_interval = timedelta(hours=6)
Expand Down Expand Up @@ -396,7 +415,8 @@ def setup_schism_model(

# Workardoun for hydrology param bug #34
nm_list = f90nml.read(schism_dir / 'param.nml')
nm_list['opt']['if_source'] = 1
if with_hydrology:
nm_list['opt']['if_source'] = 1
nm_list.write(schism_dir / 'param.nml', force=True)
## end of workaround

Expand Down Expand Up @@ -430,12 +450,14 @@ def main(args):
nwm_dir = args.nwm_dir
use_wwm = args.use_wwm

if TPXO_LINK_PATH.is_dir():
shutil.rmtree(TPXO_LINK_PATH)
if NWM_LINK_PATH.is_dir():
shutil.rmtree(NWM_LINK_PATH)
os.symlink(tpxo_dir, TPXO_LINK_PATH, target_is_directory=True)
os.symlink(nwm_dir, NWM_LINK_PATH, target_is_directory=True)
with_hydrology = args.with_hydrology

# if TPXO_LINK_PATH.is_dir():
# shutil.rmtree(TPXO_LINK_PATH)
# if NWM_LINK_PATH.is_dir():
# shutil.rmtree(NWM_LINK_PATH)
# os.symlink(tpxo_dir, TPXO_LINK_PATH, target_is_directory=True)
# os.symlink(nwm_dir, NWM_LINK_PATH, target_is_directory=True)

setup_schism_model(
mesh_path,
Expand All @@ -448,7 +470,9 @@ def main(args):
nhc_track_file=nhc_track,
storm_id=f'{storm_name}{storm_year}',
use_wwm=use_wwm,
)
tpxo_dir=tpxo_dir,
with_hydrology=with_hydrology,
)


if __name__ == '__main__':
Expand Down Expand Up @@ -504,11 +528,20 @@ def main(args):
'--out', help='path to the setup output (solver input) directory', type=pathlib.Path
)

parser.add_argument('--use-wwm', action='store_true')
parser.add_argument(
"--use-wwm", action="store_true"
)

parser.add_argument(
"--with-hydrology", action="store_true"
)

parser.add_argument(
"name", help="name of the storm", type=str)

parser.add_argument('name', help='name of the storm', type=str)
parser.add_argument(
"year", help="year of the storm", type=int)

parser.add_argument('year', help='year of the storm', type=int)

args = parser.parse_args()

Expand Down
3 changes: 3 additions & 0 deletions singularity/prep/prep.def
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ From: continuumio/miniconda3:23.5.2-0-alpine
mamba install -y -n $ENV_NAME -cconda-forge \
--force-reinstall geopandas geopandas-base

pip uninstall pygeos # We use shapely 2
mamba install -y -cconda-forge --force-reinstall geopandas

git clone https://github.com/schism-dev/schism
cp -v schism/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Source_sink/Relocate/relocate_source_feeder.py /scripts
cp -v schism/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Source_sink/feeder_heads_bases_v2.1.xy /refs
Expand Down

0 comments on commit d48c0cb

Please sign in to comment.