diff --git a/.idea/alfasim-sdk.iml b/.idea/alfasim-sdk.iml new file mode 100644 index 00000000..aad402c4 --- /dev/null +++ b/.idea/alfasim-sdk.iml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..9e8e6940 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..ee2ae346 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + { + "associatedIndex": 8 +} + + + + + { + "keyToString": { + "Python tests.pytest for test_aggregator.test_read_history_matching_result_data.executor": "Run", + "Python tests.pytest for test_aggregator.test_read_uncertainty_propagation_results.executor": "Run", + "Python tests.pytest for test_generator_source.testGlobalSensitivityAnalysisGenerator.executor": "Run", + "Python tests.pytest for test_generator_source.testUncertaintyPropagationGeneratorSource.executor": "Run", + "Python tests.pytest for test_global_sensitivity_analysis_editor.testGlobalSensitivityAnalysisPlot.executor": "Run", + "Python tests.pytest for test_jobs_getter.testGetUncertaintyPropagationJob.executor": "Run", + "Python tests.pytest for test_main_window.testCreatePlotViewPlain.executor": "Run", + "Python tests.pytest for test_main_window.testReOpenProjectWithSAEditorOpened.executor": "Run", + "Python tests.pytest for test_uncertainty_analyses_editor.testPropagationSmoke.executor": "Run", + "Python tests.pytest for test_uncertainty_analyses_editor.testQuantificationBasics.executor": "Run", + "Python tests.pytest for test_uncertainty_propagation.test_uncertainty_propagation.executor": "Run", + "Python tests.pytest in test_aggregator.py.executor": "Run", + "Python tests.pytest in test_alfasim_result.py.executor": "Run", + "Python tests.pytest in test_generator_source.py.executor": "Run", + "Python tests.pytest in test_global_sensitivity_analysis_editor.py.executor": "Run", + "Python tests.pytest in test_jobs_getter.py.executor": "Run", + "Python tests.pytest in test_main_window.py.executor": "Run", + "Python tests.pytest in test_uncertainty_analyses_editor.py.executor": "Run", + "Python tests.pytest in test_uncertainty_propagation.py.executor": "Run", + "Python.generator_source.executor": "Debug", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "last_opened_file_path": "/home/users/gustavopb/Projects/alfasim-sdk" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1720196553831 + + + + + + + + file://$PROJECT_DIR$/../alfasim/alfasim_core/source/python/alfasim_core/communication/app_facade.py + 508 + + + file://$PROJECT_DIR$/../alfasim/alfasim_core/source/python/alfasim_core/curves/generator_source.py + 125 + + + file://$PROJECT_DIR$/../alfasim/alfasim_core/source/python/alfasim_core/curves/generators.py + 225 + + + file://$PROJECT_DIR$/../etk/coilib50io/source/python/coilib50io/reader/reader.py + 125 + + + + + \ No newline at end of file diff --git a/src/alfasim_sdk/result_reader/aggregator.py b/src/alfasim_sdk/result_reader/aggregator.py index 6250bc68..28f73023 100644 --- a/src/alfasim_sdk/result_reader/aggregator.py +++ b/src/alfasim_sdk/result_reader/aggregator.py @@ -6,7 +6,7 @@ from collections import namedtuple from contextlib import contextmanager from pathlib import Path -from typing import Any +from typing import Any, Type, TypeVar from typing import Callable from typing import DefaultDict from typing import Dict @@ -24,7 +24,9 @@ from typing_extensions import Self from alfasim_sdk.result_reader.aggregator_constants import ( - GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME, + GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME, UNCERTAINTY_PROPAGATION_GROUP_META_ATTR_NAME, + UNCERTAINTY_PROPAGATION_DSET_REALIZATION_OUTPUS, UNCERTAINTY_PROPAGATION_GROUP_NAME, + UNCERTAINTY_PROPAGATION_DSET_MEAN_RESULT, UNCERTAINTY_PROPAGATION_DSET_STD_RESULT, ) from alfasim_sdk.result_reader.aggregator_constants import ( HISTORY_MATCHING_DETERMINISTIC_DSET_NAME, @@ -109,6 +111,100 @@ class ResultsNeedFullReloadError(RuntimeError): "restart file" and the option "keep old results" is selected. """ +@attr.s(slots=True, hash=False) +class BaseUQMetaData: + """ + Base class for UQ metadata analysis. + + :ivar property_id: + The property name (holdup, total mass flow rate). + :ivar trend_id: + The id associated a specific trend. + :ivar category: + The property category. For global sensitivity analysis + this always be dimensionless. + :ivar network_element_name: + The name of network where this data is associated. + :ivar position: + The element position in a pipe. + :ivar position_unit: + The position unit (m, Km, cm). + :ivar unit: + The unit of a dimensionless property (-, %) + """ + property_id: str = attr.ib(validator=attr.validators.instance_of(str)) + trend_id: str = attr.ib(validator=attr.validators.instance_of(str)) + category: str = attr.ib(validator=attr.validators.instance_of(str)) + network_element_name: Optional[str] = attr.ib( + validator=attr.validators.optional(attr.validators.instance_of(str)) + ) + position: Optional[float] = attr.ib( + validator=attr.validators.optional(attr.validators.instance_of(float)) + ) + position_unit: Optional[str] = attr.ib( + validator=attr.validators.optional(attr.validators.instance_of(str)) + ) + unit: str = attr.ib(validator=attr.validators.instance_of(str)) + + +@attr.s(slots=True, hash=False) +class UncertaintyPropagationAnalysesMetaData: + """ + A class that hold the uncertainty propagation analyses metadata. + """ + + @attr.s(slots=True, hash=False) + class UPItem(BaseUQMetaData): + """ + A class that hold each uncertainty propagation analyses metadata. + + :ivar samples: + The total samples generate to construct the result. + :ivar result_index: + The index to access the mean and std result. + :ivar sample_indexes: + The indexes to access each sample of an item. + """ + samples: int = attr.ib(validator=attr.validators.instance_of(int)) + result_index: int = attr.ib(validator=attr.validators.instance_of(int)) + sample_indexes: List[List[int]] = attr.ib(validator=attr.validators.instance_of(List)) + + @classmethod + def from_dict(cls, data: Dict[str, Any]) -> Self: + return cls( + property_id=data["property_id"], + trend_id=data["trend_id"], + category=data["category"], + network_element_name=data["network_element_name"], + position=data["position"], + position_unit=data["position_unit"], + unit=data["unit"], + samples=data["samples"], + result_index=data['result_index'], + sample_indexes=data['sample_indexes'] + ) + + items: Dict[str, UPItem] = attr.ib(validator=attr.validators.instance_of(Dict)) + result_directory: Path = attr.ib(validator=attr.validators.instance_of(Path)) + + @classmethod + def empty(cls, result_directory: Path) -> Self: + return UncertaintyPropagationAnalysesMetaData( + items={}, result_directory=result_directory + ) + + @classmethod + def get_metadata_from_dir(cls, result_directory: Path) -> Self: + + def map_data( + up_metadata: Dict, + ) -> Dict[str, UncertaintyPropagationAnalysesMetaData.UPItem]: + return { + key: UncertaintyPropagationAnalysesMetaData.UPItem.from_dict(data) + for key, data in up_metadata.items() + } + + return read_results_file(result_directory=result_directory, metadata_class=cls, meta_data_attrs=UNCERTAINTY_PROPAGATION_GROUP_META_ATTR_NAME, map_data=map_data) @attr.s(slots=True, hash=False) class GlobalSensitivityAnalysisMetadata: @@ -117,50 +213,21 @@ class GlobalSensitivityAnalysisMetadata: """ @attr.s(slots=True, hash=False) - class GSAItem: + class GSAItem(BaseUQMetaData): """ A class that hold each global sensitivity analysis metadata information. - :ivar property_id: - The property name (holdup, total mass flow rate). - :ivar trend_id: - The id associated a specific trend. - :ivar category: - The property category. For global sensitivity analysis - this always be dimensionless. :ivar parametric_var_id: The id associated a parametric variable. :ivar parametric_var_name: The name associated a parametric variable. - :ivar network_element_name: - The name of network where this data is associated. - :ivar position: - The element position in a pipe. - :ivar position_unit: - The position unit (m, Km, cm). - :ivar unit: - The unit of a dimensionless property (-, %) :ivar qoi_index: The index of a quantity of interest in the results file. :ivar qoi_data_index: The data index of a quantity of interest. """ - - property_id: str = attr.ib(validator=attr.validators.instance_of(str)) - trend_id: str = attr.ib(validator=attr.validators.instance_of(str)) - category: str = attr.ib(validator=attr.validators.instance_of(str)) parametric_var_id: str = attr.ib(validator=attr.validators.instance_of(str)) parametric_var_name: str = attr.ib(validator=attr.validators.instance_of(str)) - network_element_name: Optional[str] = attr.ib( - validator=attr.validators.optional(attr.validators.instance_of(str)) - ) - position: Optional[float] = attr.ib( - validator=attr.validators.optional(attr.validators.instance_of(float)) - ) - position_unit: Optional[str] = attr.ib( - validator=attr.validators.optional(attr.validators.instance_of(str)) - ) - unit: str = attr.ib(validator=attr.validators.instance_of(str)) qoi_index: Optional[int] = attr.ib( validator=attr.validators.optional(attr.validators.instance_of(int)) ) @@ -184,13 +251,13 @@ def from_dict(cls, data: Dict[str, Any]) -> Self: qoi_data_index=data["qoi_data_index"], ) - gsa_items: Dict[str, GSAItem] = attr.ib(validator=attr.validators.instance_of(Dict)) + items: Dict[str, GSAItem] = attr.ib(validator=attr.validators.instance_of(Dict)) result_directory: Path = attr.ib(validator=attr.validators.instance_of(Path)) @classmethod def empty(cls, result_directory: Path) -> Self: return GlobalSensitivityAnalysisMetadata( - gsa_items={}, result_directory=result_directory + items={}, result_directory=result_directory ) @classmethod @@ -209,20 +276,41 @@ def map_data( key: GlobalSensitivityAnalysisMetadata.GSAItem.from_dict(data) for key, data in gsa_metadata.items() } + return read_results_file(result_directory=result_directory,metadata_class=cls, map_data=map_data,meta_data_attrs=GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME) - with open_result_file( - result_directory, result_filename="result" - ) as result_file: - if not result_file: - return cls.empty(result_directory=result_directory) +UQMetadataClass = Union[GlobalSensitivityAnalysisMetadata,UncertaintyPropagationAnalysesMetaData] - loaded_metadata = json.loads( - result_file[META_GROUP_NAME].attrs["global_sensitivity_analysis"] - ) - return cls( - gsa_items=map_data(loaded_metadata), result_directory=result_directory - ) +@attr.s(frozen=True) +class UPResult: + """ + Holder for each uncertainty propagation result. + """ + category: str = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(str))) + unit: str = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(str))) + realization_output: List[np.ndarray] = attr.ib(default=attr.Factory(List)) + std_result: np.ndarray = attr.ib(default=attr.Factory(lambda: np.array([]))) + mean_result: np.ndarray = attr.ib(default=attr.Factory(lambda: np.array([]))) + + +MetadataClassType = TypeVar("MetadataClassType", bound=UQMetadataClass) +def read_results_file( + result_directory: Path, + metadata_class: Type[MetadataClassType], + map_data: Callable, + meta_data_attrs: str) -> MetadataClassType: + + with open_result_file( + result_directory, result_filename="result" + ) as result_file: + if not result_file: + return metadata_class.empty(result_directory=result_directory) + loaded_metadata = json.loads( + result_file[META_GROUP_NAME].attrs[meta_data_attrs] + ) + return metadata_class( + items=map_data(loaded_metadata), result_directory=result_directory + ) @attr.define(slots=True, hash=True) class HistoricDataCurveMetadata: @@ -1725,17 +1813,64 @@ def read_global_sensitivity_analysis_meta_data( result_directory=result_directory ) +def read_uncertainty_propagation_analyses_meta_data( + result_directory: Path, +)-> Optional[UncertaintyPropagationAnalysesMetaData]: + """ + Read the uncertainty propagation analyses metadata persisted in a result file. + """ + + return UncertaintyPropagationAnalysesMetaData.get_metadata_from_dir( + result_directory=result_directory + ) + -def read_global_sensitivity_analysis_time_set( +def read_uncertainty_propagation_results(metadata: UncertaintyPropagationAnalysesMetaData, results_key: str) -> Optional[UPResult]: + """ + Get the uncertainty propagation results. + + :param metadata: + The uncertainty propagation metadata previously read. + + :param results_key: + The result key as follows: + """ + meta = metadata.items.get(results_key) + if not meta: + return None + + with open_result_file(metadata.result_directory) as file: + up_group = file[UNCERTAINTY_PROPAGATION_GROUP_NAME] + realization_output_samples = up_group[UNCERTAINTY_PROPAGATION_DSET_REALIZATION_OUTPUS] + + realization_outputs = [realization_output_samples[sample_index][qoi_index] for qoi_index, sample_index in meta.sample_indexes] + mean_result = up_group[UNCERTAINTY_PROPAGATION_DSET_MEAN_RESULT][meta.result_index] + std_result = up_group[UNCERTAINTY_PROPAGATION_DSET_STD_RESULT][meta.result_index] + return UPResult( + realization_output=realization_outputs, + mean_result=mean_result, + std_result=std_result, + category=meta.category, + unit=meta.unit + ) + +def read_uq_time_set( result_directory: Path, + group_name: str ) -> Optional[numpy.array]: """ - Get the time set for sensitivity analysis results. + Get the time set for uq-based analysis results (Global Sensitivity Analysis or Uncertainty Propagation). + + :param result_directory: + The directory which contains the uncertainty propagation results. + + :param group_name: + The result group name. """ with open_result_file(result_directory, result_filename="result") as result_file: if not result_file: return - return result_file[GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME]["time_set"][:] + return result_file[group_name]["time_set"][:] def read_global_sensitivity_coefficients( @@ -1746,9 +1881,9 @@ def read_global_sensitivity_coefficients( Read the global sensitivity analysis coefficients results. """ # The metadata is empty. - if not metadata.gsa_items: + if not metadata.items: return None - meta = metadata.gsa_items[coefficients_key] + meta = metadata.items[coefficients_key] with open_result_file( metadata.result_directory, result_filename="result" ) as result_file: diff --git a/src/alfasim_sdk/result_reader/aggregator_constants.py b/src/alfasim_sdk/result_reader/aggregator_constants.py index 3a0ceda2..0a9799df 100644 --- a/src/alfasim_sdk/result_reader/aggregator_constants.py +++ b/src/alfasim_sdk/result_reader/aggregator_constants.py @@ -14,7 +14,7 @@ ) UNCERTAINTY_PROPAGATION_DSET_MEAN_RESULT = "uncertainty_propagation_mean_results" UNCERTAINTY_PROPAGATION_DSET_STD_RESULT = "uncertainty_propagation_std_results" -UNCERTAINTY_PROPAGATION = "uncertainty_propagation" +UNCERTAINTY_PROPAGATION_GROUP_NAME = 'uncertainty_propagation' TIME_SET_DSET_NAME = "time_set" diff --git a/tests/conftest.py b/tests/conftest.py index 6715cb12..22e20631 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,7 +16,9 @@ HISTORY_MATCHING_HISTORIC_DATA_GROUP_NAME, ) from alfasim_sdk.result_reader.aggregator_constants import ( - GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME, + GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME, UNCERTAINTY_PROPAGATION_GROUP_META_ATTR_NAME, UNCERTAINTY_PROPAGATION_GROUP_NAME, + UNCERTAINTY_PROPAGATION_DSET_REALIZATION_OUTPUS, UNCERTAINTY_PROPAGATION_DSET_MEAN_RESULT, + UNCERTAINTY_PROPAGATION_DSET_STD_RESULT, ) from alfasim_sdk.result_reader.aggregator_constants import ( HISTORY_MATCHING_DETERMINISTIC_DSET_NAME, @@ -272,6 +274,76 @@ def global_sa_results_dir(datadir: Path) -> Path: file.close() return result_dir +@pytest.fixture() +def up_results_dir(datadir: Path) -> Path: + """ + Crete a uncertainty propagation analyses result folder + with a result file. + """ + + import numpy as np + + result_dir = datadir / "fake_dir" + result_dir.mkdir(parents=True) + time_set = np.array([0, 1, 2, 3, 4, 5, 6, 7]) + realization_outputs = np.array( + [ + [ + [i + (qoi_index*10) + tl for tl in (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7)] + for qoi_index, trend_property in enumerate([('trend_id_1','temperature'), ('trend_id_1','absolute_pressure')]) + ] + for i in range(5) + ] + ) + file_name = result_dir / "result" + with h5py.File(file_name, "x", libver="latest", locking=False) as file: + meta_group = file.create_group(META_GROUP_NAME, track_order=True) + uncertainty_propagation_group = file.create_group( + UNCERTAINTY_PROPAGATION_GROUP_NAME, track_order=True + ) + fake_meta = { + "temperature@trend_id_1": { + "property_id": "temperature", + "trend_id": "trend_id_1", + "category": "temperature", + "network_element_name": "Conexao 1", + "position": 100.0, + "position_unit": "m", + "unit": "K", + "samples": 5, + "sample_indexes": [[0,0], [0,1], [0,2],[0,3],[0,4]], + "result_index": 0, + }, + "absolute_pressure@trend_id_1": { + "property_id": "absolute_pressure", + "trend_id": "trend_id_1", + "category": "pressure", + "network_element_name": "Conexao 1", + "position": 100.0, + "position_unit": "m", + "unit": "bar", + "samples": 5, + "sample_indexes": [[1, 0],[1, 1], [1, 2], [1, 3],[1,4]], + "result_index": 1, + }, + } + meta_group.attrs[UNCERTAINTY_PROPAGATION_GROUP_META_ATTR_NAME] = json.dumps(fake_meta) + time_set_dset = uncertainty_propagation_group.create_dataset(name=TIME_SET_DSET_NAME, shape=time_set.shape) + time_set_dset[:] = time_set + + realization_outputs_dset = uncertainty_propagation_group.create_dataset(name=UNCERTAINTY_PROPAGATION_DSET_REALIZATION_OUTPUS, shape=realization_outputs.shape, maxshape=(None, None, None)) + realization_outputs = realization_outputs + realization_outputs_dset[:] = realization_outputs + + mean_results_array = np.mean(realization_outputs, axis=0) + mean_results = uncertainty_propagation_group.create_dataset(name=UNCERTAINTY_PROPAGATION_DSET_MEAN_RESULT, shape=mean_results_array.shape, maxshape=(None, None)) + mean_results[:] = mean_results_array + + std_results_array = np.std(realization_outputs, axis=0) + std_results = uncertainty_propagation_group.create_dataset(name=UNCERTAINTY_PROPAGATION_DSET_STD_RESULT, shape=std_results_array.shape, maxshape=(None, None)) + std_results[:] = std_results_array + file.swmr_mode = True + return result_dir def _create_and_populate_hm_result_file( result_dir: Path, diff --git a/tests/results/test_aggregator.py b/tests/results/test_aggregator.py index 12a49a57..a7baf659 100644 --- a/tests/results/test_aggregator.py +++ b/tests/results/test_aggregator.py @@ -12,15 +12,16 @@ from pytest_mock import MockerFixture from pytest_regressions.num_regression import NumericRegressionFixture -from alfasim_sdk.result_reader.aggregator import concatenate_metadata from alfasim_sdk.result_reader.aggregator import HistoricDataCurveMetadata +from alfasim_sdk.result_reader.aggregator import concatenate_metadata, read_uncertainty_propagation_analyses_meta_data, \ + read_uncertainty_propagation_results from alfasim_sdk.result_reader.aggregator import HistoryMatchingMetadata from alfasim_sdk.result_reader.aggregator import open_result_files from alfasim_sdk.result_reader.aggregator import ( read_global_sensitivity_analysis_meta_data, ) from alfasim_sdk.result_reader.aggregator import ( - read_global_sensitivity_analysis_time_set, + read_uq_time_set, ) from alfasim_sdk.result_reader.aggregator import read_global_sensitivity_coefficients from alfasim_sdk.result_reader.aggregator import ( @@ -34,7 +35,8 @@ from alfasim_sdk.result_reader.aggregator import read_trends_data from alfasim_sdk.result_reader.aggregator import ResultsNeedFullReloadError from alfasim_sdk.result_reader.aggregator import TimeSetInfoItem -from alfasim_sdk.result_reader.aggregator_constants import HISTORY_MATCHING_GROUP_NAME +from alfasim_sdk.result_reader.aggregator_constants import HISTORY_MATCHING_GROUP_NAME, \ + GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME from alfasim_sdk.result_reader.aggregator_constants import META_GROUP_NAME from alfasim_sdk.result_reader.aggregator_constants import RESULTS_FOLDER_NAME from alfasim_sdk.result_reader.reader import Results @@ -319,19 +321,19 @@ def test_read_empty_gsa_metadata(datadir: Path) -> None: uq_metadata = read_global_sensitivity_analysis_meta_data( result_directory=fake_uq_dir ) - assert uq_metadata.gsa_items == {} + assert uq_metadata.items == {} assert Path(uq_metadata.result_directory) == fake_uq_dir fake_uq_dir.mkdir(parents=True) uq_metadata = read_global_sensitivity_analysis_meta_data( result_directory=fake_uq_dir ) - assert uq_metadata.gsa_items == {} + assert uq_metadata.items == {} def test_read_gsa_metadata(global_sa_results_dir: Path) -> None: uq_metadata = read_global_sensitivity_analysis_meta_data(global_sa_results_dir) - global_gsa_meta_data = uq_metadata.gsa_items + global_gsa_meta_data = uq_metadata.items meta_var_1 = global_gsa_meta_data["temperature::parametric_var_1@trend_id_1"] assert meta_var_1.qoi_index == 0 assert meta_var_1.qoi_data_index == 0 @@ -346,8 +348,9 @@ def test_read_gsa_metadata(global_sa_results_dir: Path) -> None: def test_read_gsa_timeset(global_sa_results_dir: Path) -> None: - time_set = read_global_sensitivity_analysis_time_set( - result_directory=global_sa_results_dir + time_set = read_uq_time_set( + result_directory=global_sa_results_dir, + group_name=GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME ) assert numpy.all(time_set == [0, 1, 2, 3, 4, 5, 6, 7]) @@ -373,10 +376,10 @@ def test_read_incomplete_gsa_metadata(global_sa_results_dir: Path) -> None: """ creating_file = global_sa_results_dir / "result.creating" creating_file.touch() - gsa_time_set = read_global_sensitivity_analysis_time_set(global_sa_results_dir) + gsa_time_set = read_uq_time_set(global_sa_results_dir, GLOBAL_SENSITIVITY_ANALYSIS_GROUP_NAME) assert gsa_time_set is None gsa_meta_data = read_global_sensitivity_analysis_meta_data(global_sa_results_dir) - assert gsa_meta_data.gsa_items == {} + assert gsa_meta_data.items == {} coefficients = read_global_sensitivity_coefficients( coefficients_key="temperature::parametric_var_1@trend_id_1", metadata=gsa_meta_data, @@ -560,3 +563,36 @@ def test_read_history_matching_historic_data_curves_backward_compatibility( metadata = read_history_matching_metadata(result_dir) curves = read_history_matching_historic_data_curves(metadata) assert curves == {} + +def test_read_uncertainty_propagation_results(datadir: Path, up_results_dir: Path, num_regression: NumericRegressionFixture) -> None: + + empty_metadata = read_uncertainty_propagation_analyses_meta_data(result_directory=datadir) + assert empty_metadata.items == {} + result = read_uncertainty_propagation_results(metadata=empty_metadata,results_key='absolute_pressure@trend_id_1') + assert result is None + + metadata = read_uncertainty_propagation_analyses_meta_data(result_directory=up_results_dir) + assert list(metadata.items.keys()) == ['temperature@trend_id_1', 'absolute_pressure@trend_id_1'] + + assert metadata.items['temperature@trend_id_1'].result_index == 0 + assert metadata.items['temperature@trend_id_1'].sample_indexes == [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]] + + assert metadata.items['absolute_pressure@trend_id_1'].result_index == 1 + assert metadata.items['absolute_pressure@trend_id_1'].sample_indexes == [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4]] + + result = read_uncertainty_propagation_results(metadata=metadata,results_key='temperature@trend_id_1') + dict_1 = { + "sample_0": result.realization_output[0], + "sample_1": result.realization_output[-1], + "mean_result": result.mean_result, + "std_result": result.std_result + } + num_regression.check(dict_1, basename="temperature@trend_id_1") + result = read_uncertainty_propagation_results(metadata=metadata,results_key='absolute_pressure@trend_id_1') + dict_2 = { + "sample_0": result.realization_output[0], + "sample_1": result.realization_output[-1], + "mean_result": result.mean_result, + "std_result": result.std_result + } + num_regression.check(dict_2, basename="absolute_pressure@trend_id_1") diff --git a/tests/results/test_aggregator/absolute_pressure@trend_id_1.csv b/tests/results/test_aggregator/absolute_pressure@trend_id_1.csv new file mode 100644 index 00000000..92dd0aa9 --- /dev/null +++ b/tests/results/test_aggregator/absolute_pressure@trend_id_1.csv @@ -0,0 +1,8 @@ +,sample_0,sample_1,mean_result,std_result +0,10.100000381469727,14.100000381469727,12.100000381469727,1.4142135381698608 +1,10.199999809265137,14.199999809265137,12.199999809265137,1.4142135381698608 +2,10.300000190734863,14.300000190734863,12.300000190734863,1.4142135381698608 +3,10.399999618530273,14.399999618530273,12.399999618530273,1.4142135381698608 +4,10.5,14.5,12.5,1.4142135381698608 +5,10.600000381469727,14.600000381469727,12.600000381469727,1.4142135381698608 +6,10.699999809265137,14.699999809265137,12.699999809265137,1.4142135381698608 diff --git a/tests/results/test_aggregator/temperature@trend_id_1.csv b/tests/results/test_aggregator/temperature@trend_id_1.csv new file mode 100644 index 00000000..7033afda --- /dev/null +++ b/tests/results/test_aggregator/temperature@trend_id_1.csv @@ -0,0 +1,8 @@ +,sample_0,sample_1,mean_result,std_result +0,0.10000000149011612,4.0999999046325684,2.0999999046325684,1.4142135381698608 +1,0.20000000298023224,4.1999998092651367,2.2000000476837158,1.4142135381698608 +2,0.30000001192092896,4.3000001907348633,2.2999999523162842,1.4142135381698608 +3,0.40000000596046448,4.4000000953674316,2.4000000953674316,1.4142135381698608 +4,0.5,4.5,2.5,1.4142135381698608 +5,0.60000002384185791,4.5999999046325684,2.5999999046325684,1.4142135381698608 +6,0.69999998807907104,4.6999998092651367,2.7000000476837158,1.4142135381698608