Skip to content

Commit

Permalink
run pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Jun 20, 2023
1 parent 2b59c04 commit c338393
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 66 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import utide


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down
3 changes: 0 additions & 3 deletions tests/test_HNL.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import numpy as np
import pytest

from numpy.testing import assert_array_almost_equal, assert_array_equal

import utide

from utide.utilities import Bunch, convert_unicode_arrays, loadbunch


thisdir = os.path.dirname(__file__)
datapath = os.path.join(thisdir, "data")
HNL_path = os.path.join(datapath, "HNL2010.asc")
Expand Down
1 change: 0 additions & 1 deletion tests/test_harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from utide.harmonics import FUV
from utide.utilities import loadbunch


fname = os.path.join(_base_dir, "FUV0.npz")


Expand Down
2 changes: 0 additions & 2 deletions tests/test_order_constit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from utide import reconstruct, solve
from utide._ut_constants import constit_index_dict, ut_constants


ts = 735604
duration = 35

Expand Down Expand Up @@ -42,7 +41,6 @@

@pytest.mark.parametrize("conf_int", ["none", "linear", "MC"])
def test_order(conf_int):

orders = [None, "PE", "frequency", opts0["constit"]]
if conf_int != "none":
orders.append("SNR")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from utide._ut_constants import ut_constants
from utide.utilities import Bunch


ts = 735604
duration = 35

Expand Down Expand Up @@ -196,7 +195,7 @@ def test_MC():
):
print(f"{name:>5} {AA:10.4g} {AA_ci:10.4g} {gg:10.4g} {gg_ci:10.4g}")

