Skip to content

Commit 68f01c7

Browse files
committed
Define base UncOutput class
1 parent 6906784 commit 68f01c7

2 files changed

Lines changed: 69 additions & 13 deletions

File tree

climada/engine/unsequa/calc_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import numpy as np
2929
import pandas as pd
3030

31-
from climada.engine.unsequa.unc_output import UncOutput
31+
from climada.engine.unsequa.unc_output import UncBaseOutput
3232
from climada.util.value_representation import sig_dig as u_sig_dig
3333

3434
LOGGER = logging.getLogger(__name__)
@@ -266,7 +266,7 @@ def make_sample(self, N, sampling_method="saltelli", sampling_kwargs=None):
266266
df_samples.attrs["sampling_method"] = sampling_method
267267
df_samples.attrs["sampling_kwargs"] = tuple(sampling_kwargs.items())
268268

269-
unc_output = UncOutput(df_samples)
269+
unc_output = UncBaseOutput(df_samples)
270270
LOGGER.info("Effective number of made samples: %d", unc_output.n_samples)
271271
return unc_output
272272

climada/engine/unsequa/unc_output.py

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,22 @@ class UncOutput(ABC):
112112
@abstractmethod
113113
def __init__(self, samples_df, unit=None):
114114
"""
115-
Initialize Uncertainty Data object.
116-
117-
Parameters
118-
----------
119-
samples_df : pandas.DataFrame
120-
input parameters samples
121-
unit : str, optional
122-
value unit
115+
Empty constructor to be overwritten by subclasses
123116
"""
124-
# Data
125-
self.samples_df = samples_df
126-
self.unit = unit
117+
# """
118+
# Initialize Uncertainty Data object.
119+
120+
#
121+
# Parameters
122+
# ----------
123+
# samples_df : pandas.DataFrame
124+
# input parameters samples
125+
# unit : str, optional
126+
# value unit
127+
# """
128+
## Data
129+
# self.samples_df = samples_df
130+
# self.unit = unit
127131

128132
def order_samples(self, by_parameters):
129133
"""
@@ -1235,6 +1239,58 @@ def from_hdf5(filename):
12351239
return unc_data
12361240

12371241

1242+
class UncBaseOutput(UncOutput):
1243+
"""
1244+
Class to store and plot uncertainty and sensitivity analysis output data
1245+
1246+
This is the base class to store uncertainty and sensitivity outputs of an
1247+
analysis done on climada.engine.impact.Impact() or
1248+
climada.engine.costbenefit.CostBenefit() object.
1249+
1250+
Attributes
1251+
----------
1252+
samples_df : pandas.DataFrame
1253+
Values of the sampled uncertainty parameters. It has n_samples rows
1254+
and one column per uncertainty parameter.
1255+
sampling_method : str
1256+
Name of the sampling method from SAlib.
1257+
https://salib.readthedocs.io/en/latest/api.html#
1258+
n_samples : int
1259+
Effective number of samples (number of rows of samples_df)
1260+
param_labels : list
1261+
Name of all the uncertainty parameters
1262+
distr_dict : dict
1263+
Comon flattened dictionary of all the distr_dict of all input variables.
1264+
It represents the distribution of all the uncertainty parameters.
1265+
problem_sa : dict
1266+
The description of the uncertainty variables and their
1267+
distribution as used in SALib.
1268+
https://salib.readthedocs.io/en/latest/basics.html.
1269+
"""
1270+
1271+
_metadata = [
1272+
"sampling_method",
1273+
"sampling_kwargs",
1274+
"sensitivity_method",
1275+
"sensitivity_kwargs",
1276+
]
1277+
1278+
def __init__(self, samples_df, unit=None):
1279+
"""
1280+
Initialize Uncertainty Data object.
1281+
1282+
Parameters
1283+
----------
1284+
samples_df : pandas.DataFrame
1285+
input parameters samples
1286+
unit : str, optional
1287+
value unit
1288+
"""
1289+
# Data
1290+
self.samples_df = samples_df
1291+
self.unit = unit
1292+
1293+
12381294
class UncImpactOutput(UncOutput):
12391295
"""Extension of UncOutput specific for CalcImpact, returned by the
12401296
uncertainty() method.

0 commit comments

Comments
 (0)