Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dascore/core/coordmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ def disassociate_coord(self, *coord: str) -> Self:

These coordinates will no longer be associated with a dimension in
the coord manager but can still be retrieved.
If one of the provided names is a dimension, coordinates associated
with that dimension are dropped unless they are also explicitly listed
in ``coord``.

Parameters
----------
Expand Down
7 changes: 5 additions & 2 deletions dascore/transform/fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ def _get_stft_dims(dim, dims, axis):
time = dc.to_timedelta64(time)
# Get new dimensions
new_dims = list(_get_stft_dims(dim, patch.dims, axis))
# Make dict of coordinates and return coord manager.
coord_map = dict(patch.coords.coord_map)
# Match dft behavior by removing coords associated with transformed dim,
# while keeping the transformed dim itself as a non-dimensional coord.
coord_map = patch.coords.disassociate_coord(dim).get_coord_tuple_map()
new_units = invert_quantity(coord.units)
coord_map.update(
{
Expand Down Expand Up @@ -431,6 +432,8 @@ def stft(
- If an array is passed for taper_window that has a different length
than specified in kwargs, artificial enriching of frequency resolution
(equivalent to zero padding in time domain) can occur.
- Non-dimensional coordinates associated with transformed coordinates
are dropped in the output.

See Also
--------
Expand Down
5 changes: 5 additions & 0 deletions docs/tutorial/transformations.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ inverse = transformed.istft()

transformed.abs().select(distance=0, samples=True).squeeze().viz.waterfall();
```

:::{.callout-note}
`stft` drops non-dimensional coordinates associated with the transformed
dimension, matching `dft` behavior.
:::
13 changes: 13 additions & 0 deletions tests/test_transform/test_fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ def test_none_for_overlap(self, random_patch):
out = random_patch.stft(time=1, overlap=None)
assert isinstance(out, dc.Patch)

def test_non_dim_coord_associated_with_transform(self):
"""See #611."""
patch = dc.get_example_patch("random_das", shape=(10, 200))
aux_time = np.arange(len(patch.get_coord("time")), dtype=float)
aux_dist = np.arange(len(patch.get_coord("distance")), dtype=float)
patch = patch.update_coords(
aux_time=("time", aux_time),
aux_dist=("distance", aux_dist),
)
out = patch.stft(time=0.1)
assert "aux_time" not in out.coords.coord_map
assert "aux_dist" in out.coords.coord_map


class TestInverseSTFT:
"""Tests for the inverse short-time Fourier transform."""
Expand Down
Loading