argopy Python Library

repository·master·Indexed 42 days ago

https://github.com/euroargodev/argopy

A Python library for accessing, visualizing, and manipulating Argo ocean data. It provides tools for data fetching via ERDDAP, FTP, local files, or Argovis, and supports loading data into xarray. Advanced features include Argo vocabulary and reference table management (NVS), retrieval of deployment plans via OceanOPS, GDAC snapshot DOI discovery, and access to Argo Data Management Team manuals.

Tokens
49.9K
Snippets
193
Records
237
Agent score
52%

What's inside argopy

  1. Perform data quality control in argopy

    master

    argopy provides a suite of tools designed to complement existing Argo quality control (QC) procedures. Instead of a single monolithic QC function, it offers elementary blocks to help you build a custom Python-based QC pipeline. These tools include:

    • Argo file stores: Separates I/O operations from data analysis.
    • OWC salinity calibration: Tools for data preprocessing related to Ocean Working Group (OWC) salinity calibration.
    • Reference dataset access: Facilitated access to reference datasets for comparison.
    • Topographic data: Access to topographic data specifically for trajectory analysis.
    • CLS altimetry QC: Easy access to CLS altimetry QC test results.
  2. Advanced data manipulation and features

    master

    Beyond basic fetching, argopy supports several advanced operations:

    • Data Transformation: Convert data between collections of individual measurements and collections of vertical profiles.
    • Interpolation: Interpolate irregularly sampled measurements onto standard pressure levels.
    • Caching: Cache fetched data locally to speed up subsequent requests and save bandwidth.
    • Local Fetching: Fetch data from a local copy of the Argo database instead of online servers.
    • Metadata/Index Lookup: Fetch only metadata (organized in index lookup tables) to determine regional Argo sampling without downloading full measurement datasets.
  3. Advanced argopy features and capabilities

    master

    Argopy provides several advanced capabilities for working with Argo data:

    • Filtering: Apply filters at fetch time (standard vs expert modes, QC flags, etc.).
    • Data Sources: Select between different sources like erddap, ftp, local, or argovis.
    • Data Manipulation: Perform operations like interpolation, binning, and working with profiles or points.
    • Visualisation: Generate trajectories, topography, and histograms.
    • Quality Control: Access tools like OWC and specialized figures.
    • Metadata: Access reference tables, deployment plans, topography, and DOIs.
    • Performance: Utilize caching and parallel data fetching to improve speed.
  4. Use the gdacfs store for GDAC files

    master

    The gdacfs class provides a generic file system interface for accessing Argo Global Data Assembly Centre (GDAC) files. It abstracts the underlying host protocol (local filesystem, HTTP, FTP, or S3), allowing you to write GDAC-agnostic code.

    When you create a gdacfs instance, it returns a specific store (like httpstore or s3store) with a prefixed directory. This means you can access files using paths relative to the GDAC root without including the root URL or path in every call.

    from argopy import gdacfs
    
    # Create a GDAC-agnostic file system instance
    fs = gdacfs("https://data-argo.ifremer.fr")
    
    # Access files using paths relative to the GDAC root
    fs.glob("dac/aoml/13857/*_meta.nc")
  5. Register custom Xarray argo accessor extensions

    master

    You can extend the Dataset.argo accessor by using the @register_argo_accessor decorator. This allows you to add custom methods and properties to Argo datasets, making them accessible via the .argo namespace.

    from argopy.extensions import register_argo_accessor, ArgoAccessorExtension
    import argopy
    import numpy as np
    
    @register_argo_accessor('floats')
    class WorkWithWMO(ArgoAccessorExtension):
        """Example of a new Argo dataset feature"""
    
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self._uid = argopy.utils.to_list(np.unique(self._obj["PLATFORM_NUMBER"].values))
    
        @property
        def wmo(self):
            return self._uid
    
        @property
        def N(self):
             return len(self.wmo)
    
    # Usage after registration:
    # ds.argo.floats.N
    # ds.argo.floats.wmo
  6. Understand the argopy user modes

    master

    To simplify data access and reduce complexity, argopy provides three different user modes. These modes control the level of verbosity and the amount of data processing/wrangling applied to the Argo measurements. Choosing the right mode allows you to focus on scientific analysis rather than managing complex Argo-specific metadata and quality control flags.

    User Modes

    • standard (Default): Designed for users who may not be experts in the Argo dataset. It hides or removes variables that are primarily meaningful to experts, providing a cleaner dataset for common scientific tasks.
    • research: A middle ground between standard and expert modes.
    • expert: Provides full access to all variables, reference tables, and raw data details, including complex quality control (QC) flags and adjusted parameters.

    How to choose a mode

    If you are unsure which mode to use, ask yourself if you know the following:

    1. What is a WMO number?
    2. What is the difference between Delayed and Real Time data modes?
    3. What is an adjusted parameter?
    4. What does a QC flag of 3 mean?

    If you cannot answer more than one of these questions, you should use the standard or research modes.

  7. Use the ArgoFloat store for specific WMO floats

    master

    The ArgoFloat class is a specialized store designed to facilitate loading and reading all Argo files associated with a specific WMO (World Meteorological Organization) float number. It handles transfer protocols and GDAC (Global Data Assembly Centre) path construction automatically, whether the data is hosted locally or remotely.

    from argopy import ArgoFloat
    WMO = 3902492
    # Fetch profile data directly
    ds = ArgoFloat(WMO).open_dataset('prof')
  8. Available Argo data sources in argopy

    master

    argopy can fetch data from three primary sources, each with different characteristics:

    1. erddap (Default): Uses the Ifremer ERDDAP server. It is highly efficient because it only downloads the specific data requested. It is based on mono-profile files from the GDAC.
    2. gdac: Accesses official Argo GDAC online servers (Ifremer or US HTTPS/FTP) or a local GDAC-compliant folder. This is useful for offline work or using a local mirror.
    3. argovis: Uses the Argovis server, which provides curated Argo data (QC=1 only) and is updated daily.

    To start using argopy, perform a standard import and reset options to ensure a clean state:

    import argopy
    from argopy import DataFetcher as ArgoDataFetcher
    argopy.reset_options()
  9. Switch between xarray and pandas data formats

    master

    By default, argopy provides data as an xarray.Dataset or a pandas.DataFrame. You can explicitly switch between these formats using the to_dataframe() or to_xarray() methods on a DataFetcher instance. This allows you to choose the data structure that best fits your specific analysis workflow.

    Internally, argopy also utilizes pyarrow.Table for data handling.

    from argopy import DataFetcher
    
    # Fetch a profile and convert it to a pandas DataFrame
    DataFetcher().profile(6902746, 34).to_dataframe()
  10. Access NVS data online or offline

    master

    Argopy includes local copies of NVS data so it can function offline. When offline, the data reflects the state at the time of the Argopy release. When online, it queries the NVS server directly.

    To configure online access, you can use the argopy.stores.NVS class with the following options:

    • nvs: The URL of the server.
    • cache: Boolean to enable/disable caching.
    • cachedir: Directory for cached files.
    • api_timeout: HTTP request timeout in seconds.

    Note: The NVS class is a singleton. Options must be defined during the first instantiation in a session to take effect.

    from argopy.stores import NVS
    
    # Initialize the NVS store (singleton)
    nvs = NVS(cache=True, cachedir='./cache')
    
    # Load vocabularies
    nvs.load_vocabulary('R27')
    
    # Load specific concepts
    nvs.load_concept('AANDERAA_OPTODE_3835')
    
    # Load mappings
    nvs.load_mapping('R24', 'R23')