Skip to content

Commit

Permalink
refactor(goes): convert methods to static
Browse files Browse the repository at this point in the history
Convert the truncate_to_hour and next_time methods in the GOESProductLocator class to static methods. This improves code organization and allows these methods to be called without creating an instance of the class.
  • Loading branch information
wvenialbo committed Oct 20, 2024
1 parent eacb5f1 commit 06f6142
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/GOES_DL/dataset/goes/locator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"""
Provide the GOESProductLocator class for locating GOES-R data files.
Module for .
The `GOESProductLocator` class implements the `ProductLocator` interface
for locating GOES-R Series imagery dataset products. It includes methods
for generating dataset directory paths, verifying product filenames, and
extracting datetime information from filenames.
Classes:
GOESProductLocator: Abstract a product locator for GOES-R Series
imagery dataset.
"""

from datetime import datetime, timedelta
from typing import ClassVar

Expand Down Expand Up @@ -103,7 +118,7 @@ class GOESProductLocator(ProductLocatorGG):
next_time(current_time: datetime) -> datetime:
Get the next time interval. GOES-R Series dataset organises the
data by hour.
normalize_times(datetime_ini: datetime, datetime_fin: datetime) -> tuple[datetime, datetime]:
normalize_times(datetime_ini: datetime, datetime_fin: datetime):
Normalise the initial and final datetimes.
truncate_to_hour(time: datetime) -> datetime:
Truncate the `datetime` to the current hour.
Expand Down Expand Up @@ -140,6 +155,13 @@ class GOESProductLocator(ProductLocatorGG):
# reflectance/brightness [Kelvin] units)
AVAILABLE_LEVELS: set[str] = {"L1b", "L2"}

AVAILABLE_SCENES: dict[str, str] = {
"F": "F",
"C": "C",
"M1": "M",
"M2": "M",
}

def __init__(
self,
name: str,
Expand Down Expand Up @@ -190,6 +212,9 @@ def __init__(
if an unexpected or unsupported setting is required for an
instrument that does not support it.
"""
# TODO: Too many positional arguments. Solve it by using
# the Builder or Factory methods, or patterns like
# Essence or Fluent.
if origin not in self.AVAILABLE_ORIGINS:
available_origins: list[str] = sorted(self.AVAILABLE_ORIGINS)
raise ValueError(
Expand Down Expand Up @@ -257,22 +282,15 @@ def get_base_url(self, datasource: str) -> tuple[str, ...]:
f"Supported datasources: {supported_datasources}"
)

AVAILABLE_SCENES: dict[str, str] = {
"F": "F",
"C": "C",
"M1": "M",
"M2": "M",
}

scene: str = AVAILABLE_SCENES[self.scene] if self.scene else ""
scene: str = self.AVAILABLE_SCENES[self.scene] if self.scene else ""
product: str = f"{self.instrument}-{self.level}-{self.name}{scene}"
satellite: str = self.AVAILABLE_ORIGINS[self.origin]

AVAILABLE_DATASOURCES: dict[str, str] = {
available_datasources: dict[str, str] = {
"AWS": f"s3://noaa-{satellite}/{product}/"
}

return (AVAILABLE_DATASOURCES[datasource], "")
return (available_datasources[datasource], "")

def get_date_format(self) -> str:
"""
Expand Down

0 comments on commit 06f6142

Please sign in to comment.