Skip to content

Commit 888a0cc

Browse files
committed
update tide tools following pyTMD changes (#1)
interpolate GOT model over complex constituent space nearest and linear interpolation with regulargridinterpolators add EPSG option to spatial coordinate option add function doc strings for tide programs add PR flake8 lint check with ubuntu, macos, windows using conda to install dependencies from environment.yml flake8 updates of programs test corrtide.py
1 parent 5cc4d08 commit 888a0cc

19 files changed

+1314
-542
lines changed

.github/workflows/python-publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflows will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.x'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*
32+

.github/workflows/python-request.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python on pull request
5+
6+
on:
7+
pull_request:
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [ubuntu-20.04, macos-latest, windows-latest]
17+
python-version: [3.6, 3.7, 3.8]
18+
env:
19+
OS: ${{ matrix.os }}
20+
PYTHON: ${{ matrix.python-version }}
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set up Conda ${{ matrix.python-version }}
25+
uses: goanpeca/[email protected]
26+
with:
27+
auto-update-conda: true
28+
auto-activate-base: true
29+
python-version: ${{ matrix.python-version }}
30+
environment-file: environment.yml
31+
activate-environment: captoolkit
32+
- name: Lint with flake8
33+
shell: bash -l {0}
34+
run: |
35+
# stop the build if there are Python syntax errors or undefined names
36+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

captoolkit/fitsec.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
dmin = args.radius[0] * 1e3 # min search radius (km -> m)
204204
dmax = args.radius[1] * 1e3 + 1e-4 # max search radius (km -> m)
205205
dres_ = args.resparam[0] # resolution param for weighting func [1]
206-
nreloc = args.nreloc[0] # number of relocations
206+
nreloc = args.nreloc[0] # number of relocations
207207
nlim = args.minobs[0] # min obs for solution
208208
niter = args.niter[0] # number of iterations for solution
209209
tspan = args.tspan # min/max time for solution (d.yr)
@@ -229,7 +229,7 @@
229229
# [4] If err and id cols = -1, then they are not used.
230230

231231

232-
def binning(x, y, xmin=None, xmax=None, dx=1/12.,
232+
def binning(x, y, xmin=None, xmax=None, dx=1/12.,
233233
window=3/12., interp=False, median=False):
234234
"""Time-series binning (w/overlapping windows).
235235
@@ -304,7 +304,7 @@ def sigma_filter(x, y, order=1, window=3/12., n_iter=3, n_sigma=3):
304304
if len(idx) == 0: break # if no data to filter, stop iterating
305305
y_res[idx] = np.nan
306306
if np.sum(~np.isnan(y_res)) < 10: break ##NOTE: Arbitrary min obs
307-
y_filt[np.isnan(y_res)] = np.nan
307+
y_filt[np.isnan(y_res)] = np.nan
308308
return y_filt
309309

310310

@@ -360,7 +360,7 @@ def get_radius_idx(x, y, x0, y0, r, Tree, n_reloc=0):
360360
# Either no relocation or not enough points to do relocation
361361
if n_reloc < 1 or len(idx) < 2: return idx, reloc_dist
362362

363-
# Relocate center of search radius and query again
363+
# Relocate center of search radius and query again
364364
for k in range(n_reloc):
365365

366366
# Compute new search location => relocate initial center
@@ -400,7 +400,7 @@ def is_empty(ifile):
400400

401401
# Main function for computing parameters
402402
def main(ifile, n='', robust_fit=True, n_iter=niter):
403-
403+
404404
# Check for empty file
405405
if is_empty(ifile):
406406
print(('SKIP FILE: EMPTY OR CORRUPTED FILE:', ifile))
@@ -471,9 +471,9 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
471471

472472
# Check bbox for obs.
473473
if len(x[Ig]) == 0:
474-
print(('SKIP FILE: NO DATA POINTS INSIDE BBOX:', ifile))
474+
print(('SKIP FILE: NO DATA POINTS INSIDE BBOX:', ifile))
475475
return
476-
476+
477477
print(('Number of obs. edited by bbox!', 'before:', len(x), 'after:', len(x[Ig])))
478478

479479
# Only select wanted data
@@ -519,7 +519,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
519519
# Grid solution - defined by nodes
520520
Xi, Yi = make_grid(xmin, xmax, ymin, ymax, dx, dy)
521521

522-
xi, yi = Xi.ravel(), Yi.ravel()
522+
xi, yi = Xi.ravel(), Yi.ravel()
523523
coord = list(zip(x.ravel(), y.ravel()))
524524

525525
print('building the k-d tree ...')
@@ -563,11 +563,11 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
563563

564564
if len(i_cell) < nlim: continue # use larger radius
565565

566-
tcap, hcap = time[i_cell], height[i_cell]
566+
tcap, hcap = time[i_cell], height[i_cell]
567567

568568
Nb = sum(~np.isnan(hcap)) # length before editing
569569

570-
# 3-sigma filter
570+
# 3-sigma filter
571571
if SIGMAFILT:
572572
#hcap = sigma_filter(tcap, hcap, order=1, n_sigma=3, n_iter=3) ##NOTE: It removes too much!!!
573573
hcap[np.abs( hcap - np.nanmedian(hcap) ) > mad_std(hcap) * 3] = np.nan
@@ -578,7 +578,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
578578
n_mon, t_span = n_months(tcap, hcap, tstep=tstep)
579579

580580
##NOTE: Not using n_mon and t_span to constrain the solution! <<<<<<<<<<<<<<<<<<<<<
581-
# If enough data accept radius
581+
# If enough data accept radius
582582
#if Na >= nlim and n_mon >= MINMONTHS and t_span >= dtlim:
583583
if Na >= nlim:
584584
break
@@ -609,8 +609,8 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
609609
xc = np.median(xcap) # update inversion cell coords
610610
yc = np.median(ycap)
611611

612-
# Define resolution param (a fraction of the accepted radius)
613-
dres = dres_ * rad
612+
# Define resolution param (a fraction of the accepted radius)
613+
dres = dres_ * rad
614614

615615
# Estimate variance
616616
vcap = scap * scap
@@ -622,7 +622,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
622622
tref = np.nanmean(tcap)
623623
else:
624624
tref = np.float(tref_)
625-
625+
626626
# Design matrix elements
627627
c0 = np.ones(len(xcap)) # intercept (0)
628628
c1 = xcap - xc # dx (1)
@@ -645,7 +645,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
645645
Wcap = 1.0 / (vcap * (1.0 + (dist/dres)*(dist/dres)))
646646

647647
# Create some intermediate output variables
648-
sx, sy, at, ae, bi = np.nan, np.nan, np.nan, np.nan, np.nan
648+
sx, sy, at, ae, bi = np.nan, np.nan, np.nan, np.nan, np.nan
649649

650650
# Setup design matrix
651651
if model == 0:
@@ -666,7 +666,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
666666
mcol = [6, 7, 8, 9]
667667

668668
has_bias = False # bias flag
669-
669+
670670
# Check if bias is needed
671671
if len(np.unique(mcap)) > 1:
672672
# Add bias to design matrix
@@ -694,10 +694,10 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
694694
Cm = model_fit.params # coeffs
695695
Ce = model_fit.bse # std err
696696
resid = model_fit.resid # data - model
697-
697+
698698
# Check rate and error
699699
if np.abs(Cm[-1]) > dhlim or np.isinf(Ce[-1]): continue ##NOTE: Important for ICESat !!!
700-
700+
701701
# Residuals dH = H - A * Cm (remove linear trend)
702702
dh = hcap - np.dot(Acap, Cm)
703703

@@ -796,7 +796,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
796796
DATA2 = np.delete(DATA2.T, i_nan, 1).T
797797
else:
798798
##NOTE: NaNs are not removed in case a grid soluction (n_reloc=0) is selected.
799-
if not nreloc: grids = [d.reshape(Xi.shape) for d in DATA0.T] # 1d -> 2d (grids)
799+
if not nreloc: grids = [d.reshape(Xi.shape) for d in DATA0.T] # 1d -> 2d (grids)
800800

801801
variables = ['lat', 'lon', 'trend', 'trend_err', 'accel', 'accel_err',
802802
'height', 'height_err', 'model_rms', 'slope_x', 'slope_y',
@@ -830,7 +830,7 @@ def main(ifile, n='', robust_fit=True, n_iter=niter):
830830
for v,a in zip(variables, DATA0.T): fo0[v] = a # 1d arrays
831831
else:
832832
for v,g in zip(variables, grids): fo0[v] = g # 2d arrays
833-
fo0['x'], fo0['y'] = Xi[0,:], Yi[:,0]
833+
fo0['x'], fo0['y'] = Xi[0,:], Yi[:,0]
834834

835835
# Save binned time series values
836836
with h5py.File(ofile1, 'w') as fo1:

0 commit comments

Comments
 (0)