Computing new data#
Once you fetched Argo data, argopy comes with a handy xarray.Dataset accessor argo to perform new data computation. This means that if your dataset is named ds, then you can use ds.argo to access more argopy functions. The full list is available in the API documentation page Dataset.argo (xarray accessor).
In this section, we present how argopy can help compute new, complementary, data from Argo measurements and parameters.
TEOS-10 variables#
You can compute additional ocean variables from TEOS-10. The default list of variables is: âSAâ, âCTâ, âSIG0â, âN2â, âPVâ, âPTEMPâ (âSOUND_SPEEDâ, âCNDCâ are optional). Simply raise an issue to add a new one.
This can be done using the Dataset.argo.teos10() method and indicating the list of variables you want to compute:
In [1]: from argopy import DataFetcher
In [2]: ds = DataFetcher().float(2901623).to_xarray()
In [3]: ds.argo.teos10(['SA', 'CT', 'PV'])
Out[3]:
<xarray.Dataset> Size: 1MB
Dimensions: (N_POINTS: 8341)
Coordinates:
LATITUDE (N_POINTS) float64 67kB 0.012 0.012 0.012 ... 3.388 3.388
LONGITUDE (N_POINTS) float64 67kB 92.28 92.28 92.28 ... 94.77 94.77
TIME (N_POINTS) datetime64[ns] 67kB 2010-05-14T03:35:00 ... 2...
* N_POINTS (N_POINTS) int64 67kB 0 1 2 3 4 ... 8337 8338 8339 8340
Data variables: (12/18)
CYCLE_NUMBER (N_POINTS) int64 67kB 0 0 0 0 0 0 0 ... 96 96 96 96 96 96
DATA_MODE (N_POINTS) <U1 33kB 'D' 'D' 'D' 'D' 'D' ... 'D' 'D' 'D' 'D'
DIRECTION (N_POINTS) <U1 33kB 'D' 'D' 'D' 'D' 'D' ... 'A' 'A' 'A' 'A'
PLATFORM_NUMBER (N_POINTS) int64 67kB 2901623 2901623 ... 2901623 2901623
POSITION_QC (N_POINTS) int64 67kB 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
PRES (N_POINTS) float32 33kB 17.0 25.0 ... 1.112e+03 1.137e+03
... ...
TEMP_ERROR (N_POINTS) float32 33kB 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
TEMP_QC (N_POINTS) int64 67kB 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
TIME_QC (N_POINTS) int64 67kB 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
SA (N_POINTS) float64 67kB 34.44 34.44 34.44 ... 35.09 35.08
CT (N_POINTS) float64 67kB 30.2 30.2 30.2 ... 6.078 5.959
PV (N_POINTS) float64 67kB nan -1.78e-15 ... 1.573e-12 nan
Attributes:
DATA_ID: ARGO
DOI: http://doi.org/10.17882/42182
Fetched_from: erddap.ifremer.fr
Fetched_by: docs
Fetched_date: 2026/07/01
Fetched_constraints: WMO2901623
Fetched_uri: https://erddap.ifremer.fr/erddap/tabledap/ArgoFloat...
Processing_history: [PRES,TEMP,PSAL] real-time and adjusted/delayed var...
In [4]: ds['SA']
Out[4]:
<xarray.DataArray 'SA' (N_POINTS: 8341)> Size: 67kB
array([34.43600343, 34.43701333, 34.43703491, ..., 35.09205948,
35.09221486, 35.08231586])
Coordinates:
LATITUDE (N_POINTS) float64 67kB 0.012 0.012 0.012 ... 3.388 3.388 3.388
LONGITUDE (N_POINTS) float64 67kB 92.28 92.28 92.28 ... 94.77 94.77 94.77
TIME (N_POINTS) datetime64[ns] 67kB 2010-05-14T03:35:00 ... 2013-01...
* N_POINTS (N_POINTS) int64 67kB 0 1 2 3 4 5 ... 8336 8337 8338 8339 8340
Attributes:
long_name: Absolute Salinity
standard_name: sea_water_absolute_salinity
unit: g/kg
Nutrient and carbonate system variables#
For BGC, it may be possible to complement a dataset with predictions of the water-column nutrient concentrations and carbonate system variables.
argopy provides three models to perform such predictions:
CANYON-MED (Mediterranean Sea)#
CANYON-MED is a model that was developed for data located in the Mediterranean Sea. CANYON-MED is a Regional Neural Network Approach to Estimate Water-Column Nutrient Concentrations and Carbonate System Variables in the Mediterranean Sea [1] [2]. When using this method, please cite the paper [1].
This model is available in argopy as an extension to the argo accessor: Dataset.argo.canyon_med. It can be used to predict PO4, NO3, DIC, SiOH4, AT and pHT.
As an example, letâs load one float data with oxygen measurements:
from argopy import DataFetcher
ArgoSet = DataFetcher(ds='bgc', mode='standard', params='DOXY', measured='DOXY').float(1902605)
ds = ArgoSet.to_xarray()
We can then predict all possible variables:
ds.argo.canyon_med.predict()
or select variables to predict, like PO4:
ds = ds.argo.canyon_med.predict('PO4')
ds['PO4']
CANYON-B (Global Ocean)#
CANYON-B is a Bayesian neural network approach that estimates water-column nutrient concentrations (NO3, PO4, SiOH4) and carbonate system variables (AT, DIC, pHT, pCO2) ([3]). It provides more robust neural networks than CANYON-MED and includes a local uncertainty estimate for each predicted parameter.
This model is available in argopy as an extension to the argo accessor: Dataset.argo.canyon_b. It can be used to predict NO3, PO4, SiOH4, AT, DIC, pHT and pCO2 with uncertainty estimates.
As an example, letâs load one float data with oxygen measurements:
from argopy import DataFetcher
ArgoSet = DataFetcher(ds='bgc', mode='standard', params='DOXY', measured='DOXY').float(1902605)
ds = ArgoSet.to_xarray()
We can then predict all possible variables:
ds.argo.canyon_b.predict()
or select specific variable(s) to predict:
ds.argo.canyon_b.predict(['PO4', 'NO3'])
In addition, the user can provide input errors for pressure (float), temperature (float), salinity (float) and oxygen (float or array):
ds.argo.canyon_b.predict('PO4', epres = 0.5, etemp = 0.005, epsal = 0.005, edoxy = 0.01)
and include uncertainty estimates in the output:
ds = ds.argo.canyon_b.predict('PO4', epres = 0.5, etemp = 0.005, epsal = 0.005, edoxy = 0.01, include_uncertainties=True)
ds['PO4'] # PO4 estimates
ds['PO4_ci'] # Uncertainty on PO4
ds['PO4_cim'] # Measurement uncertainty on PO4
ds['PO4_cin'] # Uncertainty for Bayesian neural network mapping on PO4
ds['PO4_cii'] # Uncertainty due to input errors on PO4
CONTENT (Global Ocean)#
CONTENT is a combination of CANYON-B Bayesian neural network mappings of AT, CT, pH and pCO2 made consistent with carbonate chemistry constraints for any set of water column P, T, S, O2 location data as an alternative to (spatial) climatological interpolation ([3])
This model is available in argopy as an extension to the argo accessor: Dataset.argo.content. This model refines CANYON-Bâs estimates of AT, DIC, pHT and pCO2 and provides uncertainty estimates.
Note that CANYON-Bâs estimates of NO3, PO4 and SiOH4 are also returned by default and are unchanged when using CONTENT.
As an example, letâs load one float data with oxygen measurements:
from argopy import DataFetcher
ArgoSet = DataFetcher(ds='bgc', mode='standard', params='DOXY', measured='DOXY').float(1902605)
ds = ArgoSet.to_xarray()
We predict all carbonate system variables (with CONTENT, it is not possible to predict one variable only):
ds.argo.content.predict()
In addition, the user can provide input errors for pressure (float), temperature (float), salinity (float) and oxygen (float or array):
ds.argo.content.predict(epres = 0.5, etemp = 0.005, epsal = 0.005, edoxy = 0.01)
and include uncertainty estimates in the output:
ds.argo.content.predict(epres = 0.5, etemp = 0.005, epsal = 0.005, edoxy = 0.01, include_uncertainties=True)
ds['AT'] # AT estimates
ds['AT_SIGMA'] # Total uncertainty on AT
ds['AT_SIGMA_MIN'] # Uncertainty propagated from the input variables on AT
Optical modeling#
This extension provides methods to compute standard variables from optical modeling of the upper ocean. This feature is available in argopy as an extension to the argo accessor: Dataset.argo.optic. It can be used to:
compute the depth of the euphotic zone, from PAR:
Dataset.argo.optic.Zeucompute the first optical depth, from depth of the euphotic zone:
Dataset.argo.optic.Zpdcompute the depth where PAR reaches some threshold value:
Dataset.argo.optic.Z_iPAR_thresholdsearch and qualify Deep Chlorophyll Maxima:
Dataset.argo.optic.DCM
As an example, letâs load one BGC float data with DOWNWELLING_PAR measurements:
ds = DataFetcher(ds='bgc', mode='expert', params='DOWNWELLING_PAR').float(6901864).data
dsp = ds.argo.point2profile()
Note that we could have loaded these data with a ArgoFloat:
from argopy import ArgoFloat
dsp = ArgoFloat(6901864).open_dataset('Sprof')
We can then simply call on the extension methods to add variables to the dataset:
dsp.argo.optic.Zeu()
dsp.argo.optic.Zeu(method='percentage', max_surface=5.)
dsp.argo.optic.Zeu(method='KdPAR', layer_min=10., layer_max=50.)
dsp.argo.optic.Zpd()
dsp.argo.optic.Z_iPAR_threshold(threshold=15.)
For the Deep Chlorophyll Maxima diagnostic, we need CHLA data, so letâs load data from another BGC float:
from argopy import ArgoFloat
dsp = ArgoFloat(1902303).open_dataset('Sprof')
dsp.argo.optic.DCM()
Per profile custom diagnostic#
If you want to execute your own diagnostic method on a collection of Argo profiles, argopy provides an efficient method to do so, based on the xarray.apply_ufunc() method.
The Dataset.argo.reduce_profile() method allows to execute a per profile diagnostic function very efficiently. Such a diagnostic function takes vertical profiles as input and return a single value as output (see examples below). Typical usage example would include computation of mixed layer depth or euphotic layer depth.
In other words, the Dataset.argo.reduce_profile() applies a vectorized function for unlabeled arrays on each Argo profiles loaded with argopy.
Diagnostic without option#
Letâs start with a trivial example. We load one BGC float synthetic data:
from argopy import ArgoFloat
dsp = ArgoFloat(6901864).open_dataset('Sprof')
we then define a function that compute pressure of the salinity maximum. Note that this function deals with numpy or dask 1D arrays:
def max_salinity_depth(pres, psal):
# A dummy function returning depth of the maximum salinity
idx = ~np.logical_or(np.isnan(pres), np.isnan(psal))
return pres[idx][np.argmax(psal[idx])]
and apply this function to all float profiles:
dsp.argo.reduce_profile(max_salinity_depth, params=['PRES', 'PSAL'])
argopy and xarray will handle all the axis and dimensions manipulation, so that you can focus on writing a reducer function dealing with 1D arrays for each requested parameters.
Diagnostic with option#
A more complex example will imply a function taking arguments. In the following we use the same trivial max_salinity_depth function as above, but provide a maximum depth argument.
def max_salinity_depth(pres, psal, max_layer=1000.):
# A dummy function returning depth of the maximum salinity above max_layer:
idx = ~np.logical_or(np.isnan(pres), np.isnan(psal))
idx = np.logical_and(idx, pres<=max_layer)
if np.any(idx):
return pres[idx][np.argmax(psal[idx])]
else:
return np.NaN
Simply provide the function argument to the reducer:
dsp.argo.reduce_profile(max_salinity_depth,
params=['PRES', 'PSAL'],
max_layer=400.)
Optimisation with Dask#
At last, note that you can optimize this computation using Dask by simply chunking the dataset along the N_PROF dimension.
from argopy import ArgoFloat
dsp = ArgoFloat(6901864).open_dataset('Sprof')
Make sure weâre working with dask arrays:
dsp = dsp.chunk({'N_PROF': 10})
In this case, the Dataset.argo.reduce_profile() will return a dask array:
da = dsp.argo.reduce_profile(max_salinity_depth, params=['PRES', 'PSAL'])
da
And we need to trigger the computation to have it done:
da.compute()