webviz-subsurface 0.2.39__py3-none-any.whl → 0.2.41__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. webviz_subsurface/_figures/timeseries_figure.py +1 -1
  2. webviz_subsurface/_providers/ensemble_summary_provider/_provider_impl_arrow_lazy.py +3 -1
  3. webviz_subsurface/_providers/ensemble_summary_provider/_provider_impl_arrow_presampled.py +3 -1
  4. webviz_subsurface/_providers/ensemble_table_provider/ensemble_table_provider_impl_arrow.py +3 -1
  5. webviz_subsurface/_utils/dataframe_utils.py +1 -1
  6. webviz_subsurface/_version.py +34 -0
  7. webviz_subsurface/plugins/_bhp_qc/views/_view_functions.py +5 -5
  8. webviz_subsurface/plugins/_co2_migration/__init__.py +1 -0
  9. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_plugin.py +86 -46
  10. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/callbacks.py +53 -30
  11. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/co2volume.py +283 -40
  12. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/color_tables.py +1 -1
  13. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/containment_data_provider.py +6 -4
  14. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/containment_info.py +6 -0
  15. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/ensemble_well_picks.py +1 -1
  16. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/generic.py +59 -6
  17. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/initialization.py +73 -10
  18. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/polygon_handler.py +1 -1
  19. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/summary_graphs.py +20 -18
  20. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/surface_publishing.py +18 -20
  21. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/unsmry_data_provider.py +8 -8
  22. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/views/mainview/mainview.py +98 -44
  23. webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/views/mainview/settings.py +7 -5
  24. webviz_subsurface/plugins/_disk_usage.py +19 -8
  25. webviz_subsurface/plugins/_line_plotter_fmu/controllers/build_figure.py +4 -4
  26. webviz_subsurface/plugins/_map_viewer_fmu/layout.py +2 -1
  27. webviz_subsurface/plugins/_map_viewer_fmu/map_viewer_fmu.py +1 -1
  28. webviz_subsurface/plugins/_parameter_analysis/_utils/_parameters_model.py +5 -5
  29. webviz_subsurface/plugins/_property_statistics/property_statistics.py +1 -1
  30. webviz_subsurface/plugins/_relative_permeability.py +6 -6
  31. webviz_subsurface/plugins/_reservoir_simulation_timeseries_regional.py +12 -12
  32. webviz_subsurface/plugins/_running_time_analysis_fmu.py +6 -1
  33. webviz_subsurface/plugins/_seismic_misfit.py +2 -3
  34. webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_utils/vector_statistics.py +4 -4
  35. webviz_subsurface/plugins/_structural_uncertainty/views/intersection_and_map.py +1 -1
  36. webviz_subsurface/plugins/_swatinit_qc/_business_logic.py +1 -1
  37. webviz_subsurface-0.2.41.dist-info/METADATA +822 -0
  38. {webviz_subsurface-0.2.39.dist-info → webviz_subsurface-0.2.41.dist-info}/RECORD +51 -102
  39. {webviz_subsurface-0.2.39.dist-info → webviz_subsurface-0.2.41.dist-info}/WHEEL +1 -1
  40. {webviz_subsurface-0.2.39.dist-info → webviz_subsurface-0.2.41.dist-info}/entry_points.txt +1 -1
  41. {webviz_subsurface-0.2.39.dist-info → webviz_subsurface-0.2.41.dist-info}/top_level.txt +0 -1
  42. tests/integration_tests/test_parameter_filter.py +0 -28
  43. tests/integration_tests/test_surface_selector.py +0 -53
  44. tests/unit_tests/abbreviations_tests/test_reservoir_simulation.py +0 -94
  45. tests/unit_tests/data_input/__init__.py +0 -0
  46. tests/unit_tests/data_input/test_calc_from_cumulatives.py +0 -178
  47. tests/unit_tests/data_input/test_image_processing.py +0 -11
  48. tests/unit_tests/mocks/__init__.py +0 -0
  49. tests/unit_tests/mocks/ensemble_summary_provider_dummy.py +0 -67
  50. tests/unit_tests/model_tests/__init__.py +0 -0
  51. tests/unit_tests/model_tests/test_ensemble_model.py +0 -176
  52. tests/unit_tests/model_tests/test_ensemble_set_model.py +0 -105
  53. tests/unit_tests/model_tests/test_gruptree_model.py +0 -89
  54. tests/unit_tests/model_tests/test_property_statistics_model.py +0 -42
  55. tests/unit_tests/model_tests/test_surface_set_model.py +0 -48
  56. tests/unit_tests/model_tests/test_well_attributes_model.py +0 -110
  57. tests/unit_tests/model_tests/test_well_set_model.py +0 -70
  58. tests/unit_tests/plugin_tests/__init__.py +0 -0
  59. tests/unit_tests/plugin_tests/test_grouptree.py +0 -175
  60. tests/unit_tests/plugin_tests/test_simulation_time_series/__init__.py +0 -0
  61. tests/unit_tests/plugin_tests/test_simulation_time_series/mocks/__init__.py +0 -0
  62. tests/unit_tests/plugin_tests/test_simulation_time_series/mocks/derived_vectors_accessor_ensemble_summary_provider_mock.py +0 -60
  63. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/__init__.py +0 -0
  64. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_create_vector_traces_utils.py +0 -530
  65. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_dataframe_utils.py +0 -119
  66. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_datetime_utils.py +0 -51
  67. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_delta_ensemble_utils.py +0 -222
  68. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_derived_delta_ensemble_vectors_accessor_impl.py +0 -319
  69. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_derived_ensemble_vectors_accessor_impl.py +0 -271
  70. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_derived_ensemble_vectors_accessor_utils.py +0 -78
  71. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_derived_vector_accessor.py +0 -57
  72. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_ensemble_summary_provider_set_utils.py +0 -213
  73. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_from_timeseries_cumulatives.py +0 -322
  74. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_history_vectors.py +0 -201
  75. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_trace_line_shape.py +0 -56
  76. tests/unit_tests/plugin_tests/test_simulation_time_series/test_utils/test_vector_statistics.py +0 -171
  77. tests/unit_tests/plugin_tests/test_tornado_data.py +0 -130
  78. tests/unit_tests/plugin_tests/test_well_completions.py +0 -158
  79. tests/unit_tests/provider_tests/__init__.py +0 -0
  80. tests/unit_tests/provider_tests/test_ensemble_summary_provider.py +0 -255
  81. tests/unit_tests/provider_tests/test_ensemble_summary_provider_impl_arrow_lazy.py +0 -388
  82. tests/unit_tests/provider_tests/test_ensemble_summary_provider_impl_arrow_presampled.py +0 -160
  83. tests/unit_tests/provider_tests/test_ensemble_summary_provider_resampling.py +0 -320
  84. tests/unit_tests/provider_tests/test_ensemble_table_provider.py +0 -190
  85. tests/unit_tests/utils_tests/__init__.py +0 -0
  86. tests/unit_tests/utils_tests/test_dataframe_utils.py +0 -281
  87. tests/unit_tests/utils_tests/test_ensemble_summary_provider_set/__init__.py +0 -0
  88. tests/unit_tests/utils_tests/test_ensemble_summary_provider_set/test_ensemble_summary_provider_set.py +0 -306
  89. tests/unit_tests/utils_tests/test_formatting.py +0 -10
  90. tests/unit_tests/utils_tests/test_simulation_timeseries.py +0 -51
  91. webviz_subsurface/plugins/_co2_leakage/__init__.py +0 -1
  92. webviz_subsurface/plugins/_co2_leakage/_utilities/__init__.py +0 -0
  93. webviz_subsurface/plugins/_co2_leakage/views/__init__.py +0 -0
  94. webviz_subsurface/plugins/_co2_leakage/views/mainview/__init__.py +0 -0
  95. webviz_subsurface-0.2.39.dist-info/METADATA +0 -147
  96. /webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_error.py +0 -0
  97. /webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_types.py +0 -0
  98. {tests/integration_tests → webviz_subsurface/plugins/_co2_migration/_utilities}/__init__.py +0 -0
  99. /webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/_misc.py +0 -0
  100. /webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/fault_polygons_handler.py +0 -0
  101. /webviz_subsurface/plugins/{_co2_leakage → _co2_migration}/_utilities/plume_extent.py +0 -0
  102. {tests/unit_tests → webviz_subsurface/plugins/_co2_migration/views}/__init__.py +0 -0
  103. {tests/unit_tests/abbreviations_tests → webviz_subsurface/plugins/_co2_migration/views/mainview}/__init__.py +0 -0
  104. {webviz_subsurface-0.2.39.dist-info → webviz_subsurface-0.2.41.dist-info/licenses}/LICENSE +0 -0
  105. {webviz_subsurface-0.2.39.dist-info → webviz_subsurface-0.2.41.dist-info/licenses}/LICENSE.chromedriver +0 -0
