Skip to content

Commit

Permalink
Merge pull request GESS-research-group#90 from abhimhamane/89-pip-com…
Browse files Browse the repository at this point in the history
…patibility

Changes to function calling using the module and updating the module
  • Loading branch information
abhimhamane authored Jan 8, 2024
2 parents c82bef9 + afc12d9 commit 7ced8aa
Show file tree
Hide file tree
Showing 17 changed files with 561 additions and 453 deletions.
Binary file modified dist/pyshbundle-0.1.1.tar.gz
Binary file not shown.
362 changes: 233 additions & 129 deletions notebooks/TWS_time_series.ipynb

Large diffs are not rendered by default.

114 changes: 58 additions & 56 deletions notebooks/intro_spherical_harmonics_with_pyshbundle.ipynb

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions notebooks/load_data.ipynb

Large diffs are not rendered by default.

297 changes: 147 additions & 150 deletions notebooks/visualizations.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyshbundle.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Author: Amin Shakya
Author-email: [email protected]
License: GNU General Public License v3
Keywords: pyshbundle
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Expand Down Expand Up @@ -188,3 +189,5 @@ TODO: Add citing info
## Follow the Research Group

<a href="https://ultra-pluto-7f6d1.netlify.app" rel="Geodesy for Earth system science (GESS) research Group at ICWaR, IISc">![Geodesy for Earth system science (GESS) research Group at ICWaR, IISc](../notebooks/imgs/logoGESS.jpg)</a>


2 changes: 2 additions & 0 deletions pyshbundle.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ ipykernel
jupyterlab
rioxarray
cartopy
salem
#conda install -c conda-forge --file requirements_dev.txt -y

37 changes: 19 additions & 18 deletions pyshbundle.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
pip
Sphinx
bump2version
wheel
watchdog
flake8
tox
cartopy
cartopy
coverage
Sphinx
twine
flake8
geopandas
grip
ipykernel
julian
jupyterlab
matplotlib
netCDF4
numpy
pandas
netCDF4
pip
rasterio
rioxarray
salem
scipy
xarray
julian
scipy
geopandas
matplotlib
rasterio
shapely
tox
tqdm
cartopy
ipykernel
jupyterlab
rioxarray
cartopy
twine
watchdog
wheel
xarray
22 changes: 11 additions & 11 deletions pyshbundle/GRACE_Data_Driven_Correction_Vishwakarma.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def GRACE_Data_Driven_Correction_Vishwakarma(F, cf, GaussianR, basins):
else:
flag_cs = 1

Weights = gaussian.gaussian(l-1, GaussianR)
Weights = gaussian(l-1, GaussianR)
#gaussian returns weights as a list #gaussian is np.array()

try: #Broadcase Weights into dimensions
Expand All @@ -162,13 +162,13 @@ def GRACE_Data_Driven_Correction_Vishwakarma(F, cf, GaussianR, basins):
if l == cfield:
for m in range(r):
if flag_cs == 0:
Ft = cs2sc.cs2sc(f[m][0]).astype('longdouble')
Ft = cs2sc(f[m][0]).astype('longdouble')
else:
Ft = f[m][0].astype('longdouble')


fFld__, _, _ = gshs.gshs(Ft * filter_, qty, 'cell', int(180/deg), 0, 0)
ffFld__, _, _ = gshs.gshs((Ft * filter_ * filter_), qty, 'cell', int(180/deg), 0, 0)
fFld__, _, _ = gshs(Ft * filter_, qty, 'cell', int(180/deg), 0, 0)
ffFld__, _, _ = gshs((Ft * filter_ * filter_), qty, 'cell', int(180/deg), 0, 0)

if m == 0:
fFld = np.zeros((r,fFld__.shape[0],fFld__.shape[1]), dtype = 'longdouble')
Expand Down Expand Up @@ -210,8 +210,8 @@ def GRACE_Data_Driven_Correction_Vishwakarma(F, cf, GaussianR, basins):

