From cd609d56eb2db443a6f06f2518c2cf537938fd0c Mon Sep 17 00:00:00 2001 From: Marius Isken Date: Fri, 31 May 2024 13:54:30 +0000 Subject: [PATCH] bugfixes --- src/qseek/pre_processing/downsample.py | 9 ++++++++- src/qseek/pre_processing/frequency_filters.py | 20 +++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/qseek/pre_processing/downsample.py b/src/qseek/pre_processing/downsample.py index 14ced59b..b1098e2f 100644 --- a/src/qseek/pre_processing/downsample.py +++ b/src/qseek/pre_processing/downsample.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import logging from typing import TYPE_CHECKING, Literal from pydantic import Field, PositiveFloat @@ -10,6 +11,8 @@ if TYPE_CHECKING: from qseek.waveforms.base import WaveformBatch +logger = logging.getLogger(__name__) + class Downsample(BatchPreProcessing): """Downsample the traces to a new sampling frequency.""" @@ -26,7 +29,11 @@ async def process_batch(self, batch: WaveformBatch) -> WaveformBatch: def worker() -> None: for trace in self.select_traces(batch): if trace.deltat < desired_deltat: - trace.downsample_to(deltat=desired_deltat, allow_upsample_max=5) + try: + trace.downsample_to(deltat=desired_deltat, allow_upsample_max=5) + except Exception as e: + logger.exception("Failed to downsample trace: %s", e) + ... await asyncio.to_thread(worker) return batch diff --git a/src/qseek/pre_processing/frequency_filters.py b/src/qseek/pre_processing/frequency_filters.py index e6eb2df8..3d526184 100644 --- a/src/qseek/pre_processing/frequency_filters.py +++ b/src/qseek/pre_processing/frequency_filters.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import logging from typing import TYPE_CHECKING, Literal from pydantic import Field, PositiveFloat, field_validator @@ -12,6 +13,9 @@ from qseek.waveforms.base import WaveformBatch +logger = logging.getLogger(__name__) + + class Bandpass(BatchPreProcessing): """Apply a bandpass filter to the traces.""" @@ -43,12 +47,16 @@ def _check_bandpass(cls, value) -> Range: async def process_batch(self, batch: WaveformBatch) -> WaveformBatch: def worker() -> None: for trace in self.select_traces(batch): - trace.bandpass( - order=self.corners, - corner_hp=self.bandpass[0], - corner_lp=self.bandpass[1], - demean=self.demean, - ) + try: + trace.bandpass( + order=self.corners, + corner_hp=self.bandpass[0], + corner_lp=self.bandpass[1], + demean=self.demean, + ) + except Exception as e: + logger.exception("Failed to apply bandpass filter: %s", e) + ... await asyncio.to_thread(worker) return batch