Skip to content

Syntax and codes Amin

Amin Shakya edited this page Dec 6, 2022 · 1 revision

Codes

GRACE_Data_Driven_Correction_Vishwakarma

Description:

the function uses data-driven approach published and explained in Vishwakarma et al. 2017, AGU WRR paper. doi:10.1002/2017WR021150.

Inputs

F     a cell matrix with one column containing SH coefficients
cf     the column in F that contains SH coefficients from GRACE
GaussianR  radius of the Gaussian filter (recommened = 400)
basins  mask functions of basin, a cell data format with one column and each entry is a 360 x 720 matrix with 1 inside the catchment and 0 outside

Outputs

every output has a size (number of months x basins)
RecoveredTWS    corrected data-driven time-series (Least Squares fit method)
RecoveredTWS2    corrected data-driven time-series (shift and amplify method)
FilteredTS    gaussian filtered GRACE TWS time-series for all the basins.

Modules used

gaussian, cs2sc, gshs, gsha, naninterp, Phase_calc


gshs

Description:

Global Spherical Harmonic Synthesis

Inputs

field  set of SH coefficients, either in SC-triangle or CS-square format
quant  [‘none’, ‘water’]
grd    [‘pole’, ‘mesh’, ‘block’, ‘cell’]
n      grid size parameter n. (default: n = lmax, determined from field)
        longitude samples: 2*n
        latitude samples n ('blocks') or n+1.
h      (default: 0), height above Earth mean radius [m]
jflag  (default: true), determines whether to subtract GRS80.

Outputs

gshs   Global spheric harmonic synthesis

Modules used

cs2sc, normalklm, plm, eigengrav, ispec


gsha

Description:

calculates the spherical harmonic coefficients for a gridded global field by:
   • least squares
   • weighted least squares
   • approximate quadrature
   • first Neumann method
   • second Neumann method
   • block mean values

Inputs

f     set of SH coefficients, either in SC-triangle or CS-square format
quant  global field of size (lmax+1)2lmax or lmax2lmax
method  string argument, defining the analysis method:
   ls  least squares
   wls  weighted least squares
   aq  approximate quadrature
   fnm  first Neumann method
   snm  second Neumann method
   mean block mean values
grd  optional string argument, defining the grid:
   pole, mesh   (default if lmax+1), equi-angular (lmax+1)2lmax, including poles and Greenwich meridian.
   block, cell  (default if lmax), equi-angular block midpoints lmax2lmax
   neumann, gauss  Gauss-Neumann grid (lmax+1)2lmax; where lmax is the maximum degree of development
        longitude samples: 2
n
        latitude samples n ('blocks') or n+1.
h      (default: 0), height above Earth mean radius [m]
jflag  (default: true), determines whether to subtract GRS80.

Outputs

cs    Clm, Slm in |C\S| format

Modules used

plm, iplm, neumann, sc2cs


neumann

Description:

returns the weights and nodes for Neumann's numerical integration
NB1 In 1st N-method, length(x) should not become too high, since a linear system of this size is solved. Eg: 500.
NB2 No use is made of potential symmetries of nodes.

Inputs

inn     input; can either be n -> number of weights and number of base points; or x -> base points (nodes) in the interval [-1;1]
If the input is n, we apply 1st Neumann method
If the input is x, we apply 2nd Neumann method

Outputs

w    quadrature weights
x    base points (nodes) in the interval [-1;1]

Modules used

plm, grule


normalklm

Description:

NORMALKLM returns an ellipsoidal normal field consisting of normalized -Jn, n=0,2,4,6,8
Reference: J2,J4 values for hydrostatic equilibrium ellipsoid from Lambeck (1988) "Geophysical Geodesy", p.18

Inputs

lmax     maximum degree
typ      (default: wgs84) either wgs84 (equipotential ellipsoid), grs80,or he (hydrostatic equilibrium ellipsoid)

Outputs

