Skip to content

Commit

Permalink
Merge branch 'wesleybowman:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal919 authored Apr 21, 2022
2 parents ce1a21e + 46a80e2 commit 354f0e5
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 48 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ name: pre-commit
on:
pull_request:
push:
branches: [master]
branches: [master, main]

jobs:
pre-commit:
runs-on: ubuntu-latest
env:
FORCE_COLOR: "1"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- id: file_changes
uses: trilom/[email protected]
with:
output: ' '
- uses: pre-commit/[email protected]
with:
extra_args: --files ${{ steps.file_changes.outputs.files}}
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.x"

- name: Get tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
Expand All @@ -41,7 +41,7 @@ jobs:
shell: bash

- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@main
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ name: Tests
on:
pull_request:
push:
branches: [master]
branches: [master, main]

jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9"]
python-version: [ "3.7", "3.8", "3.9", "3.10"]
os: [windows-latest, ubuntu-latest, macos-latest]
# Oldest one based on NEP-29 and latest one.
# See https://numpy.org/neps/nep-0029-deprecation_policy.html
numpy-version: ["1.17", "1.20"]
numpy-version: ["1.19", "1.22"]
exclude:
- python-version: "3.10"
numpy-version: "1.19"

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.2.0
hooks:
- id: check-ast
- id: end-of-file-fixer
Expand All @@ -15,33 +15,33 @@ repos:
- id: debug-statements

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.2
hooks:
- id: flake8
exclude: docs/source/conf.py
args: [--max-line-length=105]

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.7.0
rev: v5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
args: [--project=utide, --multi-line=3, --lines-after-imports=2, --lines-between-types=1, --trailing-comma, --force-grid-wrap=0, --use-parentheses, --line-width=88]

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/asottile/pyupgrade
rev: v2.10.0
rev: v2.32.0
hooks:
- id: pyupgrade
args:
- --py36-plus

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
rev: v2.2.2
hooks:
- id: add-trailing-comma
2 changes: 1 addition & 1 deletion utide/astronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def ut_astron(jd):
d = jd - daten
D = d / 10000

args = np.vstack((np.ones(jd.shape), d, D * D, D ** 3))
args = np.vstack((np.ones(jd.shape), d, D * D, D**3))

astro = np.fmod((np.dot(_coefs, args) / 360), 1)

