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

refactor: use idealized Azimuthal equidistant for Arctic models #332

Merged
merged 4 commits into from
Sep 7, 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
10 changes: 5 additions & 5 deletions .github/workflows/python-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ jobs:
- name: "Check if repository secrets are accessible"
id: secrets
run: |
if [ "${{ secrets.MY_KEY }}" == '' ] ; then
if [ "${{ secrets.EARTHDATA_USERNAME }}" == '' ] ; then
echo "accessible=false" >> $GITHUB_OUTPUT;
echo "::debug::GitHub secrets unavailable for Actions";
else
echo "accessible=true" >> $GITHUB_OUTPUT;
echo "::debug::GitHub secrets available for Actions";
fi
- name: Checkout Matlab TMD Toolbox
if: steps.changes.secrets.accessible == 'true'
if: steps.secrets.outputs.accessible == 'true'
uses: actions/checkout@v4
with:
repository: EarthAndSpaceResearch/TMD_Matlab_Toolbox_v2.5
path: TMD_Matlab_Toolbox
ref: master
- name: Test with pytest
if: steps.changes.secrets.accessible == 'true'
if: steps.secrets.outputs.accessible == 'true'
run: |
pip install --no-deps .
pytest --verbose --capture=no --cov=./ --cov-report=xml \
Expand All @@ -82,7 +82,7 @@ jobs:
--aws-secret=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
--aws-region=${{ secrets.AWS_REGION_NAME }}
- name: Upload coverage to Codecov
if: steps.changes.secrets.accessible == 'true'
if: steps.secrets.outputs.accessible == 'true'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -93,7 +93,7 @@ jobs:
fail_ci_if_error: true
verbose: true
- name: Archive code coverage results
if: steps.changes.secrets.accessible == 'true'
if: steps.secrets.outputs.accessible == 'true'
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
Expand Down
2 changes: 1 addition & 1 deletion doc/source/getting_started/Getting-Started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ OTIS models may be projected into a separate coordinate system. The available OT
- ``'3413'`` (NSIDC Sea Ice Polar Stereographic North in kilometers)
- ``'CATS2008'`` (CATS2008 Polar Stereographic in kilometers)
- ``'3976'`` (NSIDC Sea Ice Polar Stereographic South in kilometers)
- ``'PSNorth'`` (idealized polar stereographic in kilometers)
- ``'AEDNorth'`` (idealized polar Azimuthal equidistant projection in kilometers)

For other model projections, a formatted coordinate reference system (CRS) descriptor (e.g. PROJ, WKT, or EPSG code) can be used.

Expand Down
12 changes: 6 additions & 6 deletions providers/ESR.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"u": "aodtm5_tmd/UV0_Arc5km"
},
"name": "AODTM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aodtm-5/",
"type": [
"u",
Expand All @@ -21,7 +21,7 @@
"u": "aotim5_tmd/UV_Arc5km"
},
"name": "AOTIM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": [
"u",
Expand All @@ -35,7 +35,7 @@
"u": "Arc5km2018/UV_Arc5km2018"
},
"name": "AOTIM-5-2018",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": [
"u",
Expand Down Expand Up @@ -122,7 +122,7 @@
"grid_file": "aodtm5_tmd/grid_Arc5km",
"model_file": "aodtm5_tmd/h0_Arc5km.oce",
"name": "AODTM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aodtm-5/",
"type": "z",
"variable": "tide_ocean"
Expand All @@ -132,7 +132,7 @@
"grid_file": "aotim5_tmd/grid_Arc5km",
"model_file": "aotim5_tmd/h_Arc5km.oce",
"name": "AOTIM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": "z",
"variable": "tide_ocean"
Expand All @@ -142,7 +142,7 @@
"grid_file": "Arc5km2018/grid_Arc5km2018",
"model_file": "Arc5km2018/h_Arc5km2018",
"name": "AOTIM-5-2018",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": "z",
"variable": "tide_ocean",
Expand Down
2 changes: 1 addition & 1 deletion providers/TPXO.json
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@
"TPXO8_atlas_v1/hf.p1_tpxo8_atlas_30c_v1.nc",
"TPXO8_atlas_v1/hf.m4_tpxo8_atlas_30c_v1.nc",
"TPXO8_atlas_v1/hf.m2_tpxo8_atlas_30c_v1.nc"
],
],
"grid_file": "TPXO8_atlas_v1/grid_tpxo8atlas_30_v1.nc",
"type": "z",
"version": "v1",
Expand Down
24 changes: 23 additions & 1 deletion pyTMD/crs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
crs.py
Written by Tyler Sutterley (07/2024)
Written by Tyler Sutterley (09/2024)
Coordinates Reference System (CRS) routines

CALLING SEQUENCE:
Expand Down Expand Up @@ -30,6 +30,7 @@
https://pyproj4.github.io/pyproj/

UPDATE HISTORY:
Updated 09/2024: added function for idealized Arctic Azimuthal projection
Updated 07/2024: added function to get the CRS transform
Updated 05/2024: make subscriptable and allow item assignment
Updated 04/2024: use wrapper to importlib for optional dependencies
Expand Down Expand Up @@ -143,6 +144,7 @@ def get(self, PROJ: str, EPSG: int | str = 4326):
transforms['CATS2008'] = self._CATS2008
transforms['3976'] = self._EPSG3976
transforms['PSNorth'] = self._PSNorth
transforms['AEDNorth'] = self._AEDNorth
transforms['4326'] = self._EPSG4326
# check that PROJ for conversion was entered correctly
# run named conversion program and return values
Expand Down Expand Up @@ -330,6 +332,26 @@ def _PSNorth(self, EPSG: int | str = 4326):
always_xy=True)
return self

