Skip to content

Commit

Permalink
Better coverage, cleanup, default to rm_resp=inv
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgjs committed Oct 9, 2023
1 parent 05837ef commit ef41617
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/noisepy/seis/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ConfigParameters(BaseModel):
stationxml: bool = Field(
default=False, description="station.XML file used to remove instrument response for SAC/miniseed data"
)
rm_resp: str = Field(default="no", description="select 'no' to not remove response and use 'inv','spectrum',")
rm_resp: str = Field(default="inv", description="select 'no' to not remove response and use 'inv','spectrum',")
rm_resp_out: str = Field(default="VEL", description="output location from response removal")
respdir: Optional[str] = Field(default=None, description="response directory")
# some control parameters
Expand Down
33 changes: 23 additions & 10 deletions tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
CrossCorrelation,
Station,
)
from noisepy.seis.stack import stack_cross_correlations, stack_pair, validate_pairs
from noisepy.seis.stack import (
stack_cross_correlations,
stack_pair,
stack_store_pair,
validate_pairs,
)


def test_validate_pairs():
Expand All @@ -34,9 +39,7 @@ def __reduce__(self):

def test_stack_error():
ts = date_range(1, 1, 2)
config = ConfigParameters()
config.start_date = ts.start_datetime
config.end_date = ts.end_datetime
config = ConfigParameters(start_date=ts.start_datetime, end_date=ts.end_datetime)
sta = Station("CI", "BAK")
cc_store = SerializableMock()
cc_store.get_timespans.return_value = [ts]
Expand All @@ -46,20 +49,30 @@ def test_stack_error():
stack_store = SerializableMock()
stack_store.get_station_pairs.return_value = []
stack_store.contains.return_value = False
# , new_callable=lambda: ThreadPoolExecutor(1)
with patch("noisepy.seis.stack.ProcessPoolExecutor") as mock_executor:
mock_executor.return_value = ThreadPoolExecutor(1)
with pytest.raises(RuntimeError) as e:
stack_cross_correlations(cc_store, stack_store, config)
assert "CI.BAK" in str(e)


def test_stack_pair():
config = ConfigParameters()
def test_stack_contains():
ts = date_range(1, 1, 2)
config = ConfigParameters(start_date=ts.start_datetime, end_date=ts.end_datetime)
sta = Station("CI", "BAK")
cc_store = SerializableMock()
stack_store = SerializableMock()
stack_store.contains.return_value = True
# should not stack but succeed if stack_store contains the stack
result = stack_store_pair(sta, sta, cc_store, stack_store, config)
stack_store.append.assert_not_called()
assert result


def test_stack_pair():
ts = date_range(1, 1, 2)
config.start_date = ts.start_datetime
config.end_date = ts.end_datetime
config = ConfigParameters(start_date=ts.start_datetime, end_date=ts.end_datetime)
sta = Station("CI", "BAK")
params = {
"ngood": 4,
"time": 1548979200.0,
Expand All @@ -76,5 +89,5 @@ def test_stack_pair():
stacks = stack_pair(sta, sta, [ts, ts], cc_store, config)
assert len(stacks) == 6
ts2 = date_range(1, 20, 22)
stacks = stacks = stack_pair(sta, sta, [ts2], cc_store, config)
stacks = stack_pair(sta, sta, [ts2], cc_store, config)
assert len(stacks) == 0

0 comments on commit ef41617

Please sign in to comment.