#Basin functions, filtered basin function and transfer function Kappa
Rb = basins[rbasin][0]
csRb = gsha.gsha(Rb, 'mean', 'block', long/2)
csF = cs2sc.cs2sc(csRb[0:l, 0:l])
csRb = gsha(Rb, 'mean', 'block', long/2)
csF = cs2sc(csRb[0:l, 0:l])
filRb_ = gshs(csF * filter_, 'none', 'cell', int(long/2), 0, 0)
filRb = filRb_[0]
kappa = (1-Rb) * filRb
Expand Down Expand Up @@ -268,8 +268,8 @@ def GRACE_Data_Driven_Correction_Vishwakarma(F, cf, GaussianR, basins):


A = np.ones([60,2])
A[:,1] = naninterp.naninterp(tsleaktotalff[:, i])
lssol_ = sc.linalg.lstsq(A, naninterp.naninterp(tsleaktotalf[:, i])) #returns a tuple of solution "x", residue and rank of matrix A; for A x = B
A[:,1] = naninterp(tsleaktotalff[:, i])
lssol_ = sc.linalg.lstsq(A, naninterp(tsleaktotalf[:, i])) #returns a tuple of solution "x", residue and rank of matrix A; for A x = B
lssol = lssol_[0]
bl.append(lssol[2-1])
#Working till here 2022-10-21 1530pm
Expand All @@ -280,15 +280,15 @@ def GRACE_Data_Driven_Correction_Vishwakarma(F, cf, GaussianR, basins):
leakLS = tsleaktotalf * multp


ps = Phase_calc.Phase_calc(tsleaktotalf,tsleaktotalff)
ps = Phase_calc(tsleaktotalf,tsleaktotalff)



#Compute the near true leakage

for i in range(0, cid):
ftsleaktotal[:,i] = naninterp.naninterp(tsleaktotalf[:,i]) #Replaces gaps (NaN values) with an itnerpolated value in the leakage time series from once filtered fields
fftsleaktotal[:,i] = naninterp.naninterp(tsleaktotalff[:,i]) #replace the gaps (NaN values) with an interpolated value in leakage time series from twice filtered fields
ftsleaktotal[:,i] = naninterp(tsleaktotalf[:,i]) #Replaces gaps (NaN values) with an itnerpolated value in the leakage time series from once filtered fields
fftsleaktotal[:,i] = naninterp(tsleaktotalff[:,i]) #replace the gaps (NaN values) with an interpolated value in leakage time series from twice filtered fields

