Auxillary Codes¶
The rest of the important functions have been bundled under the auxillary codes
module.
Computing Legendre functions¶
The
PLM(l, m, thetaRAD, nargin, nargout)
¶
PLM Fully normalized associated Legendre functions for a selected order M
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l |
array
|
Degree, but not necessarily monotonic. For l < m a vector of zeros will be returned. |
required |
m |
int
|
order (scalar). If absent, m = 0 is assumed. |
required |
thetaRAD |
array
|
co-latitude [rad] (vector) |
required |
nargin |
int
|
number of input argument |
required |
nargout |
int
|
number of output argument |
required |
Returns: (np.array): PLM fully normalized
Source code in pyshbundle/plm.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
derivALF(inn, miin, plin, m, lmax)
¶
HelpeFunction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inn |
_type_
|
description |
required |
miin |
_type_
|
description |
required |
plin |
_type_
|
description |
required |
m |
_type_
|
description |
required |
lmax |
_type_
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in pyshbundle/plm.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
lrecur(inn, x, m, lmax)
¶
[Helper Function]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inn |
_type_
|
description |
required |
x |
_type_
|
description |
required |
m |
_type_
|
description |
required |
lmax |
_type_
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in pyshbundle/plm.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
secrecur(m, y)
¶
Helper Function:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m |
_type_
|
description |
required |
y |
_type_
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in pyshbundle/plm.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
iplm(l, m, theRAD, dt=-9999)
¶
IPLM Integrals of the fully normalized associated Legendre functions over blocks for a selected order M.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l |
_type_
|
degree (vector). Integer, but not necessarily monotonic. For l < m a vector of zeros will be returned. |
required |
m |
int
|
order (scalar) |
required |
theRAD |
array
|
co-latitude [rad] (vector) |
required |
dt |
int
|
integration block-size [rad] (scalar). Defaults to -9999. |
-9999
|
Returns:
Type | Description |
---|---|
np.ndarray: Matrix with integrated Legendre functions. Functions are integrated from theRAD(i)-dt/2 till theRAD(i)+dt/2. The matrix has length(TH) rows and length(L) columns, unless L or TH is scalar. Then the output vector follows the shape of respectively L or TH. |
Notes
The blocks at the pole might become too large under circumstances. This is not treated separately, i.e. unwanted output may appear. In case TH is scalar, dt will be 1 (arbitrarily).
TO DO
Instead of using sys.exit() we could raise exceptions - that would be a better way of error handling
Uses
plm
Source code in pyshbundle/iplm.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
GRACE Data Pre-Processing¶
lovenr(lmax)
¶
Created on Mon May 11 11:09:28 2022
Todo
- Add type and input checking functionality
author: Dr. Bramha Dutt Vishwakarma, Interdisciplinary Center for Water Research (ICWaR), Indian Institute of Science (IISc)
Source code in pyshbundle/GRACEpy.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
lovenrPREM(lmax, frame)
¶
Created on Mon May 11 11:51:29 2022
@author: Dr. Bramha Dutt Vishwakarma, Interdisciplinary Center for Water Research (ICWaR), Indian Institute of Science (IISc)
Source code in pyshbundle/GRACEpy.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
upwcon(degree, height)
¶
Returns the upward continuation \((R/r)^l\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
degree |
int
|
Spherical harmonic degree |
required |
height |
int
|
Height above mean Earth radius [m] [scalar/vector] |
required |
Returns:
Name | Type | Description |
---|---|---|
uc |
_type_
|
Upward continuation terms |
Uses
GRACEconstants.GC
Todo
- Add input checking functionality and raise exceptions
- Add reference to formula
Source code in pyshbundle/GRACEpy.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
Filtering the GRACE Data¶
Gaussian(L, cap)
¶
The program delivers the spherical harmonic coefficients of a gaussian smoothing filter. The coefficients are calculated according to Wahr et. al.(1998) equation (34) and Swenson and Wahr equation (34)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
L |
int
|
maximum degree |
required |
cap |
int
|
half width of Gaussian smoothing function [km] |
required |
Returns:
Type | Description |
---|---|
np.ndarray: smoothing coefficients |
Raises:
Type | Description |
---|---|
TypeError
|
Degree must be integer |
ValueError
|
Maximum degree must be higher than 2 |
TypeError
|
Cap size must be an integer |
References
Wahr et.al. (1998) equation (34) and Swenson and Wahr equation (34)
Source code in pyshbundle/gaussian.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
Numerical Integration¶
grule(n)
¶
This function computes Gauss base points and weight factors using the algorithm-see Reference
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
number of base points required |
required |
Returns:
Type | Description |
---|---|
np.array: cosine of the base points |
|
np.array: weight factors for computing integrals and such |
References
- 'Methods of Numerical Integration' by Davis and Rabinowitz, page 365, Academic Press, 1975.
Source code in pyshbundle/grule.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
naninterp(X)
¶
This function uses cubic interpolation to replace NaNs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
_type_
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in pyshbundle/naninterp.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
neumann(inn)
¶
Returns the weights and nodes for Neumann's numerical integration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inn |
(int, array)
|
base points (nodes) in the interval [-1;1] |
required |
Raises:
Type | Description |
---|---|
TypeError
|
Integer input argument required |
ValueError
|
Error in input dimensions |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
quadrature weights |
|
_type_ |
base points (nodes) in the interval [-1;1] |
Remarks
- 1st N.-method: see Sneeuw (1994) GJI 118, pp 707-716, eq. 19.5
- 2nd N.-method: see uberall/GRULE
Todo
- TypeError is more relavant and shape error from numpy
Uses
grule
, plm
Examples:
>>> TO DO: write example how to use the function
Source code in pyshbundle/neumann.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
Important for Spherical Harmonic Synthesis¶
ispec(a, b=-9999)
¶
Returns the function F from the spectra A and B
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
_type_
|
cosine coefficients |
required |
b |
int
|
sine coefficients. Defaults to -9999. |
-9999
|
Returns:
Name | Type | Description |
---|---|---|
f |
_type_
|
description |
See Also
spec
Source code in pyshbundle/ispec.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
normalklm(lmax, typ='wgs84')
¶
NORMALKLM returns an ellipsoidal normal field consisting of normalized -Jn, n=0,2,4,6,8
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lmax |
int
|
maximum degree |
required |
typ |
str
|
Ellipsoids can be either 'wgs84' - World Geodetic System 84, 'grs80' - , 'he' - hydrostatic equilibrium ellipsoid |
'wgs84'
|
Returns:
Name | Type | Description |
---|---|---|
nklm |
array
|
normal field in CS-format (sparse array - [1, -J2, -J4, -J6, -J8]) |
TODO
Find type of nklm; I think raising TypeError, VlueError or NameError instad of general Exception
Raises:
Type | Description |
---|---|
TypeError
|
lmax should be an integer |
ValueError
|
lmax should be positive |
ValueError
|
Unknown type of ellipsoid, supports 'wgs84', |
References
- J2,J4 values for hydrostatic equilibrium ellipsoid from Lambeck (1988) "Geophysical Geodesy", p.18
Source code in pyshbundle/normalklm.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
eigengrav(lmax, fstr, h)
¶
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lmax |
int
|
Maximum degree of Spherical Coefficients |
required |
fstr |
str
|
gravity quantity, options: 'None', 'geoid', 'potential', 'gravity', 'tr', 'trr', 'slope' 'water', 'smd', 'height' |
required |
h |
float
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Raises:
Type | Description |
---|---|
TypeError
|
Enter a valid lmax value |
TO DO
Can we think about the raising a ValueError instead of instantly terminating the function Adding comments as variable names are not much descriptive
Source code in pyshbundle/eigengrav.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
Time Series¶
PhaseCalc(fts, ffts)
¶
calculates the phase difference between two time series based on the Hilbert transform method explained by Phillip et al.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fts |
ndarray
|
description |
required |
ffts |
ndarray
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
References
- Phillips, T., R. S. Nerem, B. Fox-Kemper, J. S. Famiglietti, and B. Rajagopalan (2012), The influence of ENSO on global terrestrial water storage using GRACE, Geophysical Research Letters, 39 (16), L16,705, doi:10.1029/2012GL052495.
Source code in pyshbundle/Phase_calc.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|