From 05837ef78ae02c1a63f6b9e233a5dbce6c5f4db0 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Jurado Suarez Date: Mon, 9 Oct 2023 15:00:35 -0700 Subject: [PATCH] fix checks --- tests/test_datatypes.py | 15 +++++++++++++++ tests/test_stack.py | 3 +++ tutorials/noisepy_scedc_tutorial.ipynb | 9 +++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index a86445a7..e1fc7adf 100644 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -1,5 +1,6 @@ from pathlib import Path +import dateutil import pytest from noisepy.seis.datatypes import ChannelType, ConfigParameters, StackMethod, Station @@ -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) diff --git a/tests/test_stack.py b/tests/test_stack.py index fdd5b420..99e2305f 100644 --- a/tests/test_stack.py +++ b/tests/test_stack.py @@ -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 diff --git a/tutorials/noisepy_scedc_tutorial.ipynb b/tutorials/noisepy_scedc_tutorial.ipynb index 04e84e01..85de56cb 100644 --- a/tutorials/noisepy_scedc_tutorial.ipynb +++ b/tutorials/noisepy_scedc_tutorial.ipynb @@ -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", @@ -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)" ] @@ -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",