Skip to content

Commit

Permalink
Merge pull request #35 from noaa-ocs-modeling/develop
Browse files Browse the repository at this point in the history
update examples, use `appdirs` for downloading TPXO dataset, use newer version of `adcircpy`
  • Loading branch information
zacharyburnett authored Mar 8, 2021
2 parents f055b3c + 71293c5 commit d6d50df
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 52 deletions.
29 changes: 22 additions & 7 deletions coupledmodeldriver/adcirc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
RunScript,
SlurmEmailType,
)
from .utilities import get_logger
from .utilities import create_symlink, get_logger

LOGGER = get_logger('adcirc')

Expand Down Expand Up @@ -113,11 +113,19 @@ def write_adcirc_configurations(
output_directory, overwrite=overwrite, include_version=True
)

for filename in coldstart_filenames + [atm_namelist_filename]:
coldstart_filenames.append(atm_namelist_filename)
for filename in coldstart_filenames:
coldstart_filename = Path(f'{filename}.coldstart')
if coldstart_filename.exists():
os.remove(coldstart_filename)
filename.rename(coldstart_filename)
if filename.is_symlink():
target = filename.resolve()
if target in coldstart_filenames:
target = f'{target}.coldstart'
create_symlink(target, coldstart_filename)
os.remove(filename)
else:
filename.rename(coldstart_filename)

if spinup is not None:
hotstart_filenames = nems.write(
Expand All @@ -127,10 +135,17 @@ def write_adcirc_configurations(
hotstart_filenames = []

for filename in hotstart_filenames + [atm_namelist_filename]:
coldstart_filename = Path(f'{filename}.hotstart')
if coldstart_filename.exists():
os.remove(coldstart_filename)
filename.rename(coldstart_filename)
hotstart_filename = Path(f'{filename}.hotstart')
if hotstart_filename.exists():
os.remove(hotstart_filename)
if filename.is_symlink():
target = filename.resolve()
if target in hotstart_filenames:
target = f'{target}.coldstart'
create_symlink(target, hotstart_filename)
os.remove(filename)
else:
filename.rename(hotstart_filename)

coldstart_directory = output_directory / 'coldstart'
runs_directory = output_directory / 'runs'
Expand Down
8 changes: 4 additions & 4 deletions coupledmodeldriver/job_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def __init__(

if self.fort67_filename is not None:
self.commands.extend(
[f'ln -sf {self.fort67_filename} ./fort.67.nc', '', ]
[f'ln -sf {self.fort67_filename} ./fort.67.nc', '']
)

self.commands.append(f'{self.launcher} {self.nems_path}')
Expand Down Expand Up @@ -408,7 +408,7 @@ def __str__(self) -> str:
'# run every hotstart configuration',
bash_for_loop(
'for hotstart in $DIRECTORY/runs/*/',
['cd "$hotstart"', self.hotstart, 'cd $DIRECTORY', ],
['cd "$hotstart"', self.hotstart, 'cd $DIRECTORY'],
),
]

Expand Down Expand Up @@ -441,7 +441,7 @@ def coldstart(self) -> str:
)
else:
lines.extend(
['sh adcprep.job', 'sh nems_adcirc.job', ]
['sh adcprep.job', 'sh nems_adcirc.job']
)
return '\n'.join(lines)

Expand All @@ -457,7 +457,7 @@ def hotstart(self) -> str:
)
else:
lines.extend(
['sh adcprep.job', 'sh nems_adcirc.job', ]
['sh adcprep.job', 'sh nems_adcirc.job']
)
return '\n'.join(lines)

Expand Down
19 changes: 10 additions & 9 deletions coupledmodeldriver/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ def filter(self, rec):
LOGGER = get_logger('utilities')


def create_symlink(from_filename: PathLike, to_filename: PathLike, overwrite: bool = False):
if not isinstance(from_filename, Path):
from_filename = Path(from_filename)
if not isinstance(to_filename, Path):
to_filename = Path(to_filename)
def create_symlink(source_filename: PathLike, symlink_filename: PathLike):
if not isinstance(source_filename, Path):
source_filename = Path(source_filename)
if not isinstance(symlink_filename, Path):
symlink_filename = Path(symlink_filename)

if to_filename.exists() and overwrite:
os.remove(to_filename)
if symlink_filename.is_symlink():
LOGGER.debug(f'removing symlink {symlink_filename}')
os.remove(symlink_filename)

try:
to_filename.symlink_to(from_filename)
symlink_filename.symlink_to(source_filename)
except Exception as error:
LOGGER.warning(f'could not create symbolic link: {error}')
shutil.copyfile(from_filename, to_filename)
shutil.copyfile(source_filename, symlink_filename)


def ellipsoidal_distance(
Expand Down
5 changes: 4 additions & 1 deletion examples/hera/hera_hsofs_irma.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -28,6 +29,8 @@
# directory to which to write configuration
OUTPUT_DIRECTORY = Path(__file__).parent.parent / 'data' / 'configuration' / 'hera_hsofs_irma'

HAMTIDE_DIRECTORY = '/scratch2/COASTAL/coastal/save/shared/models/forcings/tides/hamtide'

if __name__ == '__main__':
# dictionary defining runs with ADCIRC value perturbations - in this case, a single run with no perturbation
runs = {f'test_case_1': (None, None)}
Expand Down Expand Up @@ -56,7 +59,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=HAMTIDE_DIRECTORY)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
5 changes: 4 additions & 1 deletion examples/hera/hera_hsofs_sandy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -28,6 +29,8 @@
# directory to which to write configuration
OUTPUT_DIRECTORY = Path(__file__).parent.parent / 'data' / 'configuration' / 'hera_hsofs_sandy'

HAMTIDE_DIRECTORY = '/scratch2/COASTAL/coastal/save/shared/models/forcings/tides/hamtide'

if __name__ == '__main__':
# dictionary defining runs with ADCIRC value perturbations - in this case, a single run with no perturbation
runs = {f'test_case_1': (None, None)}
Expand Down Expand Up @@ -56,7 +59,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=HAMTIDE_DIRECTORY)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
5 changes: 4 additions & 1 deletion examples/hera/hera_shinnecock_ike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -30,6 +31,8 @@
Path(__file__).parent.parent / 'data' / 'configuration' / 'hera_shinnecock_ike'
)

HAMTIDE_DIRECTORY = '/scratch2/COASTAL/coastal/save/shared/models/forcings/tides/hamtide'

if __name__ == '__main__':
# dictionary defining runs with ADCIRC value perturbations - in this case, a single run with no perturbation
runs = {f'test_case_1': (None, None)}
Expand Down Expand Up @@ -60,7 +63,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=HAMTIDE_DIRECTORY)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
5 changes: 4 additions & 1 deletion examples/hera/hera_shinnecock_ike_perturbed_mannings_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand Down Expand Up @@ -34,6 +35,8 @@
/ 'hera_shinnecock_ike_perturbed_mannings_n'
)

HAMTIDE_DIRECTORY = '/scratch2/COASTAL/coastal/save/shared/models/forcings/tides/hamtide'

if __name__ == '__main__':
# dictionary defining runs with ADCIRC value perturbations - in this case, a range of Manning's N values
range = [0.016, 0.08]
Expand Down Expand Up @@ -67,7 +70,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=HAMTIDE_DIRECTORY)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
5 changes: 3 additions & 2 deletions examples/local/local_hsofs_irma.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -17,7 +18,7 @@

# directory containing input ADCIRC mesh nodes (`fort.14`) and (optionally) mesh values (`fort.13`)
MESH_DIRECTORY = (
Path(__file__).parent.parent / 'data' / 'input' / 'meshes' / 'hsofs' / 'irma' / 'grid_v1'
Path(__file__).parent.parent / 'data' / 'input' / 'meshes' / 'hsofs' / 'grid_v1'
)

# directory containing input atmospheric mesh forcings (`wind_atm_fin_ch_time_vec.nc`) and WaveWatch III forcings (`ww3.Constant.20151214_sxy_ike_date.nc`)
Expand Down Expand Up @@ -56,7 +57,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
5 changes: 3 additions & 2 deletions examples/local/local_hsofs_sandy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -17,7 +18,7 @@

