From ca7eaed97c00d55371541a6e49b3e893e4e12fcf Mon Sep 17 00:00:00 2001 From: Jon Myers Date: Thu, 6 Nov 2025 17:22:31 -0800 Subject: [PATCH] fix: preserve time_resolution in crop_frequency() and crop_time() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both crop methods were not passing time_resolution to new SpectrogramData instances, causing them to fall back to DEFAULT_TIME_RESOLUTION (0.01508s) instead of the accurate value calculated from database duration (e.g. 0.015103s). This small discrepancy accumulates over long recordings, causing significant timing misalignment. For a 2192-second recording, the error reached ~0.15s. Now both methods preserve the parent spectrogram's time_resolution, ensuring accurate timing throughout the crop chain. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- idtap/spectrogram.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/idtap/spectrogram.py b/idtap/spectrogram.py index 94e1fab..19804e1 100644 --- a/idtap/spectrogram.py +++ b/idtap/spectrogram.py @@ -243,7 +243,8 @@ def crop_frequency(self, min_hz: Optional[float] = None, cropped_data, self.audio_id, freq_range=(freq_bins[min_idx], freq_bins[max_idx - 1] if max_idx > min_idx else freq_bins[min_idx]), - bins_per_octave=self.bins_per_octave + bins_per_octave=self.bins_per_octave, + time_resolution=self._time_resolution ) def crop_time(self, start_time: Optional[float] = None, @@ -277,7 +278,8 @@ def crop_time(self, start_time: Optional[float] = None, cropped_data, self.audio_id, freq_range=self.freq_range, - bins_per_octave=self.bins_per_octave + bins_per_octave=self.bins_per_octave, + time_resolution=self._time_resolution ) def get_extent(self) -> List[float]: