Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include inference of eps2 and eta2 when predicting from GOT models #319

Merged
merged 4 commits into from
Aug 9, 2024
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
128 changes: 74 additions & 54 deletions pyTMD/arguments.py

Large diffs are not rendered by default.

43 changes: 30 additions & 13 deletions pyTMD/compute.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
compute.py
Written by Tyler Sutterley (07/2024)
Written by Tyler Sutterley (08/2024)
Calculates tidal elevations for correcting elevation or imagery data
Calculates tidal currents at locations and times

Expand Down Expand Up @@ -60,6 +60,7 @@
interpolate.py: interpolation routines for spatial data

UPDATE HISTORY:
Updated 08/2024: allow inferring only specific minor constituents
Updated 07/2024: assert that data type is a known value
make number of days to convert JD to MJD a variable
added option to crop tide models to the domain of the input data
Expand Down Expand Up @@ -191,7 +192,7 @@ def tide_elevations(
ATLAS_FORMAT: str = 'ATLAS-netcdf',
GZIP: bool = False,
DEFINITION_FILE: str | pathlib.Path | IOBase | None = None,
DEFINITION_FORMAT: str = 'ascii',
DEFINITION_FORMAT: str = 'auto',
CROP: bool = False,
BOUNDS: list | np.ndarray | None = None,
EPSG: str | int = 3031,
Expand All @@ -202,6 +203,7 @@ def tide_elevations(
EXTRAPOLATE: bool = False,
CUTOFF: int | float=10.0,
INFER_MINOR: bool = True,
MINOR_CONSTITUENTS: list | None = None,
APPLY_FLEXURE: bool = False,
FILL_VALUE: float = np.nan,
**kwargs
Expand All @@ -228,11 +230,12 @@ def tide_elevations(
Tide model files are gzip compressed
DEFINITION_FILE: str, pathlib.Path, io.IOBase or NoneType, default None
Tide model definition file for use
DEFINITION_FORMAT: str, default 'ascii'
DEFINITION_FORMAT: str, default 'auto'
Format for model definition file

- ``'ascii'``: tab-delimited definition file
- ``'json'``: JSON formatted definition file
- ``'auto'``: auto-detect the definition file format
CROP: bool, default False
Crop tide model data to (buffered) bounds
BOUNDS: list, np.ndarray or NoneType, default None
Expand Down Expand Up @@ -271,6 +274,8 @@ def tide_elevations(
Set to ``np.inf`` to extrapolate for all points
INFER_MINOR: bool, default True
Infer the height values for minor tidal constituents
MINOR_CONSTITUENTS: list or None, default None
Specify constituents to infer
APPLY_FLEXURE: bool, default False
Apply ice flexure scaling factor to height values

Expand Down Expand Up @@ -346,7 +351,7 @@ def tide_elevations(
deltat = np.zeros((nt), dtype=np.float64)
elif model.format in ('ATLAS-netcdf',):
amp,ph,D,c = pyTMD.io.ATLAS.extract_constants(lon, lat, model.grid_file,
model.model_file, type=model.type, crop=CROP, bounds=BOUNDS,
model.model_file, type=model.type, crop=CROP, bounds=BOUNDS,
method=METHOD, extrapolate=EXTRAPOLATE, cutoff=CUTOFF,
scale=model.scale, compressed=model.compressed)
# use delta time at 2000.0 to match TMD outputs
Expand Down Expand Up @@ -374,6 +379,7 @@ def tide_elevations(
hc = amp*np.exp(cph)

# predict tidal elevations at time
minor_constituents = MINOR_CONSTITUENTS or model.minor
if (TYPE.lower() == 'grid'):
ny,nx = np.shape(x)
tide = np.ma.zeros((ny,nx,nt),fill_value=FILL_VALUE)
Expand All @@ -384,7 +390,8 @@ def tide_elevations(
# calculate values for minor constituents by inferrence
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide[i], hc, c,
deltat=deltat[i], corrections=corrections)
deltat=deltat[i], corrections=corrections,
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components and reform grid
Expand All @@ -398,7 +405,8 @@ def tide_elevations(
# calculate values for minor constituents by inferrence
if INFER_MINOR:
minor = pyTMD.predict.infer_minor(ts.tide, hc, c,
deltat=deltat, corrections=corrections)
deltat=deltat, corrections=corrections,
minor=minor_constituents)
tide.data[:] += minor.data[:]
elif (TYPE.lower() == 'time series'):
nstation = len(x)
Expand All @@ -411,7 +419,8 @@ def tide_elevations(
# calculate values for minor constituents by inferrence
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide, HC, c,
deltat=deltat, corrections=corrections)
deltat=deltat, corrections=corrections,
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components
Expand Down Expand Up @@ -442,6 +451,7 @@ def tide_currents(
EXTRAPOLATE: bool = False,
CUTOFF: int | float=10.0,
INFER_MINOR: bool = True,
MINOR_CONSTITUENTS: list | None = None,
FILL_VALUE: float = np.nan,
**kwargs
):
Expand All @@ -467,11 +477,12 @@ def tide_currents(
Tide model files are gzip compressed
DEFINITION_FILE: str, pathlib.Path, io.IOBase or NoneType, default None
Tide model definition file for use
DEFINITION_FORMAT: str, default 'ascii'
DEFINITION_FORMAT: str, default 'auto'
Format for model definition file

- ``'ascii'``: tab-delimited definition file
- ``'json'``: JSON formatted definition file
- ``'auto'``: auto-detect the definition file format
CROP: bool, default False
Crop tide model data to (buffered) bounds
BOUNDS: list, np.ndarray or NoneType, default None
Expand Down Expand Up @@ -510,6 +521,8 @@ def tide_currents(
Set to ``np.inf`` to extrapolate for all points
INFER_MINOR: bool, default True
Infer the height values for minor tidal constituents
MINOR_CONSTITUENTS: list or None, default None
Specify constituents to infer
FILL_VALUE: float, default np.nan
Output invalid value

Expand Down Expand Up @@ -585,14 +598,14 @@ def tide_currents(
deltat = np.zeros((nt), dtype=np.float64)
elif model.format in ('ATLAS-netcdf',):
amp,ph,D,c = pyTMD.io.ATLAS.extract_constants(lon, lat, model.grid_file,
model.model_file[t], type=t, crop=CROP, bounds=BOUNDS,
model.model_file[t], type=t, crop=CROP, bounds=BOUNDS,
method=METHOD, extrapolate=EXTRAPOLATE, cutoff=CUTOFF,
scale=model.scale, compressed=model.compressed)
# use delta time at 2000.0 to match TMD outputs
deltat = np.zeros((nt), dtype=np.float64)
elif model.format in ('FES-ascii', 'FES-netcdf'):
amp,ph = pyTMD.io.FES.extract_constants(lon, lat, model.model_file[t],
type=t, version=model.version, crop=CROP, bounds=BOUNDS,
type=t, version=model.version, crop=CROP, bounds=BOUNDS,
method=METHOD, extrapolate=EXTRAPOLATE, cutoff=CUTOFF,
scale=model.scale, compressed=model.compressed)
# available model constituents
Expand All @@ -606,6 +619,7 @@ def tide_currents(
hc = amp*np.exp(cph)

# predict tidal currents at time
minor_constituents = MINOR_CONSTITUENTS or model.minor
if (TYPE.lower() == 'grid'):
ny,nx = np.shape(x)
tide[t] = np.ma.zeros((ny,nx,nt),fill_value=FILL_VALUE)
Expand All @@ -616,7 +630,8 @@ def tide_currents(
# calculate values for minor constituents by inferrence
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide[i], hc, c,
deltat=deltat[i], corrections=corrections)
deltat=deltat[i], corrections=corrections,
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components and reform grid
Expand All @@ -630,7 +645,8 @@ def tide_currents(
# calculate values for minor constituents by inferrence
if INFER_MINOR:
minor = pyTMD.predict.infer_minor(ts.tide, hc, c,
deltat=deltat, corrections=corrections)
deltat=deltat, corrections=corrections,
minor=minor_constituents)
tide[t].data[:] += minor.data[:]
elif (TYPE.lower() == 'time series'):
nstation = len(x)
Expand All @@ -643,7 +659,8 @@ def tide_currents(
# calculate values for minor constituents by inferrence
if INFER_MINOR:
MINOR = pyTMD.predict.infer_minor(ts.tide, HC, c,
deltat=deltat, corrections=corrections)
deltat=deltat, corrections=corrections,
minor=minor_constituents)
else:
MINOR = np.ma.zeros_like(TIDE)
# add major and minor components
Expand Down
2 changes: 1 addition & 1 deletion pyTMD/io/constituents.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def __next__(self):
constituent = getattr(self, field)
self.__index__ += 1
return (field, constituent)

def __getitem__(self, key):
return getattr(self, key)

Expand Down
Loading
Loading