Skip to content

Commit

Permalink
Removing douplicate code // adding annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed Apr 6, 2023
1 parent a2e284d commit a3a2d97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 61 deletions.
83 changes: 22 additions & 61 deletions lightguide/blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from pyrocko.trace import Trace
from scipy import signal

from lightguide.utils import PathStr

from .filters import afk_filter
from .signal import decimation_coefficients

Expand Down Expand Up @@ -417,12 +419,17 @@ def copy(self) -> Blast:
"""
return deepcopy(self)

def save_mseed(self, filename: Path | str) -> None:
def save_mseed(self, filename: PathStr) -> None:
"""Save as miniSeed.
Args:
filename (PathStr):
"""
filename = Path(filename)
traces = self.as_traces()
io.save(traces, filename_template=str(filename), format="mseed")

def as_traces(self):
def as_traces(self) -> list[Trace]:
traces = []
for icha in range(self.n_channels):
channel = icha + self.start_channel
Expand All @@ -438,6 +445,19 @@ def as_traces(self):

@classmethod
def from_pyrocko(cls, traces: list[Trace], channel_spacing: float = 0.0) -> Blast:
"""Create Blast from a list of Pyrocko traces.
Args:
traces (list[Trace]): List of input traces
channel_spacing (float, optional): Spatial channel spacing in meter.
Defaults to 0.0.
Raises:
ValueError: If input is odd.
Returns:
Blast: Assembled Blast.
"""
if not traces:
raise ValueError("Empty list of traces")

Expand Down Expand Up @@ -547,62 +567,3 @@ def __len__(self) -> int:

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
afk_filter = shared_function(Blast.afk_filter)
decimate = shared_function(Blast.decimate)

trim_time = shared_function(Blast.trim_time)
trim_channels = shared_function(Blast.trim_channels)

mute_median = shared_function(Blast.mute_median)
one_bit_normalization = shared_function(Blast.one_bit_normalization)
2 changes: 2 additions & 0 deletions lightguide/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import numpy as np
import requests

PathStr = Path | str


class ExampleData:
VSPData = "https://data.pyrocko.org/testing/lightguide/das-data.npy"
Expand Down

0 comments on commit a3a2d97

Please sign in to comment.