Skip to content

Commit

Permalink
Fixed TPXO environment variables issue in #118
Browse files Browse the repository at this point in the history
  • Loading branch information
cuill committed Feb 3, 2024
1 parent 445ea19 commit 5d453fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/Bctides/gen_bctides.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from pyschism.mesh import Hgrid
from pyschism.forcing.bctides import Bctides

##Optional: set up environment variable for TPXO files
#os.environ['TPXO_ELEVATION'] = '/path-to-your-hfile/h_tpxo9.v1.nc'
#os.environ['TPXO_VELOCITY'] = '/path-to-your-ufile/u_tpxo9.v1.nc'

logging.basicConfig(
format = "[%(asctime)s] %(name)s %(levelname)s: %(message)s",
force=True,
Expand Down
6 changes: 6 additions & 0 deletions pyschism/forcing/bctides/tpxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ def h(self):
if self._h_file is None:
self._h_file = pathlib.Path(
appdirs.user_data_dir('tpxo')) / TPXO_ELEVATION
elif type(self._h_file) is str:
self._h_file = pathlib.Path(self._h_file)
if not self._h_file.exists():
raise_missing_file(self._h_file, TPXO_ELEVATION)
logger.info(f'h_file is {self._h_file}')
self._h = Dataset(self._h_file)
return self._h

Expand All @@ -114,8 +117,11 @@ def uv(self):
if self._u_file is None:
self._u_file = pathlib.Path(
appdirs.user_data_dir('tpxo')) / TPXO_VELOCITY
elif type(self._u_file) is str:
self._u_file = pathlib.Path(self._u_file)
if not self._u_file.exists():
raise_missing_file(self._u_file, TPXO_VELOCITY)
logger.info(f'u_file is {self._u_file}')
self._uv = Dataset(self._u_file)
return self._uv

Expand Down

0 comments on commit 5d453fc

Please sign in to comment.