Skip to content

Commit a3a2d97

Browse files
author
Marius Isken
committed
Removing douplicate code // adding annotations
1 parent a2e284d commit a3a2d97

File tree

2 files changed

+24
-61
lines changed

2 files changed

+24
-61
lines changed

lightguide/blast.py

+22-61
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from pyrocko.trace import Trace
2525
from scipy import signal
2626

27+
from lightguide.utils import PathStr
28+
2729
from .filters import afk_filter
2830
from .signal import decimation_coefficients
2931

@@ -417,12 +419,17 @@ def copy(self) -> Blast:
417419
"""
418420
return deepcopy(self)
419421

420-
def save_mseed(self, filename: Path | str) -> None:
422+
def save_mseed(self, filename: PathStr) -> None:
423+
"""Save as miniSeed.
424+
425+
Args:
426+
filename (PathStr):
427+
"""
421428
filename = Path(filename)
422429
traces = self.as_traces()
423430
io.save(traces, filename_template=str(filename), format="mseed")
424431

425-
def as_traces(self):
432+
def as_traces(self) -> list[Trace]:
426433
traces = []
427434
for icha in range(self.n_channels):
428435
channel = icha + self.start_channel
@@ -438,6 +445,19 @@ def as_traces(self):
438445

439446
@classmethod
440447
def from_pyrocko(cls, traces: list[Trace], channel_spacing: float = 0.0) -> Blast:
448+
"""Create Blast from a list of Pyrocko traces.
449+
450+
Args:
451+
traces (list[Trace]): List of input traces
452+
channel_spacing (float, optional): Spatial channel spacing in meter.
453+
Defaults to 0.0.
454+
455+
Raises:
456+
ValueError: If input is odd.
457+
458+
Returns:
459+
Blast: Assembled Blast.
460+
"""
441461
if not traces:
442462
raise ValueError("Empty list of traces")
443463

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

548568
trim_time = shared_function(Blast.trim_time)
549569
trim_channels = shared_function(Blast.trim_channels)
550-
551-
mute_median = shared_function(Blast.mute_median)
552-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
553-
afk_filter = shared_function(Blast.afk_filter)
554-
decimate = shared_function(Blast.decimate)
555-
556-
trim_time = shared_function(Blast.trim_time)
557-
trim_channels = shared_function(Blast.trim_channels)
558-
559-
mute_median = shared_function(Blast.mute_median)
560-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
561-
afk_filter = shared_function(Blast.afk_filter)
562-
decimate = shared_function(Blast.decimate)
563-
564-
trim_time = shared_function(Blast.trim_time)
565-
trim_channels = shared_function(Blast.trim_channels)
566-
567-
mute_median = shared_function(Blast.mute_median)
568-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
569-
afk_filter = shared_function(Blast.afk_filter)
570-
decimate = shared_function(Blast.decimate)
571-
572-
trim_time = shared_function(Blast.trim_time)
573-
trim_channels = shared_function(Blast.trim_channels)
574-
575-
mute_median = shared_function(Blast.mute_median)
576-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
577-
afk_filter = shared_function(Blast.afk_filter)
578-
decimate = shared_function(Blast.decimate)
579-
580-
trim_time = shared_function(Blast.trim_time)
581-
trim_channels = shared_function(Blast.trim_channels)
582-
583-
mute_median = shared_function(Blast.mute_median)
584-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
585-
afk_filter = shared_function(Blast.afk_filter)
586-
decimate = shared_function(Blast.decimate)
587-
588-
trim_time = shared_function(Blast.trim_time)
589-
trim_channels = shared_function(Blast.trim_channels)
590-
591-
mute_median = shared_function(Blast.mute_median)
592-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
593-
afk_filter = shared_function(Blast.afk_filter)
594-
decimate = shared_function(Blast.decimate)
595-
596-
trim_time = shared_function(Blast.trim_time)
597-
trim_channels = shared_function(Blast.trim_channels)
598-
599-
mute_median = shared_function(Blast.mute_median)
600-
one_bit_normalization = shared_function(Blast.one_bit_normalization)
601-
afk_filter = shared_function(Blast.afk_filter)
602-
decimate = shared_function(Blast.decimate)
603-
604-
trim_time = shared_function(Blast.trim_time)
605-
trim_channels = shared_function(Blast.trim_channels)
606-
607-
mute_median = shared_function(Blast.mute_median)
608-
one_bit_normalization = shared_function(Blast.one_bit_normalization)

lightguide/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import numpy as np
1010
import requests
1111

12+
PathStr = Path | str
13+
1214

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

0 commit comments

Comments
 (0)