Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilities refactoring #290

Merged
merged 35 commits into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
689b0ca
[skip-ci]
gmaze Sep 6, 2023
3e49033
Move TopoFetcher to argopy.related
gmaze Sep 6, 2023
beae1af
[skip-ci]
gmaze Sep 6, 2023
3d3cff9
[skip-ci]
gmaze Sep 6, 2023
3db2954
Update __init__.py
gmaze Sep 6, 2023
b64fabe
refactor tests locations
gmaze Sep 6, 2023
975913f
Update api-hidden.rst
gmaze Sep 6, 2023
ec22c17
update MyThreadPoolExecutor access [skip-ci]
gmaze Sep 6, 2023
0077f35
Merge branch 'master' into refactor-utils
gmaze Sep 7, 2023
44025d2
Update __init__.py
gmaze Sep 7, 2023
6891cbd
Delete gdac_snapshot.py
gmaze Sep 7, 2023
8723078
Create doi_snapshot.py
gmaze Sep 7, 2023
0b8c9d7
Refactor MyThreadPoolExecutor as MonitoredThreadPoolExecutor
gmaze Sep 7, 2023
01669bd
refactor most checkers
gmaze Sep 7, 2023
a5da176
[skip-ci]
gmaze Sep 8, 2023
9ac43a2
[skip-ci]
gmaze Sep 8, 2023
33d2423
[skip-ci]
gmaze Sep 8, 2023
28f7702
let's try this
gmaze Sep 8, 2023
d313af2
Update transform.py
gmaze Sep 11, 2023
eb4f7af
Delete plotters.py
gmaze Sep 11, 2023
29d9355
Make uniform internal module import
gmaze Sep 11, 2023
459846f
import fix
gmaze Sep 11, 2023
463e751
Deprec messages in argopy.utilities
gmaze Sep 12, 2023
0b6b9e9
Black new utils files
gmaze Sep 12, 2023
b39c868
fix the doc
gmaze Sep 12, 2023
e28ea34
misc
gmaze Sep 18, 2023
48a039d
Update argo_documentation.py
gmaze Sep 18, 2023
9e0af22
fix documentation
gmaze Sep 18, 2023
8ca4c95
Update utilities.py
gmaze Sep 18, 2023
dcd92ab
move ADMT docs list to assets
gmaze Sep 18, 2023
009727d
fix doc
gmaze Sep 18, 2023
77be87c
More doc fixes
gmaze Sep 18, 2023
ea07821
Merge branch 'master' into refactor-utils
gmaze Sep 18, 2023
79f4b40
Remove deprecated unicode in doc [skip-ci]
gmaze Sep 26, 2023
369f5fb
Update data_sources.rst
gmaze Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions argopy/__init__.py
Expand Up @@ -26,22 +26,23 @@
from .fetchers import ArgoIndexFetcher as IndexFetcher # noqa: E402

from .xarray import ArgoAccessor # noqa: E402
from . import tutorial # noqa: E402

# Other Import
from . import utilities # noqa: E402
# from . import utils as utilities # noqa: E402
from . import utilities # noqa: E402 # being deprecated until 0.1.15, then remove
from . import stores # noqa: E402
from . import errors # noqa: E402
from . import plot # noqa: E402
from . import tutorial # noqa: E402
from .plot import dashboard, ArgoColors # noqa: E402
from .utilities import show_versions, show_options, clear_cache, lscache # noqa: E402
from .utilities import TopoFetcher, ArgoNVSReferenceTables, OceanOPSDeployments, ArgoDocs # noqa: E402
from .utilities import monitor_status as status # noqa: E402
from .options import set_options, reset_options # noqa: E402
from .data_fetchers import CTDRefDataFetcher # noqa: E402
from .stores import ArgoIndex # noqa: E402
from .related import ArgoDOI # noqa: E402
from .utils import compute # noqa: E402, F401
from .utils import show_versions, show_options # noqa: E402
from .utils import clear_cache, lscache # noqa: E402
from .utils import MonitoredThreadPoolExecutor # noqa: E402, F401
from .utils import monitor_status as status # noqa: E402
from .related import TopoFetcher, OceanOPSDeployments, ArgoNVSReferenceTables, ArgoDocs, ArgoDOI # noqa: E402


#
Expand Down Expand Up @@ -71,11 +72,10 @@
"ArgoDOI", # Class

# Submodules:
"utilities",
"utilities", # being deprecated until 0.1.15, then remove
"errors",
"plot",
"ArgoColors", # Class
# "plotters", # Deprec, to be removed after 0.1.13
"stores",
"tutorial",
# Constants
Expand Down
11 changes: 6 additions & 5 deletions argopy/data_fetchers/argovis_data.py
Expand Up @@ -9,14 +9,15 @@
import xarray as xr
import getpass
import logging
from .proto import ArgoDataFetcherProto
from abc import abstractmethod
import warnings