nklm    normal field in CS-format (sparse)

sc2cs

Description:

The function converts the rectangular (L+1)x(2L+1) matrix field, containing spherical harmonics coefficients in /S|C\ storage format into a square (L+1)x(L+1) matrix in |C\S| format. (inverse of cs2sc)

Inputs

field     the rectangular (L+1)x(2L+1) matrix FIELD, containing spherical harmonics coefficients in /S|C\ storage format

Outputs

cs     square (L+1)x(L+1) matrix in |C\S| format

cs2sc

Description:

The function converts the storage format into a square (L+1)x(L+1) matrix in |C\S| format to rectangular (L+1)x(2L+1) matrix field, containing spherical harmonics coefficients in /S|C\ . (inverse of sc2cs)

Inputs

field     the square (L+1)x(L+1) matrix FIELD , containing spherical harmonics coefficients in |C\S| storage format

Outputs

cs     rectangular (L+1)x(2L+1) matrix in /S|C\format

grule

Description:

The function computes Gauss base points and weight factors using the algorithm given by Davis and Rabinowitz in 'Methods of Numerical Integration', page 365, Academic Press, 1975.

Inputs

n     number of base points required

Outputs

bp     A numpy array containing cosines of the base points
wf     A numpy array containing weight factor for computing integrals, etc.

Phase_calc

Description:

Computes the phase difference between two timeseries based on the Hilbert transform method by Philip et al. (2012) doi:10.1029/2012GL052495. The function is called by the Grace_Data_Driven_Correction function based on the paper Vishwakarma et al. 2017, AGU WRR paper. doi:10.1002/2017WR021150.

Inputs

fts     filtered monthly fields
ffts    twice-filtered monthly fields

Outputs

ps     phase difference between filtered monthly fields and twice-filtered monthly fields

ispec

Description:

ispec(a,b) returns the function F from the spectra a to b

Inputs

a     cosine coefficients
b     (default: b = -9999) sine coefficients
a and b are defined by:
f(t) = a_0 + SUM_(i=1)^n2 a_i*cos(iwt) + b_i*sin(iwt) with
w = ground-frequency and
n2 = half the number of samples (+1).
Note that no factor 2 appears in front of the sum.

Outputs

F = ispec(a,b)    considers A the cosine- and B the sine-spectrum.
F = ispec(s)     assumes s is a list of [a,b]
If A and B are matrices, Fourier operations are columnwise.

gaussian

Description:

Delivers the spherical harmonic coefficients of a gaussian smoothing filter. The coefficients are calculates according to Wahr et. al. (1998) equation (34) and Swenson and Wahr equation (34)

Inputs

L     (integer) maximum degree
cap     (integer) half width of Gaussian smoothing function [km]

Outputs

Wl     [L+1 x 1] smoothing coefficients

naninterp

Description:

Interpolates NaNs in the input timeseries using scipy PchipInterpolator (cubic interpolation)

Inputs

X     numpy timeseries with some NaN values

Outputs

X     input numpy timeseries with NaN values filled using scipy PchipInterpolator (cubic interpolation)

GRACEconstants

Description:

A python file consisting of frequently used constants for GRACE signal processing.

Constants

clight = 2.99792458e8    speed of light
G = 6.67259e-11         gravitational constant [m^3 /(kg s^2)]
au = 149.597870691e9    astronomical unit [m]

GRS80 defining constants
ae = 6378137         semi-major axis of ellipsoid [m]
GM = 3.986005e14      geocentric grav. constant [m^3 / s^2]
J2 = 1.08263e-3       earth's dyn. form factor (= -C20 unnormalized)
Omega = 7.292115e-5    mean ang. velocity [rad/s]

GRS80 derived constants
flat = 1/298.257222101   flattening
J4 = -0.237091222e-5    -C40 unnormalized
J6 = 0.608347e-8       -C60 unnormalized
J8 = -0.1427e-10       -C80 unnormalized