# function for models in (idealized) Azimuthal Equidistant projection
def _AEDNorth(self, EPSG: int | str = 4326):
"""
Transform for models in idealized Azimuthal Equidistant projections

Parameters
----------
EPSG: int or str, default 4326 (WGS84 Latitude/Longitude)
input (``'F'``) or output (``'B'``) coordinate system
"""
# projections for converting to and from input EPSG
crs1 = self.from_input(EPSG)
R = 111700.0*180.0/np.pi
crs2 = pyproj.CRS.from_user_input({'proj':'aeqd','lat_0':90,
'lon_0':270,'x_0':0.,'y_0':0.,'ellps':'sphere',
'R':R,'units':'km'})
self.transformer = pyproj.Transformer.from_crs(crs1, crs2,
always_xy=True)
return self

# wrapper function to pass lat/lon values or convert if EPSG
def _EPSG4326(self, EPSG: int | str = 4326):
"""
Expand Down
12 changes: 6 additions & 6 deletions pyTMD/data/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"u": "aodtm5_tmd/UV0_Arc5km"
},
"name": "AODTM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aodtm-5/",
"type": [
"u",
Expand All @@ -21,7 +21,7 @@
"u": "aotim5_tmd/UV_Arc5km"
},
"name": "AOTIM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": [
"u",
Expand All @@ -35,7 +35,7 @@
"u": "Arc5km2018/UV_Arc5km2018"
},
"name": "AOTIM-5-2018",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": [
"u",
Expand Down Expand Up @@ -773,7 +773,7 @@
"grid_file": "aodtm5_tmd/grid_Arc5km",
"model_file": "aodtm5_tmd/h0_Arc5km.oce",
"name": "AODTM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aodtm-5/",
"type": "z",
"variable": "tide_ocean"
Expand All @@ -783,7 +783,7 @@
"grid_file": "aotim5_tmd/grid_Arc5km",
"model_file": "aotim5_tmd/h_Arc5km.oce",
"name": "AOTIM-5",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": "z",
"variable": "tide_ocean"
Expand All @@ -793,7 +793,7 @@
"grid_file": "Arc5km2018/grid_Arc5km2018",
"model_file": "Arc5km2018/h_Arc5km2018",
"name": "AOTIM-5-2018",
"projection": "PSNorth",
"projection": "AEDNorth",
"reference": "https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/aotim-5/",
"type": "z",
"variable": "tide_ocean",
Expand Down
19 changes: 10 additions & 9 deletions pyTMD/interpolate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
interpolate.py
Written by Tyler Sutterley (07/2024)
Written by Tyler Sutterley (09/2024)
Interpolators for spatial data

PYTHON DEPENDENCIES:
Expand All @@ -12,6 +12,7 @@
https://docs.scipy.org/doc/

UPDATE HISTORY:
Updated 09/2024: deprecation fix case where an array is output to scalars
Updated 07/2024: changed projection flag in extrapolation to is_geographic
Written 12/2022
"""
Expand Down Expand Up @@ -88,17 +89,17 @@
WM[3-j], = np.abs(lon[i]-ilon[XI])*np.abs(lat[i]-ilat[YI])
# if on corner value: use exact
if (np.isclose(lat[i],ilat[iy]) & np.isclose(lon[i],ilon[ix])):
data.data[i] = idata.data[iy,ix].astype(dtype)
data.mask[i] = idata.mask[iy,ix]
data.data[i] = np.squeeze(idata.data[iy,ix]).astype(dtype)
data.mask[i] = np.squeeze(idata.mask[iy,ix])
elif (np.isclose(lat[i],ilat[iy+1]) & np.isclose(lon[i],ilon[ix])):
data.data[i] = idata.data[iy+1,ix].astype(dtype)
data.mask[i] = idata.mask[iy+1,ix]
data.data[i] = np.squeeze(idata.data[iy+1,ix]).astype(dtype)
data.mask[i] = np.squeeze(idata.mask[iy+1,ix])

Check warning on line 96 in pyTMD/interpolate.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/interpolate.py#L95-L96

Added lines #L95 - L96 were not covered by tests
elif (np.isclose(lat[i],ilat[iy]) & np.isclose(lon[i],ilon[ix+1])):
data.data[i] = idata.data[iy,ix+1].astype(dtype)
data.mask[i] = idata.mask[iy,ix+1]
data.data[i] = np.squeeze(idata.data[iy,ix+1]).astype(dtype)
data.mask[i] = np.squeeze(idata.mask[iy,ix+1])

Check warning on line 99 in pyTMD/interpolate.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/interpolate.py#L98-L99

Added lines #L98 - L99 were not covered by tests
elif (np.isclose(lat[i],ilat[iy+1]) & np.isclose(lon[i],ilon[ix+1])):
data.data[i] = idata.data[iy+1,ix+1].astype(dtype)
data.mask[i] = idata.mask[iy+1,ix+1]
data.data[i] = np.squeeze(idata.data[iy+1,ix+1]).astype(dtype)
data.mask[i] = np.squeeze(idata.mask[iy+1,ix+1])

Check warning on line 102 in pyTMD/interpolate.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/interpolate.py#L101-L102

Added lines #L101 - L102 were not covered by tests
elif np.any(np.isfinite(IM) & (~IM.mask)):
# find valid indices for data summation and weight matrix
ii, = np.nonzero(np.isfinite(IM) & (~IM.mask))
Expand Down
Loading
Loading