StudyManager References¶
The examples in the API reference use the synthetic platform of Synthetic Test Data. They use these names without an import: pd (pandas), study = make_dummy_study() and dataset = study.scen.get_dataset('base'). An example also uses the names that its own module defines, for example the class it documents. It imports all other names.
StudyManager
¶
The scenarios and the comparisons of a study, each as a collection with one fetch interface.
scen: the scenario datasets, aDatasetConcatCollection.comp: the comparisons, aDatasetConcatCollectionOfComparisons. A comparison gives the variation minus its reference.scen_comp: the scenarios and the comparisons, with the extra column leveltypeon top ('scenario' or 'comparison').
Each collection concatenates the data of its datasets along the columns,
with the dataset name in the level dataset. add_scenario and
add_comparison add datasets after creation.
Attributes:
| Name | Type | Description |
|---|---|---|
scen |
DatasetConcatCollection
|
The scenario datasets. |
comp |
DatasetConcatCollectionOfComparisons
|
The scenario comparisons. |
scen_comp |
DatasetConcatCollection
|
The scenarios and the comparisons. |
Examples:
>>> from mesqual.datasets import DatasetConfig
>>> from mesqual.testing import DummyDataset, DummyScenario
>>> base = DummyScenario(name='base')
>>> study = StudyManager.factory_from_scenarios(
... scenarios=[DummyDataset(base), DummyDataset(base.replace(name='high_demand', demand_factor=1.2))],
... comparisons=[('high_demand', 'base')],
... )
>>> prices = study.scen_comp.fetch('Node.Results.price')
>>> prices.columns.droplevel('Node').unique().tolist()
[('scenario', 'base'), ('scenario', 'high_demand'), ('comparison', 'high_demand vs base')]
A study config applies to all three collections:
>>> quarter_hourly = base.replace(resolution='15min')
>>> study = StudyManager.factory_from_scenarios(
... scenarios=[DummyDataset(quarter_hourly), DummyDataset(quarter_hourly.replace(name='high_demand', demand_factor=1.2))],
... comparisons=[('high_demand', 'base')],
... config=DatasetConfig(granularity='1h'),
... )
>>> len(study.scen_comp.fetch('Node.Results.price')) # 2 days of quarter-hours converted to hours
48
Source code in src/mesqual/study_manager.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
__init__
¶
__init__(scenarios: DatasetConcatCollection, comparisons: DatasetConcatCollectionOfComparisons, study_folder: str | Path = None, config: DatasetConfig | None = None)
Build the study from a scenario collection and a comparison collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenarios
|
DatasetConcatCollection
|
Collection of the scenario datasets, |
required |
comparisons
|
DatasetConcatCollectionOfComparisons
|
Collection of the scenario comparisons, |
required |
study_folder
|
str | Path
|
Optional folder of the study, see |
None
|
config
|
DatasetConfig | None
|
Optional config of the study. It merges on top of the
instance config of each of |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/mesqual/study_manager.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
describe_study
¶
describe_study(as_records: bool = False) -> dict
Describe the scenarios and comparisons of the study. Loads no time series data.
The result has these keys:
scenarios:scen.describe_datasets(max_depth=1), the scenario collection and its scenarios.comparisons:comp.describe_datasets(max_depth=1).scenario_flags:scen.describe_flags(), the union over the scenarios, with the scenarios that have each flag.comparison_flags:comp.describe_flags().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_records
|
bool
|
Give all four parts as lists of plain dicts, ready for JSON. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
A dict of the four descriptions. |
Examples:
>>> overview = study.describe_study()
>>> list(overview)
['scenarios', 'comparisons', 'scenario_flags', 'comparison_flags']
>>> overview['scenarios'].index.tolist()
['scenario', 'scenario/base', 'scenario/high_demand', 'scenario/without_N4', 'scenario/short']
Source code in src/mesqual/study_manager.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
factory_from_scenarios
classmethod
¶
factory_from_scenarios(scenarios: list[Dataset], comparisons: list[tuple[str, str]], study_folder: str | Path = None, config: DatasetConfig | None = None) -> StudyManager
Build the study from scenario datasets and (variation, reference) name pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenarios
|
list[Dataset]
|
The scenario datasets. |
required |
comparisons
|
list[tuple[str, str]]
|
One |
required |
study_folder
|
str | Path
|
Optional folder of the study. |
None
|
config
|
DatasetConfig | None
|
Optional config of the study, see |
None
|
Returns:
| Type | Description |
|---|---|
StudyManager
|
The study. |
Source code in src/mesqual/study_manager.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |