API reference
This page provides an auto-generated summary of pyXpcm’s API. For more details and examples, refer to the relevant chapters in the main part of the documentation.
Top-level PCM functions
Creating a PCM
|
Profile Classification Model class constructor |
|
Load a PCM model from netcdf file |
Attributes
Return the number of classes |
|
Return the number of features |
|
Return features definition dictionnary |
Computation
|
Estimate PCM parameters |
|
Estimate PCM parameters and predict classes. |
|
Predict labels for profile samples |
|
Predict posterior probability of each components given the data |
|
Compute the per-sample average log-likelihood of the given data |
|
Compute Bayesian information criterion for the current model on the input dataset |
Low-level PCM properties and functions
Return a |
|
|
Extract from N-d array a X(feature,sample) 2-d array and vertical dimension z |
|
Create a DataArray from a numpy array and sampling dimensions |
Plotting
Access plotting functions |
Plot PCM Contents
|
Plot q-th quantiles of a dataArray for each PCM components |
|
Plot PCM scalers properties |
|
Plot PCM reducers properties |
|
Plot preprocessed features as pairwise scatter plots |
|
Plot PCM registered timing of operations |
Tools
|
Return categorical colormaps |
|
Add a colorbar to the current plot with centered ticks on discrete colors |
|
Return (figure, axis) with one subplot per cluster |
|
Add latitude/longitude grid line and labels to a cartopy geoaxes |
Statistics
Access statistics functions |
|
|
Compute q-th quantile of a |
|
Compute classification robustness |
|
Digitize classification robustness |
Save/load PCM models
|
Save a PCM to a netcdf file |
|
Load a PCM model from netcdf file |
Helper
|
Open a dataset from the pyXpcm online data repository (requires internet). |
Xarray pyxpcm name space
Provide accessor to enhance interoperability between xarray and pyxpcm.
Provide a scope named pyxpcm as accessor to xarray.Dataset objects.
- class pyxpcm.xarray.pyXpcmDataSetAccessor[source]
Class registered under scope
pyxpcmto accessxarray.Datasetobjects.- add(da)[source]
Add a
xarray.DataArrayto thisxarray.Dataset
- bic(this_pcm, **kwargs)[source]
Compute Bayesian information criterion for the current model on the input dataset
Only for a GMM classifier
- Parameters:
- ds: :class:`xarray.Dataset`
The dataset to work with
- features: dict()
Definitions of PCM features in the input
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dim: str
Name of the vertical dimension in the input
xarray.Dataset
- Returns:
- bic: float
The lower the better
- drop_all()[source]
Remove
xarray.DataArraycreated with pyXpcm front thisxarray.Dataset
- feature_dict(this_pcm, features=None)[source]
Return dictionary of features for this
xarray.Datasetand a PCM- Parameters:
- pcm
pyxpcm.pcmmodel.pcm - featuresdict
Keys are PCM feature name, Values are corresponding
xarray.Datasetvariable names
- pcm
- Returns:
- dict()
Dictionary where keys are PCM feature names and values the corresponding
xarray.Datasetvariables
- fit(this_pcm, **kwargs)[source]
Estimate PCM parameters
For a PCM, the fit method consists in the following operations:
- pre-processing
interpolation to the
feature_axislevels of the modelscaling
reduction
estimate classifier parameters
- Parameters:
- ds: :class:`xarray.Dataset`
The dataset to work with
- features: dict()
Definitions of PCM features in the input
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dim: str
Name of the vertical dimension in the input
xarray.Dataset
- Returns:
- self
- fit_predict(this_pcm, **kwargs)[source]
Estimate PCM parameters and predict classes.
This method add these properties to the PCM object:
llh: The log likelihood of the model with regard to new data
- Parameters:
- ds: :class:`xarray.Dataset`
The dataset to work with
- features: dict()
Definitions of PCM features in the input
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dim: str
Name of the vertical dimension in the input
xarray.Dataset- inplace: boolean, False by default
If False, return a
xarray.DataArraywith predicted labels If True, return the inputxarray.Datasetwith labels added as a newxarray.DataArray- name: string (‘PCM_LABELS’)
Name of the DataArray holding labels.
- Returns:
xarray.DataArrayComponent labels (if option ‘inplace’ = False)
- or
xarray.DatasetInput dataset with component labels as a ‘PCM_LABELS’ new
xarray.DataArray(if option ‘inplace’ = True)
- mask(this_pcm, features=None, dim=None)[source]
Create a mask where all PCM features are defined
Create a mask where all feature profiles are not null over the PCM feature axis.
- Parameters:
- :class:`pyxpcm.pcmmodel.pcm`
- featuresdict()
Definitions of this_pcm features in the
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dimstr
Name of the vertical dimension in the
xarray.Dataset. If not specified or set to None, dim is identified as thexarray.DataArrayvariables with attributes ‘axis’ set to ‘z’.
- Returns:
- predict(this_pcm, inplace=False, **kwargs)[source]
Predict labels for profile samples
This method add these properties to the PCM object:
llh: The log likelihood of the model with regard to new data
- Parameters:
- ds: :class:`xarray.Dataset`
The dataset to work with
- features: dict()
Definitions of PCM features in the input
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dim: str
Name of the vertical dimension in the input
xarray.Dataset- inplace: boolean, False by default
If False, return a
xarray.DataArraywith predicted labels If True, return the inputxarray.Datasetwith labels added as a newxarray.DataArray- name: str, default is ‘PCM_LABELS’
Name of the
xarray.DataArraywith labels
- Returns:
xarray.DataArrayComponent labels (if option ‘inplace’ = False)
- or
xarray.DatasetInput dataset with Component labels as a ‘PCM_LABELS’ new
xarray.DataArray(if option ‘inplace’ = True)
- predict_proba(this_pcm, **kwargs)[source]
Predict posterior probability of each components given the data
This method adds these properties to the PCM instance:
llh: The log likelihood of the model with regard to new data
- Parameters:
- ds: :class:`xarray.Dataset`
The dataset to work with
- features: dict()
Definitions of PCM features in the input
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dim: str
Name of the vertical dimension in the input
xarray.Dataset- inplace: boolean, False by default
If False, return a
xarray.DataArraywith predicted probabilities If True, return the inputxarray.Datasetwith probabilities added as a newxarray.DataArray- name: str, default is ‘PCM_POST’
Name of the DataArray with prediction probability (posteriors)
- classdimname: str, default is ‘pcm_class’
Name of the dimension holding classes
- Returns:
xarray.DataArrayProbability of each Gaussian (state) in the model given each sample (if option ‘inplace’ = False)
- or
xarray.DatasetInput dataset with Component Probability as a ‘PCM_POST’ new
xarray.DataArray(if option ‘inplace’ = True)
- quantile(this_pcm, inplace=False, **kwargs)[source]
Compute q-th quantile of a
xarray.DataArrayfor each PCM components- Parameters:
- q: float in the range of [0,1] (or sequence of floats)
Quantiles to compute, which must be between 0 and 1 inclusive.
- of: str
Name of the
xarray.Datasetvariable to compute quantiles for.- using: str
Name of the
xarray.Datasetvariable with classification labels to use. Use ‘PCM_LABELS’ by default.- outname: ‘PCM_QUANT’ or str
Name of the
xarray.DataArraywith quantile- keep_attrs: boolean, False by default
Preserve
ofxarray.Datasetattributes or not in the new quantile variable.
- Returns:
xarray.Datasetwith shape (K, n_quantiles, N_z=n_features)- or
xarray.DataArraywith shape (K, n_quantiles, N_z=n_features)
- robustness(this_pcm, inplace=False, **kwargs)[source]
Compute classification robustness
- Parameters:
- name: str, default is ‘PCM_POST’
Name of the
xarray.DataArraywith prediction probability (posteriors)- classdimname: str, default is ‘pcm_class’
Name of the dimension holding classes
- outname: ‘PCM_ROBUSTNESS’ or str
Name of the
xarray.DataArraywith robustness- inplace: boolean, False by default
If False, return a
xarray.DataArraywith robustness If True, return the inputxarray.Datasetwith robustness added as a newxarray.DataArray
- Returns:
xarray.Datasetif inplace=True- or
xarray.DataArrayif inplace=False
- robustness_digit(this_pcm, inplace=False, **kwargs)[source]
Digitize classification robustness
- Parameters:
- ds: :class:`xarray.Dataset`
Input dataset
- name: str, default is ‘PCM_POST’
Name of the
xarray.DataArraywith prediction probability (posteriors)- classdimname: str, default is ‘pcm_class’
Name of the dimension holding classes
- outname: ‘PCM_ROBUSTNESS_CAT’ or str
Name of the
xarray.DataArraywith robustness categories- inplace: boolean, False by default
If False, return a
xarray.DataArraywith robustness If True, return the inputxarray.Datasetwith robustness categories added as a newxarray.DataArray
- Returns:
xarray.Datasetif inplace=True- or
xarray.DataArrayif inplace=False
- sampling_dim(this_pcm, features=None, dim=None)[source]
Return the list of dimensions to be stacked for sampling
- Parameters:
- pcm
pyxpcm.pcm - featuresNone (default) or dict()
Keys are PCM feature name, Values are corresponding
xarray.Datasetvariable names. It set to None, all PCM features are used.- dimNone (default) or str()
The
xarray.Datasetdimension to use as vertical axis in all features. If set to None, it is automatically set to the dimension with an attributeaxisset toZ.
- pcm
- Returns:
- dict()
Dictionary where keys are
xarray.Datasetvariable names of features and values are another dictionary with the list of sampling dimension in DIM_SAMPLING key and the name of the vertical axis in the DIM_VERTICAL key.
- score(this_pcm, **kwargs)[source]
Compute the per-sample average log-likelihood of the given data
- Parameters:
- ds: :class:`xarray.Dataset`
The dataset to work with
- features: dict()
Definitions of PCM features in the input
xarray.Dataset. If not specified or set to None, features are identified usingxarray.DataArrayattributes ‘feature_name’.- dim: str
Name of the vertical dimension in the input
xarray.Dataset
- Returns:
- log_likelihood: float
In the case of a GMM classifier, this is the Log likelihood of the Gaussian mixture given data
- split()[source]
Split pyXpcm variables from the original
xarray.Dataset- Returns:
- list of
xarray.Dataset,xarray.Dataset Two DataSest: one with pyXpcm variables, one with the original DataSet
- list of