Skip to content

Commit

Permalink
import xdas.signal as xs.
Browse files Browse the repository at this point in the history
  • Loading branch information
atrabattoni committed Dec 3, 2024
1 parent 37d5e90 commit 3b32b8a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/user-guide/atoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
8 changes: 4 additions & 4 deletions docs/user-guide/convert-displacement.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```

Expand Down
4 changes: 2 additions & 2 deletions tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions tests/test_xarray.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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


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",
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions xdas/atoms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -217,7 +217,7 @@ class Sequential(Atom, list):
>>> seq = Sequential(
... [
... Partial(xp.decimate, 16, dim="distance"),
... Partial(xs.decimate, 16, dim="distance"),
... seq,
... ]
... )
Expand Down Expand Up @@ -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)
Expand All @@ -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(<ndarray>, ..., dim=time) [stateful]
"""
Expand Down
32 changes: 16 additions & 16 deletions xdas/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
<xdas.DataArray (time: 300, distance: 401)>
[[ 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]
Expand Down Expand Up @@ -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')
<xdas.DataArray (time: 100, distance: 401)>
[[ 0.039988 0.04855 -0.08251 ... 0.02539 -0.055219 -0.006693]
[-0.032913 -0.016732 0.033743 ... 0.028534 -0.037685 0.032918]
Expand Down Expand Up @@ -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')
<xdas.DataArray (time: 120, distance: 401)>
[[-0.006378 0.012767 -0.002068 ... -0.033461 0.002603 -0.027478]
[ 0.008851 -0.037799 0.009595 ... 0.053291 -0.0396 0.026909]
Expand Down Expand Up @@ -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')
<xdas.DataArray (time: 300, distance: 401)>
[[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618]
[ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521]
Expand Down Expand Up @@ -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')
<xdas.DataArray (time: 300, distance: 401)>
[[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618]
[ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521]
Expand Down Expand Up @@ -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')
<xdas.DataArray (time: 300, distance: 401)>
[[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618]
[ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521]
Expand Down Expand Up @@ -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')
<xdas.DataArray (time: 300, distance: 401)>
[[ 0.04968 -0.063651 0.078731 ... -0.146869 0.135149 -0.283111]
[-0.01724 0.018588 -0.037267 ... 0.025092 -0.107095 0.127912]
Expand Down Expand Up @@ -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})
<xdas.DataArray (time: 300, distance: 401)>
[[ 0. 0. 0. ... 0. 0. 0. ]
[ 0. 0. 0. ... 0. 0. 0. ]
Expand Down

0 comments on commit 3b32b8a

Please sign in to comment.