from argopy.stores import httpstore
from argopy.options import OPTIONS
from argopy.utilities import format_oneline, Chunker
from argopy.errors import DataNotFound
from ..stores import httpstore
from ..options import OPTIONS
from ..utils.format import format_oneline
from ..utils.chunking import Chunker
from ..errors import DataNotFound
from .proto import ArgoDataFetcherProto


access_points = ["wmo", "box"]
Expand Down
22 changes: 10 additions & 12 deletions argopy/data_fetchers/erddap_data.py
Expand Up @@ -10,7 +10,6 @@

"""

import argopy.utilities
import xarray as xr
import pandas as pd
import numpy as np
Expand All @@ -21,18 +20,17 @@
import getpass
from typing import Union
import fnmatch
from aiohttp import ClientResponseError
import logging

from .proto import ArgoDataFetcherProto
from argopy.options import OPTIONS
from argopy.utilities import Chunker, format_oneline, to_list
from argopy.stores import httpstore
from ..options import OPTIONS
from ..utils.format import format_oneline
from ..stores import httpstore
from ..errors import ErddapServerError, DataNotFound
from ..stores import (
indexstore_pd as ArgoIndex,
) # make sure to work with the Pandas index store
from ..stores import indexstore_pd as ArgoIndex # make sure we work with the Pandas index store
from ..utils import is_list_of_strings, to_list,Chunker
from .proto import ArgoDataFetcherProto

from aiohttp import ClientResponseError
import logging

# Load erddapy according to available version (breaking changes in v0.8.0)
try:
Expand Down Expand Up @@ -201,7 +199,7 @@ def __init__( # noqa: C901
raise ValueError()
elif params[0] == "all":
params = self._bgc_vlist_avail
elif not argopy.utilities.is_list_of_strings(params):
elif not is_list_of_strings(params):
raise ValueError("'params' argument must be a list of strings")
# raise ValueError("'params' argument must be a list of strings (possibly with a * wildcard)")
self._bgc_vlist_requested = [p.upper() for p in params]
Expand All @@ -222,7 +220,7 @@ def __init__( # noqa: C901
measured = []
elif self._bgc_measured[0] == "all":
measured = self._bgc_vlist_requested
elif not argopy.utilities.is_list_of_strings(self._bgc_measured):
elif not is_list_of_strings(self._bgc_measured):
raise ValueError("'measured' argument must be a list of strings")
# raise ValueError("'measured' argument must be a list of strings (possibly with a * wildcard)")
self._bgc_vlist_measured = [m.upper() for m in measured]
Expand Down
7 changes: 4 additions & 3 deletions argopy/data_fetchers/erddap_index.py
Expand Up @@ -17,9 +17,10 @@

from abc import ABC, abstractmethod

from argopy.utilities import load_dict, mapp_dict, format_oneline
from argopy.stores import httpstore
from argopy.options import OPTIONS
from ..utils.format import format_oneline
from ..related import load_dict, mapp_dict
from ..stores import httpstore
from ..options import OPTIONS

log = logging.getLogger("argopy.fetchers.erddap_index")

Expand Down
8 changes: 4 additions & 4 deletions argopy/data_fetchers/erddap_refdata.py
Expand Up @@ -2,11 +2,11 @@
Fetcher to retrieve CTD reference data from Ifremer erddap
"""
import xarray as xr
from .erddap_data import ErddapArgoDataFetcher
from argopy.options import OPTIONS
from argopy.utilities import Chunker
from argopy.stores import httpstore_erddap_auth
import logging
from ..options import OPTIONS
from ..utils.chunking import Chunker
from ..stores import httpstore_erddap_auth
from .erddap_data import ErddapArgoDataFetcher

# Load erddapy according to available version (breaking changes in v0.8.0)
try:
Expand Down
4 changes: 2 additions & 2 deletions argopy/data_fetchers/gdacftp_data.py
Expand Up @@ -12,11 +12,11 @@
import getpass
import logging

from .proto import ArgoDataFetcherProto
from ..utilities import format_oneline, argo_split_path
from ..utils.format import format_oneline, argo_split_path
from ..options import OPTIONS, check_gdac_path
from ..errors import DataNotFound
from ..stores import ArgoIndex
from .proto import ArgoDataFetcherProto

log = logging.getLogger("argopy.gdacftp.data")
access_points = ["wmo", "box"]
Expand Down
17 changes: 1 addition & 16 deletions argopy/data_fetchers/gdacftp_index.py
Expand Up @@ -11,7 +11,7 @@
import logging
import importlib

from ..utilities import format_oneline
from ..utils.format import format_oneline
from ..options import OPTIONS, check_gdac_path
from ..plot import dashboard

Expand Down Expand Up @@ -161,21 +161,6 @@ def clear_cache(self):
def to_dataframe(self):
""" Filter index file and return a pandas dataframe """
df = self.indexfs.run().to_dataframe()

