Skip to content

Commit 4f64c6b

Browse files
authored
fix: define int/float precision to prevent deprecation warning (#35)
feat: use try/except for retrieving netrc credentials feat: add figshare secure FTP uploader to utilities ci: use cartopy no-binary in build fix: use first value in requirements in setup ci: brew install `pkg-config` ci: use older proj7 in brew install for cartopy ci: add LD and CPP flags for proj7 ci: add cython to installations ci: `ACCEPT_USE_OF_DEPRECATED_PROJ_API_H` ci: set pkg-config path
1 parent 3b4de57 commit 4f64c6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+562
-421
lines changed

.github/workflows/python-request.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ jobs:
3939
- name: Install dependencies for MacOS
4040
if: matrix.os == 'macos-latest'
4141
run: |
42-
brew install proj
42+
brew install proj@7
4343
brew install geos
4444
brew install hdf5
4545
brew install netcdf
4646
brew install libxml2
4747
brew install libxslt
48+
brew install pkg-config
4849
pip install --upgrade pip
49-
pip install flake8 pytest pytest-cov numpy
50+
pip install flake8 pytest pytest-cov numpy cython
51+
export LDFLAGS="-L/usr/local/opt/proj@7/lib"
52+
export CPPFLAGS="-I/usr/local/opt/proj@7/include"
53+
export ACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1
54+
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/proj@7/lib/pkgconfig"
5055
pip install git+https://github.com/tsutterley/geoid-toolkit.git
5156
pip install git+https://github.com/tsutterley/read-GRACE-geocenter.git
5257
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

doc/source/user_guide/utilities.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,35 @@ General Methods
343343
.. _figshare: https://doi.org/10.6084/m9.figshare.7388540
344344

345345

346+
.. method:: gravity_toolkit.utilities.to_figshare(files,username=None,password=None,directory=None,timeout=None,context=ssl.SSLContext(ssl.PROTOCOL_TLS),get_ca_certs=False,verbose=False,chunk=8192)
347+
348+
Send files to `figshare`_ using secure `FTP uploader <https://help.figshare.com/article/upload-large-datasets-and-bulk-upload-using-the-ftp-uploader-desktop-uploader-or-api>`_
349+
350+
Arguments:
351+
352+
``files``: list of files to upload
353+
354+
Keyword arguments:
355+
356+
``username``: ftp username
357+
358+
``password``: ftp password
359+
360+
``directory``: figshare subdirectory for sending data
361+
362+
``timeout``: timeout in seconds for blocking operations
363+
364+
``context``: SSL context for ftp connection
365+
366+
``get_ca_certs``: get list of loaded “certification authority” certificates
367+
368+
``verbose``: print ftp transfer information
369+
370+
``chunk``: chunk size for transfer encoding
371+
372+
.. _figshare: https://doi.org/10.6084/m9.figshare.7388540
373+
374+
346375
.. method:: gravity_toolkit.utilities.from_csr(directory,timeout=None,context=ssl.SSLContext(),chunk=16384,verbose=False,fid=sys.stdout,mode=0o775)
347376

348377
Download `satellite laser ranging (SLR)`__ files from the University of Texas Center for Space Research (UTCSR)

gravity_toolkit/destripe_harmonics.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
destripe_harmonics.py
44
Original Fortran program remove_errors.f written by Isabella Velicogna
55
Adapted by Chia-Wei Hsu (05/2018)
6-
Updated by Tyler Sutterley (02/2021)
6+
Updated by Tyler Sutterley (05/2021)
77
88
Filters spherical harmonic coefficients for correlated "striping" errors
99
@@ -45,6 +45,7 @@
4545
http://dx.doi.org/10.1029/2005GL025285
4646
4747
UPDATE HISTORY:
48+
Updated 05/2021: define int/float precision to prevent deprecation warning
4849
Updated 02/2021: replaced numpy bool to prevent deprecation warning
4950
Updated 07/2020: added function docstrings
5051
Updated 03/2020: Updated for public release
@@ -135,8 +136,8 @@ def destripe_harmonics(clm1, slm1, LMIN=2, LMAX=60, MMAX=None,
135136
#-- put the even and odd l's into their own arrays
136137
ieven = -1
137138
iodd = -1
138-
leven = np.zeros((LMAX), dtype=np.int)
139-
lodd = np.zeros((LMAX), dtype=np.int)
139+
leven = np.zeros((LMAX), dtype=np.int64)
140+
lodd = np.zeros((LMAX), dtype=np.int64)
140141

141142
for l in range(int(m),int(LMAX+1)):
142143
#-- check if degree is odd or even

gravity_toolkit/gen_harmonics.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
gen_harmonics.py
4-
Written by Tyler Sutterley (01/2021)
4+
Written by Tyler Sutterley (05/2021)
55
Converts data from the spatial domain to spherical harmonic coefficients
66
77
Differs from the gen_stokes() function as it does not
@@ -46,6 +46,7 @@
4646
Associated Legendre Functions", Journal of Geodesy (2002)
4747
4848
UPDATE HISTORY:
49+
Updated 05/2021: define int/float precision to prevent deprecation warning
4950
Updated 01/2021: use harmonics class for spherical harmonic operations
5051
Updated 07/2020: added function docstrings
5152
Updated 04/2020: include degrees and orders in output dictionary
@@ -86,8 +87,8 @@ def gen_harmonics(data, lon, lat, LMAX=60, MMAX=None, PLM=0):
8687
MMAX = np.copy(LMAX)
8788

8889
#-- dimensions of the longitude and latitude arrays
89-
nlon = np.int(len(lon))
90-
nlat = np.int(len(lat))
90+
nlon = np.int64(len(lon))
91+
nlat = np.int64(len(lat))
9192

9293
#-- grid step
9394
dlon = np.abs(lon[1]-lon[0])
@@ -98,8 +99,8 @@ def gen_harmonics(data, lon, lat, LMAX=60, MMAX=None, PLM=0):
9899
dth = dlat*np.pi/180.0
99100

100101
#-- convert latitude and longitude to float if integers
101-
lon = lon.astype(np.float)
102-
lat = lat.astype(np.float)
102+
lon = lon.astype(np.float64)
103+
lat = lat.astype(np.float64)
103104
#-- reformatting longitudes to range 0:360 (if previously -180:180)
104105
if np.count_nonzero(lon < 0):
105106
lon[lon < 0] += 360.0

gravity_toolkit/gen_stokes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
gen_stokes.py
4-
Written by Tyler Sutterley (01/2021)
4+
Written by Tyler Sutterley (05/2021)
55
66
Converts data from the spatial domain to spherical harmonic coefficients
77
@@ -46,6 +46,7 @@
4646
hdf5_stokes.py: writes output spherical harmonic data to HDF5
4747
4848
UPDATE HISTORY:
49+
Updated 05/2021: define int/float precision to prevent deprecation warning
4950
Updated 01/2021: use harmonics class for spherical harmonic operations
5051
Updated 07/2020: added function docstrings
5152
Updated 04/2020: reading load love numbers outside of this function
@@ -103,13 +104,13 @@ def gen_stokes(data, lon, lat, LMIN=0, LMAX=60, MMAX=None, UNITS=1,
103104
"""
104105

105106
#-- converting LMIN and LMAX to integer
106-
LMIN = np.int(LMIN)
107-
LMAX = np.int(LMAX)
107+
LMIN = np.int64(LMIN)
108+
LMAX = np.int64(LMAX)
108109
#-- upper bound of spherical harmonic orders (default = LMAX)
109110
MMAX = np.copy(LMAX) if (MMAX is None) else MMAX
110111

111112
#-- grid dimensions
112-
nlat = np.int(len(lat))
113+
nlat = np.int64(len(lat))
113114
#-- grid step
114115
dlon = np.abs(lon[1]-lon[0])
115116
dlat = np.abs(lat[1]-lat[0])

gravity_toolkit/grace_date.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
grace_date.py
4-
Written by Tyler Sutterley (02/2021)
4+
Written by Tyler Sutterley (05/2021)
55
66
Reads index file from podaac_grace_sync.py or gfz_isdc_grace_ftp.py
77
Parses dates of each GRACE/GRACE-FO file and assigns the month number
@@ -38,6 +38,7 @@
3838
time.py: utilities for calculating time operations
3939
4040
UPDATE HISTORY:
41+
Updated 05/2021: define int/float precision to prevent deprecation warning
4142
Updated 02/2021: use adjust_months function to fix special months cases
4243
Updated 12/2020: using utilities from time module
4344
Updated 10/2020: use argparse to set command line parameters
@@ -135,7 +136,7 @@ def grace_date(base_dir, PROC='', DREL='', DSET='', OUTPUT=True, MODE=0o775):
135136
mid_day = np.zeros((n_files))#-- mid-month day
136137
tot_days = np.zeros((n_files))#-- number of days since Jan 2002
137138
tdec = np.zeros((n_files))#-- tdec is the date in decimal form
138-
mon = np.zeros((n_files,),dtype=np.int)#-- GRACE/GRACE-FO month number
139+
mon = np.zeros((n_files,),dtype=np.int64)#-- GRACE/GRACE-FO month number
139140

140141
#-- compile numerical expression operator for parameters from files
141142
#-- will work with previous releases and releases for GRACE-FO
@@ -153,10 +154,10 @@ def grace_date(base_dir, PROC='', DREL='', DSET='', OUTPUT=True, MODE=0o775):
153154
#-- extract parameters from input filename
154155
PFX,start_date,end_date,AUX,PRC,F1,DRL,F2,SFX = rx.findall(infile).pop()
155156
#-- find start date, end date and number of days
156-
start_yr[t] = np.float(start_date[:4])
157-
end_yr[t] = np.float(end_date[:4])
158-
start_day[t] = np.float(start_date[4:])
159-
end_day[t] = np.float(end_date[4:])
157+
start_yr[t] = np.float64(start_date[:4])
158+
end_yr[t] = np.float64(end_date[:4])
159+
start_day[t] = np.float64(start_date[4:])
160+
end_day[t] = np.float64(end_date[4:])
160161

161162
#-- number of days in the starting year for leap and standard years
162163
dpy = gravity_toolkit.time.calendar_days(start_yr[t]).sum()
@@ -176,7 +177,7 @@ def grace_date(base_dir, PROC='', DREL='', DSET='', OUTPUT=True, MODE=0o775):
176177

177178
#-- Calculation of total days since start of campaign
178179
count = 0
179-
n_yrs = np.int(start_yr[t]-2002)
180+
n_yrs = np.int64(start_yr[t]-2002)
180181
#-- for each of the GRACE years up to the file year
181182
for iyr in range(n_yrs):
182183
#-- year

gravity_toolkit/grace_find_months.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
grace_find_months.py
4-
Written by Tyler Sutterley (07/2020)
4+
Written by Tyler Sutterley (05/2021)
55
66
Parses date index file from grace_date.py
77
Finds the months available for a GRACE/GRACE-FO product
@@ -29,6 +29,7 @@
2929
grace_date.py: reads GRACE index file and calculates dates for each month
3030
3131
UPDATE HISTORY:
32+
Updated 05/2021: define int/float precision to prevent deprecation warning
3233
Updated 07/2020: added function docstrings
3334
Updated 03/2020: check that GRACE/GRACE-FO date file exists
3435
Updated 10/2019: using local() function to set subdirectories
@@ -91,18 +92,18 @@ def grace_find_months(base_dir, PROC, DREL, DSET='GSM'):
9192
#-- skip the header row and extract dates (decimal format) and months
9293
date_input = np.loadtxt(date_file, skiprows=1)
9394
tdec = date_input[:,0]
94-
months = date_input[:,1].astype(np.int)
95+
months = date_input[:,1].astype(np.int64)
9596

9697
#-- array of all possible months (or in case of CNES RL01/2: 10-day sets)
97-
all_months = np.arange(1,months.max(),dtype=np.int)
98+
all_months = np.arange(1,months.max(),dtype=np.int64)
9899
#-- missing months (values in all_months but not in months)
99100
missing = sorted(set(all_months)-set(months))
100101
#-- If CNES RL01/2: simply convert into numpy array
101102
#-- else: remove months 1-3 and convert into numpy array
102103
if ((PROC == 'CNES') & (DREL in ('RL01','RL02'))):
103-
missing = np.array(missing,dtype=np.int)
104+
missing = np.array(missing,dtype=np.int64)
104105
else:
105-
missing = np.array(missing[3:],dtype=np.int)
106+
missing = np.array(missing[3:],dtype=np.int64)
106107

107108
return {'time':tdec, 'start':months[0], 'end':months[-1], 'months':months,
108109
'missing':missing}

gravity_toolkit/grace_input_months.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
9393
UPDATE HISTORY:
9494
Updated 05/2021: can use SLR low-degree harmonic values produced by GFZ
95+
define int/float precision to prevent deprecation warning
9596
Updated 04/2021: can replace figure axis and azimuthal dependence with SLR
9697
Updated 12/2020: updated SLR geocenter for new solutions from Minkang Cheng
9798
Updated 11/2020: set regress_model RELATIVE option to 2003.3 to match others
@@ -384,7 +385,7 @@ def grace_input_months(base_dir, PROC, DREL, DSET, LMAX, start_mon, end_mon,
384385
grace_clm = np.zeros((LMAX+1,MMAX+1,n_cons))
385386
grace_slm = np.zeros((LMAX+1,MMAX+1,n_cons))
386387
tdec = np.zeros((n_cons))
387-
mon = np.zeros((n_cons),dtype=np.int)
388+
mon = np.zeros((n_cons),dtype=np.int64)
388389
#-- output dimensions
389390
lout = np.arange(LMAX+1)
390391
mout = np.arange(MMAX+1)
@@ -400,7 +401,7 @@ def grace_input_months(base_dir, PROC, DREL, DSET, LMAX, start_mon, end_mon,
400401
grace_clm[:,:,i] = Ylms['clm'][0:LMAX+1,0:MMAX+1]
401402
grace_slm[:,:,i] = Ylms['slm'][0:LMAX+1,0:MMAX+1]
402403
tdec[i] = Ylms['time']
403-
mon[i] = np.int(grace_month)
404+
mon[i] = np.int64(grace_month)
404405

405406
#-- Replace C20 with SLR coefficients
406407
if SLR_C20 in ('CSR','GFZ','GSFC'):
@@ -580,12 +581,12 @@ def read_ecmwf_corrections(base_dir, LMAX, months, MMAX=None):
580581
#-- split the line into individual components
581582
line_contents = line.split()
582583
#-- degree and order for the line
583-
l1 = np.int(line_contents[1])
584-
m1 = np.int(line_contents[2])
584+
l1 = np.int64(line_contents[1])
585+
m1 = np.int64(line_contents[2])
585586
#-- if degree and order are below the truncation limits
586587
if ((l1 <= LMAX) and (m1 <= MMAX)):
587-
atm_corr_clm[key][l1,m1] = np.float(line_contents[3])
588-
atm_corr_slm[key][l1,m1] = np.float(line_contents[4])
588+
atm_corr_clm[key][l1,m1] = np.float64(line_contents[3])
589+
atm_corr_slm[key][l1,m1] = np.float64(line_contents[4])
589590

590591
#-- create output atmospheric corrections to be removed/added to data
591592
atm_corr = {}
@@ -647,10 +648,10 @@ def regress_model(t_in, d_in, t_out, ORDER=2, CYCLES=None, RELATIVE=0.0):
647648
MMAT.append((t_out-RELATIVE)**o)
648649
#-- add cyclical terms (0.5=semi-annual, 1=annual)
649650
for c in CYCLES:
650-
DMAT.append(np.sin(2.0*np.pi*t_in/np.float(c)))
651-
DMAT.append(np.cos(2.0*np.pi*t_in/np.float(c)))
652-
MMAT.append(np.sin(2.0*np.pi*t_out/np.float(c)))
653-
MMAT.append(np.cos(2.0*np.pi*t_out/np.float(c)))
651+
DMAT.append(np.sin(2.0*np.pi*t_in/np.float64(c)))
652+
DMAT.append(np.cos(2.0*np.pi*t_in/np.float64(c)))
653+
MMAT.append(np.sin(2.0*np.pi*t_out/np.float64(c)))
654+
MMAT.append(np.cos(2.0*np.pi*t_out/np.float64(c)))
654655
#-- Calculating Least-Squares Coefficients
655656
#-- Standard Least-Squares fitting (the [0] denotes coefficients output)
656657
beta_mat = np.linalg.lstsq(np.transpose(DMAT), d_in, rcond=-1)[0]

gravity_toolkit/grace_months_index.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
grace_months_index.py
4-
Written by Tyler Sutterley (10/2020)
4+
Written by Tyler Sutterley (05/2021)
55
66
Creates a file with the start and end days for each dataset
77
Shows the range of each month for (CSR/GFZ/JPL) (RL04/RL05/RL06)
@@ -33,6 +33,7 @@
3333
numpy: Scientific Computing Tools For Python (https://numpy.org)
3434
3535
UPDATE HISTORY:
36+
Updated 05/2021: define int/float precision to prevent deprecation warning
3637
Updated 10/2020: use argparse to set command line parameters
3738
Updated 09/2020: add column for GSFC v02.4 GRACE mascons
3839
Updated 07/2020: added function docstrings
@@ -112,20 +113,20 @@ def grace_months_index(base_dir, DREL=['RL06','v02.4'], MODE=None):
112113
#-- Adding data to dictionary for data processing and release
113114
var_info[var_name] = {}
114115
#-- allocate for output variables
115-
var_info[var_name]['mon'] = np.zeros((nmon),dtype=np.int)
116-
var_info[var_name]['styr'] = np.zeros((nmon),dtype=np.int)
117-
var_info[var_name]['stday'] = np.zeros((nmon),dtype=np.int)
118-
var_info[var_name]['endyr'] = np.zeros((nmon),dtype=np.int)
119-
var_info[var_name]['endday'] = np.zeros((nmon),dtype=np.int)
116+
var_info[var_name]['mon'] = np.zeros((nmon),dtype=np.int64)
117+
var_info[var_name]['styr'] = np.zeros((nmon),dtype=np.int64)
118+
var_info[var_name]['stday'] = np.zeros((nmon),dtype=np.int64)
119+
var_info[var_name]['endyr'] = np.zeros((nmon),dtype=np.int64)
120+
var_info[var_name]['endday'] = np.zeros((nmon),dtype=np.int64)
120121
#-- place output variables in dictionary
121122
for i,key in enumerate(['mon','styr','stday','endyr','endday']):
122123
#-- first column is date in decimal form (start at 1 not 0)
123-
var_info[var_name][key] = date_input[:,i+1].astype(np.int)
124+
var_info[var_name][key] = date_input[:,i+1].astype(np.int64)
124125
#-- Finding the maximum month measured
125126
if (var_info[var_name]['mon'].max() > max_mon):
126127
#-- if the maximum month in this dataset is greater
127128
#-- than the previously read datasets
128-
max_mon = np.int(var_info[var_name]['mon'].max())
129+
max_mon = np.int64(var_info[var_name]['mon'].max())
129130

130131
#-- sort datasets alphanumerically
131132
var_name = sorted(var_info.keys())

0 commit comments

Comments
 (0)