# directory containing input ADCIRC mesh nodes (`fort.14`) and (optionally) mesh values (`fort.13`)
MESH_DIRECTORY = (
Path(__file__).parent.parent / 'data' / 'input' / 'meshes' / 'hsofs' / 'sandy' / 'grid_v1'
Path(__file__).parent.parent / 'data' / 'input' / 'meshes' / 'hsofs' / 'grid_v1'
)

# directory containing input atmospheric mesh forcings (`wind_atm_fin_ch_time_vec.nc`) and WaveWatch III forcings (`ww3.Constant.20151214_sxy_ike_date.nc`)
Expand Down Expand Up @@ -56,7 +57,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
11 changes: 3 additions & 8 deletions examples/local/local_shinnecock_ike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -17,13 +18,7 @@

# directory containing input ADCIRC mesh nodes (`fort.14`) and (optionally) mesh values (`fort.13`)
MESH_DIRECTORY = (
Path(__file__).parent.parent
/ 'data'
/ 'input'
/ 'meshes'
/ 'shinnecock'
/ 'ike'
/ 'grid_v1'
Path(__file__).parent.parent / 'data' / 'input' / 'meshes' / 'shinnecock' / 'grid_v1'
)

# directory containing input atmospheric mesh forcings (`wind_atm_fin_ch_time_vec.nc`) and WaveWatch III forcings (`ww3.Constant.20151214_sxy_ike_date.nc`)
Expand Down Expand Up @@ -62,7 +57,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
11 changes: 3 additions & 8 deletions examples/local/local_shinnecock_ike_perturbed_mannings_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand All @@ -18,13 +19,7 @@

# directory containing input ADCIRC mesh nodes (`fort.14`) and (optionally) mesh values (`fort.13`)
MESH_DIRECTORY = (
Path(__file__).parent.parent
/ 'data'
/ 'input'
/ 'meshes'
/ 'shinnecock'
/ 'ike'
/ 'grid_v1'
Path(__file__).parent.parent / 'data' / 'input' / 'meshes' / 'shinnecock' / 'grid_v1'
)

# directory containing input atmospheric mesh forcings (`wind_atm_fin_ch_time_vec.nc`) and WaveWatch III forcings (`ww3.Constant.20151214_sxy_ike_date.nc`)
Expand Down Expand Up @@ -73,7 +68,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
3 changes: 2 additions & 1 deletion examples/stampede2/stampede2_hsofs_sandy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand Down Expand Up @@ -52,7 +53,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
3 changes: 2 additions & 1 deletion examples/stampede2/stampede2_shinnecock_ike.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand Down Expand Up @@ -54,7 +55,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from adcircpy import Tides
from adcircpy.forcing.tides.tides import TidalSource
from adcircpy.forcing.waves.ww3 import WaveWatch3DataForcing
from adcircpy.forcing.winds.atmesh import AtmosphericMeshForcing
from nemspy import ModelingSystem
Expand Down Expand Up @@ -62,7 +63,7 @@
]

# initialize `adcircpy` forcing objects
tidal_forcing = Tides()
tidal_forcing = Tides(tidal_source=TidalSource.HAMTIDE, resource=None)
tidal_forcing.use_all()
wind_forcing = AtmosphericMeshForcing(nws=17, interval_seconds=3600)
wave_forcing = WaveWatch3DataForcing(nrs=5, interval_seconds=3600)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
packages=find_packages(),
python_requires='>=3.6',
setup_requires=['dunamai', 'setuptools>=41.2'],
install_requires=['adcircpy==1.0.20', 'nemspy>=0.6.2', 'numpy', 'requests'],
install_requires=['adcircpy>=1.0.21', 'nemspy>=0.6.5', 'numpy', 'requests'],
extras_require={'testing': ['flake8', 'pytest', 'pytest-cov'], 'development': ['oitnb']},
)
Loading

0 comments on commit d6d50df

Please sign in to comment.