# Post-processing of the filtered index is done at the indexstore level
# if 'wmo' not in df:
# df['wmo'] = df['file'].apply(lambda x: int(x.split('/')[1]))
#
# # institution & profiler mapping for all users
# # todo: may be we need to separate this for standard and expert users
# institution_dictionnary = load_dict('institutions')
# df['tmp1'] = df.institution.apply(lambda x: mapp_dict(institution_dictionnary, x))
# df = df.rename(columns={"institution": "institution_code", "tmp1": "institution"})
#
# profiler_dictionnary = load_dict('profilers')
# df['profiler'] = df.profiler_type.apply(lambda x: mapp_dict(profiler_dictionnary, int(x)))
# df = df.rename(columns={"profiler_type": "profiler_code"})

return df

def to_xarray(self):
Expand Down
2 changes: 1 addition & 1 deletion argopy/data_fetchers/proto.py
Expand Up @@ -5,7 +5,7 @@
import hashlib
import warnings
from ..plot import dashboard
from ..utilities import list_standard_variables
from ..utils.lists import list_standard_variables


class ArgoDataFetcherProto(ABC):
Expand Down
17 changes: 10 additions & 7 deletions argopy/fetchers.py
Expand Up @@ -15,17 +15,20 @@
import numpy as np
import logging

from argopy.options import OPTIONS, _VALIDATORS
from .options import OPTIONS, _VALIDATORS
from .errors import InvalidFetcherAccessPoint, InvalidFetcher, OptionValueError

from .utilities import (
list_available_data_src,
list_available_index_src,
from .related import (
get_coriolis_profile_id,
)
from .utils.checkers import (
is_box,
is_indexbox,
check_wmo,
check_cyc,
get_coriolis_profile_id,
check_cyc
)
from .utils.lists import (
list_available_data_src,
list_available_index_src,
)
from .plot import plot_trajectory, bar_plot, open_sat_altim_report

Expand Down
2 changes: 1 addition & 1 deletion argopy/options.py
Expand Up @@ -5,13 +5,13 @@
# https://github.com/pydata/xarray/blob/cafab46aac8f7a073a32ec5aa47e213a9810ed54/xarray/core/options.py
"""
import os
from argopy.errors import OptionValueError, FtpPathError, ErddapPathError
import warnings
import logging
import fsspec
from fsspec.core import split_protocol
from socket import gaierror
from urllib.parse import urlparse
from .errors import OptionValueError, FtpPathError, ErddapPathError


# Define a logger
Expand Down
2 changes: 1 addition & 1 deletion argopy/plot/argo_colors.py
@@ -1,7 +1,7 @@
import numpy as np
from packaging import version
from .utils import has_mpl, has_seaborn
from ..utilities import warnUnless
from ..utils.loggers import warnUnless

if has_mpl:
from .utils import mpl, cm, mcolors, plt
Expand Down
4 changes: 3 additions & 1 deletion argopy/plot/dashboards.py
Expand Up @@ -11,7 +11,9 @@
from packaging import version

from .utils import has_ipython
from ..utilities import warnUnless, check_wmo, check_cyc, get_ea_profile_page
from ..utils.loggers import warnUnless
from ..related.euroargo_api import get_ea_profile_page
from ..utils import check_wmo, check_cyc
from ..errors import InvalidDashboard
from .. import __version__ as argopy_version

Expand Down
3 changes: 2 additions & 1 deletion argopy/plot/plot.py
Expand Up @@ -18,7 +18,8 @@
from .utils import axes_style, latlongrid, land_feature
from .argo_colors import ArgoColors

from ..utilities import warnUnless, check_wmo
from ..utils.loggers import warnUnless
from ..utils.checkers import check_wmo
from ..errors import InvalidDatasetStructure

if has_mpl:
Expand Down
2 changes: 1 addition & 1 deletion argopy/plot/utils.py
@@ -1,7 +1,7 @@
import numpy as np
from contextlib import contextmanager
import importlib
from ..utilities import deprecated
from ..utils.decorators import deprecated


def _importorskip(modname):
Expand Down
40 changes: 0 additions & 40 deletions argopy/plotters.py

This file was deleted.

20 changes: 19 additions & 1 deletion argopy/related/__init__.py
@@ -1,7 +1,25 @@
from .gdac_snapshot import ArgoDOI
from .topography import TopoFetcher
from .ocean_ops_deployments import OceanOPSDeployments
from .reference_tables import ArgoNVSReferenceTables
from .argo_documentation import ArgoDocs
from .doi_snapshot import ArgoDOI
from .euroargo_api import get_coriolis_profile_id, get_ea_profile_page
from .utils import load_dict, mapp_dict

#
__all__ = (
# Classes:
"TopoFetcher",
"OceanOPSDeployments",
"ArgoNVSReferenceTables",
"ArgoDocs",
"ArgoDOI",

# Functions:
"get_coriolis_profile_id",
"get_ea_profile_page",

# Utilities:
"load_dict",
"mapp_dict",
)