Skip to content

Commit

Permalink
fix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgjs committed Oct 9, 2023
1 parent 6bbf0fd commit 05837ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
15 changes: 15 additions & 0 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path

import dateutil
import pytest

from noisepy.seis.datatypes import ChannelType, ConfigParameters, StackMethod, Station
Expand Down Expand Up @@ -51,3 +52,17 @@ def test_storage_options():
# scheme is '' for local files
c.storage_options[""]["foo"] = "bar"
assert c.get_storage_options("/local/file") == {"foo": "bar"}


def test_config_dates():
c = ConfigParameters()
# defaults should be valid
c = ConfigParameters.model_validate(dict(c), strict=True)
c.start_date = dateutil.parser.isoparse("2021-01-01") # no timezone
with pytest.raises(Exception):
c = ConfigParameters.model_validate(dict(c), strict=True)
c.start_date = dateutil.parser.isoparse("2021-01-01T09:00:00+09:00") # not utc
with pytest.raises(Exception):
c = ConfigParameters.model_validate(dict(c), strict=True)
c.start_date = dateutil.parser.isoparse("2021-01-01T09:00:00+00:00") # utc
c = ConfigParameters.model_validate(dict(c), strict=True)
3 changes: 3 additions & 0 deletions tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ def test_stack_pair():
cc_store.read.return_value = ccs
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)
assert len(stacks) == 0
9 changes: 5 additions & 4 deletions tutorials/noisepy_scedc_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"from noisepy.seis.datatypes import ConfigParameters, StackMethod # Main configuration object\n",
"from noisepy.seis.channelcatalog import XMLStationChannelCatalog # Required stationXML handling object\n",
"import os\n",
"from datetime import datetime\n",
"from datetime import datetime, timezone\n",
"from datetimerange import DateTimeRange\n",
"\n",
"\n",
Expand Down Expand Up @@ -108,8 +108,8 @@
"# SCEDC S3 bucket common URL characters for that day.\n",
"S3_DATA = \"s3://scedc-pds/continuous_waveforms/\"\n",
"# timeframe for analysis\n",
"start = datetime(2002, 1, 1)\n",
"end = datetime(2002, 1, 3)\n",
"start = datetime(2002, 1, 1, tzinfo=timezone.utc)\n",
"end = datetime(2002, 1, 3, tzinfo=timezone.utc)\n",
"timerange = DateTimeRange(start, end)\n",
"print(timerange)"
]
Expand Down Expand Up @@ -174,7 +174,8 @@
},
"outputs": [],
"source": [
"\n",
"config.start_date = start\n",
"config.end_date = end\n",
"config.acorr_only = False # only perform auto-correlation or not\n",
"config.xcorr_only = True # only perform cross-correlation or not\n",
"\n",
Expand Down

0 comments on commit 05837ef

Please sign in to comment.