Data

class uncertainpy.Data(filename=None, backend=u'auto', logger_level=u'info')[source]

Store the results of each statistical metric calculated from the uncertainty quantification and sensitivity analysis for each model/features.

Has all standard dictionary methods, such as items, value, contains and so implemented. Can be indexed as a regular dictionary with model/feature names as keys and returns a DataFeature object that contains the data for all statistical metrics for that model/feature. Additionally it contains information on how the calculations was performed

Parameters:
  • filename (str, optional) – Name of the file to load data from. If None, no data is loaded. Default is None.
  • backend ({“auto”, “hdf5”, “exdir”}, optional) – The fileformat used to save and load data to/from file. “auto” assumes the filenamess ends with either “.h5” for HDF5 files or “.exdir” for Exdir files. If unknown fileextension defaults to saving as HDF5 files. “hdf5” saves and loads files from HDF5 files. “exdir” saves and loads files from Exdir files. Default is “auto”.
  • logger_level ({“info”, “debug”, “warning”, “error”, “critical”, None}, optional) – Set the threshold for the logging level. Logging messages less severe than this level is ignored. If None, no logging to file is performed Default logger level is “info”.
Variables:
  • uncertain_parameters (list) – A list of the uncertain parameters in the uncertainty quantification.
  • model_name (str) – Name of the model.
  • incomplete (list) – List of all model/features that have missing model/feature evaluations.
  • error (list) – List of all model/features that were irregular, but not set to be interpolated.
  • method (str) – A string that describes the method used to perform the uncertainty quantification.
  • data (dictionary) – A dictionary with a DataFeature for each model/feature.
  • data_information (list) – List of attributes containing additional information.

Notes

The statistical metrics calculated for each feature and model in Uncertainpy are:

  • evaluations - the results from the model/feature evaluations.
  • time - the time of the model/feature.
  • mean - the mean of the model/feature.
  • variance. - the variance of the model/feature.
  • percentile_5 - the 5th percentile of the model/feature.
  • percentile_95 - the 95th percentile of the model/feature.
  • sobol_first - the first order Sobol indices (sensitivity) of the model/feature.
  • sobol_first_average - the average of the first order Sobol indices (sensitivity) of the model/feature.
  • sobol_total - the total order Sobol indices (sensitivity) of the model/feature.
  • sobol_total_average - the average of the total order Sobol indices (sensitivity) of the model/feature.
Raises:ValueError – If unsupported backend is chosen.
__delitem__(feature)[source]

Delete data for feature.

Parameters:feature (str) – Name of feature.
__getitem__(feature)[source]

Get the DataFeature containing the data for feature.

Parameters:feature (str) – Name of feature/model.
Returns:The DataFeature containing the data for feature.
Return type:DataFeature
__iter__()[source]

Iterate over each feature/model that has not errored.

Yields:str – Name of feature/model.
__len__()[source]

Get the number of model/features that have not errored.

Returns:The number of model/features that have not errored.
Return type:int
__setitem__(feature, data)[source]

Set data for feature. Data must be a DataFeature object.

Parameters:
  • feature (str) – Name of feature/model.
  • data (DataFeature) – DataFeature with the data for feature.
Raises:

ValueError – If data is not a DataFeature.

__str__()[source]

Convert all data to a readable string.

Returns:A human readable string of all stored data.
Return type:str
add_features(features)[source]

Add features (which contain no data).

Parameters:features ({str, list}) – Name of feature to add, or list of features to add.
clear()[source]

Clear all data.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_labels(feature)[source]

Get labels for a feature. If no labels are defined, returns a list with the correct number of empty strings.

Parameters:feature (str) – Name of the model or a feature.
Returns:A list of labels for plotting, [x-axis, y-axis, z-axis]. If no labels are defined (labels = []), returns a list with the correct number of empty strings.
Return type:list
items() → list of D's (key, value) pairs, as 2-tuples
iteritems() → an iterator over the (key, value) items of D
iterkeys() → an iterator over the keys of D
itervalues() → an iterator over the values of D
keys() → list of D's keys
load(filename)[source]

Load data from a HDF5 or Exdir file with name filename.

Parameters:

filename (str) – Name of the file to load data from.

Raises:
  • ImportError – If h5py is not installed.
  • ImportError – If Exdir is not installed.
ndim(feature)[source]

Get the number of dimensions of a feature.

Parameters:feature (str) – Name of the model or a feature.
Returns:The number of dimensions of the model/feature result. Returns None if the feature has no evaluations or only contains nan.
Return type:int, None
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

remove_only_invalid_features()[source]

Remove all features that only have invalid results (NaN).

save(filename)[source]

Save data to a HDF5 or Exdir file with name filename.

Parameters:

filename (str) – Name of the file to load data from.

Raises:
  • ImportError – If h5py is not installed.
  • ImportError – If Exdir is not installed.
seed

Seed used in the calculations.

Parameters:new_seed ({None, int}) – Seed used in the calculations. If None, converted to “”.
Returns:seed – Seed used in the calculations.
Return type:{int, str}
setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → list of D's values