Skip to content

Commit

Permalink
replaced numpy bool/int/float to prevent deprecation warnings (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley authored Mar 27, 2021
1 parent 00cdcf9 commit 92a523c
Show file tree
Hide file tree
Showing 35 changed files with 295 additions and 271 deletions.
6 changes: 3 additions & 3 deletions notebooks/Check Tide Map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
" mz = np.invert(hz.mask)\n",
" # adjust longitudinal convention of input latitude and longitude\n",
" # to fit tide model convention\n",
" x,y = np.copy([LON,LAT]).astype(np.float)\n",
" x,y = np.copy([LON,LAT]).astype(np.float64)\n",
" lt0, = np.nonzero(x < 0)\n",
" x[lt0] += 360.0\n",
"elif (model_format == 'GOT'):\n",
Expand All @@ -283,7 +283,7 @@
" mz = np.invert(hc.mask)\n",
" # adjust longitudinal convention of input latitude and longitude\n",
" # to fit tide model convention\n",
" x,y = np.copy([LON,LAT]).astype(np.float)\n",
" x,y = np.copy([LON,LAT]).astype(np.float64)\n",
" lt0, = np.nonzero(x < 0)\n",
" x[lt0] += 360.0\n",
"elif (model_format == 'FES'):\n",
Expand All @@ -295,7 +295,7 @@
" mz = np.invert(hc.mask)\n",
" # adjust longitudinal convention of input latitude and longitude\n",
" # to fit tide model convention\n",
" x,y = np.copy([LON,LAT]).astype(np.float)\n",
" x,y = np.copy([LON,LAT]).astype(np.float64)\n",
" lt0, = np.nonzero(x < 0)\n",
" x[lt0] += 360.0\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Plot Antarctic Tidal Currents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@
"y = np.arange(ylimits[1],ylimits[0]+spacing[1],spacing[1])\n",
"xgrid,ygrid = np.meshgrid(x,y)\n",
"#-- x and y dimensions\n",
"nx = np.int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = np.int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"nx = int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"#-- convert image coordinates from polar stereographic to latitude/longitude\n",
"crs1 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(3031))\n",
"crs2 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(4326))\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Plot Antarctic Tide Range.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@
"y = np.arange(ylimits[1],ylimits[0]+spacing[1],spacing[1])\n",
"xgrid,ygrid = np.meshgrid(x,y)\n",
"#-- x and y dimensions\n",
"nx = np.int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = np.int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"nx = int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"#-- convert image coordinates from polar stereographic to latitude/longitude\n",
"crs1 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(3031))\n",
"crs2 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(4326))\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Plot Arctic Ocean Map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@
"y = np.arange(ylimits[1],ylimits[0]+spacing[1],spacing[1])\n",
"xgrid,ygrid = np.meshgrid(x,y)\n",
"#-- x and y dimensions\n",
"nx = np.int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = np.int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"nx = int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"#-- convert image coordinates from polar stereographic to latitude/longitude\n",
"crs1 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(3413))\n",
"crs2 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(4326))\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Plot Ross Ice Shelf Map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@
"y = np.arange(ylimits[1],ylimits[0]+spacing[1],spacing[1])\n",
"xgrid,ygrid = np.meshgrid(x,y)\n",
"#-- x and y dimensions\n",
"nx = np.int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = np.int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"nx = int((xlimits[1]-xlimits[0])/spacing[0])+1\n",
"ny = int((ylimits[0]-ylimits[1])/spacing[1])+1\n",
"#-- convert image coordinates from polar stereographic to latitude/longitude\n",
"crs1 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(3031))\n",
"crs2 = pyproj.CRS.from_string(\"epsg:{0:d}\".format(4326))\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/Plot Tide Forecasts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
"TIDE.data[:] *= 100.0\n",
"\n",
"#-- differentiate to calculate high and low tides\n",
"diff = np.zeros_like(tide_time, dtype=np.float)\n",
"diff = np.zeros_like(tide_time, dtype=np.float64)\n",
"#-- forward differentiation for starting point\n",
"diff[0] = TIDE.data[1] - TIDE.data[0]\n",
"#-- backward differentiation for end point\n",
Expand Down
6 changes: 3 additions & 3 deletions pyTMD/bilinear_interp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
u"""
bilinear_interp.py (02/2021)
bilinear_interp.py (03/2021)
Bilinear interpolation of input data to output coordinates
CALLING SEQUENCE:
Expand All @@ -26,7 +26,7 @@
https://numpy.org/doc/stable/user/numpy-for-matlab-users.html
UPDATE HISTORY:
Updated 02/2021: replaced numpy bool to prevent deprecation warning
Updated 03/2021: replaced numpy bool/int to prevent deprecation warnings
Updated 12/2020: using numpy isclose to check corner points
Updated 08/2020: check that output coordinates are within bounds
allow small extrapolations if individual grid cells are invalid
Expand All @@ -38,7 +38,7 @@

#-- PURPOSE: bilinear interpolation of input data to output data
def bilinear_interp(ilon,ilat,idata,lon,lat,fill_value=np.nan,
dtype=np.float):
dtype=np.float64):
"""
Bilinear interpolation of input data to output coordinates
Expand Down
5 changes: 3 additions & 2 deletions pyTMD/eop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
eop.py
Written by Tyler Sutterley (11/2020)
Written by Tyler Sutterley (03/2021)
Utilities for maintaining Earth Orientation Parameter (EOP) files
PYTHON DEPENDENCIES:
Expand All @@ -14,6 +14,7 @@
utilities: download and management utilities for syncing files
UPDATE HISTORY:
Updated 03/2021: replaced numpy bool/int to prevent deprecation warnings
Written 11/2020
"""
import os
Expand Down Expand Up @@ -107,7 +108,7 @@ def calculate_mean_pole(verbose=False, mode=0o775):
for i,line in enumerate(file_contents[1:]):
line_contents = line.split()
for h,l in zip(header,line_contents):
data[h][i] = np.float(l)
data[h][i] = np.float64(l)
#-- output mean pole coordinates
xm = np.zeros((nlines))
ym = np.zeros((nlines))
Expand Down
3 changes: 2 additions & 1 deletion pyTMD/nearest_extrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Updated 03/2021: add checks to prevent runtime exception
where there are no valid points within the input bounds
or no points to be extrapolated
replaced numpy bool/int to prevent deprecation warnings
Updated 02/2021: replaced numpy bool to prevent deprecation warning
Written 12/2020
"""
Expand All @@ -45,7 +46,7 @@

#-- PURPOSE: Nearest-neighbor extrapolation of valid data to output data
def nearest_extrap(ilon,ilat,idata,lon,lat,fill_value=np.nan,
dtype=np.float,cutoff=np.inf,EPSG='4326'):
dtype=np.float64,cutoff=np.inf,EPSG='4326'):
"""
Nearest-neighbor extrapolation of valid model data
Expand Down
11 changes: 6 additions & 5 deletions pyTMD/read_FES_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
Updated 03/2021: add extrapolation check where there are no invalid points
prevent ComplexWarning for fill values when calculating amplitudes
simplified inputs to be similar to binary OTIS read program
replaced numpy bool/int to prevent deprecation warnings
use uuid for reading from gzipped netCDF4 files
Updated 02/2021: set invalid values to nan in extrapolation
replaced numpy bool to prevent deprecation warning
Expand Down Expand Up @@ -235,16 +236,16 @@ def read_ascii_file(input_file,GZIP=False,TYPE=None,VERSION=None):
file_contents = f.read().splitlines()
#-- parse header text
#-- longitude range (lonmin, lonmax)
lonmin,lonmax = np.array(file_contents[0].split(), dtype=np.float)
lonmin,lonmax = np.array(file_contents[0].split(), dtype=np.float64)
#-- latitude range (latmin, latmax)
latmin,latmax = np.array(file_contents[1].split(), dtype=np.float)
latmin,latmax = np.array(file_contents[1].split(), dtype=np.float64)
#-- grid step size (dlon, dlat)
dlon,dlat = np.array(file_contents[2].split(), dtype=np.float)
dlon,dlat = np.array(file_contents[2].split(), dtype=np.float64)
#-- grid dimensions (nlon, nlat)
nlon,nlat = np.array(file_contents[3].split(), dtype=np.int)
nlon,nlat = np.array(file_contents[3].split(), dtype=int)
#-- mask fill value
masked_values = file_contents[4].split()
fill_value = np.float(masked_values[0])
fill_value = np.float64(masked_values[0])
#-- create output variables
lat = np.linspace(latmin, latmax, nlat)
lon = np.linspace(lonmin,lonmax,nlon)
Expand Down
11 changes: 6 additions & 5 deletions pyTMD/read_GOT_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
Updated 03/2021: add extrapolation check where there are no invalid points
prevent ComplexWarning for fill values when calculating amplitudes
simplified inputs to be similar to binary OTIS read program
replaced numpy bool/int to prevent deprecation warnings
Updated 02/2021: set invalid values to nan in extrapolation
replaced numpy bool to prevent deprecation warning
Updated 12/2020: added valid data extrapolation with nearest_extrap
Expand Down Expand Up @@ -265,13 +266,13 @@ def read_GOT_grid(input_file, GZIP=False):
constituent_list = ['Q1','O1','P1','K1','N2','M2','S2','K2','S1','M4']
regex = re.compile(r'|'.join(constituent_list), re.IGNORECASE)
cons = regex.findall(file_contents[0]).pop().lower()
nlat,nlon = np.array(file_contents[2].split(), dtype=np.int)
nlat,nlon = np.array(file_contents[2].split(), dtype=int)
#-- longitude range
ilat = np.array(file_contents[3].split(), dtype=np.float)
ilat = np.array(file_contents[3].split(), dtype=np.float64)
#-- latitude range
ilon = np.array(file_contents[4].split(), dtype=np.float)
ilon = np.array(file_contents[4].split(), dtype=np.float64)
#-- mask fill value
fill_value = np.array(file_contents[5].split(), dtype=np.float)
fill_value = np.array(file_contents[5].split(), dtype=np.float64)
#-- create output variables
lat = np.linspace(ilat[0],ilat[1],nlat)
lon = np.linspace(ilon[0],ilon[1],nlon)
Expand All @@ -282,7 +283,7 @@ def read_GOT_grid(input_file, GZIP=False):
ph.mask = np.zeros((nlat,nlon),dtype=bool)
#-- starting lines to fill amplitude and phase variables
l1 = 7
l2 = 14 + np.int(nlon//11)*nlat + nlat
l2 = 14 + int(nlon//11)*nlat + nlat
#-- for each latitude
for i in range(nlat):
for j in range(nlon//11):
Expand Down
9 changes: 5 additions & 4 deletions pyTMD/read_iers_EOP.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
read_iers_EOP.py
Written by Tyler Sutterley (07/2020)
Written by Tyler Sutterley (03/2021)
Provides the daily earth orientation parameters (EOP) from IERS
http://www.usno.navy.mil/USNO/earth-orientation/eo-products/weekly
Data format: http://maia.usno.navy.mil/ser7/readme.finals
Expand All @@ -25,6 +25,7 @@
IERS Technical Note No. 36, BKG (2010)
UPDATE HISTORY:
Updated 03/2021: replaced numpy bool/int to prevent deprecation warnings
Updated 07/2020: added function docstrings
Written 09/2017
"""
Expand Down Expand Up @@ -62,13 +63,13 @@ def read_iers_EOP(input_file):
while (flag == 'I'):
line = file_contents[counter]
i = 2+2+2+1; j = i+8
dinput['MJD'][counter] = np.float(line[i:j])
dinput['MJD'][counter] = np.float64(line[i:j])
i = j+1
flag = line[i]
i += 2; j = i+9
dinput['x'][counter] = np.float(line[i:j])
dinput['x'][counter] = np.float64(line[i:j])
i = j+10; j = i+9
dinput['y'][counter] = np.float(line[i:j])
dinput['y'][counter] = np.float64(line[i:j])
counter += 1
#-- reduce to data values
dinput['MJD'] = dinput['MJD'][:counter]
Expand Down
7 changes: 4 additions & 3 deletions pyTMD/read_ocean_pole_tide.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
u"""
read_ocean_pole_tide.py (08/2020)
read_ocean_pole_tide.py (03/2021)
Reads ocean pole load tide coefficients provided by IERS
http://maia.usno.navy.mil/conventions/2010/2010_official/chapter7/tn36_c7.pdf
http://maia.usno.navy.mil/conventions/2010/2010_update/chapter7/icc7.pdf
Expand Down Expand Up @@ -29,6 +29,7 @@
doi: 10.1007/s00190-015-0848-7
UPDATE HISTORY:
Updated 03/2021: replaced numpy bool/int to prevent deprecation warnings
Updated 08/2020: output north load and east load deformation components
Updated 07/2020: added function docstrings
Updated 12/2018: Compatibility updates for Python3
Expand Down Expand Up @@ -84,8 +85,8 @@ def read_ocean_pole_tide(input_file):
#-- read lines of file and add to output variables
for i,line in enumerate(file_contents[count:]):
ln,lt,urr,uri,unr,uni,uer,uei = np.array(line.split(), dtype='f8')
ilon = np.int(ln/dlon)
ilat = np.int((90.0-lt)/dlat)
ilon = int(ln/dlon)
ilat = int((90.0-lt)/dlat)
ur[ilon,ilat] = urr + 1j*uri
un[ilon,ilat] = unr + 1j*uni
ue[ilon,ilat] = uer + 1j*uei
Expand Down
23 changes: 12 additions & 11 deletions pyTMD/read_tide_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
Updated 03/2021: add extrapolation check where there are no invalid points
prevent ComplexWarning for fill values when calculating amplitudes
can read from single constituent TPXO9 ATLAS binary files
replaced numpy bool/int to prevent deprecation warnings
Updated 02/2021: set invalid values to nan in extrapolation
replaced numpy bool to prevent deprecation warning
Updated 12/2020: added valid data extrapolation with nearest_extrap
Expand Down Expand Up @@ -964,8 +965,8 @@ def create_atlas_mask(xi,yi,mz,local,VARIABLE=None):
for indy,indx in zip(validy,validx):
#-- check if model is -180:180
lon30 = (X[indy,indx]+360.) if (X[indy,indx]<=0.0) else X[indy,indx]
ii = np.int((lon30 - x30[0])/d30)
jj = np.int((Y[indy,indx] - y30[0])/d30)
ii = int((lon30 - x30[0])/d30)
jj = int((Y[indy,indx] - y30[0])/d30)
#-- fill global mask with regional solution
m30[jj,ii] = 1
#-- return the 2 arc-minute mask
Expand Down Expand Up @@ -1028,8 +1029,8 @@ def combine_atlas_model(xi,yi,zi,pmask,local,VARIABLE=None):
for indy,indx in zip(validy,validx):
#-- check if model is -180:180
lon30 = (X[indy,indx]+360.) if (X[indy,indx]<=0.0) else X[indy,indx]
ii = np.int((lon30 - x30[0])/d30)
jj = np.int((Y[indy,indx] - y30[0])/d30)
ii = int((lon30 - x30[0])/d30)
jj = int((Y[indy,indx] - y30[0])/d30)
#-- fill global model with regional solution
z30.data[jj,ii] = zlocal[indy,indx]
#-- return 2 arc-minute solution and coordinates
Expand All @@ -1042,18 +1043,18 @@ def Muv(hz):
Construct masks for zeta, u and v nodes on a C-grid
"""
ny,nx = np.shape(hz)
mz = (hz > 0).astype(np.int)
mz = (hz > 0).astype(int)
#-- x-indices
indx = np.zeros((nx),dtype=np.int)
indx = np.zeros((nx),dtype=int)
indx[:-1] = np.arange(1,nx)
indx[-1] = 0
#-- y-indices
indy = np.zeros((ny),dtype=np.int)
indy = np.zeros((ny),dtype=int)
indy[:-1] = np.arange(1,ny)
indy[-1] = 0
#-- calculate mu and mv
mu = np.zeros((ny,nx),dtype=np.int)
mv = np.zeros((ny,nx),dtype=np.int)
mu = np.zeros((ny,nx),dtype=int)
mv = np.zeros((ny,nx),dtype=int)
mu[indy,:] = mz*mz[indy,:]
mv[:,indx] = mz*mz[:,indx]
return (mu,mv,mz)
Expand All @@ -1066,11 +1067,11 @@ def Huv(hz):
ny,nx = np.shape(hz)
mu,mv,mz = Muv(hz)
#-- x-indices
indx = np.zeros((nx),dtype=np.int)
indx = np.zeros((nx),dtype=int)
indx[0] = nx-1
indx[1:] = np.arange(1,nx)
#-- y-indices
indy = np.zeros((ny),dtype=np.int)
indy = np.zeros((ny),dtype=int)
indy[0] = ny-1
indy[1:] = np.arange(1,ny)
#-- calculate hu and hv
Expand Down
5 changes: 3 additions & 2 deletions pyTMD/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
UPDATE HISTORY:
Updated 03/2021: added polar stereographic area scale calculation
add routines for converting to and from cartesian coordinates
eplaced numpy bool/int to prevent deprecation warnings
Updated 01/2021: add streaming from bytes for ascii, netCDF4, HDF5, geotiff
set default time for geotiff files to 0
Updated 12/2020: added module for converting ellipsoids
Expand Down Expand Up @@ -111,7 +112,7 @@ def from_ascii(filename, compression=None, verbose=False,
dinput[c] = np.zeros((file_lines-count))
dinput['attributes'][c] = YAML_HEADER['header']['variables'][c]
#-- update number of file lines to skip for reading data
header = np.int(count)
header = int(count)
else:
#-- output spatial data and attributes
dinput = {c:np.zeros((file_lines-header)) for c in columns}
Expand All @@ -124,7 +125,7 @@ def from_ascii(filename, compression=None, verbose=False,
column = {c:r.replace('D','E') for c,r in zip(columns,rx.findall(line))}
#-- copy variables from column dict to output dictionary
for c in columns:
dinput[c][i] = np.float(column[c])
dinput[c][i] = np.float64(column[c])
#-- convert to masked array if fill values
if '_FillValue' in dinput['attributes']['data'].keys():
dinput['data'] = np.ma.asarray(dinput['data'])
Expand Down
Loading

0 comments on commit 92a523c

Please sign in to comment.