@@ -1,530 +0,0 @@
1
- import copy
2
- import datetime
3
-
4
- import numpy as np
5
- import pandas as pd
6
- import pytest
7
-
8
- from webviz_subsurface._providers import Frequency
9
- from webviz_subsurface._utils.dataframe_utils import make_date_column_datetime_object
10
- from webviz_subsurface.plugins._simulation_time_series._views._subplot_view._types import (
11
- FanchartOptions,
12
- StatisticsOptions,
13
- )
14
-
15
- # pylint: disable=line-too-long
16
- from webviz_subsurface.plugins._simulation_time_series._views._subplot_view._utils.create_vector_traces_utils import (
17
- create_history_vector_trace,
18
- create_vector_fanchart_traces,
19
- create_vector_observation_traces,
20
- create_vector_realization_traces,
21
- create_vector_statistics_traces,
22
- render_hovertemplate,
23
- )
24
-
25
- # *******************************************************************
26
- #####################################################################
27
- #
28
- # CONFIGURE TESTDATA
29
- #
30
- #####################################################################
31
- # *******************************************************************
32
-
33
- INPUT_VECTOR_STATISTICS_DF = pd.DataFrame(
34
- columns=[
35
- "DATE",
36
- StatisticsOptions.MEAN,
37
- StatisticsOptions.MIN,
38
- StatisticsOptions.MAX,
39
- StatisticsOptions.P10,
40
- StatisticsOptions.P90,
41
- StatisticsOptions.P50,
42
- ],
43
- data=[
44
- [datetime.datetime(2020, 1, 1), 1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
45
- [datetime.datetime(2020, 1, 2), 1.5, 2.5, 3.5, 4.5, 5.5, 6.5],
46
- ],
47
- )
48
- make_date_column_datetime_object(INPUT_VECTOR_STATISTICS_DF)
49
-
50
-
51
- # *******************************************************************
52
- #####################################################################
53
- #
54
- # UNIT TESTS
55
- #
56
- #####################################################################
57
- # *******************************************************************
58
-
59
-
60
- def test_crate_vector_observation_traces() -> None:
61
- first_observation = {
62
- "date": datetime.datetime(2020, 1, 1),
63
- "value": 2.0,
64
- "comment": "first obs",
65
- "error": 0.5,
66
- }
67
- second_observation = {
68
- "date": datetime.datetime(2020, 6, 5),
69
- "value": 5.0,
70
- "comment": "second obs",
71
- "error": 1.2,
72
- }
73
- vector_observations = {"observations": [first_observation, second_observation]}
74
-
75
- expected_traces = [
76
- {
77
- "name": "Observation",
78
- "legendgroup": "Observation",
79
- "x": [datetime.datetime(2020, 1, 1), []],
80
- "y": [2.0, []],
81
- "marker": {"color": "black"},
82
- "hovertemplate": "(%{x}, %{y})<br>first obs",
83
- "showlegend": False,
84
- "error_y": {
85
- "type": "data",
86
- "array": [0.5, []],
87
- "visible": True,
88
- },
89
- },
90
- {
91
- "name": "Observation",
92
- "legendgroup": "Observation",
93
- "x": [datetime.datetime(2020, 6, 5), []],
94
- "y": [5.0, []],
95
- "marker": {"color": "black"},
96
- "hovertemplate": "(%{x}, %{y})<br>second obs",
97
- "showlegend": False,
98
- "error_y": {
99
- "type": "data",
100
- "array": [1.2, []],
101
- "visible": True,
102
- },
103
- },
104
- ]
105
-
106
- # Add legendgroup info for verification
107
- legend_group = "test group"
108
- expected_traces_with_legend_group = copy.deepcopy(expected_traces)
109
- expected_traces_with_legend_group[0]["name"] = "Observation: " + legend_group
110
- expected_traces_with_legend_group[0]["legendgroup"] = legend_group
111
- expected_traces_with_legend_group[1]["name"] = "Observation: " + legend_group
112
- expected_traces_with_legend_group[1]["legendgroup"] = legend_group
113
-
114
- assert expected_traces == create_vector_observation_traces(vector_observations)
115
- assert expected_traces_with_legend_group == create_vector_observation_traces(
116
- vector_observations, legend_group=legend_group
117
- )
118
-
119
-
120
- def test_create_vector_realization_traces() -> None:
121
- vector_df = pd.DataFrame(
122
- columns=["DATE", "REAL", "A"],
123
- data=[
124
- [datetime.datetime(2020, 1, 1), 1, 1.0],
125
- [datetime.datetime(2020, 2, 1), 1, 2.0],
126
- [datetime.datetime(2031, 5, 10), 2, 5.0],
127
- [datetime.datetime(2031, 6, 10), 2, 6.0],
128
- ],
129
- )
130
- make_date_column_datetime_object(vector_df)
131
-
132
- created_traces = create_vector_realization_traces(
133
- vector_df=vector_df,
134
- ensemble="Test ensemble",
135
- color="red",
136
- legend_group="Test group",
137
- line_shape="linear",
138
- hovertemplate="Test hovertemplate ",
139
- show_legend=True,
140
- legendrank=2,
141
- )
142
-
143
- expected_traces = [
144
- {
145
- "line": {"width": 1, "shape": "linear", "color": "red"},
146
- "mode": "lines",
147
- "x": [datetime.datetime(2020, 1, 1), datetime.datetime(2020, 2, 1)],
148
- "y": [1.0, 2.0],
149
- "hovertemplate": "Test hovertemplate Realization: 1, Ensemble: Test ensemble",
150
- "name": "Test group",
151
- "legendgroup": "Test group",
152
- "legendrank": 2,
153
- "showlegend": True,
154
- },
155
- {
156
- "line": {"width": 1, "shape": "linear", "color": "red"},
157
- "mode": "lines",
158
- "x": [datetime.datetime(2031, 5, 10), datetime.datetime(2031, 6, 10)],
159
- "y": [5.0, 6.0],
160
- "hovertemplate": "Test hovertemplate Realization: 2, Ensemble: Test ensemble",
161
- "name": "Test group",
162
- "legendgroup": "Test group",
163
- "legendrank": 2,
164
- "showlegend": False,
165
- },
166
- ]
167
-
168
- assert expected_traces == created_traces
169
-
170
-
171
- def test_create_vector_realization_traces_raise_error() -> None:
172
- multiple_vectors_df = pd.DataFrame(columns=["DATE", "REAL", "A", "B"])
173
-
174
- with pytest.raises(ValueError) as err:
175
- create_vector_realization_traces(
176
- vector_df=multiple_vectors_df,
177
- ensemble="Test ensemble",
178
- color="red",
179
- legend_group="Test group",
180
- line_shape="linear",
181
- hovertemplate="Test hovertemplate ",
182
- )
183
- assert str(err.value) == "Expected one vector column present in dataframe, got 2!"
184
-
185
-
186
- def test_create_history_vector_trace() -> None:
187
- input_samples = [
188
- datetime.datetime(2020, 1, 1),
189
- datetime.datetime(2020, 1, 2),
190
- datetime.datetime(2020, 1, 3),
191
- ]
192
- input_history_data = np.array([1.0, 2.0, 3.0])
193
-
194
- created_trace = create_history_vector_trace(
195
- samples=input_samples,
196
- history_data=input_history_data,
197
- line_shape="linear",
198
- color="green",
199
- vector_name="Test hist vector",
200
- )
201
-
202
- expected_trace = {
203
- "line": {"shape": "linear", "color": "green"},
204
- "mode": "lines",
205
- "x": input_samples,
206
- "y": input_history_data,
207
- "hovertext": "History: Test hist vector",
208
- "hoverinfo": "y+x+text",
209
- "name": "History",
210
- "showlegend": False,
211
- "legendgroup": "History",
212
- "legendrank": None,
213
- }
214
-
215
- assert created_trace == expected_trace
216
-
217
-
218
- def test_create_history_vector_trace_raise_error() -> None:
219
- with pytest.raises(ValueError) as err:
220
- create_history_vector_trace(
221
- samples=[datetime.datetime(2020, 1, 1)],
222
- history_data=np.array([1.0, 2.0]),
223
- line_shape="linear",
224
- color="green",
225
- vector_name="Test hist vector",
226
- )
227
- assert str(err.value) == "Number of samples unequal number of data points!"
228
-
229
-
230
- def test_render_hovertemplate() -> None:
231
- template_daily = "(%{x|%b} %{x|%-d}, %{x|%Y}, %{y})<br>"
232
- template_weekly = template_daily
233
- template_monthly = "(%{x|%b} %{x|%Y}, %{y})<br>"
234
- template_quarterly = "(Q%{x|%q} %{x|%Y}, %{y})<br>"
235
- template_yearly = "(%{x|%Y}, %{y})<br>"
236
- template_default = "(%{x}, %{y})<br>"
237
-
238
- # Test PER_DAY_/PER_INTVL_ vector names
239
- assert template_daily == render_hovertemplate("PER_DAY_a", Frequency.DAILY)
240
- assert template_weekly == render_hovertemplate("PER_DAY_a", Frequency.WEEKLY)
241
- assert template_monthly == render_hovertemplate("PER_DAY_a", Frequency.MONTHLY)
242
- assert template_quarterly == render_hovertemplate("PER_DAY_a", Frequency.QUARTERLY)
243
- assert template_yearly == render_hovertemplate("PER_DAY_a", Frequency.YEARLY)
244
- assert template_default == render_hovertemplate("PER_DAY_a", None)
245
-
246
- # Test other vector names
247
- assert template_default == render_hovertemplate("Vector_a", Frequency.DAILY)
248
- assert template_default == render_hovertemplate("Vector_a", Frequency.WEEKLY)
249
- assert template_default == render_hovertemplate("Vector_a", Frequency.MONTHLY)
250
- assert template_default == render_hovertemplate("Vector_a", Frequency.QUARTERLY)
251
- assert template_default == render_hovertemplate("Vector_a", Frequency.YEARLY)
252
- assert template_default == render_hovertemplate("Vector_a", None)
253
-
254
-
255
- def test_create_vector_fanchart_traces_all_fanchart_options() -> None:
256
- created_fanchart_traces = create_vector_fanchart_traces(
257
- INPUT_VECTOR_STATISTICS_DF,
258
- fanchart_options=[
259
- FanchartOptions.MEAN,
260
- FanchartOptions.MIN_MAX,
261
- FanchartOptions.P10_P90,
262
- ],
263
- hex_color="#2b00ff",
264
- legend_group="First Legendgroup",
265
- line_shape="linear",
266
- show_legend=True,
267
- )
268
-
269
- # Verify number of trace dicts in list
270
- assert len(created_fanchart_traces) == 5
271
-
272
- # Verify Min
273
- assert created_fanchart_traces[0]["name"] == "First Legendgroup"
274
- assert created_fanchart_traces[0].get("fill", None) is None
275
- assert created_fanchart_traces[0]["hovertemplate"] == "(%{x}, %{y})<br>Minimum"
276
- assert np.array_equal(created_fanchart_traces[0]["y"], np.array([2.0, 2.5]))
277
- assert created_fanchart_traces[0]["x"] == [
278
- datetime.datetime(2020, 1, 1),
279
- datetime.datetime(2020, 1, 2),
280
- ]
281
-
282
- # Verify P90
283
- assert created_fanchart_traces[1]["name"] == "First Legendgroup"
284
- assert created_fanchart_traces[1].get("fill", None) == "tonexty"
285
- assert created_fanchart_traces[1]["hovertemplate"] == "(%{x}, %{y})<br>P90"
286
- assert np.array_equal(created_fanchart_traces[1]["y"], np.array([5.0, 5.5]))
287
- assert created_fanchart_traces[1]["x"] == [
288
- datetime.datetime(2020, 1, 1),
289
- datetime.datetime(2020, 1, 2),
290
- ]
291
-
292
- # Verify P10
293
- assert created_fanchart_traces[2]["name"] == "First Legendgroup"
294
- assert created_fanchart_traces[2].get("fill", None) == "tonexty"
295
- assert created_fanchart_traces[2]["hovertemplate"] == "(%{x}, %{y})<br>P10"
296
- assert np.array_equal(created_fanchart_traces[2]["y"], np.array([4.0, 4.5]))
297
- assert created_fanchart_traces[2]["x"] == [
298
- datetime.datetime(2020, 1, 1),
299
- datetime.datetime(2020, 1, 2),
300
- ]
301
-
302
- # Verify Max
303
- assert created_fanchart_traces[3]["name"] == "First Legendgroup"
304
- assert created_fanchart_traces[3].get("fill", None) == "tonexty"
305
- assert created_fanchart_traces[3]["hovertemplate"] == "(%{x}, %{y})<br>Maximum"
306
- assert np.array_equal(created_fanchart_traces[3]["y"], np.array([3.0, 3.5]))
307
- assert created_fanchart_traces[3]["x"] == [
308
- datetime.datetime(2020, 1, 1),
309
- datetime.datetime(2020, 1, 2),
310
- ]
311
-
312
- # Verify Mean
313
- assert created_fanchart_traces[4]["name"] == "First Legendgroup"
314
- assert created_fanchart_traces[4].get("fill", None) is None
315
- assert created_fanchart_traces[4]["hovertemplate"] == "(%{x}, %{y})<br>Mean"
316
- assert np.array_equal(created_fanchart_traces[4]["y"], np.array([1.0, 1.5]))
317
- assert created_fanchart_traces[4]["x"] == [
318
- datetime.datetime(2020, 1, 1),
319
- datetime.datetime(2020, 1, 2),
320
- ]
321
-
322
-
323
- def test_create_vector_fanchart_traces_subset_fanchart_options() -> None:
324
- created_fanchart_traces = create_vector_fanchart_traces(
325
- INPUT_VECTOR_STATISTICS_DF,
326
- fanchart_options=[
327
- FanchartOptions.MEAN,
328
- FanchartOptions.P10_P90,
329
- ],
330
- hex_color="#2b00ff",
331
- legend_group="Second Legendgroup",
332
- line_shape="linear",
333
- show_legend=True,
334
- )
335
-
336
- # Verify number of trace dicts in list
337
- assert len(created_fanchart_traces) == 3
338
-
339
- # Verify P90
340
- assert created_fanchart_traces[0]["name"] == "Second Legendgroup"
341
- assert created_fanchart_traces[0].get("fill", None) is None
342
- assert created_fanchart_traces[0]["hovertemplate"] == "(%{x}, %{y})<br>P90"
343
- assert np.array_equal(created_fanchart_traces[0]["y"], np.array([5.0, 5.5]))
344
- assert created_fanchart_traces[0]["x"] == [
345
- datetime.datetime(2020, 1, 1),
346
- datetime.datetime(2020, 1, 2),
347
- ]
348
-
349
- # Verify P10
350
- assert created_fanchart_traces[1]["name"] == "Second Legendgroup"
351
- assert created_fanchart_traces[1].get("fill", None) == "tonexty"
352
- assert created_fanchart_traces[1]["hovertemplate"] == "(%{x}, %{y})<br>P10"
353
- assert np.array_equal(created_fanchart_traces[1]["y"], np.array([4.0, 4.5]))
354
- assert created_fanchart_traces[1]["x"] == [
355
- datetime.datetime(2020, 1, 1),
356
- datetime.datetime(2020, 1, 2),
357
- ]
358
-
359
- # Verify Mean
360
- assert created_fanchart_traces[2]["name"] == "Second Legendgroup"
361
- assert created_fanchart_traces[2].get("fill", None) is None
362
- assert created_fanchart_traces[2]["hovertemplate"] == "(%{x}, %{y})<br>Mean"
363
- assert np.array_equal(created_fanchart_traces[2]["y"], np.array([1.0, 1.5]))
364
- assert created_fanchart_traces[2]["x"] == [
365
- datetime.datetime(2020, 1, 1),
366
- datetime.datetime(2020, 1, 2),
367
- ]
368
-
369
-
370
- def test_create_vector_statistics_traces_all_statistics_options() -> None:
371
- created_statistics_traces = create_vector_statistics_traces(
372
- INPUT_VECTOR_STATISTICS_DF,
373
- statistics_options=[
374
- StatisticsOptions.MEAN,
375
- StatisticsOptions.MIN,
376
- StatisticsOptions.MAX,
377
- StatisticsOptions.P10,
378
- StatisticsOptions.P50,
379
- StatisticsOptions.P90,
380
- ],
381
- color="green",
382
- legend_group="Third Legendgroup",
383
- line_shape="linear",
384
- )
385
-
386
- # Verify number of trace dicts in list
387
- assert len(created_statistics_traces) == 6
388
-
389
- # Verify Min
390
- assert created_statistics_traces[0]["name"] == "Third Legendgroup"
391
- assert created_statistics_traces[0]["hovertemplate"] == "(%{x}, %{y})<br>Minimum"
392
- assert np.array_equal(created_statistics_traces[0]["y"], np.array([2.0, 2.5]))
393
- assert np.array_equal(
394
- created_statistics_traces[0]["x"],
395
- np.array(
396
- [
397
- datetime.datetime(2020, 1, 1),
398
- datetime.datetime(2020, 1, 2),
399
- ]
400
- ),
401
- )
402
-
403
- # Verify P90
404
- assert created_statistics_traces[1]["name"] == "Third Legendgroup"
405
- assert created_statistics_traces[1]["hovertemplate"] == "(%{x}, %{y})<br>P90"
406
- assert np.array_equal(created_statistics_traces[1]["y"], np.array([5.0, 5.5]))
407
- assert np.array_equal(
408
- created_statistics_traces[1]["x"],
409
- np.array(
410
- [
411
- datetime.datetime(2020, 1, 1),
412
- datetime.datetime(2020, 1, 2),
413
- ]
414
- ),
415
- )
416
-
417
- # Verify P50
418
- assert created_statistics_traces[2]["name"] == "Third Legendgroup"
419
- assert created_statistics_traces[2]["hovertemplate"] == "(%{x}, %{y})<br>P50"
420
- assert np.array_equal(created_statistics_traces[2]["y"], np.array([6.0, 6.5]))
421
- assert np.array_equal(
422
- created_statistics_traces[2]["x"],
423
- np.array(
424
- [
425
- datetime.datetime(2020, 1, 1),
426
- datetime.datetime(2020, 1, 2),
427
- ]
428
- ),
429
- )
430
-
431
- # Verify P10
432
- assert created_statistics_traces[3]["name"] == "Third Legendgroup"
433
- assert created_statistics_traces[3]["hovertemplate"] == "(%{x}, %{y})<br>P10"
434
- assert np.array_equal(created_statistics_traces[3]["y"], np.array([4.0, 4.5]))
435
- assert np.array_equal(
436
- created_statistics_traces[3]["x"],
437
- np.array(
438
- [
439
- datetime.datetime(2020, 1, 1),
440
- datetime.datetime(2020, 1, 2),
441
- ]
442
- ),
443
- )
444
-
445
- # Verify Max
446
- assert created_statistics_traces[4]["name"] == "Third Legendgroup"
447
- assert created_statistics_traces[4]["hovertemplate"] == "(%{x}, %{y})<br>Maximum"
448
- assert np.array_equal(created_statistics_traces[4]["y"], np.array([3.0, 3.5]))
449
- assert np.array_equal(
450
- created_statistics_traces[4]["x"],
451
- np.array(
452
- [
453
- datetime.datetime(2020, 1, 1),
454
- datetime.datetime(2020, 1, 2),
455
- ]
456
- ),
457
- )
458
-
459
- # Verify Mean
460
- assert created_statistics_traces[5]["name"] == "Third Legendgroup"
461
- assert created_statistics_traces[5]["hovertemplate"] == "(%{x}, %{y})<br>Mean"
462
- assert np.array_equal(created_statistics_traces[5]["y"], np.array([1.0, 1.5]))
463
- assert np.array_equal(
464
- created_statistics_traces[5]["x"],
465
- np.array(
466
- [
467
- datetime.datetime(2020, 1, 1),
468
- datetime.datetime(2020, 1, 2),
469
- ]
470
- ),
471
- )
472
-
473
-
474
- def test_create_vector_statistics_traces_subset_statistics_options() -> None:
475
- created_statistics_traces = create_vector_statistics_traces(
476
- INPUT_VECTOR_STATISTICS_DF,
477
- statistics_options=[
478
- StatisticsOptions.MEAN,
479
- StatisticsOptions.MIN,
480
- StatisticsOptions.P10,
481
- ],
482
- color="green",
483
- legend_group="Fourth Legendgroup",
484
- line_shape="linear",
485
- )
486
-
487
- # Verify number of trace dicts in list
488
- assert len(created_statistics_traces) == 3
489
-
490
- # Verify P50
491
- assert created_statistics_traces[0]["name"] == "Fourth Legendgroup"
492
- assert created_statistics_traces[0]["hovertemplate"] == "(%{x}, %{y})<br>Minimum"
493
- assert np.array_equal(created_statistics_traces[0]["y"], np.array([2.0, 2.5]))
494
- assert np.array_equal(
495
- created_statistics_traces[0]["x"],
496
- np.array(
497
- [
498
- datetime.datetime(2020, 1, 1),
499
- datetime.datetime(2020, 1, 2),
500
- ]
501
- ),
502
- )
503
-
504
- # Verify P10
505
- assert created_statistics_traces[1]["name"] == "Fourth Legendgroup"
506
- assert created_statistics_traces[1]["hovertemplate"] == "(%{x}, %{y})<br>P10"
507
- assert np.array_equal(created_statistics_traces[1]["y"], np.array([4.0, 4.5]))
508
- assert np.array_equal(
509
- created_statistics_traces[1]["x"],
510
- np.array(
511
- [
512
- datetime.datetime(2020, 1, 1),
513
- datetime.datetime(2020, 1, 2),
514
- ]
515
- ),
516
- )
517
-
518
- # Verify Mean
519
- assert created_statistics_traces[2]["name"] == "Fourth Legendgroup"
520
- assert created_statistics_traces[2]["hovertemplate"] == "(%{x}, %{y})<br>Mean"
521
- assert np.array_equal(created_statistics_traces[2]["y"], np.array([1.0, 1.5]))
522
- assert np.array_equal(
523
- created_statistics_traces[2]["x"],
524
- np.array(
525
- [
526
- datetime.datetime(2020, 1, 1),
527
- datetime.datetime(2020, 1, 2),
528
- ]
529
- ),
530
- )
@@ -1,119 +0,0 @@
1
- import datetime
2
-
3
- import pandas as pd
4
- from pandas._testing import assert_frame_equal
5
-
6
- # pylint: disable=line-too-long
7
- from webviz_subsurface.plugins._simulation_time_series._views._subplot_view._utils.dataframe_utils import (
8
- create_relative_to_date_df,
9
- )
10
-
11
-
12
- def test_create_relative_to_date_df_consistent_realization_for_all_dates() -> None:
13
- # All dates are represented across all realizations
14
- input_df = pd.DataFrame(
15
- columns=["DATE", "REAL", "A", "B"],
16
- data=[
17
- [datetime.datetime(2263, 1, 1), 1, 10.0, 130.0],
18
- [datetime.datetime(2263, 2, 1), 1, 45.0, 135.0],
19
- [datetime.datetime(2263, 3, 1), 1, 50.0, 140.0],
20
- [datetime.datetime(2263, 4, 1), 1, 55.0, 145.0],
21
- [datetime.datetime(2263, 1, 1), 2, 11.0, 150.0],
22
- [datetime.datetime(2263, 2, 1), 2, 65.0, 155.0],
23
- [datetime.datetime(2263, 3, 1), 2, 70.0, 160.0],
24
- [datetime.datetime(2263, 4, 1), 2, 75.0, 165.0],
25
- [datetime.datetime(2263, 1, 1), 3, 12.0, 170.0],
26
- [datetime.datetime(2263, 2, 1), 3, 85.0, 175.0],
27
- [datetime.datetime(2263, 3, 1), 3, 90.0, 180.0],
28
- [datetime.datetime(2263, 4, 1), 3, 95.0, 185.0],
29
- ],
30
- )
31
- expected_df = pd.DataFrame(
32
- columns=["DATE", "REAL", "A", "B"],
33
- data=[
34
- [datetime.datetime(2263, 1, 1), 1, 0.0, 0.0],
35
- [datetime.datetime(2263, 2, 1), 1, 35.0, 5.0],
36
- [datetime.datetime(2263, 3, 1), 1, 40.0, 10.0],
37
- [datetime.datetime(2263, 4, 1), 1, 45.0, 15.0],
38
- [datetime.datetime(2263, 1, 1), 2, 0.0, 0.0],
39
- [datetime.datetime(2263, 2, 1), 2, 54.0, 5.0],
40
- [datetime.datetime(2263, 3, 1), 2, 59.0, 10.0],
41
- [datetime.datetime(2263, 4, 1), 2, 64.0, 15.0],
42
- [datetime.datetime(2263, 1, 1), 3, 0.0, 0.0],
43
- [datetime.datetime(2263, 2, 1), 3, 73.0, 5.0],
44
- [datetime.datetime(2263, 3, 1), 3, 78.0, 10.0],
45
- [datetime.datetime(2263, 4, 1), 3, 83.0, 15.0],
46
- ],
47
- )
48
-
49
- assert_frame_equal(
50
- create_relative_to_date_df(input_df, datetime.datetime(2263, 1, 1)), expected_df
51
- )
52
-
53
-
54
- def test_create_relative_to_date_df_relative_date_missing_a_realization() -> None:
55
- # Missing datetime.datetime(2263, 1, 1) for real = 3!
56
- input_df = pd.DataFrame(
57
- columns=["DATE", "REAL", "A", "B"],
58
- data=[
59
- [datetime.datetime(2263, 1, 1), 1, 10.0, 130.0],
60
- [datetime.datetime(2263, 2, 1), 1, 45.0, 135.0],
61
- [datetime.datetime(2263, 3, 1), 1, 50.0, 140.0],
62
- [datetime.datetime(2263, 4, 1), 1, 55.0, 145.0],
63
- [datetime.datetime(2263, 1, 1), 2, 11.0, 150.0],
64
- [datetime.datetime(2263, 2, 1), 2, 65.0, 155.0],
65
- [datetime.datetime(2263, 3, 1), 2, 70.0, 160.0],
66
- [datetime.datetime(2263, 4, 1), 2, 75.0, 165.0],
67
- [datetime.datetime(2263, 2, 1), 3, 85.0, 175.0],
68
- [datetime.datetime(2263, 3, 1), 3, 90.0, 180.0],
69
- [datetime.datetime(2263, 4, 1), 3, 95.0, 185.0],
70
- ],
71
- )
72
- expected_df = pd.DataFrame(
73
- columns=["DATE", "REAL", "A", "B"],
74
- data=[
75
- [datetime.datetime(2263, 1, 1), 1, 0.0, 0.0],
76
- [datetime.datetime(2263, 2, 1), 1, 35.0, 5.0],
77
- [datetime.datetime(2263, 3, 1), 1, 40.0, 10.0],
78
- [datetime.datetime(2263, 4, 1), 1, 45.0, 15.0],
79
- [datetime.datetime(2263, 1, 1), 2, 0.0, 0.0],
80
- [datetime.datetime(2263, 2, 1), 2, 54.0, 5.0],
81
- [datetime.datetime(2263, 3, 1), 2, 59.0, 10.0],
82
- [datetime.datetime(2263, 4, 1), 2, 64.0, 15.0],
83
- ],
84
- )
85
-
86
- assert_frame_equal(
87
- create_relative_to_date_df(input_df, datetime.datetime(2263, 1, 1)), expected_df
88
- )
89
-
90
-
91
- def test_create_relative_to_date_df_relative_date_not_existing() -> None:
92
- # Missing datetime.datetime(2263, 5, 1)
93
- input_df = pd.DataFrame(
94
- columns=["DATE", "REAL", "A", "B"],
95
- data=[
96
- [datetime.datetime(2263, 1, 1), 1, 10.0, 130.0],
97
- [datetime.datetime(2263, 2, 1), 1, 45.0, 135.0],
98
- [datetime.datetime(2263, 3, 1), 1, 50.0, 140.0],
99
- [datetime.datetime(2263, 4, 1), 1, 55.0, 145.0],
100
- [datetime.datetime(2263, 1, 1), 2, 11.0, 150.0],
101
- [datetime.datetime(2263, 2, 1), 2, 65.0, 155.0],
102
- [datetime.datetime(2263, 3, 1), 2, 70.0, 160.0],
103
- [datetime.datetime(2263, 4, 1), 2, 75.0, 165.0],
104
- [datetime.datetime(2263, 1, 1), 3, 12.0, 170.0],
105
- [datetime.datetime(2263, 2, 1), 3, 85.0, 175.0],
106
- [datetime.datetime(2263, 3, 1), 3, 90.0, 180.0],
107
- [datetime.datetime(2263, 4, 1), 3, 95.0, 185.0],
108
- ],
109
- )
110
-
111
- # Ensure dtype for columns for df with no rows
112
- _columns = {
113
- name: pd.Series(dtype=input_df.dtypes[name]) for name in input_df.columns
114
- }
115
- expected_df = pd.DataFrame(_columns)
116
-
117
- assert_frame_equal(
118
- create_relative_to_date_df(input_df, datetime.datetime(2263, 5, 1)), expected_df
119
- )
@@ -1,51 +0,0 @@
1
- import datetime
2
-
3
- import pytest
4
-
5
- # pylint: disable=line-too-long
6
- from webviz_subsurface.plugins._simulation_time_series._views._subplot_view._utils.datetime_utils import (
7
- from_str,
8
- to_str,
9
- )
10
-
11
-
12
- def test_from_str_success() -> None:
13
- assert from_str("2021-03-11") == datetime.datetime(2021, 3, 11)
14
- assert from_str("1956-08-26") == datetime.datetime(1956, 8, 26)
15
-
16
-
17
- def test_from_str_assert() -> None:
18
- # Invalid datetime arguments (hour, minute, second, microsecond)
19
- invalid_dates = ["2021-03-11-23-55-11", "1996-05-26-23", "2001-08-11-11-43"]
20
- for _date in invalid_dates:
21
- with pytest.raises(ValueError) as err:
22
- from_str(_date)
23
- assert str(err.value) == f"unconverted data remains: {_date[10:]}"
24
-
25
-
26
- def test_to_str_success() -> None:
27
- assert to_str(datetime.datetime(2021, 6, 13)) == "2021-06-13"
28
- assert to_str(datetime.datetime(2021, 12, 28)) == "2021-12-28"
29
- assert to_str(datetime.datetime(2021, 3, 7, 0)) == "2021-03-07"
30
- assert to_str(datetime.datetime(2021, 10, 22, 0, 0)) == "2021-10-22"
31
- assert to_str(datetime.datetime(2021, 1, 23, 0, 0, 0)) == "2021-01-23"
32
- assert to_str(datetime.datetime(2021, 12, 28, 0, 0, 0, 0)) == "2021-12-28"
33
-
34
-
35
- def test_to_str_assert() -> None:
36
- # Invalid datetime arguments (hour, minute, second, microsecond)
37
- invalid_dates = [
38
- datetime.datetime(2021, 6, 13, 15, 32, 11, 43),
39
- datetime.datetime(2021, 6, 13, 5, 21, 45),
40
- datetime.datetime(2021, 6, 13, 23, 55),
41
- datetime.datetime(2021, 6, 13, 5),
42
- ]
43
-
44
- for _date in invalid_dates:
45
- with pytest.raises(ValueError) as err:
46
- to_str(_date)
47
- assert (
48
- str(err.value)
49
- == f"Invalid date resolution, expected no data for hour, minute, second"
50
- f" or microsecond for {str(_date)}"
51
- )