Skip to content

Commit

Permalink
Updated changes based on suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jejjohnson committed Dec 18, 2023
1 parent 6df301f commit 5731a05
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 294 deletions.
4 changes: 2 additions & 2 deletions helio_tools/_src/data/sdo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def download_sdo_data(
logger.info(f"BasePath: {base_path}")

# check datetime object
start_date: datetime = check_datetime_format(start_date)
end_date: datetime = check_datetime_format(end_date)
start_date: datetime = check_datetime_format(start_date, sensor="sodo")
end_date: datetime = check_datetime_format(end_date, sensor="sodo")

logger.info(f"Period: {start_date}-{end_date}")

Expand Down
6 changes: 3 additions & 3 deletions helio_tools/_src/data/solo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from loguru import logger
import typer
from helio_tools._src.utils.time import (
check_datetime_format_solo,
check_datetime_format,
get_num_months,
get_month_dates,
)
Expand Down Expand Up @@ -192,8 +192,8 @@ def download_solo_data(
end_date: str = "2021-06-2 00:00",
base_path: Optional[str] = None,
):
start_date = check_datetime_format_solo(start_date)
end_date = check_datetime_format_solo(end_date)
start_date = check_datetime_format(start_date, sensor="solo")
end_date = check_datetime_format(end_date, sensor="solo")
logger.info(f"Period: {start_date} --- {end_date}")
if base_path is None:
base_path = os.getcwd() + "/solo-data"
Expand Down
17 changes: 5 additions & 12 deletions helio_tools/_src/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
from dateutil.relativedelta import relativedelta


def check_datetime_format(datetime_str: str) -> datetime:
try:
datetime_obj = datetime.strptime(datetime_str, "%Y-%m-%d")
return datetime_obj
except ValueError:
msg = "Datetime string format is incorrect."
msg += f"\nInput: {datetime_str}"
print(msg)
DATETIME_FORMATS = {"solo": "%Y-%m-%d %H:%M", "sodo": "%Y-%m-%d"}


def check_datetime_format_solo(datetime_str: str) -> datetime:
def check_datetime_format(datetime_str: str, sensor: str = "sodo") -> datetime:
try:
datetime_obj = datetime.strptime(datetime_str, "%Y-%m-%d %H:%M")
datetime_obj = datetime.strptime(datetime_str, DATETIME_FORMATS[sensor])
return datetime_obj
except ValueError:
msg = "Datetime string format is incorrect."
msg = f"Datetime string format is incorrect for sensor: {sensor}."
msg += f"\nInput: {datetime_str}"
print(msg)
raise ValueError(msg)


def get_num_months(start_date: datetime, end_date: datetime) -> int:
Expand Down
28 changes: 17 additions & 11 deletions notebooks/0.1_data_download_sdo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"id": "d3020752-6a78-4dae-a5e3-8c67e0820a6a",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"name": "stdout",
"output_type": "stream",
"text": [
"/tmp/ipykernel_1632229/966476422.py:6: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
" from tqdm.autonotebook import tqdm\n"
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
Expand All @@ -40,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"id": "2f3875ac-d1ce-4113-be45-7dd54f42ac1a",
"metadata": {},
"outputs": [],
Expand All @@ -55,17 +55,23 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-07 10:45:03.899\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mhelio_tools._src.data.sdo.base\u001b[0m:\u001b[36mdownload_sdo_data\u001b[0m:\u001b[36m213\u001b[0m - \u001b[1mBasePath: /home/juanjohn/projects/helio_tools/notebooks/sdo-data\u001b[0m\n",
"\u001b[32m2023-12-07 10:45:03.901\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mhelio_tools._src.data.sdo.base\u001b[0m:\u001b[36mdownload_sdo_data\u001b[0m:\u001b[36m219\u001b[0m - \u001b[1mPeriod: 2023-01-01 00:00:00-2023-01-02 00:00:00\u001b[0m\n",
"\u001b[32m2023-12-07 10:45:03.901\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mhelio_tools._src.data.sdo.base\u001b[0m:\u001b[36mdownload_sdo_data\u001b[0m:\u001b[36m223\u001b[0m - \u001b[1mEmail: [email protected]\u001b[0m\n",
"Date: 2023-01-01 12:00:00: 100%|██████████| 2/2 [00:05<00:00, 2.83s/it]\n"
"\u001b[32m2023-12-18 11:55:03.092\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mhelio_tools._src.data.sdo.base\u001b[0m:\u001b[36mdownload_sdo_data\u001b[0m:\u001b[36m213\u001b[0m - \u001b[1mBasePath: /home/juanjohn/projects/helio_tools/notebooks/sdo-data\u001b[0m\n",
"\u001b[32m2023-12-18 11:55:03.094\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mhelio_tools._src.data.sdo.base\u001b[0m:\u001b[36mdownload_sdo_data\u001b[0m:\u001b[36m219\u001b[0m - \u001b[1mPeriod: 2023-01-01 00:00:00-2023-01-02 00:00:00\u001b[0m\n",
"\u001b[32m2023-12-18 11:55:03.094\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mhelio_tools._src.data.sdo.base\u001b[0m:\u001b[36mdownload_sdo_data\u001b[0m:\u001b[36m223\u001b[0m - \u001b[1mEmail: [email protected]\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Date: 2023-01-01 12:00:00: 100%|██████████| 2/2 [00:06<00:00, 3.35s/it]\n"
]
}
],
Expand All @@ -79,7 +85,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"id": "75da6dba-57a3-47ee-bb60-8c81e1524549",
"metadata": {
"tags": []
Expand Down
Loading

0 comments on commit 5731a05

Please sign in to comment.