argopy.xarray.ArgoAccessor.reduce_profile#
- ArgoAccessor.reduce_profile(func, params=[], **kwargs) DataArray[source]#
Apply a vectorized function for unlabeled arrays for each Argo profiles
This 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.
- Parameters:
func (callable) β A function that takes one or more profile parameters as input, and return a single value as output.
params ([List, str]) β Name, or list of names, of the dataset parameters expected by
func. All of these parameters must haveN_LEVELSas a dimension.**kwargs (dict, optional) β Keyword arguments to be passed to
func.
- Return type:
Examples
Example 1#from argopy import ArgoFloat dsp = ArgoFloat(6901864).open_dataset('Sprof') 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])] # Apply reduce function on all profiles: dsp.argo.reduce_profile(max_salinity_depth, params=['PRES', 'PSAL'])
Example 2: with keyword arguments#from argopy import ArgoFloat dsp = ArgoFloat(6901864).open_dataset('Sprof') 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 # Apply reduce function on all profiles: dsp.argo.reduce_profile(max_salinity_depth, params=['PRES', 'PSAL'], max_layer=700)
Example 3: automatically parallelize func with Dask#from argopy import ArgoFloat dsp = ArgoFloat(6901864).open_dataset('Sprof') # Make sure we're working with dask arrays dsp = dsp.chunk({'N_PROF': 10}) 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])] # Apply reduce function on all profiles: da = dsp.argo.reduce_profile(max_salinity_depth, params=['PRES', 'PSAL']) # Return a dask array da.compute()