Skip to content

Commit

Permalink
feat(model-repositories): Update names
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc committed Nov 12, 2024
1 parent 6f6849b commit 631786c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/nwp_consumer/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def parse_env() -> Adaptors:
model_repository_adaptor: type[ports.ModelRepository]
match os.getenv("MODEL_REPOSITORY"):
case None | "gfs":
model_repository_adaptor = repositories.NOAAGFSS3ModelRepository
model_repository_adaptor = repositories.NOAAS3ModelRepository
case "ceda":
model_repository_adaptor = repositories.CedaMetOfficeGlobalModelRepository
model_repository_adaptor = repositories.CEDAFTPModelRepository
case "ecmwf-realtime":
model_repository_adaptor = repositories.ECMWFRealTimeS3ModelRepository
case _ as model:
Expand Down
8 changes: 4 additions & 4 deletions src/nwp_consumer/internal/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
"""

from .model_repositories import (
CedaMetOfficeGlobalModelRepository,
CEDAFTPModelRepository,
ECMWFRealTimeS3ModelRepository,
NOAAGFSS3ModelRepository,
NOAAS3ModelRepository,
)
from .notification_repositories import (
StdoutNotificationRepository,
DagsterPipesNotificationRepository,
)

__all__ = [
"CedaMetOfficeGlobalModelRepository",
"CEDAFTPModelRepository",
"ECMWFRealTimeS3ModelRepository",
"NOAAGFSS3ModelRepository",
"NOAAS3ModelRepository",
"StdoutNotificationRepository",
"DagsterPipesNotificationRepository",
]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .metoffice_global import CedaMetOfficeGlobalModelRepository
from .metoffice_global import CEDAFTPModelRepository
from .ecmwf_realtime import ECMWFRealTimeS3ModelRepository
from .noaa_gfs import NOAAGFSS3ModelRepository
from .noaa_gfs import NOAAS3ModelRepository

__all__ = [
"CedaMetOfficeGlobalModelRepository",
"CEDAFTPModelRepository",
"ECMWFRealTimeS3ModelRepository",
"NOAAGFSS3ModelRepository",
"NOAAS3ModelRepository",
]

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
`this PDF <https://www.metoffice.gov.uk/binaries/content/assets/metofficegovuk/pdf/data/global-atmospheric-model-17-km-resolution.pdf>`_.
For further details on the repository, see the
`CedaMetOfficeGlobalModelRepository.repository` implementation.
`CEDAFTPModelRepository.repository` implementation.
Data discrepancies and corrections
==================================
Expand Down Expand Up @@ -94,7 +94,7 @@
log = logging.getLogger("nwp-consumer")


class CedaMetOfficeGlobalModelRepository(ports.ModelRepository):
class CEDAFTPModelRepository(ports.ModelRepository):
"""Repository implementation for the MetOffice global model data."""

url_base: str = "ftp.ceda.ac.uk/badc/ukmo-nwp/data/global-grib"
Expand Down Expand Up @@ -202,7 +202,7 @@ def _download_and_convert(self, url: str) -> ResultE[list[xr.DataArray]]:

@classmethod
@override
def authenticate(cls) -> ResultE["CedaMetOfficeGlobalModelRepository"]:
def authenticate(cls) -> ResultE["CEDAFTPModelRepository"]:
"""Authenticate with the CEDA FTP server.
Returns:
Expand Down Expand Up @@ -283,9 +283,9 @@ def _convert(path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
)
try:
da: xr.DataArray = (
CedaMetOfficeGlobalModelRepository._rename_or_drop_vars(
CEDAFTPModelRepository._rename_or_drop_vars(
ds=ds,
allowed_parameters=CedaMetOfficeGlobalModelRepository.model().expected_coordinates.variable,
allowed_parameters=CEDAFTPModelRepository.model().expected_coordinates.variable,
)
.sel(step=[np.timedelta64(i, "h") for i in range(0, 48, 1)])
.expand_dims(dim={"init_time": [ds["time"].values]})
Expand All @@ -296,7 +296,7 @@ def _convert(path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
if v not in ["init_time", "step", "latitude", "longitude"]
],
)
.to_dataarray(name=CedaMetOfficeGlobalModelRepository.model().name)
.to_dataarray(name=CEDAFTPModelRepository.model().name)
.transpose("init_time", "step", "variable", "latitude", "longitude")
# Remove the last value of the longitude dimension as it overlaps with the next file
# Reverse the latitude dimension to be in descending order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
log = logging.getLogger("nwp-consumer")


class NOAAGFSS3ModelRepository(ports.ModelRepository):
class NOAAS3ModelRepository(ports.ModelRepository):
"""Model repository implementation for GFS data stored in S3."""

@staticmethod
Expand Down Expand Up @@ -115,7 +115,7 @@ def fetch_init_data(

@classmethod
@override
def authenticate(cls) -> ResultE["NOAAGFSS3ModelRepository"]:
def authenticate(cls) -> ResultE["NOAAS3ModelRepository"]:
return Success(cls())

def _download_and_convert(self, url: str) -> ResultE[list[xr.DataArray]]:
Expand Down Expand Up @@ -226,7 +226,7 @@ def _convert(self, path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
processed_das: list[xr.DataArray] = []
for i, ds in enumerate(dss):
try:
ds = NOAAGFSS3ModelRepository._rename_or_drop_vars(
ds = NOAAS3ModelRepository._rename_or_drop_vars(
ds=ds,
allowed_parameters=self.model().expected_coordinates.variable,
)
Expand All @@ -243,7 +243,7 @@ def _convert(self, path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
.rename(name_dict={"time": "init_time"})
.expand_dims(dim="init_time")
.expand_dims(dim="step")
.to_dataarray(name=NOAAGFSS3ModelRepository.model().name)
.to_dataarray(name=NOAAS3ModelRepository.model().name)
)
da = (
da.drop_vars(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from nwp_consumer.internal import entities

from .metoffice_global import CedaMetOfficeGlobalModelRepository
from .metoffice_global import CEDAFTPModelRepository


class TestCedaMetOfficeGlobalModelRepository(unittest.TestCase):
"""Test the business methods of the CedaMetOfficeGlobalModelRepository class."""
class TestCEDAFTPModelRepository(unittest.TestCase):
"""Test the business methods of the CEDAFTPModelRepository class."""

@unittest.skipIf(
condition="CI" in os.environ,
Expand All @@ -21,7 +21,7 @@ class TestCedaMetOfficeGlobalModelRepository(unittest.TestCase):
def test__download_and_convert(self) -> None:
"""Test the _download_and_convert method."""

auth_result = CedaMetOfficeGlobalModelRepository.authenticate()
auth_result = CEDAFTPModelRepository.authenticate()
self.assertTrue(is_successful(auth_result), msg=f"Error: {auth_result.failure}")
c = auth_result.unwrap()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from returns.pipeline import is_successful

from ...entities import NWPDimensionCoordinateMap
from .noaa_gfs import NOAAGFSS3ModelRepository
from .noaa_gfs import NOAAS3ModelRepository

if TYPE_CHECKING:
import xarray as xr
Expand All @@ -26,7 +26,7 @@ class TestECMWFRealTimeS3ModelRepository(unittest.TestCase):
def test__download_and_convert(self) -> None:
"""Test the _download_and_convert method."""

c: NOAAGFSS3ModelRepository = NOAAGFSS3ModelRepository.authenticate().unwrap()
c: NOAAS3ModelRepository = NOAAS3ModelRepository.authenticate().unwrap()

test_it: dt.datetime = dt.datetime(2024, 10, 24, 12, tzinfo=dt.UTC)
test_coordinates: entities.NWPDimensionCoordinateMap = dataclasses.replace(
Expand Down Expand Up @@ -102,10 +102,10 @@ class TestCase:

for t in tests:
with self.subTest(name=t.name):
result = NOAAGFSS3ModelRepository._wanted_file(
result = NOAAS3ModelRepository._wanted_file(
filename=t.filename,
it=test_it,
max_step=max(NOAAGFSS3ModelRepository.model().expected_coordinates.step),
max_step=max(NOAAS3ModelRepository.model().expected_coordinates.step),
)
self.assertEqual(result, t.expected)

4 changes: 2 additions & 2 deletions src/test_integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class TestIntegration(unittest.TestCase):
def test_ceda_metoffice_global_model(self) -> None:
c = handlers.CLIHandler(
consumer_usecase=services.ConsumerService(
model_repository=repositories.CedaMetOfficeGlobalModelRepository,
model_repository=repositories.CEDAFTPModelRepository,
notification_repository=repositories.StdoutNotificationRepository,
),
archiver_usecase=services.ArchiverService(
model_repository=repositories.CedaMetOfficeGlobalModelRepository,
model_repository=repositories.CEDAFTPModelRepository,
notification_repository=repositories.StdoutNotificationRepository,
),
)
Expand Down

0 comments on commit 631786c

Please sign in to comment.