From 58be77988b3a19933a8a1fa28c58c0b5c2ee03a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Herje?= <82032112+jorgenherje@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:19:05 +0200 Subject: [PATCH] Fix bug when using presampled providers in SimulationTimeSeries plugin (#1241) When preform_presamling was set true in config, the presampled provider retrieved resampling_frequency not equal None in request of dates. Prevent requesting resampling frequency when presampled providers are utilized. --- .../_simulation_time_series/_plugin.py | 9 +++---- .../_settings/_resampling_frequency.py | 22 ++++++++--------- .../_views/_subplot_view/_view.py | 24 +++++++++++++------ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/webviz_subsurface/plugins/_simulation_time_series/_plugin.py b/webviz_subsurface/plugins/_simulation_time_series/_plugin.py index 3bc6fc1ae..afea85188 100644 --- a/webviz_subsurface/plugins/_simulation_time_series/_plugin.py +++ b/webviz_subsurface/plugins/_simulation_time_series/_plugin.py @@ -122,7 +122,7 @@ def __init__( "is not supported by plugin yet!" ) self._sampling = Frequency(sampling) - self._presampled_frequency = None + self._has_presampled_providers = False # TODO: Update functionality when allowing raw data and csv file input # NOTE: If csv is implemented-> handle/disable statistics, PER_INTVL_, PER_DAY_, delta @@ -135,10 +135,11 @@ def __init__( for ensemble_name in ensembles } if perform_presampling: - self._presampled_frequency = self._sampling + presampled_frequency = self._sampling + self._has_presampled_providers = True self._input_provider_set = ( create_presampled_ensemble_summary_provider_set_from_paths( - ensemble_paths, rel_file_pattern, self._presampled_frequency + ensemble_paths, rel_file_pattern, presampled_frequency ) ) else: @@ -324,7 +325,7 @@ def __init__( SubplotView( custom_vector_definitions=self._custom_vector_definitions, custom_vector_definitions_base=self._custom_vector_definitions_base, - disable_resampling_dropdown=self._presampled_frequency is not None, + has_presampled_providers=self._has_presampled_providers, initial_selected_vectors=self._initial_vectors, initial_vector_selector_data=self._initial_vector_selector_data, initial_visualization=self._initial_visualization_selection, diff --git a/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_settings/_resampling_frequency.py b/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_settings/_resampling_frequency.py index f35706544..8d5289052 100644 --- a/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_settings/_resampling_frequency.py +++ b/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_settings/_resampling_frequency.py @@ -21,25 +21,31 @@ class Ids(StrEnum): def __init__( self, - disable_resampling_dropdown: bool, + disable_dropdowns: bool, selected_resampling_frequency: Frequency, ensembles_dates: List[datetime.datetime], input_provider_set: EnsembleSummaryProviderSet, ) -> None: super().__init__("Resampling frequency") - self._disable_resampling_dropdown = disable_resampling_dropdown + self._disable_dropdowns = disable_dropdowns self._selected_resampling_frequency = selected_resampling_frequency self._ensembles_dates = ensembles_dates self._input_provider_set = input_provider_set def layout(self) -> List[Component]: return [ + wcc.Label( + "NB: Disabled for pre-sampled data", + style={"font-style": "italic", "font-weight": "bold"} + if self._disable_dropdowns + else {"display": "none"}, + ), wcc.Dropdown( id=self.register_component_unique_id( ResamplingFrequencySettings.Ids.RESAMPLING_FREQUENCY_DROPDOWN ), clearable=False, - disabled=self._disable_resampling_dropdown, + disabled=self._disable_dropdowns, options=[ { "label": frequency.value, @@ -59,11 +65,11 @@ def layout(self) -> List[Component]: }, ), wcc.Dropdown( - clearable=True, - disabled=self._disable_resampling_dropdown, id=self.register_component_unique_id( ResamplingFrequencySettings.Ids.RELATIVE_DATE_DROPDOWN ), + clearable=True, + disabled=self._disable_dropdowns, options=[ { "label": datetime_utils.to_str(_date), @@ -72,10 +78,4 @@ def layout(self) -> List[Component]: for _date in sorted(self._ensembles_dates) ], ), - wcc.Label( - "NB: Disabled for pre-sampled data", - style={"font-style": "italic"} - if self._disable_resampling_dropdown - else {"display": "none"}, - ), ] diff --git a/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_view.py b/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_view.py index 21a424f5c..0f5d488dd 100644 --- a/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_view.py +++ b/webviz_subsurface/plugins/_simulation_time_series/_views/_subplot_view/_view.py @@ -71,7 +71,7 @@ def __init__( self, custom_vector_definitions: dict, custom_vector_definitions_base: dict, - disable_resampling_dropdown: bool, + has_presampled_providers: bool, initial_selected_vectors: List[str], initial_vector_selector_data: list, initial_visualization: VisualizationOptions, @@ -90,15 +90,20 @@ def __init__( column = self.add_column() column.add_view_element(SubplotGraph(), SubplotView.Ids.SUBPLOT) + # Do not request resampling frequency for pre-sampled providers + ensemble_dates = ( + [] + if has_presampled_providers + else input_provider_set.all_dates(selected_resampling_frequency) + ) + self.add_settings_groups( { SubplotView.Ids.GROUP_BY_SETTINGS: GroupBySettings(), SubplotView.Ids.RESAMPLING_FREQUENCY_SETTINGS: ResamplingFrequencySettings( - disable_resampling_dropdown=disable_resampling_dropdown, + disable_dropdowns=has_presampled_providers, selected_resampling_frequency=selected_resampling_frequency, - ensembles_dates=input_provider_set.all_dates( - selected_resampling_frequency - ), + ensembles_dates=ensemble_dates, input_provider_set=input_provider_set, ), SubplotView.Ids.ENSEMBLE_SETTINGS: EnsemblesSettings( @@ -129,6 +134,7 @@ def __init__( self._line_shape_fallback = line_shape_fallback self._user_defined_vector_definitions = user_defined_vector_definitions self._observations = observations + self._has_presampled_providers = has_presampled_providers # pylint: disable=too-many-statements def set_callbacks(self) -> None: @@ -305,7 +311,7 @@ def _update_graph( relative_date: Optional[datetime.datetime] = ( None - if relative_date_value is None + if relative_date_value is None or self._has_presampled_providers else datetime_utils.from_str(relative_date_value) ) @@ -682,7 +688,7 @@ def _user_download_data( ) relative_date: Optional[datetime.datetime] = ( None - if relative_date_value is None + if relative_date_value is None or self._has_presampled_providers else datetime_utils.from_str(relative_date_value) ) @@ -912,6 +918,10 @@ def _update_relative_date_dropdown_and_trace_options_style( If dates are not existing for a provider, the data accessor must handle invalid relative date selection! """ + # Early return when providers are pre-sampled + if self._has_presampled_providers: + return ([], None, {"display": "block"}) + resampling_frequency = Frequency.from_string_value( resampling_frequency_value )