From 19ef8c3519bb913dae2f54197437d90e8d900bfc Mon Sep 17 00:00:00 2001 From: Derrick Chambers Date: Wed, 11 Feb 2026 15:18:01 +0100 Subject: [PATCH] fix #611 --- dascore/core/coordmanager.py | 3 +++ dascore/transform/fourier.py | 7 +++++-- docs/tutorial/transformations.qmd | 5 +++++ tests/test_transform/test_fourier.py | 13 +++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dascore/core/coordmanager.py b/dascore/core/coordmanager.py index 964a3931..8b518625 100644 --- a/dascore/core/coordmanager.py +++ b/dascore/core/coordmanager.py @@ -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 ---------- diff --git a/dascore/transform/fourier.py b/dascore/transform/fourier.py index f7f79a04..20a61a74 100644 --- a/dascore/transform/fourier.py +++ b/dascore/transform/fourier.py @@ -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( { @@ -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 -------- diff --git a/docs/tutorial/transformations.qmd b/docs/tutorial/transformations.qmd index e9305239..a0aa0c29 100644 --- a/docs/tutorial/transformations.qmd +++ b/docs/tutorial/transformations.qmd @@ -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. +::: diff --git a/tests/test_transform/test_fourier.py b/tests/test_transform/test_fourier.py index e6a76fca..08b57289 100644 --- a/tests/test_transform/test_fourier.py +++ b/tests/test_transform/test_fourier.py @@ -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."""