|
2 | 2 |
|
3 | 3 | import json |
4 | 4 | import logging |
| 5 | +import math |
5 | 6 | import os |
6 | 7 | import time |
7 | 8 | from collections.abc import Iterable, Mapping |
|
22 | 23 | SurfaceConfig, |
23 | 24 | ) |
24 | 25 | from ert.config.design_matrix import DESIGN_MATRIX_GROUP |
| 26 | +from ert.config.distribution import LogNormalSettings, LogUnifSettings |
25 | 27 | from ert.config.ert_config import create_forward_model_json |
26 | 28 | from ert.substitutions import Substitutions, substitute_runpath_name |
27 | 29 | from ert.utils import log_duration |
@@ -128,23 +130,42 @@ def _generate_parameter_files( |
128 | 130 | df = fs._load_scalar_keys(keys=keys, realizations=iens, transformed=True) |
129 | 131 | scalar_data = df.to_dicts()[0] |
130 | 132 | exports: dict[str, dict[str, float | str]] = {} |
| 133 | + log_exports: dict[str, dict[str, float | str]] = {} |
131 | 134 | for param in parameter_configs: |
132 | 135 | # For the first iteration we do not write the parameter |
133 | 136 | # to run path, as we expect to read if after the forward |
134 | 137 | # model has completed. |
135 | 138 | if param.forward_init and iteration == 0: |
136 | 139 | continue |
137 | 140 | export_values: dict[str, dict[str, float | str]] | None = None |
| 141 | + log_export_values: dict[str, dict[str, float | str]] | None = {} |
138 | 142 | if param.name in scalar_data: |
139 | | - export_values = {param.group_name: {param.name: scalar_data[param.name]}} |
| 143 | + scalar_value = scalar_data[param.name] |
| 144 | + export_values = {param.group_name: {param.name: scalar_value}} |
| 145 | + if isinstance(param, GenKwConfig) and isinstance( |
| 146 | + param.distribution, (LogNormalSettings, LogUnifSettings) |
| 147 | + ): |
| 148 | + if isinstance(scalar_value, float) and scalar_value > 0: |
| 149 | + log_value = math.log10(scalar_value) |
| 150 | + log_export_values = { |
| 151 | + f"LOG10_{param.group_name}": {param.name: log_value} |
| 152 | + } |
| 153 | + else: |
| 154 | + logger.warning( |
| 155 | + "Could not export the log10 value of " |
| 156 | + f"{scalar_value} as it is invalid" |
| 157 | + ) |
140 | 158 | else: |
141 | 159 | export_values = param.write_to_runpath(Path(run_path), iens, fs) |
142 | 160 | if export_values: |
143 | 161 | for group, vals in export_values.items(): |
144 | 162 | exports.setdefault(group, {}).update(vals) |
| 163 | + if log_export_values: |
| 164 | + for group, vals in log_export_values.items(): |
| 165 | + log_exports.setdefault(group, {}).update(vals) |
145 | 166 | continue |
146 | 167 |
|
147 | | - _value_export_txt(run_path, export_base_name, exports) |
| 168 | + _value_export_txt(run_path, export_base_name, exports | log_exports) |
148 | 169 | _value_export_json(run_path, export_base_name, exports) |
149 | 170 | return exports |
150 | 171 |
|
|
0 commit comments