Expand Down
24 changes: 12 additions & 12 deletions utide/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ def _confidence(
varImap += 0.25 * varcov[nNR + k, 2, 2]
rp = ref.I.Rp
rm = ref.I.Rm
varXuHH = (rp.real ** 2 + rm.real ** 2) * varReap + (
rp.imag ** 2 + rm.imag ** 2
varXuHH = (rp.real**2 + rm.real**2) * varReap + (
rp.imag**2 + rm.imag**2
) * varImap
varYuHH = (rp.real ** 2 + rm.real ** 2) * varImap + (
rp.imag ** 2 + rm.imag ** 2
varYuHH = (rp.real**2 + rm.real**2) * varImap + (
rp.imag**2 + rm.imag**2
) * varReap
for varX, varY in zip(varXuHH, varYuHH):
if not opt.twodim:
Expand Down Expand Up @@ -438,10 +438,10 @@ def ut_linci(X, Y, sigX, sigY):

rp = 0.5 * np.sqrt((Xu + Yv) ** 2 + (Xv - Yu) ** 2)
rm = 0.5 * np.sqrt((Xu - Yv) ** 2 + (Xv + Yu) ** 2)
sigXu2 = sigXu ** 2
sigYu2 = sigYu ** 2
sigXv2 = sigXv ** 2
sigYv2 = sigYv ** 2
sigXu2 = sigXu**2
sigYu2 = sigYu**2
sigXv2 = sigXv**2
sigYv2 = sigYv**2

ex = (Xu + Yv) / rp
fx = (Xu - Yv) / rm
Expand All @@ -457,8 +457,8 @@ def ut_linci(X, Y, sigX, sigY):

# phase
rn = 2 * (Xu * Yu + Xv * Yv)
rd = Xu ** 2 - Yu ** 2 + Xv ** 2 - Yv ** 2
den = rn ** 2 + rd ** 2
rd = Xu**2 - Yu**2 + Xv**2 - Yv**2
den = rn**2 + rd**2
dXu2 = ((rd * Yu - rn * Xu) / den) ** 2
dYu2 = ((rd * Xu + rn * Yu) / den) ** 2
dXv2 = ((rd * Yv - rn * Xv) / den) ** 2
Expand All @@ -480,8 +480,8 @@ def ut_linci(X, Y, sigX, sigY):

# Orientation.
rn = 2.0 * (Xu * Xv + Yu * Yv)
rd = Xu ** 2 + Yu ** 2 - (Xv ** 2 + Yv ** 2)
den = rn ** 2 + rd ** 2
rd = Xu**2 + Yu**2 - (Xv**2 + Yv**2)
den = rn**2 + rd**2
dXu2 = ((rd * Xv - rn * Xu) / den) ** 2
dYu2 = ((rd * Yv - rn * Yu) / den) ** 2
dXv2 = ((rd * Xu + rn * Xv) / den) ** 2
Expand Down
2 changes: 1 addition & 1 deletion utide/harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def FUV(t, tref, lind, lat, ngflgs):
rr = sat.amprat.copy()

j = sat.ilatfac == 1
rr[j] *= 0.36309 * (1.0 - 5.0 * slat ** 2) / slat
rr[j] *= 0.36309 * (1.0 - 5.0 * slat**2) / slat

j = sat.ilatfac == 2
rr[j] *= 2.59808 * slat
Expand Down
32 changes: 15 additions & 17 deletions utide/periodogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,16 @@ def _psd_lomb(t, x, window=None, freq=None, ofac=1):
PSD units are [`x`-units^2 per cycle per unit time]
"""
out = Bunch()

# copy inputs
x = np.array(x)
t = np.array(t, dtype=float)
# In scipy 1.7.x, the new pythran-based lombscargle requires contiguous
# array arguments.
def _lombscargle(*args):
newargs = [np.ascontiguousarray(a, dtype=np.float64) for a in args]
return signal.lombscargle(*newargs)

# remove mean
x -= x.mean()
out = Bunch()

xdm = x - x.mean()
n = len(x)

if window is None:
Expand All @@ -184,8 +185,7 @@ def _psd_lomb(t, x, window=None, freq=None, ofac=1):
# interpolate window from uniform grid to nonuniform t
t_uniform = np.linspace(np.min(t), np.max(t), n)
w = np.interp(t, t_uniform, window)

x *= w
xdm *= w

# Estimated record length as n delta-t, where delta-t
# is the *average* time per sample.
Expand All @@ -201,24 +201,22 @@ def _psd_lomb(t, x, window=None, freq=None, ofac=1):

out.F = freq

xr = np.real(x)

# signal.lombscargle returns "(A**2) * N/4 for a harmonic signal
# with amplitude A for sufficiently large N."
# It takes *angular* frequencies as 3rd argument.
freq_radian = freq * 2 * np.pi
psdnorm = 2 * delta_t * n / (w ** 2).sum()
out.Pxx = psdnorm * signal.lombscargle(t, xr, freq_radian)
psdnorm = 2 * delta_t * n / (w**2).sum()
out.Pxx = psdnorm * _lombscargle(t, np.real(xdm), freq_radian)

if x.dtype.kind == "f":
return out

out.Pyy = psdnorm * signal.lombscargle(t, x.imag, freq_radian)
out.Pyy = psdnorm * _lombscargle(t, xdm.imag, freq_radian)

# If we need to limit memory usage and don't want to use
# Cython, we can segment the frequencies and loop over the
# segments. The speed penalty will be minimal.
out.Pxy = psdnorm * _ls_cross(t, x, freq_radian)
out.Pxy = psdnorm * _ls_cross(t, xdm, freq_radian)

return out

Expand Down Expand Up @@ -247,14 +245,14 @@ def _ls_cross(t, x, fr):
tmpy = np.empty(fr.shape, dtype=complex)

c = np.cos(arg)
a = 1 / np.sqrt(sum(c ** 2))
a = 1 / np.sqrt(sum(c**2))
tmpx.real = a * (xr[:, np.newaxis] * c).sum(axis=0)
tmpy.real = a * (xi[:, np.newaxis] * c).sum(axis=0)

del c

s = np.sin(arg)
b = 1 / np.sqrt(sum(s ** 2))
b = 1 / np.sqrt(sum(s**2))
tmpx.imag = b * (xr[:, np.newaxis] * s).sum(axis=0)
tmpy.imag = -b * (xi[:, np.newaxis] * s).sum(axis=0)

Expand Down Expand Up @@ -289,7 +287,7 @@ def _psd(e, window, fs):

# cs = cs[:iny]
cs[1:-1] *= 2
psdnorm = (1 / fs) * (1 / (window ** 2).sum()) # dt / sum of win squared.
psdnorm = (1 / fs) * (1 / (window**2).sum()) # dt / sum of win squared.
return cs * psdnorm


Expand Down
6 changes: 3 additions & 3 deletions utide/robustfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def andrews(r):

def bisquare(r):
r = np.abs(r)
w = (r < 1) * (1 - r ** 2) ** 2
w = (r < 1) * (1 - r**2) ** 2
return w


def cauchy(r):
r = np.abs(r)
w = 1 / (1 + r ** 2)
w = 1 / (1 + r**2)
return w


Expand Down Expand Up @@ -57,7 +57,7 @@ def talwar(r):

def welsch(r):
r = np.abs(r)
w = np.exp(-(r ** 2))
w = np.exp(-(r**2))
return w


Expand Down
4 changes: 2 additions & 2 deletions utide/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _showmatbunch(b, elements=None, origin=None):
else:
entry = f"ndarray, shape {v.shape}, dtype {v.dtype}"
else:
entry = "{} {}".format(type(v).__name__, v)
entry = f"{type(v).__name__} {v}"
elements.append((_origin, entry))
elements.sort()
return elements
Expand All @@ -273,7 +273,7 @@ def showmatbunch(b):
b = loadbunch(b)
elist = _showmatbunch(b)
names = [n for n, v in elist]
namelen = min(40, max([len(n) for n in names]))
namelen = min(40, max(len(n) for n in names))
str_fmt = "{0!s:<{namelen}} : {1!s}\n"
strlist = [str_fmt.format(n[1:], v, namelen=namelen) for (n, v) in elist]
return "".join(strlist)
Expand Down

0 comments on commit 354f0e5

Please sign in to comment.