Skip to content

Commit

Permalink
feat: add functions to read and interpolate from all constituents to …
Browse files Browse the repository at this point in the history
…address #91

to do: need to add tests that outputs are as expected
to do: need to see if these are actual optimizations
test: switch interpolation test to soft tabs
  • Loading branch information
tsutterley committed Dec 22, 2022
1 parent b74c01e commit d0653e3
Show file tree
Hide file tree
Showing 14 changed files with 1,397 additions and 246 deletions.
15 changes: 15 additions & 0 deletions doc/source/api_reference/constituents.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
============
constituents
============

Basic tide model constituent class

`Source code`__

.. __: https://github.com/tsutterley/pyTMD/blob/main/pyTMD/constituents.py

General Attributes and Methods
==============================

.. autoclass:: pyTMD.constituents
:members:
4 changes: 4 additions & 0 deletions doc/source/api_reference/io/ATLAS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Calling Sequence

.. autofunction:: pyTMD.io.ATLAS.extract_constants

.. autofunction:: pyTMD.io.ATLAS.read_constants

.. autofunction:: pyTMD.io.ATLAS.interpolate_constants

.. autofunction:: pyTMD.io.ATLAS.read_netcdf_grid

.. autofunction:: pyTMD.io.ATLAS.read_netcdf_elevation
Expand Down
4 changes: 4 additions & 0 deletions doc/source/api_reference/io/FES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Calling Sequence

.. autofunction:: pyTMD.io.FES.extract_constants

.. autofunction:: pyTMD.io.FES.read_constants

.. autofunction:: pyTMD.io.FES.interpolate_constants

.. autofunction:: pyTMD.io.FES.read_ascii_file

.. autofunction:: pyTMD.io.FES.read_netcdf_file
4 changes: 4 additions & 0 deletions doc/source/api_reference/io/GOT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Calling Sequence

.. autofunction:: pyTMD.io.GOT.extract_constants

.. autofunction:: pyTMD.io.GOT.read_constants

.. autofunction:: pyTMD.io.GOT.interpolate_constants

.. autofunction:: pyTMD.io.GOT.read_ascii_file

.. autofunction:: pyTMD.io.GOT.extend_array
Expand Down
4 changes: 4 additions & 0 deletions doc/source/api_reference/io/OTIS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Calling Sequence

.. autofunction:: pyTMD.io.OTIS.extract_constants

.. autofunction:: pyTMD.io.OTIS.read_constants

.. autofunction:: pyTMD.io.OTIS.interpolate_constants

.. autofunction:: pyTMD.io.OTIS.read_otis_grid

.. autofunction:: pyTMD.io.OTIS.read_atlas_grid
Expand Down
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ conventions for calculating radial pole tide displacements.
api_reference/check_tide_points.rst
api_reference/compute_tide_corrections.rst
api_reference/constants.rst
api_reference/constituents.rst
api_reference/convert_ll_xy.rst
api_reference/eop.rst
api_reference/io/ATLAS.rst
Expand Down
1 change: 1 addition & 0 deletions pyTMD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pyTMD.check_tide_points import check_tide_points
from pyTMD.compute_tide_corrections import compute_tide_corrections
from pyTMD.constants import constants, _ellipsoids
from pyTMD.constituents import constituents
from pyTMD.convert_ll_xy import convert_ll_xy
from pyTMD.load_constituent import load_constituent
from pyTMD.load_nodal_corrections import load_nodal_corrections
Expand Down
2 changes: 2 additions & 0 deletions pyTMD/compute_tide_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ def compute_tide_corrections(x, y, delta_time, DIRECTORY=None, MODEL=None,
model.model_file, model.projection, type=model.type,
method=METHOD, extrapolate=EXTRAPOLATE, cutoff=CUTOFF,
grid=model.format, apply_flexure=APPLY_FLEXURE)
# use delta time at 2000.0 to match TMD outputs
deltat = np.zeros_like(t)
elif (model.format == 'netcdf'):
amp,ph,D,c = pyTMD.io.ATLAS.extract_constants(lon, lat, model.grid_file,
model.model_file, type=model.type, 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_like(t)
elif (model.format == 'GOT'):
amp,ph,c = pyTMD.io.GOT.extract_constants(lon, lat, model.model_file,
Expand Down
57 changes: 57 additions & 0 deletions pyTMD/constituents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
u"""
constituents.py
Written by Tyler Sutterley (12/2022)
Basic tide model constituent class
UPDATE HISTORY:
Written 12/2022
"""

class constituents:
"""
Class for tide model constituents
Attributes
----------
fields: list
list of tide model constituents
"""
def __init__(self, **kwargs):
# set initial attributes
self.fields = []
# set optional fields
for key, val in kwargs.items():
setattr(self, key, val)

def append(self, field, constituent):
"""
Append tide model constituents
Parameters
----------
field: str
Tide model constituent name
constituent: float
Tide model constituent (complex form)
"""
# append field
self.fields.append(field)
setattr(self, field, constituent)
return self

def get(self, field):
"""
Get model constituent
Parameters
----------
field: str
Tide model constituent name
Returns
-------
constituent: float
Tide model constituent (complex form)
"""
return getattr(self, field)
Loading

0 comments on commit d0653e3

Please sign in to comment.