for (name, Lsmaj, Lsmaj_ci, Lsmin, Lsmin_ci, theta, theta_ci, gg, gg_ci) in zip(
for name, Lsmaj, Lsmaj_ci, Lsmin, Lsmin_ci, theta, theta_ci, gg, gg_ci in zip(
speed_coef.name,
speed_coef.Lsmaj,
speed_coef.Lsmaj_ci,
Expand Down
1 change: 0 additions & 1 deletion tests/test_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
import numpy as np
import pytest

from pandas import date_range

from utide import reconstruct, solve
Expand Down
1 change: 0 additions & 1 deletion utide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
ut_constants,
)


try:
__version__ = pkg_resources.get_distribution("utide").version
except Exception:
Expand Down
1 change: 0 additions & 1 deletion utide/_reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def reconstruct(


def _reconstruct(t, goodmask, coef, verbose, constit, min_SNR, min_PE):

twodim = coef["aux"]["opt"]["twodim"]

# Determine constituents to include.
Expand Down
4 changes: 0 additions & 4 deletions utide/_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from .robustfit import robustfit
from .utilities import Bunch


default_opts = {
"constit": "auto",
"order_constit": None,
Expand Down Expand Up @@ -225,7 +224,6 @@ def solve(t, u, v=None, lat=None, **opts):


def _solv1(tin, uin, vin, lat, **opts):

# The following returns a possibly modified copy of tin (ndarray).
# t, u, v are fully edited ndarrays (unless v is None).
packed = _slvinit(tin, uin, vin, lat, **opts)
Expand Down Expand Up @@ -262,7 +260,6 @@ def _solv1(tin, uin, vin, lat, **opts):
B = np.hstack((E, E.conj()))

if opt.infer is not None:

Etilp = np.empty((nt, coef.nR), dtype=complex)
Etilm = np.empty((nt, coef.nR), dtype=complex)

Expand Down Expand Up @@ -465,7 +462,6 @@ def _reorder(coef, opt):


def _slvinit(tin, uin, vin, lat, **opts):

if lat is None:
raise ValueError("Latitude must be supplied")

Expand Down
19 changes: 10 additions & 9 deletions utide/_time_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import numpy as np


# to be added to get 1 on 1st January of year 1 from unix epoch '1970-01-01'
_DAY_TO_GREGORIAN_EPOCH = 719163

# milisecond in a day
# millisecond in a day
_MS_PER_DAY = 1000 * 86400


Expand All @@ -25,17 +24,17 @@ def _date2num(date, epoch="1970-01-01 00:00:00.000"):

try:
date = date.astype("datetime64[ms]")
except ValueError:
except ValueError as err:
raise ValueError(
f"Cannot convert date argument ({date}) to scalar or array of numpy datetime64 dtype.",
)
) from err

try:
epoch = np.datetime64(epoch, "ms")
except ValueError:
except ValueError as err:
raise ValueError(
f"Cannot convert epoch argument ({epoch}) to numpy datetime64 dtype.",
)
) from err

# datenum calculation
datenum = (date - epoch).astype(float) / _MS_PER_DAY
Expand All @@ -49,7 +48,7 @@ def _python_gregorian_datenum(date):
Python gregorian time is 1 on 1st day of 1st year. Essentially, it means,
the epoch for python gregorian time is 0000-12-31. With _date2num() defined
above, this amounts to 719163 days from the unix-epoch 1970-01-01 00:00:00.
To avoid repetative calculation, this is defined as _DAY_TO_GREGORIAN_EPOCH.
To avoid repetitive calculation, this is defined as _DAY_TO_GREGORIAN_EPOCH.
"""
return _date2num(date) + _DAY_TO_GREGORIAN_EPOCH

Expand All @@ -76,8 +75,10 @@ def _normalize_time(t, epoch=None):
else:
try:
ofs = _python_gregorian_datenum(epoch)
except ValueError:
raise ValueError("Cannot parse epoch as string or date or datetime")
except ValueError as err:
raise ValueError(
"Cannot parse epoch as string or date or datetime",
) from err
else:
return t + ofs
else:
Expand Down
1 change: 0 additions & 1 deletion utide/_ut_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from .utilities import Bunch, convert_unicode_arrays, loadbunch


_base_dir = os.path.join(os.path.dirname(__file__), "data")
_ut_constants_fname = os.path.join(_base_dir, "ut_constants.npz")

Expand Down
1 change: 0 additions & 1 deletion utide/astronomy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np


# (comments based on t_tide)
# Coefficients of the formulas in the Explan. Suppl.
_sc = np.array([270.434164, 13.1763965268, -0.0000850, 0.000000039])
Expand Down
3 changes: 2 additions & 1 deletion utide/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def nearestSPD(A):
# Normally no more than one adjustment will be needed.
if k > 100:
warnings.warn(
"adjustment in nearestSPD did not converge; " "returning diagonal",
"adjustment in nearestSPD did not converge; returning diagonal",
stacklevel=2,
)
return np.diag(np.diag(A))
return Ahat
Expand Down
2 changes: 1 addition & 1 deletion utide/constituent_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def ut_cnstitsel(tref, minres, incnstit, infer):
_r = infer.reference_names
allrefs = list(OrderedDict(zip(_r, [1] * len(_r))).keys())
nR = len(allrefs)
for k, name in enumerate(allrefs):
for _k, name in enumerate(allrefs):
refstruct = Bunch(name=name)
refstruct.lind = constit_index_dict[name]
refstruct.frq = freqs[refstruct.lind]
Expand Down
13 changes: 10 additions & 3 deletions utide/data/make_FUV_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
"""

import numpy as np

from oct2py import Oct2PyError, octave
from scipy.io.matlab import savemat


octave.convert_to_float = False


Expand Down Expand Up @@ -61,7 +59,16 @@
except Oct2PyError:
print("failed")

save_args = dict(t=t, t0=t0, lat=lat, lind=lind, flags=flags, Fo=Fo, Uo=Uo, Vo=Vo)
save_args = {
"t": t,
"t0": t0,
"lat": lat,
"lind": lind,
"flags": flags,
"Fo": Fo,
"Uo": Uo,
"Vo": Vo,
}

np.savez("FUV%d.npz" % ilind, **save_args)

Expand Down
1 change: 0 additions & 1 deletion utide/data/mat2npz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from utide.utilities import loadbunch


datadir = os.path.join(os.path.dirname(__file__))

fname = "ut_constants"
Expand Down
1 change: 0 additions & 1 deletion utide/harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ._ut_constants import ut_constants
from .astronomy import ut_astron


sat = ut_constants.sat
const = ut_constants.const
shallow = ut_constants.shallow
Expand Down
5 changes: 1 addition & 4 deletions utide/periodogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
"""

import numpy as np

from scipy import signal

from utide.utilities import Bunch


# __all__ = ['freq_bands', 'band_psd']

# Frequency bands in cycles per hour for
Expand Down Expand Up @@ -115,7 +113,7 @@ def _lomb_freqs(t, fbands=None, ofac=1, max_per_band=500):
nfreq = len(freq)

freqs = []
for k, (f0, f1) in enumerate(fbands):
for _k, (f0, f1) in enumerate(fbands):
i0, i1 = np.searchsorted(freq, [f0, f1])
i1 = min(nfreq, i1 + 1)
inband = slice(i0, i1)
Expand Down Expand Up @@ -354,7 +352,6 @@ def band_psd(t, e, cfrq, equi=True, frqosamp=1):

# If e is complex, handle imaginary part.
if e.dtype.kind == "c":

if equi: # If even sampling, Welch.
Pvv1s = _psd(e.imag, hn, fs)
Puv1s = _psd(e, hn, fs) # complex cross-periodogram
Expand Down
41 changes: 20 additions & 21 deletions utide/robustfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ def welsch(r):
return w


wfuncdict = dict(
andrews=andrews,
bisquare=bisquare,
cauchy=cauchy,
fair=fair,
huber=huber,
logistic=logistic,
ols=ols,
talwar=talwar,
welsch=welsch,
)
wfuncdict = {
"andrews": andrews,
"bisquare": bisquare,
"cauchy": cauchy,
"fair": fair,
"huber": huber,
"logistic": logistic,
"ols": ols,
"talwar": talwar,
"welsch": welsch,
}

tune_defaults = {
"andrews": 1.339,
Expand Down Expand Up @@ -208,7 +208,7 @@ def robustfit(
rsumsq = rsumsq[0]
if i == 0:
rms_resid = np.sqrt(rsumsq / n)
out.update(dict(ols_b=b, ols_rms_resid=rms_resid))
out.update({"ols_b": b, "ols_rms_resid": rms_resid})

# Weighted mean of squared weighted residuals:
rmeansq = rsumsq / w.sum()
Expand Down Expand Up @@ -247,14 +247,14 @@ def robustfit(
rms_resid = np.sqrt(np.mean(np.abs(resid) ** 2))

out.update(
dict(
iterations=iterations,
b=b,
s=sing,
w=w,
rank=rank,
rms_resid=rms_resid,
),
{
"iterations": iterations,
"b": b,
"s": sing,
"w": w,
"rank": rank,
"rms_resid": rms_resid,
},
)

return out
Expand All @@ -263,7 +263,6 @@ def robustfit(
# Some simple test cases; this probably will be removed.

if __name__ == "__main__":

np.random.seed(1)
n = 10000
x = np.arange(n)
Expand Down
Loading

0 comments on commit c338393

Please sign in to comment.