Skip to content

Commit

Permalink
Merge pull request #389 from euroargodev/other-major-breaking-refacto…
Browse files Browse the repository at this point in the history
…ring

Implement other than bgc-2024 branch major breaking refactoring for major release v1.0.0
  • Loading branch information
gmaze authored Sep 25, 2024
2 parents 919484e + ce6fed9 commit 62ba4cb
Show file tree
Hide file tree
Showing 34 changed files with 260 additions and 314 deletions.
8 changes: 4 additions & 4 deletions argopy/data_fetchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from . import erddap_data
from . import erddap_index
from . import argovis_data
from . import gdacftp_data
from . import gdacftp_index
from . import gdac_data
from . import gdac_index

__all__ = (
"erddap_data",
"erddap_index",
"argovis_data",
"gdacftp_data",
"gdacftp_index",
"gdac_data.py",
"gdac_index.py",
"CTDRefDataFetcher",
)
6 changes: 3 additions & 3 deletions argopy/data_fetchers/argovis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def __init__(
Argovis API request time out in seconds. Set to OPTIONS['api_timeout'] by default.
"""
self.definition = "Argovis Argo data fetcher"
self.dataset_id = OPTIONS["dataset"] if ds == "" else ds
self.user_mode = kwargs["mode"] if "mode" in kwargs else OPTIONS["mode"]
self.dataset_id = OPTIONS["ds"] if ds == "" else ds
self.user_mode = kwargs["mode"] if "mode" in kwargs else OPTIONS["mode"]
self.server = kwargs["server"] if "server" in kwargs else api_server
timeout = OPTIONS["api_timeout"] if api_timeout == 0 else api_timeout
self.store_opts = {
Expand Down Expand Up @@ -360,7 +360,7 @@ def to_xarray(self, errors: str = "ignore"):
ds = ds.set_coords(coords)

# Cast data types and add variable attributes (not available in the csv download):
ds["TIME"] = ds["TIME"].astype("datetime64[ns]")
ds["TIME"] = pd.to_datetime(ds["TIME"], utc=True)
ds = self._add_attributes(ds)
ds = ds.argo.cast_types()

Expand Down
2 changes: 1 addition & 1 deletion argopy/data_fetchers/erddap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__( # noqa: C901
"""
timeout = OPTIONS["api_timeout"] if api_timeout == 0 else api_timeout
self.definition = "Ifremer erddap Argo data fetcher"
self.dataset_id = OPTIONS["dataset"] if ds == "" else ds
self.dataset_id = OPTIONS["ds"] if ds == "" else ds
self.user_mode = kwargs["mode"] if "mode" in kwargs else OPTIONS["mode"]
self.server = kwargs["server"] if "server" in kwargs else OPTIONS["erddap"]
self.store_opts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Argo data fetcher for remote GDAC FTP
Argo data fetcher for remote GDAC servers
This is not intended to be used directly, only by the facade at fetchers.py
Expand All @@ -18,18 +18,18 @@
from ..stores import ArgoIndex
from .proto import ArgoDataFetcherProto

log = logging.getLogger("argopy.gdacftp.data")
log = logging.getLogger("argopy.gdac.data")
access_points = ["wmo", "box"]
exit_formats = ["xarray"]
dataset_ids = ["phy", "bgc", "bgc-s", "bgc-b"] # First is default
api_server = OPTIONS["ftp"] # API root url
api_server = OPTIONS["gdac"] # API root url
api_server_check = (
api_server # URL to check if the API is alive, used by isAPIconnected
)


class FTPArgoDataFetcher(ArgoDataFetcherProto):
"""Manage access to Argo data from a remote GDAC FTP.
class GDACArgoDataFetcher(ArgoDataFetcherProto):
"""Manage access to Argo data from a GDAC server
Warnings
--------
Expand All @@ -50,7 +50,7 @@ def init(self, *args, **kwargs):
###
def __init__(
self,
ftp: str = "",
gdac: str = "",
ds: str = "",
cache: bool = False,
cachedir: str = "",
Expand All @@ -66,8 +66,8 @@ def __init__(
Parameters
----------
ftp: str (optional)
Path to the remote FTP directory where the 'dac' folder is located.
gdac: str (optional)
Path to the local or remote directory where the 'dac' folder is located
ds: str (optional)
Dataset to load: 'phy' or 'bgc'
cache: bool (optional)
Expand All @@ -88,15 +88,15 @@ def __init__(
progress: bool (optional)
Show a progress bar or not when fetching data.
api_timeout: int (optional)
FTP request time out in seconds. Set to OPTIONS['api_timeout'] by default.
Server request time out in seconds. Set to OPTIONS['api_timeout'] by default.
"""
self.timeout = OPTIONS["api_timeout"] if api_timeout == 0 else api_timeout
self.dataset_id = OPTIONS["dataset"] if ds == "" else ds
self.dataset_id = OPTIONS["ds"] if ds == "" else ds
self.user_mode = kwargs["mode"] if "mode" in kwargs else OPTIONS["mode"]
self.server = OPTIONS["ftp"] if ftp == "" else ftp
self.server = OPTIONS["gdac"] if gdac == "" else gdac
self.errors = errors

# Validate server, raise FtpPathError if not valid.
# Validate server, raise GdacPathError if not valid.
check_gdac_path(self.server, errors="raise")

index_file = "core"
Expand Down Expand Up @@ -137,10 +137,10 @@ def __init__(
self.init(**kwargs)

def __repr__(self):
summary = ["<datafetcher.ftp>"]
summary = ["<datafetcher.gdac>"]
summary.append("Name: %s" % self.definition)
summary.append("Index: %s" % self.indexfs.index_file)
summary.append("Host: %s" % self.server)
summary.append("Server: %s" % self.server)
if hasattr(self, "BOX"):
summary.append("Domain: %s" % self.cname())
else:
Expand Down Expand Up @@ -446,8 +446,8 @@ def filter_researchmode(self, ds: xr.Dataset, *args, **kwargs) -> xr.Dataset:
return ds


class Fetch_wmo(FTPArgoDataFetcher):
"""Manage access to GDAC ftp Argo data for: a list of WMOs.
class Fetch_wmo(GDACArgoDataFetcher):
"""Manage access to GDAC Argo data for: a list of WMOs.
This class is instantiated when a call is made to these facade access points:
Expand All @@ -474,7 +474,7 @@ def init(self, WMO: list = [], CYC=None, **kwargs):
if "MAX_FILES" in kwargs:
self._nrows = kwargs["MAX_FILES"]

self.definition = "Ifremer GDAC ftp Argo data fetcher"
self.definition = "Ifremer GDAC Argo data fetcher"
if self.CYC is not None:
self.definition = "%s for profiles" % self.definition
else:
Expand Down Expand Up @@ -503,8 +503,8 @@ def uri(self):
return self._list_of_argo_files


class Fetch_box(FTPArgoDataFetcher):
"""Manage access to GDAC ftp Argo data for: a rectangular space/time domain.
class Fetch_box(GDACArgoDataFetcher):
"""Manage access to GDAC Argo data for: a rectangular space/time domain.
This class is instantiated when a call is made to these facade access points:
Expand Down Expand Up @@ -535,7 +535,7 @@ def init(self, box: list, nrows=None, **kwargs):
if "MAX_FILES" in kwargs:
self._nrows = kwargs["MAX_FILES"]

self.definition = "Ifremer GDAC ftp Argo data fetcher for a space/time region"
self.definition = "Ifremer GDAC Argo data fetcher for a space/time region"
return self

@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Argo index fetcher for remote GDAC FTP
Argo index fetcher for remote GDAC server
This is not intended to be used directly, only by the facade at fetchers.py
Expand All @@ -16,7 +16,7 @@
from ..plot import dashboard


log = logging.getLogger("argopy.gdacftp.index")
log = logging.getLogger("argopy.gdac.index")

has_pyarrow = importlib.util.find_spec('pyarrow') is not None
if has_pyarrow:
Expand All @@ -30,12 +30,12 @@
access_points = ["wmo", "box"]
exit_formats = ["xarray"]
dataset_ids = ["phy", "bgc"] # First is default
api_server = OPTIONS['ftp'] # API root url
api_server = OPTIONS['gdac'] # API root url
api_server_check = api_server # URL to check if the API is alive, used by isAPIconnected


class FTPArgoIndexFetcher(ABC):
""" Manage access to Argo index from a remote GDAC FTP """
class GDACArgoIndexFetcher(ABC):
"""Manage access to Argo index from a GDAC server"""
# N_FILES = None

###
Expand All @@ -51,7 +51,7 @@ def init(self, *args, **kwargs):
###
def __init__(
self,
ftp: str = "",
gdac: str = "",
ds: str = "",
cache: bool = False,
cachedir: str = "",
Expand All @@ -63,8 +63,8 @@ def __init__(
Parameters
----------
ftp: str (optional)
Path to the remote FTP directory where the 'dac' folder is located.
gdac: str (optional)
Path to the local or remote directory where the 'dac' folder is located
ds: str (optional)
Dataset to load: 'phy' or 'ref' or 'bgc'
errors: str (optional)
Expand All @@ -75,15 +75,15 @@ def __init__(
cachedir: str (optional)
Path to cache folder
api_timeout: int (optional)
FTP request time out in seconds. Set to OPTIONS['api_timeout'] by default.
Server request time out in seconds. Set to OPTIONS['api_timeout'] by default.
"""
self.timeout = OPTIONS["api_timeout"] if api_timeout == 0 else api_timeout
self.definition = "Ifremer GDAC ftp Argo index fetcher"
self.dataset_id = OPTIONS["dataset"] if ds == "" else ds
self.server = OPTIONS['ftp'] if ftp == "" else ftp
self.definition = "Ifremer GDAC Argo index fetcher"
self.dataset_id = OPTIONS["ds"] if ds == "" else ds
self.server = OPTIONS['gdac'] if gdac == "" else gdac
self.errors = errors

# Validate server, raise FtpPathError if not valid.
# Validate server, raise GdacPathError if not valid.
check_gdac_path(self.server, errors='raise')

if self.dataset_id == 'phy':
Expand All @@ -107,10 +107,10 @@ def __init__(
self.init(**kwargs)

def __repr__(self):
summary = ["<indexfetcher.ftp>"]
summary = ["<indexfetcher.gdac>"]
summary.append("Name: %s" % self.definition)
summary.append("Index: %s" % self.indexfs.index_file)
summary.append("FTP: %s" % self.server)
summary.append("Server: %s" % self.server)
summary.append("Domain: %s" % format_oneline(self.cname()))
if hasattr(self.indexfs, 'index'):
summary.append("Index loaded: True (%i records)" % self.N_RECORDS)
Expand Down Expand Up @@ -177,8 +177,8 @@ def dashboard(self, **kw):
warnings.warn("Dashboard only available for a single float or profile request")


class Fetch_wmo(FTPArgoIndexFetcher):
""" Manage access to GDAC ftp Argo index for: a list of WMOs, CYCs """
class Fetch_wmo(GDACArgoIndexFetcher):
""" Manage access to GDAC Argo index for: a list of WMOs, CYCs """

def init(self, WMO: list = [], CYC=None, **kwargs):
""" Create Argo index fetcher for WMOs
Expand Down Expand Up @@ -217,8 +217,8 @@ def uri(self):
return self._list_of_argo_files


class Fetch_box(FTPArgoIndexFetcher):
""" Manage access to GDAC ftp Argo index for: a rectangular space/time domain """
class Fetch_box(GDACArgoIndexFetcher):
""" Manage access to GDAC Argo index for: a rectangular space/time domain """

def init(self, box: list, **kwargs):
""" Create Argo index fetcher
Expand All @@ -238,7 +238,7 @@ def init(self, box: list, **kwargs):
"""
# We use a full domain definition (x, y, z, t) as argument for compatibility with the other fetchers
# but at this point, we internally work only with x, y and t.
# log.debug("Create FTPArgoIndexFetcher.Fetch_box instance with index BOX: %s" % box)
# log.debug("Create GDACArgoIndexFetcher.Fetch_box instance with index BOX: %s" % box)
self.indexBOX = box.copy()

self._nrows = None
Expand Down
8 changes: 4 additions & 4 deletions argopy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ class NoDataLeft(NoData):
pass


class FtpPathError(ValueError):
"""Raise when a ftp path is not appropriate."""
class GdacPathError(ValueError):
"""Raise when a GDAC compliant path is not appropriate"""

pass


class ErddapPathError(ValueError):
"""Raise when a erddap path is not appropriate."""
"""Raise when an erddap path is not appropriate"""

pass


class S3PathError(ValueError):
"""Raise when a S3 path is not appropriate."""
"""Raise when a S3 path is not appropriate"""

pass

Expand Down
10 changes: 5 additions & 5 deletions argopy/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ArgoDataFetcher:
src: str, optional
Source of the data to use. Eg: ``erddap``. Set to OPTIONS['src'] by default if empty.
ds: str, optional
Name of the dataset to load. Eg: ``phy``. Set to OPTIONS['dataset'] by default if empty.
Name of the dataset to load. Eg: ``phy``. Set to OPTIONS['ds'] by default if empty.
**fetcher_kwargs: optional
Additional arguments passed on data source fetcher creation of each access points.
Expand All @@ -102,7 +102,7 @@ def __init__(self, mode: str = "", src: str = "", ds: str = "", **fetcher_kwargs

# Facade options :
self._mode = OPTIONS["mode"] if mode == "" else mode
self._dataset_id = OPTIONS["dataset"] if ds == "" else ds
self._dataset_id = OPTIONS["ds"] if ds == "" else ds
self._src = OPTIONS["src"] if src == "" else src

if self._dataset_id == "bgc":
Expand All @@ -112,9 +112,9 @@ def __init__(self, mode: str = "", src: str = "", ds: str = "", **fetcher_kwargs
raise OptionValueError(
f"option 'mode' given an invalid value: {self._mode}"
)
if not _VALIDATORS["dataset"](self._dataset_id):
if not _VALIDATORS["ds"](self._dataset_id):
raise OptionValueError(
f"option 'dataset' given an invalid value: {self._dataset_id}"
f"option 'ds' given an invalid value: {self._dataset_id}"
)
if not _VALIDATORS["src"](self._src):
raise OptionValueError(f"option 'src' given an invalid value: {self._src}")
Expand Down Expand Up @@ -817,7 +817,7 @@ def __init__(
self,
mode: str = OPTIONS["mode"],
src: str = OPTIONS["src"],
ds: str = OPTIONS["dataset"],
ds: str = OPTIONS["ds"],
**fetcher_kwargs,
):
"""Facade for Argo index fetchers
Expand Down
Loading

0 comments on commit 62ba4cb

Please sign in to comment.