pyshbundle 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. pyshbundle/GRACEconstants.py +70 -0
  2. pyshbundle/GRACEpy.py +206 -0
  3. pyshbundle/__init__.py +72 -0
  4. pyshbundle/data/CSR_TN_files/TN-13_GEOC_CSR_RL0602.txt +580 -0
  5. pyshbundle/data/CSR_TN_files/TN-14_C30_C20_GSFC_SLR.txt +271 -0
  6. pyshbundle/data/ITSG_TN_files/TN-13_GEOC_CSR_RL06.1.txt +542 -0
  7. pyshbundle/data/ITSG_TN_files/TN-14_C30_C20_SLR_GSFC.txt +252 -0
  8. pyshbundle/data/JPL_TN_files/TN-13_GEOC_JPL_RL06.txt +540 -0
  9. pyshbundle/data/JPL_TN_files/TN-14_C30_C20_GSFC_SLR.txt +242 -0
  10. pyshbundle/data/long_mean/SH_long_mean_csr.npy +0 -0
  11. pyshbundle/data/long_mean/SH_long_mean_itsg.npy +0 -0
  12. pyshbundle/data/long_mean/SH_long_mean_jpl.npy +0 -0
  13. pyshbundle/data/mrb_shapefiles/mrb_basins.cpg +1 -0
  14. pyshbundle/data/mrb_shapefiles/mrb_basins.dbf +0 -0
  15. pyshbundle/data/mrb_shapefiles/mrb_basins.prj +1 -0
  16. pyshbundle/data/mrb_shapefiles/mrb_basins.sbn +0 -0
  17. pyshbundle/data/mrb_shapefiles/mrb_basins.sbx +0 -0
  18. pyshbundle/data/mrb_shapefiles/mrb_basins.shp +0 -0
  19. pyshbundle/data/mrb_shapefiles/mrb_basins.shp.xml +1 -0
  20. pyshbundle/data/mrb_shapefiles/mrb_basins.shx +0 -0
  21. pyshbundle/data/validation_data/tws_sh.mat +0 -0
  22. pyshbundle/hydro.py +187 -0
  23. pyshbundle/io.py +877 -0
  24. pyshbundle/pysh_core.py +806 -0
  25. pyshbundle/pyshbundle.py +40 -0
  26. pyshbundle/reshape_SH_coefficients.py +294 -0
  27. pyshbundle/sc2cs.py +81 -0
  28. pyshbundle/shutils.py +826 -0
  29. pyshbundle/viz_utils.py +423 -0
  30. pyshbundle-1.3.0.dist-info/METADATA +916 -0
  31. pyshbundle-1.3.0.dist-info/RECORD +33 -0
  32. pyshbundle-1.3.0.dist-info/WHEEL +4 -0
  33. pyshbundle-1.3.0.dist-info/licenses/LICENSE.md +674 -0
