From 316686387e7707e7179859c542964095862ace4e Mon Sep 17 00:00:00 2001 From: Kevin Santana Date: Thu, 18 Jul 2024 23:55:01 -0400 Subject: [PATCH] initial changes --- clouddrift/adapters/__init__.py | 4 +++- clouddrift/adapters/ibtracs.py | 38 +++++++++++++++++++++++++++++++++ pyproject.toml | 3 ++- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 clouddrift/adapters/ibtracs.py diff --git a/clouddrift/adapters/__init__.py b/clouddrift/adapters/__init__.py index b6c462e4..81cc79b2 100644 --- a/clouddrift/adapters/__init__.py +++ b/clouddrift/adapters/__init__.py @@ -13,6 +13,7 @@ import clouddrift.adapters.gdp6h as gdp6h import clouddrift.adapters.glad as glad import clouddrift.adapters.hurdat2 as hurdat2 +import clouddrift.adapters.ibtracs as ibtracs import clouddrift.adapters.mosaic as mosaic import clouddrift.adapters.subsurface_floats as subsurface_floats import clouddrift.adapters.utils as utils @@ -21,9 +22,10 @@ __all__ = [ "andro", "gdp1h", - "hurdat2", "gdp6h", "glad", + "hurdat2", + "ibtracs", "mosaic", "subsurface_floats", "yomaha", diff --git a/clouddrift/adapters/ibtracs.py b/clouddrift/adapters/ibtracs.py new file mode 100644 index 00000000..82840d30 --- /dev/null +++ b/clouddrift/adapters/ibtracs.py @@ -0,0 +1,38 @@ +from typing import Literal, TypeAlias + +from fsspec.implementations.http import HTTPFileSystem + +SOURCE_BASE_URI = "https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs" + +SOURCE_URL_FMT = "{base_uri}/{version}/access/netcdf/IBTrACS.{kind}.{version}.nc" + +_Version: TypeAlias = Literal["v03r09"] | Literal["v04r00"] | Literal["v04r01"] + +_Kind: TypeAlias = ( + Literal["ACTIVE"] + | Literal["ALL"] + | Literal["EP"] + | Literal["NA"] + | Literal["NI"] + | Literal["SA"] + | Literal["SI"] + | Literal["SP"] + | Literal["WP"] + | Literal["LAST_3_YEARS"] + | Literal["SINCE_1980"] +) + + +def download(version: _Version, kind: _Kind): + fs = HTTPFileSystem() + return fs.open(_get_source_url(version, kind), callback=lambda: print("what")) + + +def _kind_map(kind: _Kind): + return {"LAST_3_YEARS": "last3years", "SINCE_1980": "since1980"}.get(kind, kind) + + +def _get_source_url(version: _Version, kind: _Kind): + return SOURCE_URL_FMT.format( + base_uri=SOURCE_BASE_URI, version=version, kind=_kind_map(kind) + ) diff --git a/pyproject.toml b/pyproject.toml index 9019f985..7a79af62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,8 @@ dependencies = [ "scipy>=1.11.2", "xarray>=2023.5.0", "zarr>=2.14.2", - "tenacity>=8.2.3" + "tenacity>=8.2.3", + "fsspec>=2024.3.1" ] [project.optional-dependencies]