Skip to content

Commit 4fb99bb

Browse files
AudunSektnanNRFredrikNevjenNRvegardkvjorgesicachanr
authored
CO2Leakage latest bug fixes / development (#1330)
* Merge latest from develop (#51) * Fix scale factor for Unit set to Fraction * Attempt to fix issue with containment plots failing to show up initially * Update encrypted contact information * Improve hover-information * Fix bug that removed legend text in containment plots * Fix bug with UNSMRY assuming an older csv format * Add ContainmentDataProvider wrapper class Intended to wrap an EnsembleTableProvider that reads containment summary files (either csv or arrow) * Add UnsmryDataProvider wrapper class Intended to wrap an EnsembleTableProvider that reads unsmry summary files (either csv or arrow) * Add validation to containment classes * Change summary file read order Arrow format is attempted first instead of csv * Change summary file read order Fix issue with unsmry option and missing files * Fix issue with legend when first real is not "0" * Fix bug with unsmry reset * Remove large csv file check * Remove unused file size function * Changes to adapt CO2Leakage for residual trapping maps visualization * Format changes * Solve minor issues * Solve typo * Fix issue in property_origin * Minor fixes * Rename MapGroup CO2_MASS * Add visualization menu with separate filters for each attribute * Formatting with mypy, pylint and black * Simplify MapThresholds class * Fix visualization threshold bug for plume maps * Add mean in tornado table VolumetricAnalysis (#1297) * Fix merge conflict after rebase * Fix issues related to missing polygon data * Fix black format issues * Fix another conflict from rebase * Fix another rebase conflict * Handle missing well picks and mypy errors * Remove surface cache file mode (#1298) * OS temp path for image server (#1302) * Add missing file handling for well picks * Enable usage without either maps or containment tables * CCS-194: Fix after change of units for co2 mass. (#34) * Tweak visualization filter * Add polygon provider Basically a copy of the provider for fault polygons. Renamed "fault polygon" to "polygon" and added a couple of TODOs * CCS-213: Handle plume_groups (#36) * CCS-213: Start using plume group from containment results. * CCS-213: Cont using plume group from containment results. * CCS-213: Fixes for plume groups. * CCS-213: Add plume groups to filter. * CCS-213: Some minor fixes. * CCS-213: Minor fix. * Some tests. * CCS-213: Join lines before/after merge when coloring by plume groups. * CCS-213: Some refactoring. * CCS-213: Fix combine plume group with none as mark. * CCS-213: Minor fix. * CCS-213: Remove some prints. * CCS-213: Use starting 0-values for unmerged wells. * CCS-213: Fix for multiple realization. * CCS-213: Fix case without plume groups. * CCS-213: Minor fix. * CCS-213: Fix black. * CCS-213: Some refactoring. * CCS-213: Minor change, remove temp code. * Combine time plots, add mean/P10/P90 option * Fix formatting * Fix missing issues with EnsemblePolygonProvider * Distinguish p10 and p90 from mean, turn select-all-realizations into button * Introduce new polygon provider in plugin * Fix black/lint/mypy errorss * CCS-213: Rename "?" to "undetermined" and fix warning messages (#38) * CCS-213: Fix warning message. * CCS-213: Rename ? to undetermined. * Fix issues found while testing * Minor fix in _get_menu_options() (#39) * Minor fix in _get_menu_options(). * New minor fix. * Minor change. (#40) * CCS-212: Renaming (#41) * CCS-212: Renaming, graph plots. * CCS-212: Renaming, map plots. * CCS-212: More renaming, map plots. * CCS-212: More renaming, map plots. * CCS-191: Add statistics plot (#44) * CCS-191: Start on statistics plot. * CCS-191: Minor change. * CCS-191: Use color and mark options. * CCS-191: Cont use color and mark options. * CCS-191: Cont using color and mark options. * CCS-191: Fix in label names. * CCS-191: Add default category plotted, single option. * CCS-191: Minor fig fixes. * CCS-191: Add hovering. * CCS-191: Fix some filtering. * CCS-191: Remove prints and comments. * CCS-191: Fill date options, use in plot. * CCS-191: Same fixes for date, and use in first plot. * CCS-191: Change some names, add titles. * CCS-191: Clean up. * CCS-191: Fix in set_date_option(). * Black * isort * CCS-191: Minor change. * CCS-212: Renaming, changing same labels, changing back gas_phase to sgas etc, add code for XMF2 (#45) * CCS-212: Use old file names for sgas etc maps. * CCS-212: Allow XMF2-files as default in addition to AMFG. Some changes to labels for 2D maps. * CCS-212: Some clean up. * CCS-212: Add SGSTR as option. * CCS-212: Remove prints. * Fix linting (#49) * Fix linting * Fix linting 2 * Fix linting 3 * Fix linting 4 * Fix linting 5 * Fix linting 6 * Fix linting 7 * Fix linting 8 * Develop master merged (#50) * Add mean in tornado table VolumetricAnalysis (#1297) * Remove surface cache file mode (#1298) * OS temp path for image server (#1302) * Update README.md with deprecation warning (#1303) * No Active Rfts error message (#1304) Co-authored-by: Øyvind Lind-Johansen <olind@equinor.com> * Pandas 2 compatibility for RFT plotter (#1305) * Pandas 2 compability for RFT plotter * black * Remove use of `wcc.ColorScales` (#1306) * Fix FutureWarning - cast to dtype (#1309) * Pandas 2 compability for ParameterResponseCorrelation (#1310) * Add field outline and custom well picks colors to MapViewerFMU (#1311) * Replaced use of `DashSubsurfaceViewer` with `SubsurfaceViewer` (#1312) * Expose rft input files as arguments (#1313) * exposed rft input files as arguments * black version updated * pylint fixes * pylint fixes * more fixes --------- Co-authored-by: Øyvind Lind-Johansen <olind@equinor.com> * Disable cache for statistical surfaces (#1314) * Add check for length of numpy array (#1316) * Fix ensemble colors in relperm (#1317) --------- Co-authored-by: FredrikNevjenNR <fnevjen@nr.no> Co-authored-by: FredrikNevjenNR <150343101+FredrikNevjenNR@users.noreply.github.com> Co-authored-by: Vegard Kvernelv <vegard@nr.no> Co-authored-by: Jorge Sicacha <sicacha@nr.no> Co-authored-by: jorgesicachanr <114475076+jorgesicachanr@users.noreply.github.com> Co-authored-by: vegardkv <vkvernelv@gmail.com> * Manual new commit for changes in CCS-101. (#52) * CCS-192: Add box plot, plus CCS-249: Add zone/region/phase etc in title of plots (#53) * CCS-192: Start on new box plot. * CCS-192: Fix color order, and fix none as option for mark_by. * CCS-192: Add option to plot poitns. * CCS-192: Default false for show realization points. * CCS-192: Adjust layout, add default option. * CCS-192: Option for choosing probability plot vs box plot. * CCS-192: Minor change. * CCS-192: Minor fix. * CCS-192: Remove prints. * CCS-192: Minor fix. * CCS-192: Add custom hovering template for realization points. * CCS-192: Add info to plot titles. * CCS-192: Add info to time plots. * CCS-192: Minor fix. * Black * CCS-192: Improvements to box plot (#54) * CCS-192: Change options for plotting points. * CCS-192: Fix titles. * CCS-192: Try adding hoovering info. * CCS-192: Cont attempt hoovering info. * CCS-192: Change to using go.Box, more flexibility. * CCS-192: Fix hoovering for points. * CCS-192: Better hoovering info, placement. * CCS-192: Fix in hoovering info for realization points. * CCS-192: Visual improvements. * CCS-192: Change q1-q3 calc to numpy default, and fix whiskers calc. * CCS-192: Change default box, only single if >20 categories. * CCS-192: Remove prints, fix in q1 q3. * CCS-192: Minor fixes. * CCS-192: Remove prints, old code, new fix q1 q3. * CCS-192: Minor fix, and black. * CCS-192: Change order hoovering info. * CCS-192: Some fixes in box plot (#55) * CCS-192: Make sort by color possible. * CCS-192: Print p10, p90 in hoovering * CCS-192: Remove None option for points. * CCS-192: Some label changes. * CCS-266: Fix warning. (#56) * CCS-274: Remove default for actual volume csv file. (#57) * CCS-275: Add phase as option for "Color by" (#58) * CCS-275: Start adding color by phase as option. * CCS-275: Make correct filter boxes for color by phase. * CCS-275: Fixes for plots when using phase as color by. * CCS-275: Change colors for phase-split. * CCS-275: Clean up. * CCS-275: Black. * Isort. * mypy * CCS-275: Fix colors. * Define P10 as low, P90 as high in the time plot * Suggestion for solution to issue 248 (avoid reset) * Resolve rebase conflict * Refactor CO2Leakage Create separate functions for each callback for readability * Fix bug with time graph legend Legend of the time graph was not handled correctly when toggling items and changing settings * CCS-275: Change colors. (#61) * Adapt to receive only attributes that differ from the default setting (#63) * CCS-276: Redo line types, fixing bug (#64) * CCS-276: Try fix, and some debugging print. * CCS-276: Remove debug prints. * Fix black * Fix issues with legend persistence for box plot Box plot was using the same "LegendData" as bar plot, leading to odd behaviour. Also fixed default options for statistics and box plot * Change from polygon to polygons for default dir boundaries. (#62) * CCS-275: Bug fix. (#65) * Fix bug with box/statstics plot legend persist Most changes are refactoring the dict representing containment info into a class and how containment ui IDs are referenced. This simplified unifying the legend for bar and stats plot * Fix bug when re-visiting co2leakage * Update documentation * Adjust docstring * Attempt to fix bug legend issue With large data sets, it has been observed that the legend state was not always preserved for the box plot when changing settings. This fix attempts to resolve this by removing a unnecessary re-evaluation when the legend state changes. * Fix linting (#69) * Black * isort * mypy iteration 1. * Use _utils.enum_shim for StrEnum. * mypy iteratoin 2. * Pylint iteration 1. * Pylint iteration 2. * Pylint iteration 3. * Pylint iteration 4. --------- Co-authored-by: FredrikNevjenNR <fnevjen@nr.no> Co-authored-by: FredrikNevjenNR <150343101+FredrikNevjenNR@users.noreply.github.com> Co-authored-by: Vegard Kvernelv <vegard@nr.no> Co-authored-by: Jorge Sicacha <sicacha@nr.no> Co-authored-by: jorgesicachanr <114475076+jorgesicachanr@users.noreply.github.com> Co-authored-by: vegardkv <vkvernelv@gmail.com>
1 parent bb8a20d commit 4fb99bb

File tree

8 files changed

+1068
-740
lines changed

8 files changed

+1068
-740
lines changed

webviz_subsurface/plugins/_co2_leakage/_plugin.py

Lines changed: 619 additions & 501 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import List, Optional, TypedDict
2+
3+
4+
class LegendData(TypedDict):
5+
bar_legendonly: Optional[List[str]]
6+
time_legendonly: Optional[List[str]]
7+
stats_legendonly: Optional[List[str]]

webviz_subsurface/plugins/_co2_leakage/_utilities/callbacks.py

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from webviz_subsurface._providers.ensemble_surface_provider.ensemble_surface_provider import (
2121
SurfaceStatistic,
2222
)
23+
from webviz_subsurface.plugins._co2_leakage._types import LegendData
2324
from webviz_subsurface.plugins._co2_leakage._utilities import plume_extent
2425
from webviz_subsurface.plugins._co2_leakage._utilities.co2volume import (
2526
generate_co2_box_plot_figure,
@@ -31,6 +32,10 @@
3132
from webviz_subsurface.plugins._co2_leakage._utilities.containment_data_provider import (
3233
ContainmentDataProvider,
3334
)
35+
from webviz_subsurface.plugins._co2_leakage._utilities.containment_info import (
36+
ContainmentInfo,
37+
StatisticsTabOption,
38+
)
3439
from webviz_subsurface.plugins._co2_leakage._utilities.ensemble_well_picks import (
3540
EnsembleWellPicks,
3641
)
@@ -121,6 +126,17 @@ def from_server(
121126
)
122127

123128

129+
def extract_legendonly(figure: go.Figure) -> List[str]:
130+
# Finds the names OR legendgroup of the traces in the figure which have their
131+
# visibility set to "legendonly". In the figure, these traces are toggled OFF in the
132+
# legend.
133+
return [
134+
d.get("legendgroup", d.get("name"))
135+
for d in figure["data"]
136+
if d.get("visible", "") == "legendonly"
137+
]
138+
139+
124140
def derive_surface_address(
125141
surface_name: str,
126142
attribute: MapAttribute,
@@ -386,25 +402,24 @@ def generate_containment_figures(
386402
co2_scale: Union[Co2MassScale, Co2VolumeScale],
387403
realizations: List[int],
388404
y_limits: List[Optional[float]],
389-
containment_info: Dict[str, Union[str, None, List[str], int]],
405+
containment_info: ContainmentInfo,
406+
legenddata: LegendData,
390407
) -> Tuple[go.Figure, go.Figure, go.Figure]:
391408
try:
392-
fig0 = (
393-
no_update
394-
if not containment_info["update_first_figure"]
395-
else generate_co2_volume_figure(
396-
table_provider,
397-
table_provider.realizations,
398-
co2_scale,
399-
containment_info,
400-
)
409+
fig0 = generate_co2_volume_figure(
410+
table_provider,
411+
table_provider.realizations,
412+
co2_scale,
413+
containment_info,
414+
legenddata["bar_legendonly"],
401415
)
402416
fig1 = (
403417
generate_co2_time_containment_figure(
404418
table_provider,
405419
realizations,
406420
co2_scale,
407421
containment_info,
422+
legenddata["time_legendonly"],
408423
)
409424
if len(realizations) > 1
410425
else generate_co2_time_containment_one_realization_figure(
@@ -415,19 +430,25 @@ def generate_containment_figures(
415430
containment_info,
416431
)
417432
)
418-
if containment_info["statistics_tab_option"] == "probability_plot":
433+
if (
434+
containment_info.statistics_tab_option
435+
== StatisticsTabOption.PROBABILITY_PLOT
436+
):
419437
fig2 = generate_co2_statistics_figure(
420438
table_provider,
421439
realizations,
422440
co2_scale,
423441
containment_info,
442+
legenddata["stats_legendonly"],
424443
)
425444
else: # "box_plot"
445+
# Deliberately uses same legend as statistics
426446
fig2 = generate_co2_box_plot_figure(
427447
table_provider,
428448
realizations,
429449
co2_scale,
430450
containment_info,
451+
legenddata["stats_legendonly"],
431452
)
432453
except KeyError as exc:
433454
warnings.warn(f"Could not generate CO2 figures: {exc}")
@@ -475,6 +496,7 @@ def process_visualization_info(
475496
return stored_info
476497

477498

499+
# pylint: disable=too-many-locals
478500
def process_containment_info(
479501
zone: Optional[str],
480502
region: Optional[str],
@@ -486,10 +508,10 @@ def process_containment_info(
486508
sorting: str,
487509
lines_to_show: str,
488510
date_option: str,
489-
statistics_tab_option: str,
511+
statistics_tab_option: StatisticsTabOption,
490512
box_show_points: str,
491513
menu_options: MenuOptions,
492-
) -> Dict[str, Union[str, None, List[str], int]]:
514+
) -> ContainmentInfo:
493515
if mark_choice is None:
494516
mark_choice = "phase"
495517
zones = menu_options["zones"]
@@ -513,51 +535,57 @@ def plume_sort_key(name: str) -> int:
513535
region = "all"
514536
if "region" in [mark_choice, color_choice]:
515537
zone = "all"
516-
return {
517-
"zone": zone,
518-
"region": region,
519-
"zones": zones,
520-
"regions": regions,
521-
"phase": phase,
522-
"containment": containment,
523-
"plume_group": plume_group,
524-
"color_choice": color_choice,
525-
"mark_choice": mark_choice,
526-
"sorting": sorting,
527-
"phases": [phase for phase in menu_options["phases"] if phase != "total"],
528-
"containments": ["hazardous", "outside", "contained"],
529-
"plume_groups": plume_groups,
530-
"use_stats": lines_to_show == "stat",
531-
"date_option": date_option,
532-
"statistics_tab_option": statistics_tab_option,
533-
"box_show_points": box_show_points,
534-
}
538+
return ContainmentInfo(
539+
zone=zone,
540+
region=region,
541+
zones=zones,
542+
regions=regions,
543+
phase=phase,
544+
containment=containment,
545+
plume_group=plume_group,
546+
color_choice=color_choice,
547+
mark_choice=mark_choice,
548+
sorting=sorting,
549+
phases=[phase for phase in menu_options["phases"] if phase != "total"],
550+
containments=["hazardous", "outside", "contained"],
551+
plume_groups=plume_groups,
552+
use_stats=lines_to_show == "stat",
553+
date_option=date_option,
554+
statistics_tab_option=statistics_tab_option,
555+
box_show_points=box_show_points,
556+
)
535557

536558

537559
def make_plot_ids(
538560
ensemble: str,
539561
source: GraphSource,
540562
scale: Union[Co2MassScale, Co2VolumeScale],
541-
containment_info: Dict,
563+
containment_info: ContainmentInfo,
542564
realizations: List[int],
543-
lines_to_show: str,
544-
statistics_tab_option: str,
565+
# lines_to_show: str,
545566
num_figs: int,
546567
) -> List[str]:
547-
zone_str = (
548-
containment_info["zone"] if containment_info["zone"] is not None else "None"
549-
)
568+
"""
569+
Removed some keywords from plot id that we don't want to trigger updates for
570+
with respect to visible legends and potentially zoom level.
571+
572+
Note: Currently the legends are reset if you swap to a plot with different plot id
573+
and back, so it works temporarily, in a sense. This might be good enough for now.
574+
If we want to store it more extensively, we need to do something like what's been
575+
outlined in _plugin.py.
576+
"""
577+
zone_str = containment_info.zone if containment_info.zone is not None else "None"
550578
region_str = (
551-
containment_info["region"] if containment_info["region"] is not None else "None"
579+
containment_info.region if containment_info.region is not None else "None"
552580
)
553581
plume_group_str = (
554-
containment_info["plume_group"]
555-
if containment_info["plume_group"] is not None
582+
containment_info.plume_group
583+
if containment_info.plume_group is not None
556584
else "None"
557585
)
558586
mark_choice_str = (
559-
containment_info["mark_choice"]
560-
if containment_info["mark_choice"] is not None
587+
containment_info.mark_choice
588+
if containment_info.mark_choice is not None
561589
else "None"
562590
)
563591
plot_id = "-".join(
@@ -568,18 +596,19 @@ def make_plot_ids(
568596
zone_str,
569597
region_str,
570598
plume_group_str,
571-
str(containment_info["phase"]),
572-
str(containment_info["containment"]),
573-
containment_info["color_choice"],
599+
str(containment_info.phase),
600+
str(containment_info.containment),
601+
containment_info.color_choice,
574602
mark_choice_str,
575-
containment_info["sorting"],
576-
containment_info["date_option"],
603+
containment_info.sorting,
604+
containment_info.date_option,
577605
)
578606
)
579-
ids = [plot_id]
580-
ids += [plot_id + f"-{realizations}"] * (num_figs - 1)
581-
ids[1] += f"-{lines_to_show}"
582-
ids[2] += f"-{statistics_tab_option}"
607+
ids = [plot_id] * num_figs
608+
# ids += [plot_id + f"-{realizations}"] * (num_figs - 1)
609+
# ids[1] += f"-{lines_to_show}"
610+
ids[1] += "-single" if len(realizations) == 1 else "-multiple"
611+
ids[2] += f"-{containment_info.statistics_tab_option}"
583612
return ids
584613

585614

0 commit comments

Comments
 (0)