-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into pvt_gor_bug
- Loading branch information
Showing
35 changed files
with
8,788 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/integration_tests/plugin_tests/test_simulation_timeseries_onebyone.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import warnings | ||
|
||
# pylint: disable=no-name-in-module | ||
from webviz_config.plugins import SimulationTimeSeriesOneByOne | ||
from webviz_config.testing import WebvizComposite | ||
|
||
|
||
def test_simulation_timeseries_onebyone( | ||
_webviz_duo: WebvizComposite, shared_settings: dict | ||
) -> None: | ||
plugin = SimulationTimeSeriesOneByOne( | ||
webviz_settings=shared_settings["SENS_SETTINGS"], | ||
ensembles=shared_settings["SENS_ENSEMBLES"], | ||
initial_vector="FOPT", | ||
) | ||
_webviz_duo.start_server(plugin) | ||
logs = [] | ||
for log in _webviz_duo.get_logs(): | ||
if "dash_renderer" in log.get("message"): | ||
warnings.warn(log.get("message")) | ||
else: | ||
logs.append(log) | ||
assert not logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import base64 | ||
import io | ||
import math | ||
from typing import List | ||
|
||
from PIL import Image, ImageDraw | ||
|
||
|
||
def round_to_significant(val: float, sig: int = 4) -> float: | ||
"""Roud a number to a specified number of significant digits.""" | ||
if val == 0: | ||
return 0 | ||
return round(val, sig - int(math.floor(math.log10(abs(val)))) - 1) | ||
|
||
|
||
def rgb_to_hex(color: List[int]) -> str: | ||
"""Convert an RGB color to a hex string.""" | ||
return f"#{color[1]:02x}{color[2]:02x}{color[3]:02x}" | ||
|
||
|
||
def image_to_base64(img: Image) -> str: | ||
"""Convert an image to a base64 string.""" | ||
buffer = io.BytesIO() | ||
img.save(buffer, format="PNG") | ||
buffer.seek(0) | ||
return base64.b64encode(buffer.read()).decode("utf-8") | ||
|
||
|
||
def create_colormap_image_string( | ||
colors: List, width: int = 100, height: int = 20 | ||
) -> str: | ||
"""Create a colormap image and return it as a base64 string.""" | ||
img = Image.new("RGB", (width, height)) | ||
draw = ImageDraw.Draw(img) | ||
|
||
for i, color in enumerate(colors): | ||
x_0 = int(i / len(colors) * width) | ||
x_1 = int((i + 1) / len(colors) * width) | ||
draw.rectangle([(x_0, 0), (x_1, height)], fill=rgb_to_hex(color)) | ||
|
||
return f"data:image/png;base64,{image_to_base64(img)}" |
Oops, something went wrong.