From 06f6142979b83a8df9150f33263fac0124495438 Mon Sep 17 00:00:00 2001 From: wvenialbo Date: Sun, 20 Oct 2024 09:04:35 -0300 Subject: [PATCH] refactor(goes): convert methods to static 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. --- src/GOES_DL/dataset/goes/locator.py | 40 +++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/GOES_DL/dataset/goes/locator.py b/src/GOES_DL/dataset/goes/locator.py index 81f93f4..813b2f3 100644 --- a/src/GOES_DL/dataset/goes/locator.py +++ b/src/GOES_DL/dataset/goes/locator.py @@ -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 @@ -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. @@ -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, @@ -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( @@ -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: """