@@ -0,0 +1,70 @@
1
+ # Created on Sat May 9 18:49:45 2022
2
+ # This file contains some basic constants:
3
+ # - physical
4
+ # - geodetic (GRS80)
5
+ # @author: Dr. Bramha Dutt Vishwakarma, Interdisciplinary Center for Water Research (ICWaR), Indian Institute of Science (IISc)
6
+
7
+ # License:
8
+ # This file is part of PySHbundle.
9
+ # PySHbundle is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+
14
+ # This program is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+
22
+
23
+ # Acknowledgement Statement:
24
+ # Please note that PySHbundle has adapted the following code packages,
25
+ # both licensed under GNU General Public License
26
+ # 1. SHbundle: https://www.gis.uni-stuttgart.de/en/research/downloads/shbundle/
27
+
28
+ # 2. Downscaling GRACE Total Water Storage Change using Partial Least Squares Regression
29
+ # https://springernature.figshare.com/collections/Downscaling_GRACE_Total_Water_Storage_Change_using_Partial_Least_Squares_Regression/5054564
30
+
31
+ # Key Papers Referred:
32
+ # 1. Vishwakarma, B. D., Horwath, M., Devaraju, B., Groh, A., & Sneeuw, N. (2017).
33
+ # A data‐driven approach for repairing the hydrological catchment signal damage
34
+ # due to filtering of GRACE products. Water Resources Research,
35
+ # 53(11), 9824-9844. https://doi.org/10.1002/2017WR021150
36
+
37
+ # 2. Vishwakarma, B. D., Zhang, J., & Sneeuw, N. (2021).
38
+ # Downscaling GRACE total water storage change using
39
+ # partial least squares regression. Scientific data, 8(1), 95.
40
+ # https://doi.org/10.1038/s41597-021-00862-6
41
+
42
+ """ This script contains some of the major relavant Physical and Geodetic(GRS80) constants:
43
+
44
+ + `clight` speed of light - $2.99792458e+8$ $m/s$
45
+ + `G` Gravitational constant- $6.67259e-11$ $\frac{m^3} {kg \cdot s^2}$
46
+ + `au` astronomical unit - $149.597870691e+9$ $m$
47
+
48
+ + `ae` semi-major axis of ellipsoid `GRS 80`- $6378137$ m
49
+ + `GM` geocentric grav. constant `GRS 80`- $3.986005e+14$ $\frac{m^3}{s^2}$
50
+ + `J2` earth's dynamic form factor `GRS 80` - $1.08263e-3$ [unitless C20 unnormalized coefficient]
51
+ + `Omega` mean ang. velocity `GRS 80` - $7.292115e-5 $\frac{rad}{s}$
52
+
53
+ + `flat` flattening - $\frac{1}{298.257222101}$
54
+ """
55
+
56
+ clight = 2.99792458e8 # speed of light [m/s]
57
+ G = 6.67259e-11 # gravitational constant [m^3 /(kg s^2)]
58
+ au = 149.597870691e9 # astronomical unit [m]
59
+
60
+ # GRS80 defining constants:
61
+ ae = 6378137 # semi-major axis of ellipsoid [m]
62
+ GM = 3.986005e14 # geocentric grav. constant [m^3 / s^2]
63
+ J2 = 1.08263e-3 # earth's dyn. form factor (= -C20 unnormalized)
64
+ Omega = 7.292115e-5 # mean ang. velocity [rad/s]
65
+
66
+ # GRS80 derived constants:
67
+ flat = 1/298.257222101 # flattening
68
+ J4 = -0.237091222e-5 # -C40 unnormalized
69
+ J6 = 0.608347e-8 # -C60 unnormalized
70
+ J8 = -0.1427e-10 # -C80 unnormalized
pyshbundle/GRACEpy.py ADDED
@@ -0,0 +1,206 @@
1
+ # License:
2
+ # This file is part of PySHbundle.
3
+ # PySHbundle is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17
+
18
+ # Acknowledgement Statement:
19
+ # Please note that PySHbundle has adapted the following code packages,
20
+ # both licensed under GNU General Public License
21
+ # 1. SHbundle: https://www.gis.uni-stuttgart.de/en/research/downloads/shbundle/
22
+
23
+ # 2. Downscaling GRACE Total Water Storage Change using Partial Least Squares Regression
24
+ # https://springernature.figshare.com/collections/Downscaling_GRACE_Total_Water_Storage_Change_using_Partial_Least_Squares_Regression/5054564
25
+
26
+ # Key Papers Referred:
27
+ # 1. Vishwakarma, B. D., Horwath, M., Devaraju, B., Groh, A., & Sneeuw, N. (2017).
28
+ # A data‐driven approach for repairing the hydrological catchment signal damage
29
+ # due to filtering of GRACE products. Water Resources Research,
30
+ # 53(11), 9824-9844. https://doi.org/10.1002/2017WR021150
31
+
32
+ # 2. Vishwakarma, B. D., Zhang, J., & Sneeuw, N. (2021).
33
+ # Downscaling GRACE total water storage change using
34
+ # partial least squares regression. Scientific data, 8(1), 95.
35
+ # https://doi.org/10.1038/s41597-021-00862-6
36
+
37
+ import numpy
38
+ from pyshbundle import GRACEconstants as GC
39
+ """
40
+ Functions for upward continuation, Love number calculations, and other geophysical computations.
41
+ """
42
+
43
+ def upwcon(degree: int, height):
44
+ """
45
+ Returns the upward continuation $(R/r)^l$.
46
+
47
+ Args:
48
+ degree (int): Spherical harmonic degree.
49
+ height (int): Height above mean Earth radius [m] [scalar/vector].
50
+
51
+ Returns:
52
+ (numpy.ndarray): Upward continuation terms.
53
+
54
+ Uses:
55
+ `GRACEconstants.GC`
56
+
57
+ Remarks:
58
+ If both degree and height are vectors, degree will be(come) a row vector
59
+ and height a column vector. Load necessary constants.
60
+
61
+ Todo:
62
+ - Add input checking functionality and raise exceptions.
63
+ - Add reference to formula.
64
+ """
65
+ rr = numpy.divide(GC.ae, numpy.add(GC.ae,height))
66
+ uc = numpy.power(rr, degree)
67
+
68
+ return(uc)
69
+
70
+ def lovenr(lmax: int):
71
+ """
72
+ LOVENR gives the LOVE number of the elastic earth for a certain degree n.
73
+
74
+ Args:
75
+ lmax (int): Spherical harmonic degree (up to 200).
76
+
77
+ Returns:
78
+ numpy.ndarray: LOVE number of degree lmax.
79
+
80
+ Remarks:
81
+ The elastic LOVE numbers are taken from the paper by WAHR et al.,
82
+ "Time variability of the earth's gravity field: hydrological and
83
+ oceanic effects and their possible detection using GRACE",
84
+ JGR, Vol. 103, No. B12, p 30205-30229, 1998.
85
+
86
+ Created on:
87
+ Mon May 11 11:09:28 2022
88
+
89
+ Author:
90
+ Dr. Bramha Dutt Vishwakarma, Interdisciplinary Center for Water Research (ICWaR), Indian Institute of Science (IISc)
91
+ """
92
+ l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 30, 40, 50, 70, 100, 150, 200]
93
+ kl = numpy.divide([0,270,-3030,-1940,-1320,-1040,-890,-810,-760,-720,-690,-640,-580,-510,-400,-330,-270,-200,-140,-100, -700],1e4)
94
+ n = range(0, lmax+1, 1)
95
+ kn = numpy.interp(n,l,kl)
96
+ return(kn)
97
+
98
+ def lovenrPREM(lmax:int, frame):
99
+ """
100
+ Calculates the LOVE and Shida number of the elastic earth for a certain degree n in different reference frames.
101
+
102
+ Values are given in degrees for LOVE numbers as provided by Olivier Francis from the PREM Earth model for selected degrees.
103
+
104
+ Args:
105
+ lmax (int): Spherical harmonic degree (up to 200).
106
+ frame (str): Reference frame, one of 'CM', 'CF', or 'CE'.
107
+
108
+ Returns:
109
+ tuple: A tuple containing:
110
+ - kn (numpy.ndarray): Load LOVE number of degree n.
111
+ - hn (numpy.ndarray): LOVE number of degree n.
112
+ - ln (numpy.ndarray): Shida number of degree n.
113
+
114
+ Remarks:
115
+ See also lovenr.
116
+
117
+ Created on:
118
+ Mon May 11 11:51:29 2022
119
+
120
+ Author:
121
+ Dr. Bramha Dutt Vishwakarma, Interdisciplinary Center for Water Research (ICWaR), Indian Institute of Science (IISc)
122
+ """
123
+
124
+ data = numpy.array([[ 1, -0.28476, 0.00000, 0.10462],
125
+ [2, -0.99297, -0.61274, 0.04661] ,
126
+ [3, -1.05142, -0.58897 , 0.21048] ,
127
+ [4, -1.05378, -0.53513 , 0.23564] ,
128
+ [5, -1.08658, -0.52382 , 0.23186] ,
129
+ [6, -1.14404, -0.54222 , 0.23263] ,
130
+ [7, -1.21254, -0.57464 , 0.24058] ,
131
+ [8, -1.28403, -0.61256 , 0.25308] ,
132
+ [9, -1.35479, -0.65203 , 0.26799] ,
133
+ [10, -1.42330, -0.69140, 0.28419] ,
134
+ [11, -1.48909, -0.72998, 0.30121] ,
135
+ [12, -1.55204, -0.76749, 0.31880] ,
136
+ [13, -1.61221, -0.80381, 0.33684] ,
137
+ [14, -1.66968, -0.83886, 0.35522] ,
138
+ [15, -1.72454, -0.87260, 0.37382] ,
139
+ [16, -1.77684, -0.90499, 0.39251] ,
140
+ [17, -1.82668, -0.93599, 0.41119] ,
141
+ [18, -1.87414, -0.96560, 0.42973] ,
142
+ [19, -1.91928, -0.99382, 0.44804] ,
143
+ [20, -1.96220, -1.02066, 0.46603] ,
144
+ [21, -2.00297, -1.04614, 0.48363] ,
145
+ [22, -2.04169, -1.07029, 0.50078] ,
146
+ [23, -2.07844, -1.09313, 0.51742] ,
147
+ [24, -2.11332, -1.11472, 0.53355] ,
148
+ [25, -2.14642, -1.13511, 0.54912] ,
149
+ [30, -2.28839, -1.22067, 0.61848] ,
150
+ [40, -2.48641, -1.33024, 0.71925] ,
151
+ [50, -2.61710, -1.39016, 0.78410] ,
152
+ [60, -2.71254, -1.42377, 0.82683] ,
153
+ [70, -2.78865, -1.44313, 0.85550] ,
154
+ [80, -2.85368, -1.45474, 0.87479] ,
155
+ [90, -2.91216, -1.46226, 0.88764] ,
156
+ [100, -2.96672, -1.46787, 0.89598] ,
157
+ [120, -3.06983, -1.47811, 0.90421] ,
158
+ [140, -3.16950, -1.49082, 0.90634] ,
159
+ [160, -3.26809, -1.50771, 0.90603] ,
160
+ [180, -3.36633, -1.52909, 0.90532] ,
161
+ [200, -3.48436, -1.55473, 0.90547] ,
162
+ [250, -3.70773, -1.63448, 0.91388] ,
163
+ [300, -3.94607, -1.73053, 0.93714] ,
164
+ [350, -4.17591, -1.83593, 0.97495] ,
165
+ [400, -4.39433, -1.94515, 1.02467] ,
166
+ [500, -4.78872, -2.15940, 1.14615] ,
167
+ [600, -5.12008, -2.35243, 1.27714] ,
168
+ [800, -5.59959, -2.64798, 1.50995] ,
169
+ [1000, -5.88447, -2.83157, 1.67325] ,
170
+ [1500, -6.15106, -3.00957, 1.84797] ,
171
+ [2000, -6.20058, -3.04408, 1.88423] ,
172
+ [3000, -6.21044, -3.05176, 1.89114] ,
173
+ [5000, -6.21155, -3.05324, 1.89118] ,
174
+ [10000, -6.21226, -3.05427, 1.89110]])
175
+
176
+ l = data[:,0]
177
+ hl = data[:,1]
178
+ kl = numpy.divide(data[:,2], l)
179
+ ll = numpy.divide(data[:,3], l)
180
+
181
+ if frame == 'CM':
182
+ hl[0] = hl[0] - 1
183
+ ll[0] = ll[0] - 1
184
+ kl[0] = kl[0] - 1
185
+ print('Love numbers are in center of mass frame')
186
+ elif frame == 'CF':
187
+ hlo = hl[0]
188
+ llo = ll[0]
189
+ hl[0] = (hlo - llo) * 2/3
190
+ ll[0] = (hlo - llo) * (-1/3)
191
+ kl[0] = ((-2/3)*llo) - ((-1/3)*hlo)
192
+ print('Love numbers are in center of figure frame')
193
+ elif frame == 'CE':
194
+ print('Love numbers are in center of solid Earth frame')
195
+ else:
196
+ lovenrPREM.exit('Please choose a compatible frame of reference: one of CM, CF, or CE')
197
+
198
+
199
+ n = range(0, lmax+1, 1)
200
+ kn = numpy.interp(n,l,kl)
201
+ hn = numpy.interp(n,l,hl)
202
+ ln = numpy.interp(n,l,ll)
203
+ kn[0] = 0
204
+ hn[0] = 0
205
+ ln[0] = 0
206
+ return(kn,hn,ln)
pyshbundle/__init__.py ADDED
@@ -0,0 +1,72 @@
1
+ """Top-level package for pyshbundle.
2
+
3
+ This file is part of PySHbundle.
4
+ PySHbundle is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18
+
19
+ Acknowledgement Statement:
20
+ Please note that PySHbundle has adapted the following code packages,
21
+ both licensed under GNU General Public License
22
+ 1. SHbundle: https://www.gis.uni-stuttgart.de/en/research/downloads/shbundle/
23
+
24
+ 2. Downscaling GRACE Total Water Storage Change using
25
+ Partial Least Squares Regression
26
+ https://springernature.figshare.com/collections/Downscaling_GRACE_Total_Water_Storage_Change_using_Partial_Least_Squares_Regression/5054564
27
+
28
+ Key Papers Referred:
29
+ 1. Vishwakarma, B. D., Horwath, M., Devaraju, B., Groh, A., & Sneeuw, N. (2017).
30
+ A data‐driven approach for repairing the hydrological catchment signal damage
31
+ due to filtering of GRACE products. Water Resources Research,
32
+ 53(11), 9824-9844. https://doi.org/10.1002/2017WR021150
33
+
34
+ 2. Vishwakarma, B. D., Zhang, J., & Sneeuw, N. (2021).
35
+ Downscaling GRACE total water storage change using
36
+ partial least squares regression. Scientific data, 8(1), 95.
37
+ https://doi.org/10.1038/s41597-021-00862-6
38
+ """
39
+ # 2024-06-10, updated: Vivek Kumar Yadav, IISc Bengaluru
40
+
41
+ __author__ = """Vivek Kumar Yadav"""
42
+ __email__ = 'viveky@iisc.ac.in'
43
+ __version__ = '1.3.0'
44
+
45
+ # __init__.py with initialization code
46
+ print("Initializing PySHbundle v1.3.0")
47
+
48
+ # __init__.py with __all__
49
+ __all__ = ['GRACEpy',
50
+ 'io',
51
+ 'viz_utils',
52
+ 'reshape_SH_coefficients',
53
+ 'shutils',
54
+ 'hydro',
55
+ 'pysh_core'
56
+ ]
57
+
58
+
59
+ from .GRACEpy import upwcon, lovenr, lovenrPREM
60
+ from .io import extract_SH_data, extract_deg1_coeff_tn13, extract_deg2_3_coeff_tn14, \
61
+ parse_lines, \
62
+ parse_jpl_file, parse_csr_file, parse_itsg_file, parse_jpl_header, parse_csr_header, parse_itsg_header, \
63
+ parse_tn13_header, parse_tn14_header, \
64
+ find_date_in_replacemnt_file, extract_C10_11_replcmnt_coeff, extract_C20_replcmnt_coeff, \
65
+ extract_C30_replcmnt_coeff
66
+ # read_GRACE_SH_paths, load_longterm_mean # 2 Apr 2026 deprecated functions, moved to deprecated/deprecated_functions.py
67
+ from .sc2cs import sc2cs
68
+ from .reshape_SH_coefficients import sc2cs, clm2cs, clm2sc, cs2sc, klm2sc, cklm2sc_new
69
+ from .hydro import TWSCalc, area_weighting, Basinaverage
70
+ from .shutils import plm, iplm, ispec, eigengrav, grule, Gaussian, neumann, naninterp, normalklm
71
+ from .pysh_core import gshs, gsha, GRACE_Data_Driven_Correction_Vishwakarma, PhaseCalc
72
+ from .viz_utils import sc_triplot, cs_sqplot, polar_plot, mapfield, ylm, ylm_plot, gshs_prepare