File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
_providers/ensemble_table_provider Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 10
10
from webviz_config .webviz_factory_registry import WEBVIZ_FACTORY_REGISTRY
11
11
from webviz_config .webviz_instance_info import WebvizRunMode
12
12
13
+ from webviz_subsurface ._utils .design_matrix import (
14
+ rename_design_matrix_parameter_columns ,
15
+ )
13
16
from webviz_subsurface ._utils .perf_timer import PerfTimer
14
17
15
18
from ..ensemble_summary_provider ._arrow_unsmry_import import (
@@ -283,6 +286,7 @@ def create_from_per_realization_parameter_file(
283
286
raise ValueError (
284
287
f"Failed to load 'parameter.txt' files for ensemble { ens_path } ."
285
288
)
289
+ ensemble_df = rename_design_matrix_parameter_columns (ensemble_df )
286
290
287
291
elapsed_load_parameters_s = timer .lap_s ()
288
292
Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ import pandas as pd
4
+
5
+ LOGGER = logging .getLogger (__name__ )
6
+
7
+
8
+ def rename_design_matrix_parameter_columns (parameter_df : pd .DataFrame ) -> pd .DataFrame :
9
+ """Given a dataframe of parameters, checks if the DESIGN_MATRIX prefix is present.
10
+ If present assume this is a design matrix run. Return the dataframe with the prefix
11
+ removed. Also do a check if removing the prefix result in any duplicates.
12
+ If duplicates remove those and give a warning.
13
+ """
14
+
15
+ if any (col .startswith ("DESIGN_MATRIX:" ) for col in parameter_df .columns ):
16
+ original_columns = parameter_df .columns
17
+ stripped_columns = original_columns .str .replace (
18
+ r"^DESIGN_MATRIX:" , "" , regex = True
19
+ )
20
+ rename_map = {
21
+ old : new
22
+ for old , new in zip (original_columns , stripped_columns )
23
+ if old != new
24
+ }
25
+ conflict_names = set (rename_map .values ()) & set (original_columns )
26
+ if conflict_names :
27
+ LOGGER .info (
28
+ "DESIGN_MATRIX run detected, but non design matrix parameters was found."
29
+ )
30
+ LOGGER .info (
31
+ f"The following parameters will be dropped: { sorted (conflict_names )} "
32
+ )
33
+ parameter_df = parameter_df .drop (columns = conflict_names )
34
+
35
+ parameter_df = parameter_df .rename (columns = rename_map )
36
+ return parameter_df
You can’t perform that action at this time.
0 commit comments