Skip to content

Commit

Permalink
fix: try inferring both long and short period tides for FES (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley authored Sep 27, 2024
1 parent da9de5e commit 2aa4938
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
12 changes: 6 additions & 6 deletions pyTMD/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def tide_elevations(
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide[i], hc, c,
deltat=deltat[i], corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components and reform grid
Expand All @@ -418,7 +418,7 @@ def tide_elevations(
if INFER_MINOR:
minor = pyTMD.predict.infer_minor(ts.tide, hc, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
tide.data[:] += minor.data[:]
elif (TYPE.lower() == 'time series'):
nstation = len(x)
Expand All @@ -432,7 +432,7 @@ def tide_elevations(
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide, HC, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components
Expand Down Expand Up @@ -636,7 +636,7 @@ def tide_currents(
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide[i], hc, c,
deltat=deltat[i], corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components and reform grid
Expand All @@ -651,7 +651,7 @@ def tide_currents(
if INFER_MINOR:
minor = pyTMD.predict.infer_minor(ts.tide, hc, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
tide[t].data[:] += minor.data[:]
elif (TYPE.lower() == 'time series'):
nstation = len(x)
Expand All @@ -665,7 +665,7 @@ def tide_currents(
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide, HC, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components
Expand Down
11 changes: 0 additions & 11 deletions pyTMD/io/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
add file_format and nodal correction attributes
export database as a dataclass for easier access
added variable name and descriptions for long period tides
added attribute for model bulk frequencies for long period tides
Updated 08/2024: added attribute for minor constituents to infer
allow searching over iterable glob strings in definition files
added option to try automatic detection of definition file format
Expand Down Expand Up @@ -302,16 +301,6 @@ def corrections(self) -> str:
else:
return part1

@property
def frequency(self) -> str:
"""
Returns the frequency type for the model
"""
if self.variable in ('tide_lpe',):
return 'long'
else:
return 'short'

@property
def file_format(self) -> str:
"""
Expand Down
31 changes: 19 additions & 12 deletions pyTMD/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"""
from __future__ import annotations

import logging
import numpy as np
import pyTMD.arguments
import pyTMD.astro
Expand Down Expand Up @@ -310,11 +311,8 @@ def infer_minor(
time correction for converting to Ephemeris Time (days)
corrections: str, default 'OTIS'
use nodal corrections from OTIS/ATLAS or GOT/FES models
frequency: str, default 'short'
frequency of tidal constituents to infer
- 'short': diurnal and semidiurnal constituents
- 'long': long-period constituents
raise_exception: bool, default False
Raise a ``ValueError`` if major constituents are not found
minor: list or None, default None
tidal constituent IDs
Expand Down Expand Up @@ -343,14 +341,13 @@ def infer_minor(
# set default keyword arguments
kwargs.setdefault('deltat', 0.0)
kwargs.setdefault('corrections', 'OTIS')
kwargs.setdefault('frequency', 'short')
kwargs.setdefault('raise_exception', False)
# list of minor constituents
kwargs.setdefault('minor', None)
# infer the minor tidal constituents
if kwargs['frequency'] in ('short',):
dh = _infer_short_period(t, zmajor, constituents, **kwargs)
elif kwargs['frequency'] in ('long',):
dh = _infer_long_period(t, zmajor, constituents, **kwargs)
dh = 0.0
dh += _infer_short_period(t, zmajor, constituents, **kwargs)
dh += _infer_long_period(t, zmajor, constituents, **kwargs)
# return the inferred values
return dh

Expand Down Expand Up @@ -400,6 +397,7 @@ def _infer_short_period(
# set default keyword arguments
kwargs.setdefault('deltat', 0.0)
kwargs.setdefault('corrections', 'OTIS')
kwargs.setdefault('raise_exception', False)
# list of minor constituents
kwargs.setdefault('minor', None)
# number of constituents
Expand All @@ -421,8 +419,12 @@ def _infer_short_period(
z[:,i] = zmajor[:,j1]
nz += 1

if (nz < 6):
# raise exception or log error
if (nz < 6) and kwargs['raise_exception']:
raise Exception('Not enough constituents for inference')
elif (nz < 6):
logging.debug('Not enough constituents for inference')
return 0.0

# complete list of minor constituents
minor_constituents = ['2q1', 'sigma1', 'rho1', 'm1b', 'm1',
Expand Down Expand Up @@ -528,6 +530,7 @@ def _infer_long_period(
`doi: 10.1002/2013JB010830 <https://doi.org/10.1002/2013JB010830>`_
"""
# set default keyword arguments
kwargs.setdefault('raise_exception', False)
kwargs.setdefault('deltat', 0.0)
kwargs.setdefault('corrections', 'OTIS')
# list of minor constituents
Expand Down Expand Up @@ -558,8 +561,12 @@ def _infer_long_period(
z[:,i] = zmajor[:,j1]/amajor[i]
nz += 1

if (nz < 3):
# raise exception or log error
if (nz < 3) and kwargs['raise_exception']:
raise Exception('Not enough constituents for inference')
elif (nz < 3):
logging.debug('Not enough constituents for inference')
return 0.0

# complete list of minor constituents
minor_constituents = ['sa', 'ssa', 'sta', 'msm', 'msf',
Expand Down
6 changes: 3 additions & 3 deletions scripts/compute_tidal_currents.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def compute_tidal_currents(tide_dir, input_file, output_file,
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide[i], hc, c,
deltat=deltat[i], corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components and reform grid
Expand All @@ -362,7 +362,7 @@ def compute_tidal_currents(tide_dir, input_file, output_file,
if INFER_MINOR:
minor = pyTMD.predict.infer_minor(ts.tide, hc, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
tide[t].data[:] += minor.data[:]
elif (TYPE == 'time series'):
tide[t] = np.ma.zeros((nstation,nt), fill_value=FILL_VALUE)
Expand All @@ -376,7 +376,7 @@ def compute_tidal_currents(tide_dir, input_file, output_file,
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide, HC, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components
Expand Down
6 changes: 3 additions & 3 deletions scripts/compute_tidal_elevations.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def compute_tidal_elevations(tide_dir, input_file, output_file,
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide[i], hc, c,
deltat=deltat[i], corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components and reform grid
Expand All @@ -369,7 +369,7 @@ def compute_tidal_elevations(tide_dir, input_file, output_file,
if INFER_MINOR:
minor = pyTMD.predict.infer_minor(ts.tide, hc, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
tide.data[:] += minor.data[:]
elif (TYPE == 'time series'):
tide = np.ma.zeros((nstation,nt), fill_value=FILL_VALUE)
Expand All @@ -383,7 +383,7 @@ def compute_tidal_elevations(tide_dir, input_file, output_file,
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide, HC, c,
deltat=deltat, corrections=nodal_corrections,
minor=minor_constituents, frequency=model.frequency)
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components
Expand Down

0 comments on commit 2aa4938

Please sign in to comment.