diff --git a/docs/user-guide/atoms.md b/docs/user-guide/atoms.md index ae233fd..efcb411 100644 --- a/docs/user-guide/atoms.md +++ b/docs/user-guide/atoms.md @@ -23,12 +23,12 @@ There are three "flavours" declaring the atoms that can be used to compose a seq ```{code-cell} import numpy as np import xdas -import xdas.signal as xp +import xdas.signal as xs from xdas.atoms import Partial, Sequential, IIRFilter sequence = Sequential( [ - xp.taper(..., dim="time"), + xs.taper(..., dim="time"), Partial(np.square), IIRFilter(order=4, cutoff=1.5, btype="highpass", dim="time"), ] diff --git a/docs/user-guide/convert-displacement.md b/docs/user-guide/convert-displacement.md index 398f0ed..5ae49b6 100644 --- a/docs/user-guide/convert-displacement.md +++ b/docs/user-guide/convert-displacement.md @@ -28,11 +28,11 @@ strain_rate.plot(yincrease=False, vmin=-0.5, vmax=0.5); Then convert strain rate to deformation and then to displacement. ```{code-cell} -import xdas.signal as xp +import xdas.signal as xs -strain = xp.integrate(strain_rate, dim="time") -deformation = xp.integrate(strain, dim="distance") -displacement = xp.sliding_mean_removal(deformation, wlen=2000.0, dim="distance") +strain = xs.integrate(strain_rate, dim="time") +deformation = xs.integrate(strain, dim="distance") +displacement = xs.sliding_mean_removal(deformation, wlen=2000.0, dim="distance") displacement.plot(yincrease=False, vmin=-0.5, vmax=0.5); ``` diff --git a/tests/test_signal.py b/tests/test_signal.py index 2e0f8d0..7736873 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -171,14 +171,14 @@ def test_filter(self): def test_decimate_virtual_stack(self): da = wavelet_wavefronts() - expected = xp.decimate(da, 5, dim="time") + expected = xs.decimate(da, 5, dim="time") chunks = xdas.split(da, 5, "time") with tempfile.TemporaryDirectory() as tmpdirname: for i, chunk in enumerate(chunks): chunk_path = os.path.join(tmpdirname, f"chunk_{i}.nc") chunk.to_netcdf(chunk_path) da_virtual = xdas.open_mfdataarray(os.path.join(tmpdirname, "chunk_*.nc")) - result = xp.decimate(da_virtual, 5, dim="time") + result = xs.decimate(da_virtual, 5, dim="time") assert result.equals(expected) diff --git a/tests/test_xarray.py b/tests/test_xarray.py index 88ccefa..382a4fe 100644 --- a/tests/test_xarray.py +++ b/tests/test_xarray.py @@ -1,6 +1,6 @@ import numpy as np -import xdas.core.methods as xp +import xdas.core.methods as xm from xdas.core.dataarray import DataArray from xdas.synthetics import wavelet_wavefronts @@ -8,7 +8,7 @@ class TestXarray: def test_returns_dataarray(self): da = wavelet_wavefronts() - for name, func in xp.HANDLED_METHODS.items(): + for name, func in xm.HANDLED_METHODS.items(): if callable(func): if name in [ "percentile", @@ -31,7 +31,7 @@ def test_returns_dataarray(self): def test_mean(self): da = wavelet_wavefronts() - result = xp.mean(da, "time") + result = xm.mean(da, "time") result_method = da.mean("time") expected = np.mean(da, 0) assert result.equals(expected) diff --git a/xdas/atoms/core.py b/xdas/atoms/core.py index df403d2..3375ccd 100644 --- a/xdas/atoms/core.py +++ b/xdas/atoms/core.py @@ -194,15 +194,15 @@ class Sequential(Atom, list): Examples -------- >>> from xdas.atoms import Partial, Sequential - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> import numpy as np Basic usage: >>> seq = Sequential( ... [ - ... Partial(xp.taper, dim="time"), - ... Partial(xp.lfilter, [1.0], [0.5], ..., dim="time", zi=...), + ... Partial(xs.taper, dim="time"), + ... Partial(xs.lfilter, [1.0], [0.5], ..., dim="time", zi=...), ... Partial(np.square), ... ], ... name="Low frequency energy", @@ -217,7 +217,7 @@ class Sequential(Atom, list): >>> seq = Sequential( ... [ - ... Partial(xp.decimate, 16, dim="distance"), + ... Partial(xs.decimate, 16, dim="distance"), ... seq, ... ] ... ) @@ -330,12 +330,12 @@ class Partial(Atom): -------- >>> import numpy as np >>> import scipy.signal as sp - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.atoms import Partial Examples of a stateless atom: - >>> Partial(xp.decimate, 2, dim="time") + >>> Partial(xs.decimate, 2, dim="time") decimate(..., 2, dim=time) >>> Partial(np.square) @@ -344,7 +344,7 @@ class Partial(Atom): Examples of a stateful atom with input data as second argument: >>> sos = sp.iirfilter(4, 0.1, btype="lowpass", output="sos") - >>> Partial(xp.sosfilt, sos, ..., dim="time", zi=...) + >>> Partial(xs.sosfilt, sos, ..., dim="time", zi=...) sosfilt(, ..., dim=time) [stateful] """ diff --git a/xdas/signal.py b/xdas/signal.py index cd892b4..5d15552 100644 --- a/xdas/signal.py +++ b/xdas/signal.py @@ -142,11 +142,11 @@ def hilbert(da, N=None, dim="last", parallel=None): -------- In this example we use the Hilbert transform to determine the analytic signal. - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() - >>> xp.hilbert(da, dim="time") + >>> xs.hilbert(da, dim="time") [[ 0.0497+0.1632j -0.0635+0.0125j ... 0.1352-0.3107j -0.2832-0.0126j] [-0.1096-0.0335j 0.124 +0.0257j ... -0.0444+0.2409j 0.1378-0.2702j] @@ -203,11 +203,11 @@ def resample(da, num, dim="last", window=None, domain="time", parallel=None): A synthetic dataarray is resample from 300 to 100 samples along the time dimension. The 'hamming' window is used. - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() - >>> xp.resample(da, 100, dim='time', window='hamming', domain='time') + >>> xs.resample(da, 100, dim='time', window='hamming', domain='time') [[ 0.039988 0.04855 -0.08251 ... 0.02539 -0.055219 -0.006693] [-0.032913 -0.016732 0.033743 ... 0.028534 -0.037685 0.032918] @@ -294,11 +294,11 @@ def resample_poly( with an original shape of 300 in time. The choosed window is a 'hamming' window. The dataarray is synthetic data. - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() - >>> xp.resample_poly(da, 2, 5, dim='time') + >>> xs.resample_poly(da, 2, 5, dim='time') [[-0.006378 0.012767 -0.002068 ... -0.033461 0.002603 -0.027478] [ 0.008851 -0.037799 0.009595 ... 0.053291 -0.0396 0.026909] @@ -377,12 +377,12 @@ def lfilter(b, a, da, dim="last", zi=None, parallel=None): Examples -------- >>> import scipy.signal as sp - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() >>> b, a = sp.iirfilter(4, 0.5, btype="low") - >>> xp.lfilter(b, a, da, dim='time') + >>> xs.lfilter(b, a, da, dim='time') [[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618] [ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521] @@ -485,12 +485,12 @@ def filtfilt( Examples -------- >>> import scipy.signal as sp - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() >>> b, a = sp.iirfilter(4, 0.5, btype="low") - >>> xp.lfilter(b, a, da, dim='time') + >>> xs.lfilter(b, a, da, dim='time') [[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618] [ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521] @@ -554,12 +554,12 @@ def sosfilt(sos, da, dim="last", zi=None, parallel=None): Examples -------- >>> import scipy.signal as sp - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() >>> sos = sp.iirfilter(4, 0.5, btype="low", output="sos") - >>> xp.sosfilt(sos, da, dim='time') + >>> xs.sosfilt(sos, da, dim='time') [[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618] [ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521] @@ -642,12 +642,12 @@ def sosfiltfilt(sos, da, dim="last", padtype="odd", padlen=None, parallel=None): Examples -------- >>> import scipy.signal as sp - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() >>> sos = sp.iirfilter(4, 0.5, btype="low", output="sos") - >>> xp.sosfiltfilt(sos, da, dim='time') + >>> xs.sosfiltfilt(sos, da, dim='time') [[ 0.04968 -0.063651 0.078731 ... -0.146869 0.135149 -0.283111] [-0.01724 0.018588 -0.037267 ... 0.025092 -0.107095 0.127912] @@ -904,11 +904,11 @@ def medfilt(da, kernel_dim): # TODO: parallelize A median filter is applied to some synthetic dataarray with a median window size of 7 along the time dimension and 5 along the space dimension. - >>> import xdas.signal as xp + >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts >>> da = wavelet_wavefronts() - >>> xp.medfilt(da, {"time": 7, "distance": 5}) + >>> xs.medfilt(da, {"time": 7, "distance": 5}) [[ 0. 0. 0. ... 0. 0. 0. ] [ 0. 0. 0. ... 0. 0. 0. ]