Skip to content

Instantly share code, notes, and snippets.

@gmaze
Last active January 27, 2025 17:21
Show Gist options
  • Save gmaze/6924fc26405f42aa36fd5a22a64657ea to your computer and use it in GitHub Desktop.
Save gmaze/6924fc26405f42aa36fd5a22a64657ea to your computer and use it in GitHub Desktop.
Design for an Argo float in memory "data" model

Python class API for an Argo float

What would be an Argo float object in python and the associated methods/attributes ?

Basic API

Create an instance

Must be possible to point toward all possible GDAC hosts

from argopy import ArgoFloat

# Expected API
WMO = 6903091

# Create an instance using the float WMO:
af = ArgoFloat(WMO)  # Use argopy 'gdac' option by default
af = ArgoFloat(WMO, host='/home/ref-argo/gdac')  # Use your local GDAC copy
af = ArgoFloat(WMO, host='https')  # Shortcut for https://data-argo.ifremer.fr
af = ArgoFloat(WMO, host='ftp')    # shortcut for ftp://ftp.ifremer.fr/ifremer/argo
af = ArgoFloat(WMO, host='s3')     # Shortcut for s3://argo-gdac-sandbox/pub

Access GDAC netcdf files from 'dac' folder

Get a dictionary with all available datasets for this float:

af.ls_dataset() 

then simply open dataset using any key from the list of available datasets dictionary:

ds = af.open_dataset('prof')
ds = af.open_dataset('meta')
ds = af.open_dataset('tech')
ds = af.open_dataset('Rtraj')
ds = af.open_dataset('Sprof')

Access profile data

for core-deep floats

af.profiles[1]    # Return xarray dataset with data from: profiles/<WMO>_001.nc or profiles/D<WMO>_001.nc    # Ascent by default
af.profilesD[1]   # Return xarray dataset with data from: profiles/<WMO>_001D.nc or profiles/D<WMO>_001D.nc  # Explicitly load descent profile

for BGC floats

af.profiles[1]    # Return xarray dataset with data from: profiles/R<WMO>_001.nc    # Ascent by default
af.profilesD[1]   # Return xarray dataset with data from: profiles/R<WMO>_001D.nc   # Explicitly load descent profile
af.profilesB[1]   # Return xarray dataset with data from: profiles/BR<WMO>_001.nc   # Ascent by default
af.profilesBD[1]  # Return xarray dataset with data from: profiles/BR<WMO>_001D.nc  # Explicitly load descent profile
af.profilesS[1]   # Return xarray dataset with data from: profiles/SR<WMO>_001.nc   # Ascent by default
af.profilesSD[1]  # Return xarray dataset with data from: profiles/SR<WMO>_001D.nc  # Explicitly load descent profile

Misc attributes

af.index  # Return pandas dataframe with <WMO> profile index match (but which index ?)
af.N_CYCLES   # Return nb of cycles (not to be confused with profiles)
af.N_LEVELS # Return max nb of vertical levels
af.dac  # Return name of the float DAC
af.path # Return Path or url toward the GDAC float folder/bucket
af.json_meta  # Return Float json scheme like https://github.com/euroargodev/sensor_metadata_json/blob/main/json_floats/float-SBE-NAVIS_EBR-1101.json
af.params  # Return the list of parameters
af.sensors  # Return the list of sensors

Plot

af.monitor() # Open EuroArgo-Fleet monitoring webpage
af.plot(12) # Open profile webpage like: https://dataselection.euro-argo.eu/cycle/4187022
af.plot(cyc=12) # Open profile webpage like: https://dataselection.euro-argo.eu/cycle/4187022

Iterators

Use with ArgoIndex

for float in ArgoIndex().search_lat_lon([lon_min, lon_max, lat_min, lat_max]).iterfloats():
  float.WMO  # 'float' is a ArgoFloat instance

Export

af = ArgoFloat(WMO)

ds = af.open_dataset('prof')

# Do some stuff on ds
# [...]

af.to_netcdf(ds)

ds.argo.to_netcdf(af, 'updated.nc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment