Skip to content

Commit

Permalink
fix: create mask for output gridded variables (#79)
Browse files Browse the repository at this point in the history
refactor: set plot tick formatter to not use offsets
  • Loading branch information
tsutterley committed Jul 26, 2022
1 parent 065b191 commit 2ccb3d8
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 25 deletions.
26 changes: 24 additions & 2 deletions gravity_toolkit/utilities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python
u"""
utilities.py
Written by Tyler Sutterley (05/2022)
Written by Tyler Sutterley (07/2022)
Download and management utilities for syncing time and auxiliary files
PYTHON DEPENDENCIES:
lxml: processing XML and HTML in Python
https://pypi.python.org/pypi/lxml
UPDATE HISTORY:
Updated 07/2022: add s3 endpoints and buckets for Earthdata Cumulus
Updated 05/2022: function for extracting bucket name from presigned url
Updated 04/2022: updated docstrings to numpy documentation format
update CMR queries to prepare for version 1 of RL06
Expand Down Expand Up @@ -759,8 +760,29 @@ def build_opener(username, password, context=ssl.SSLContext(),
#-- HTTPPasswordMgrWithDefaultRealm will be confused.
return opener

# NASA Cumulus AWS S3 credential endpoints
_s3_endpoints = {
'gesdisc': 'https://data.gesdisc.earthdata.nasa.gov/s3credentials',
'ghrcdaac': 'https://data.ghrc.earthdata.nasa.gov/s3credentials',
'lpdaac': 'https://data.lpdaac.earthdatacloud.nasa.gov/s3credentials',
'nsidc': 'https://data.nsidc.earthdatacloud.nasa.gov/s3credentials',
'ornldaac': 'https://data.ornldaac.earthdata.nasa.gov/s3credentials',
'podaac': 'https://archive.podaac.earthdata.nasa.gov/s3credentials'
}

# NASA Cumulus AWS S3 buckets
_s3_buckets = {
'gesdisc': 'gesdisc-cumulus-prod-protected',
'ghrcdaac': 'ghrc-cumulus-dev',
'lpdaac': 'lp-prod-protected',
'nsidc': 'nsidc-cumulus-prod-protected',
'ornldaac': 'ornl-cumulus-prod-protected',
'podaac': 'podaac-ops-cumulus-protected'
}

#-- PURPOSE: get AWS s3 client for PO.DAAC Cumulus
def s3_client(HOST=None, timeout=None, region_name='us-west-2'):
def s3_client(HOST=_s3_endpoints['podaac'], timeout=None,
region_name='us-west-2'):
"""
Get AWS s3 client for PO.DAAC Cumulus
Expand Down
3 changes: 2 additions & 1 deletion notebooks/GRACE-Spatial-Error.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@
" d_sin[:,k] = np.sum(PLM2[:,:,k]*YLM2.slm, axis=0)\n",
"\n",
"# Multiplying by c/s(phi#m) to get spatial maps (lon,lat)\n",
"grid.data = np.sqrt(np.dot(ccos.T,d_cos) + np.dot(ssin.T,d_sin)).T"
"grid.data = np.sqrt(np.dot(ccos.T,d_cos) + np.dot(ssin.T,d_sin)).T\n",
"grid.mask = np.zeros_like(grid.data, dtype=bool)"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions notebooks/GRACE-Spatial-Maps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
"# combining harmonics to calculate output spatial fields\n",
"# output spatial grid\n",
"grid.data = np.zeros((nlat,nlon,nt))\n",
"grid.mask = np.zeros((nlat,nlon,nt), dtype=bool)\n",
"for i,grace_month in enumerate(GRACE_Ylms.month):\n",
" # GRACE/GRACE-FO harmonics for time t\n",
" # and monthly files to be removed\n",
Expand Down Expand Up @@ -843,7 +844,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.9 64-bit",
"display_name": "Python 3.8.10 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -857,11 +858,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
"hash": "0a543bbca308973fff805d6c95eaeb86a663fe83f433025aa1f3fc59463e3b6f"
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
Expand Down
9 changes: 5 additions & 4 deletions scripts/calc_degree_one.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
calc_degree_one.py
Written by Tyler Sutterley (05/2022)
Written by Tyler Sutterley (07/2022)
Calculates degree 1 variations using GRACE coefficients of degree 2 and greater,
and ocean bottom pressure variations from ECCO and OMCT/MPIOM
Expand Down Expand Up @@ -153,6 +153,7 @@
https://doi.org/10.1029/2007JB005338
UPDATE HISTORY:
Updated 07/2022: set plot tick formatter to not use offsets
Updated 05/2022: use argparse descriptions within documentation
use GIA reference and citation output from GIA read program
use command line option to set degree 1 gravitational love number
Expand Down Expand Up @@ -235,7 +236,7 @@
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.offsetbox import AnchoredText
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib.ticker import MultipleLocator
import gravity_toolkit.utilities as utilities
from gravity_toolkit.grace_input_months import grace_input_months, \
read_ecmwf_corrections
Expand Down Expand Up @@ -918,7 +919,7 @@ def calc_degree_one(base_dir, PROC, DREL, MODEL, LMAX, RAD,
ax[2].xaxis.set_ticks(np.arange(2003,2008,1))
ax[2].xaxis.set_minor_locator(MultipleLocator(0.25))
ax[2].yaxis.set_ticks(np.arange(-6,8,2))
ax[2].xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
ax[2].xaxis.get_major_formatter().set_useOffset(False)
#-- add axis labels and adjust font sizes for axis ticks
fig_labels = ['C10','C11','S11']
for i in range(3):
Expand Down Expand Up @@ -969,7 +970,7 @@ def calc_degree_one(base_dir, PROC, DREL, MODEL, LMAX, RAD,
xmax = np.ceil(GSM_Ylms.month[-1]/10.)*10.
ax[2].set_xlim(xmin,xmax)
ax[2].xaxis.set_minor_locator(MultipleLocator(5))
ax[2].xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
ax[2].xaxis.get_major_formatter().set_useOffset(False)
#-- add axis labels and adjust font sizes for axis ticks
fig_labels = ['C10','C11','S11']
for i in range(3):
Expand Down
4 changes: 3 additions & 1 deletion scripts/calc_sensitivity_kernel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
calc_sensitivity_kernel.py
Written by Tyler Sutterley (04/2022)
Written by Tyler Sutterley (07/2022)
Calculates spatial sensitivity kernels through a least-squares mascon procedure
Expand Down Expand Up @@ -75,6 +75,7 @@
https://doi.org/10.1029/2009GL039401
UPDATE HISTORY:
Updated 07/2022: create mask for output gridded variables
Updated 04/2022: use wrapper function for reading load Love numbers
include utf-8 encoding in reads to be windows compliant
use argparse descriptions within sphinx documentation
Expand Down Expand Up @@ -385,6 +386,7 @@ def calc_sensitivity_kernel(LMAX, RAD,
#-- convert spherical harmonics to output spatial grid
grid.data = harmonic_summation(kern_Ylms.clm, kern_Ylms.slm,
grid.lon, grid.lat, LMAX=LMAX, MMAX=MMAX, PLM=PLM).T
grid.mask = np.zeros_like(grid.data, dtype=bool)
grid.time = total_area[k]

#-- output names for sensitivity kernel Ylm and spatial files
Expand Down
4 changes: 3 additions & 1 deletion scripts/combine_harmonics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
combine_harmonics.py
Written by Tyler Sutterley (04/2022)
Written by Tyler Sutterley (07/2022)
Converts a file from the spherical harmonic domain into the spatial domain
CALLING SEQUENCE:
Expand Down Expand Up @@ -68,6 +68,7 @@
utilities.py: download and management utilities for files
UPDATE HISTORY:
Updated 07/2022: create mask for output gridded variables
Updated 04/2022: use wrapper function for reading load Love numbers
use argparse descriptions within sphinx documentation
Updated 12/2021: can use variable loglevels for verbose output
Expand Down Expand Up @@ -230,6 +231,7 @@ def combine_harmonics(INPUT_FILE, OUTPUT_FILE,
nlat = len(grid.lat)
#-- output spatial grid
grid.data = np.zeros((nlat,nlon,nt))
grid.mask = np.zeros((nlat,nlon,nt), dtype=bool)
#-- update attributes
grid.update_spacing()
grid.update_extents()
Expand Down
3 changes: 1 addition & 2 deletions scripts/geocenter_compare_tellus.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import matplotlib
import matplotlib.font_manager
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib.offsetbox import AnchoredText,AnchoredOffsetbox,TextArea,VPacker
from matplotlib.offsetbox import AnchoredText
from gravity_toolkit.time import convert_calendar_decimal
import gravity_toolkit.geocenter as geocenter

Expand Down
4 changes: 1 addition & 3 deletions scripts/geocenter_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import matplotlib.font_manager
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as colors
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib.offsetbox import AnchoredText,AnchoredOffsetbox,TextArea,VPacker
from matplotlib.offsetbox import AnchoredText
from gravity_toolkit.time import convert_calendar_decimal
import gravity_toolkit.geocenter as geocenter

Expand Down
3 changes: 1 addition & 2 deletions scripts/geocenter_ocean_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
matplotlib.rcParams['font.family'] = 'sans-serif'
matplotlib.rcParams['font.sans-serif'] = ['Helvetica']
matplotlib.rcParams['mathtext.default'] = 'regular'
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib.offsetbox import AnchoredText,AnchoredOffsetbox,TextArea,VPacker
from matplotlib.offsetbox import AnchoredText
import gravity_toolkit.geocenter as geocenter

#-- PURPOSE: plots the GRACE/GRACE-FO geocenter time series
Expand Down
3 changes: 1 addition & 2 deletions scripts/geocenter_processing_centers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import matplotlib
import matplotlib.font_manager
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib.offsetbox import AnchoredText,AnchoredOffsetbox,TextArea,VPacker
from matplotlib.offsetbox import AnchoredText
from gravity_toolkit.time import convert_calendar_decimal
from gravity_toolkit.geocenter import geocenter

Expand Down
4 changes: 3 additions & 1 deletion scripts/grace_spatial_maps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
grace_spatial_maps.py
Written by Tyler Sutterley (04/2022)
Written by Tyler Sutterley (07/2022)
Reads in GRACE/GRACE-FO spherical harmonic coefficients and exports
monthly spatial fields
Expand Down Expand Up @@ -144,6 +144,7 @@
utilities.py: download and management utilities for files
UPDATE HISTORY:
Updated 07/2022: create mask for output gridded variables
Updated 04/2022: use wrapper function for reading load Love numbers
use argparse descriptions within sphinx documentation
Updated 12/2021: can use variable loglevels for verbose output
Expand Down Expand Up @@ -437,6 +438,7 @@ def grace_spatial_maps(base_dir, PROC, DREL, DSET, LMAX, RAD,
grid.data = harmonic_summation(Ylms.clm, Ylms.slm,
grid.lon, grid.lat, LMIN=LMIN, LMAX=LMAX,
MMAX=MMAX, PLM=PLM).T
grid.mask = np.zeros_like(grid.data, dtype=bool)
#-- copy time variables for month
grid.time = np.copy(Ylms.time)
grid.month = np.copy(Ylms.month)
Expand Down
7 changes: 4 additions & 3 deletions scripts/monte_carlo_degree_one.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
monte_carlo_degree_one.py
Written by Tyler Sutterley (05/2022)
Written by Tyler Sutterley (07/2022)
Calculates degree 1 errors using GRACE coefficients of degree 2 and greater,
and ocean bottom pressure variations from OMCT/MPIOM in a Monte Carlo scheme
Expand Down Expand Up @@ -143,6 +143,7 @@
https://doi.org/10.1029/2005GL025305
UPDATE HISTORY:
Updated 07/2022: set plot tick formatter to not use offsets
Updated 05/2022: use argparse descriptions within documentation
use GIA reference and citation output from GIA read program
use command line option to set degree 1 gravitational love number
Expand Down Expand Up @@ -192,7 +193,7 @@
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.offsetbox import AnchoredText
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib.ticker import MultipleLocator
import gravity_toolkit.utilities as utilities
from gravity_toolkit.grace_input_months import grace_input_months, \
read_ecmwf_corrections
Expand Down Expand Up @@ -803,7 +804,7 @@ def monte_carlo_degree_one(base_dir, PROC, DREL, LMAX, RAD,
ax[2].set_xlabel('Grace Month', fontsize=14)
ax[2].set_xlim(np.floor(months[0]/10.)*10.,np.ceil(months[-1]/10.)*10.)
ax[2].xaxis.set_minor_locator(MultipleLocator(5))
ax[2].xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
ax[2].xaxis.get_major_formatter().set_useOffset(False)
#-- add axis labels and adjust font sizes for axis ticks
for i,lbl in enumerate(['C10','C11','S11']):
#-- axis label
Expand Down

0 comments on commit 2ccb3d8

Please sign in to comment.