X = sc.fft.fft(ftsleaktotal[:,i]) #take fast Fourier transform #check shape of X 2022-10-21
p = -ps[0,i] / r #compute the fraction of the time period by which the time series is to be shiftes
Expand Down
8 changes: 4 additions & 4 deletions pyshbundle/clm2cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def clm2cs_new(data_mat: np.ndarray, lmax: int, sigma_flag=False):
"""
if sigma_flag:
sc_mat, dev_sc = clm2sc.clm2sc(data_mat=data_mat, lmax=lmax, sigma_flag=True)
return sc2cs.sc2cs(sc_mat), sc2cs.sc2cs(dev_sc)
sc_mat, dev_sc = clm2sc(data_mat=data_mat, lmax=lmax, sigma_flag=True)
return sc2cs(sc_mat), sc2cs.sc2cs(dev_sc)
else:
sc_mat = clm2sc.clm2sc(data_mat=data_mat, lmax=lmax, sigma_flag=False)
return sc2cs.sc2cs(sc_mat)
sc_mat = clm2sc(data_mat=data_mat, lmax=lmax, sigma_flag=False)
return sc2cs(sc_mat)


4 changes: 2 additions & 2 deletions pyshbundle/gsha.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def gsha(f, method: str, grid: str = None, lmax: int = -9999):
lam = np.arange(0, 360+(dt/4) - dt, dt)
elif (grid == 'neumann') or (grid == 'gauss'):
# gw, gx = neumann(n+1) #For some reason, grule does not work for even values
gw, gx = neumann.neumann(n)
gw, gx = neumann(n)
theta = np.arccos(np.flipud(gx)) * 180 / np.pi
lam = np.arange(0, 360+(dt/4)-dt, dt)

Expand Down Expand Up @@ -253,7 +253,7 @@ def gsha(f, method: str, grid: str = None, lmax: int = -9999):
slm[m:L+1, m] = (1 + (m == 0))/ 4 * p.T @ (si * bi)

elif method == 'fnm': #1st Neumann method (exact upto L/2)
w = neumann.neumann(np.cos(theRAD))
w = neumann(np.cos(theRAD))

for m in range(L+1):
l = np.arange(m, L+1).reshape(L+1-m, 1)
Expand Down
12 changes: 6 additions & 6 deletions pyshbundle/gshs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def gshs(field, quant = 'none', grd = 'mesh', n = -9999, h = 0, jflag = 1):

if rows == cols: #field in CS-format
lmax = rows - 1
field = cs2sc.cs2sc(field)
field = cs2sc(field)
elif cols - 2 * rows == -1: #field in SC-format already
lmax = rows - 1
else:
Expand Down Expand Up @@ -174,10 +174,10 @@ def gshs(field, quant = 'none', grd = 'mesh', n = -9999, h = 0, jflag = 1):
#% -------------------------------------------------------------------------

if jflag:
field = field - cs2sc.cs2sc(normalklm.normalklm(lmax+1))
field = field - cs2sc(normalklm(lmax+1))

l = np.arange(0, lmax+1)
transf = np.array([eigengrav.eigengrav(lmax, quant, h)])[0, :, :].T
transf = np.array([eigengrav(lmax, quant, h)])[0, :, :].T

field = field * np.matmul(transf, np.ones((1, 2*lmax+1)), dtype='longdouble')

Expand All @@ -202,7 +202,7 @@ def gshs(field, quant = 'none', grd = 'mesh', n = -9999, h = 0, jflag = 1):
m = 0
c = field[m:lmax+1, lmax+m]
l = np.array([np.arange(m,lmax+1)])
p = plm.plm(l, m, theRAD, nargin = 3, nargout = 1)[:,:,0]
p = plm(l, m, theRAD, nargin = 3, nargout = 1)[:,:,0]
a[:, m] = np.dot(p,c)
b[:, m] = np.zeros(nlat)

Expand All @@ -213,7 +213,7 @@ def gshs(field, quant = 'none', grd = 'mesh', n = -9999, h = 0, jflag = 1):
s = field[m:lmax+1,lmax-m]

l = np.array([np.arange(m,lmax+1)])
p = plm.plm(l, m, theRAD, nargin = 3, nargout = 1)[:,:,0]
p = plm(l, m, theRAD, nargin = 3, nargout = 1)[:,:,0]
a[:, m] = np.dot(p,c)
b[:, m] = np.dot(p,s)

Expand Down Expand Up @@ -244,7 +244,7 @@ def gshs(field, quant = 'none', grd = 'mesh', n = -9999, h = 0, jflag = 1):

#Code for ispec

f = ispec.ispec(a.T, b.T).T
f = ispec(a.T, b.T).T
if dlam > 1:
f = f[:,np.arange(1,dlam*nlon+1,dlam)]

Expand Down
4 changes: 2 additions & 2 deletions pyshbundle/iplm.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def iplm(l, m:int, theRAD, dt=-9999):
ctmin = np.cos(theRAD-dt/2)
plmplus = np.ones([n,lmax+1])
plmmin = np.ones([n,lmax + 1])
plmplus[:,l] = plm.plm(np.array([l]),mfix,(theRAD + dt/2),3,1)[:,:,0] # Tesserals
plmmin[:,l] = plm.plm(np.array([l]),mfix,(theRAD - dt/2),3,1)[:,:,0]
plmplus[:,l] = plm(np.array([l]),mfix,(theRAD + dt/2),3,1)[:,:,0] # Tesserals
plmmin[:,l] = plm(np.array([l]),mfix,(theRAD - dt/2),3,1)[:,:,0]
if mfix > 0:
m = np.arange(1,mfix + 1,1)
mm = 2*m
Expand Down
6 changes: 3 additions & 3 deletions pyshbundle/neumann.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def neumann(inn):
"""

