Skip to content

Commit

Permalink
feat: try to get the constituents of FES files
Browse files Browse the repository at this point in the history
fix: append None if Doodson number can't be calculated
  • Loading branch information
tsutterley committed Jan 13, 2024
1 parent 97ab183 commit 7d7e2e6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
10 changes: 8 additions & 2 deletions pyTMD/io/FES.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
FES.py
Written by Tyler Sutterley (06/2023)
Written by Tyler Sutterley (01/2024)
Reads files for a tidal model and makes initial calculations to run tide program
Includes functions to extract tidal harmonic constants from the
Expand Down Expand Up @@ -56,6 +56,7 @@
interpolate.py: interpolation routines for spatial data
UPDATE HISTORY:
Updated 01/2024: attempt to extract constituent IDs from filenames
Updated 06/2023: extract ocean tide model variables for FES2012
Updated 04/2023: added global HAMTIDE11 model
using pathlib to define and expand tide model paths
Expand Down Expand Up @@ -353,6 +354,11 @@ def read_constants(
model_file = pathlib.Path(model_file).expanduser()
if not model_file.exists():
raise FileNotFoundError(str(model_file))
# try to parse the constituent from the model file
try:
cons = pyTMD.io.model.parse_file(model_file, raise_error=True)
except ValueError as exc:
cons = str(i)

Check warning on line 361 in pyTMD/io/FES.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/io/FES.py#L360-L361

Added lines #L360 - L361 were not covered by tests
# read constituent from elevation file
if kwargs['version'] in ('FES1999','FES2004'):
# FES ascii constituent files
Expand All @@ -367,7 +373,7 @@ def read_constants(
lon = extend_array(lon, dlon)
hc = extend_matrix(hc)
# append extended constituent
constituents.append(str(i), hc)
constituents.append(cons, hc)
# set model coordinates
setattr(constituents, 'longitude', lon)
setattr(constituents, 'latitude', lat)
Expand Down
27 changes: 24 additions & 3 deletions pyTMD/io/constituents.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,35 @@ def phase(self, field: str):
def doodson_number(self):
"""constituent Doodson number
"""
return [pyTMD.arguments.doodson_number(f) for f in self.fields]
doodson_numbers = []
# for each constituent ID
for f in self.fields:
try:
# try to get the Doodson number
n = pyTMD.arguments.doodson_number(f)
except (AssertionError, ValueError) as exc:
n = None

Check warning on line 168 in pyTMD/io/constituents.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/io/constituents.py#L167-L168

Added lines #L167 - L168 were not covered by tests
# add Doodson number to the combined list
doodson_numbers.append(n)
# return the list of Doodson numbers
return doodson_numbers

@property
def cartwright_number(self):
"""constituent Cartwright numbers
"""
return [pyTMD.arguments.doodson_number(f, formalism='Cartwright')
for f in self.fields]
cartwright_numbers = []
# for each constituent ID
for f in self.fields:
try:
# try to get the Cartwright numbers
n = pyTMD.arguments.doodson_number(f, formalism='Cartwright')
except (AssertionError, ValueError) as exc:
n = None

Check warning on line 185 in pyTMD/io/constituents.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/io/constituents.py#L184-L185

Added lines #L184 - L185 were not covered by tests
# add Cartwright numbers to the combined list
cartwright_numbers.append(n)
# return the list of Cartwright numbers
return cartwright_numbers

def __str__(self):
"""String representation of the ``constituents`` object
Expand Down
2 changes: 2 additions & 0 deletions test/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def test_doodson():
exp['ssa'] = 57.555
exp['msf'] = 73.555
exp['mf'] = 75.555
exp['msqm'] = 93.555
exp['mtm'] = 85.455
# short-period species
exp['m3'] = 355.555
exp['m4'] = 455.555
Expand Down
3 changes: 2 additions & 1 deletion test/test_atlas_read.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
u"""
test_atlas_read.py (04/2023)
test_atlas_read.py (01/2024)
Tests that ATLAS compact and netCDF4 data can be downloaded from AWS S3 bucket
Tests the read program to verify that constituents are being extracted
Expand All @@ -16,6 +16,7 @@
https://boto3.amazonaws.com/v1/documentation/api/latest/index.html
UPDATE HISTORY:
Updated 01/2024: test doodson and cartwright numbers of each constituent
Updated 04/2023: using pathlib to define and expand paths
Updated 12/2022: add check for read and interpolate constants
Updated 11/2022: use f-strings for formatting verbose or ascii output
Expand Down
4 changes: 3 additions & 1 deletion test/test_fes_predict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
u"""
test_fes_predict.py (04/2023)
test_fes_predict.py (01/2024)
Tests that FES2014 data can be downloaded from AWS S3 bucket
Tests the read program to verify that constituents are being extracted
Tests that interpolated results are comparable to FES2014 program
Expand All @@ -17,6 +17,7 @@
https://boto3.amazonaws.com/v1/documentation/api/latest/index.html
UPDATE HISTORY:
Updated 01/2024: test doodson and cartwright numbers of each constituent
Updated 04/2023: using pathlib to define and expand paths
Updated 12/2022: add check for read and interpolate constants
Updated 09/2021: update check tide points to add compression flags
Expand All @@ -38,6 +39,7 @@
import pyTMD.io.model
import pyTMD.utilities
import pyTMD.predict
import pyTMD.arguments
import pyTMD.check_points

# current file path
Expand Down

0 comments on commit 7d7e2e6

Please sign in to comment.