Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed May 31, 2024
1 parent d2fc947 commit cd609d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/qseek/pre_processing/downsample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import logging
from typing import TYPE_CHECKING, Literal

from pydantic import Field, PositiveFloat
Expand All @@ -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."""
Expand All @@ -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
20 changes: 14 additions & 6 deletions src/qseek/pre_processing/frequency_filters.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +13,9 @@
from qseek.waveforms.base import WaveformBatch


logger = logging.getLogger(__name__)


class Bandpass(BatchPreProcessing):
"""Apply a bandpass filter to the traces."""

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd609d5

Please sign in to comment.