try: #if input is an integer
x, w = grule.grule(inn)
x, w = grule(inn)
except: #if input is an array
if(len(inn)==1): #2nd Neumann method
x, w = grule.grule(inn)
x, w = grule(inn)
if(np.not_equal(np.mod(x, 1), 0)): #Not integer
raise TypeError("Integer input argument required")

Expand All @@ -114,7 +114,7 @@ def neumann(inn):
x = inn
theRAD = np.arccos(x) #x in radian
l = np.array(list(range(len(x))))
pp = plm.plm(l, theRAD)
pp = plm(l, theRAD)

rr = list([2])
for i in len(x-1):
Expand Down
6 changes: 3 additions & 3 deletions pyshbundle/new_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def clm2cs_new(data):
numpy.ndarray: Standard deviations associated with SH data arranged in |C\S| format
"""
# read the data from clm to sc format
sc_mat, devsc_mat = clm2sc.clm2sc(data)
sc_mat, devsc_mat = clm2sc(data)

# number of files stacked
num_files = np.shape(sc_mat)[0]
Expand All @@ -37,8 +37,8 @@ def clm2cs_new(data):
devcs_mat = np.zeros((num_files, r, r))

for ith_file in range(num_files):
cs_mat[ith_file, :, :] = sc2cs.sc2cs(sc_mat[ith_file, :, :])
devcs_mat[ith_file, :, :] = sc2cs.sc2cs(devsc_mat[ith_file, :, :])
cs_mat[ith_file, :, :] = sc2cs(sc_mat[ith_file, :, :])
devcs_mat[ith_file, :, :] = sc2cs(devsc_mat[ith_file, :, :])

return cs_mat, devcs_mat

Expand Down
5 changes: 2 additions & 3 deletions pyshbundle/tws_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

import os
#os.chdir(path_functions)
from pyshbundle import gaussian
from pyshbundle import gshs
import numpy as np
Expand All @@ -61,7 +60,7 @@ def tws_cal(data, lmax: int, gs: float, r, m):
"""
SC = data

gfilter = gaussian.gaussian(lmax,r)
gfilter = gaussian(lmax,r)
grid_y = int(180/gs)
grid_x = int(360/gs)
tws_f = np.zeros([m,grid_y,grid_x], dtype ='longdouble')
Expand All @@ -78,7 +77,7 @@ def tws_cal(data, lmax: int, gs: float, r, m):
h = 0
jflag = 0

ff = gshs.gshs(shfil, quant, grd, n, h, jflag)[0]
ff = gshs(shfil, quant, grd, n, h, jflag)[0]

ff = ff*1000
tws_f[i,:,0:int(grid_x/2)] = ff[:,int(grid_x/2):]
Expand Down
4 changes: 2 additions & 2 deletions pyshbundle/visualisation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def ylm(l: int, m: int):
arr[0] = l


p = plm.plm(arr, m, thetaRAD, nargin=1, nargout=1)
p = plm(arr, m, thetaRAD, nargin=1, nargout=1)

ylmc = p * cosml
ylms = p * sinml
Expand Down Expand Up @@ -291,7 +291,7 @@ def gshs_prepare(lmax, gs, quant, grd, h, jflag, sc_coeff):
grid_y = int(180/gs)
grid_x = int(360/gs)

ff = gshs.gshs(sc_coeff, quant, grd, n, h, jflag)[0]
ff = gshs(sc_coeff, quant, grd, n, h, jflag)[0]

# rearranging
field = np.zeros([grid_y,grid_x], dtype ='longdouble')
Expand Down

0 comments on commit 7ced8aa

Please sign in to comment.