11#!/usr/bin/env python
22u"""
33read_GRACE_harmonics.py
4- Written by Tyler Sutterley (04 /2022)
4+ Written by Tyler Sutterley (05 /2022)
55Contributions by Hugo Lecomte
66
77Reads GRACE files and extracts spherical harmonic data and drift rates (RL04)
4242 time.py: utilities for calculating time operations
4343
4444UPDATE HISTORY:
45+ Updated 05/2022: updated comments
4546 Updated 04/2022: updated docstrings to numpy documentation format
4647 include utf-8 encoding in reads to be windows compliant
4748 check if GRACE/GRACE-FO data file is present in file-system
@@ -105,7 +106,7 @@ def read_GRACE_harmonics(input_file, LMAX, MMAX=None, POLE_TIDE=False):
105106 eslm: float
106107 sine spherical harmonic uncalibrated standard deviations
107108 header: str
108- Header text from the GRACE file
109+ Header text from the GRACE/GRACE-FO file
109110
110111 References
111112 ----------
@@ -118,9 +119,12 @@ def read_GRACE_harmonics(input_file, LMAX, MMAX=None, POLE_TIDE=False):
118119
119120 #-- parse filename
120121 PFX ,SY ,SD ,EY ,ED ,N ,PRC ,F1 ,DRL ,F2 ,SFX = parse_file (input_file )
121- file_contents = extract_file (input_file , (SFX == '.gz' ))
122+ #-- check if file is compressed
123+ compressed = (SFX == '.gz' )
124+ #-- extract file contents
125+ file_contents = extract_file (input_file , compressed )
122126
123- #-- JPL Mascon solutions
127+ #-- JPL mascon solutions in spherical harmonic form
124128 if PRC in ('JPLMSC' ,):
125129 DSET = 'GSM'
126130 DREL = np .int64 (DRL )
@@ -134,18 +138,18 @@ def read_GRACE_harmonics(input_file, LMAX, MMAX=None, POLE_TIDE=False):
134138 #-- COST-G unfiltered combination solutions
135139 #-- https://doi.org/10.5880/ICGEM.COST-G.001
136140 elif PRC in ('COSTG' ,):
137- DSET , = re .findall ('GSM|GAC' ,PFX )
141+ DSET , = re .findall (r 'GSM|GAC' ,PFX )
138142 DREL = np .int64 (DRL )
139143 FLAG = r'gfc'
140- #-- Standard GRACE solutions
144+ #-- Standard GRACE/GRACE-FO Level-2 solutions
141145 else :
142146 DSET = PFX
143147 DREL = np .int64 (DRL )
144148 FLAG = r'GRCOF2'
145149
146- #-- output python dictionary with GRACE data and date information
150+ #-- output python dictionary with GRACE/GRACE-FO data and metadata
147151 grace_L2_input = {}
148- #-- extract GRACE date information from input file name
152+ #-- extract GRACE/GRACE-FO date information from input file name
149153 start_yr = np .float64 (SY )
150154 end_yr = np .float64 (EY )
151155 start_day = np .float64 (SD )
@@ -230,10 +234,9 @@ def read_GRACE_harmonics(input_file, LMAX, MMAX=None, POLE_TIDE=False):
230234 #-- if drift rates exist at any time, will add to harmonics
231235 #-- Will convert the secular rates into a stokes contribution
232236 #-- Currently removes 2003.3 to get the temporal average close to 0.
233- #-- note: += means grace_xlm = grace_xlm + drift_x
234237 if ((DREL == 4 ) and (DSET == 'GSM' )):
235238 #-- time since 2003.3
236- dt = (grace_L2_input ['time' ]- 2003.3 )
239+ dt = (grace_L2_input ['time' ] - 2003.3 )
237240 grace_L2_input ['clm' ][:,:] += dt * drift_c [:,:]
238241 grace_L2_input ['slm' ][:,:] += dt * drift_s [:,:]
239242
@@ -261,8 +264,7 @@ def read_GRACE_harmonics(input_file, LMAX, MMAX=None, POLE_TIDE=False):
261264 #-- before computing their harmonic solutions
262265 C21_PT = - 1.551e-9 * (m1 - 0.62e-3 * dt ) - 0.012e-9 * (m2 + 3.48e-3 * dt )
263266 S21_PT = 0.021e-9 * (m1 - 0.62e-3 * dt ) - 1.505e-9 * (m2 + 3.48e-3 * dt )
264- #-- correct GRACE spherical harmonics for pole tide
265- #-- note: -= means grace_xlm = grace_xlm - PT
267+ #-- correct GRACE/GRACE-FO spherical harmonics for pole tide
266268 grace_L2_input ['clm' ][2 ,1 ] -= C21_PT
267269 grace_L2_input ['slm' ][2 ,1 ] -= S21_PT
268270 #-- GFZ Pole Tide Correction
@@ -271,13 +273,13 @@ def read_GRACE_harmonics(input_file, LMAX, MMAX=None, POLE_TIDE=False):
271273 #-- GFZ removes only a constant pole position
272274 C21_PT = - 1.551e-9 * (- 0.62e-3 * dt ) - 0.012e-9 * (3.48e-3 * dt )
273275 S21_PT = 0.021e-9 * (- 0.62e-3 * dt ) - 1.505e-9 * (3.48e-3 * dt )
274- #-- correct GRACE spherical harmonics for pole tide
275- #-- note: -= means grace_xlm = grace_xlm - PT
276+ #-- correct GRACE/GRACE-FO spherical harmonics for pole tide
276277 grace_L2_input ['clm' ][2 ,1 ] -= C21_PT
277278 grace_L2_input ['slm' ][2 ,1 ] -= S21_PT
278279
279- #-- return the GRACE data, GRACE date (mid-month in decimal), and the
280- #-- start and end days as Julian dates
280+ #-- return the header data, GRACE/GRACE-FO data
281+ #-- GRACE/GRACE-FO date (mid-month in decimal)
282+ #-- and the start and end days as Julian dates
281283 return grace_L2_input
282284
283285#-- PURPOSE: extract parameters from filename
0 commit comments