-
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.
Implement consistent handling of ensembles/realizations
- Loading branch information
Showing
5 changed files
with
133 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pandas | ||
import numpy as np | ||
import pathlib | ||
from typing import Dict | ||
|
||
|
||
def _read_co2_volumes(realization_paths: Dict[str, str]): | ||
records = [] | ||
for rz_name, rz_path in realization_paths.items(): | ||
try: | ||
df = pandas.read_csv( | ||
pathlib.Path(rz_path) / "share" / "results" / "tables" / "co2_volumes.csv", | ||
) | ||
except FileNotFoundError: | ||
continue | ||
last = df.iloc[np.argmax(df["date"])] | ||
label = str(rz_name) | ||
records += [ | ||
(label, last["co2_inside"], "inside", 0.0), | ||
(label, last["co2_outside"], "outside", last["co2_outside"]), | ||
] | ||
df = pandas.DataFrame.from_records(records, columns=["ensemble", "volume", "containment", "volume_outside"]) | ||
df.sort_values("volume_outside", inplace=True, ascending=False) | ||
return df | ||
|
||
|
||
def generate_co2_volume_figure(realization_paths: Dict[str, str], height): | ||
import plotly.express as px | ||
df = _read_co2_volumes(realization_paths) | ||
fig = px.bar(df, y="ensemble", x="volume", color="containment", title="End-state CO2 containment [m³]", orientation="h") | ||
fig.layout.height = height | ||
fig.layout.legend.title.text = "" | ||
fig.layout.legend.orientation = "h" | ||
fig.layout.yaxis.title = "" | ||
fig.layout.yaxis.tickangle = -90 | ||
fig.layout.xaxis.exponentformat = "power" | ||
fig.layout.xaxis.title = "" | ||
fig.layout.paper_bgcolor = "rgba(0,0,0,0)" | ||
fig.layout.margin.b = 10 | ||
fig.layout.margin.t = 60 | ||
fig.layout.margin.l = 10 | ||
fig.layout.margin.r = 10 | ||
return fig |
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 |
---|---|---|
@@ -1,51 +1,19 @@ | ||
import pandas | ||
import pathlib | ||
import numpy as np | ||
from typing import Optional | ||
from typing import Dict | ||
from enum import Enum | ||
from fmu.ensemble import ScratchEnsemble | ||
|
||
|
||
FAULT_POLYGON_ATTRIBUTE = "dl_extracted_faultlines" | ||
|
||
|
||
class MapAttribute(Enum): | ||
# TODO: change to upper case | ||
MigrationTime = "migration-time" | ||
MaxSaturation = "max-saturation" | ||
MIGRATION_TIME = "migration-time" | ||
MAX_SATURATION = "max-saturation" | ||
|
||
|
||
def _read_co2_volumes(ensemble_paths): | ||
records = [] | ||
for ens in ensemble_paths: | ||
try: | ||
df = pandas.read_csv( | ||
pathlib.Path(ens) / "share" / "results" / "tables" / "co2_volumes.csv", | ||
) | ||
except FileNotFoundError: | ||
continue | ||
last = df.iloc[np.argmax(df["date"])] | ||
label = pathlib.Path(ens).name | ||
records += [ | ||
(label, last["co2_inside"], "inside"), | ||
(label, last["co2_outside"], "outside"), | ||
] | ||
return pandas.DataFrame.from_records(records, columns=["ensemble", "volume", "containment"]) | ||
|
||
|
||
def generate_co2_volume_figure(ensemble_paths, height): | ||
import plotly.express as px | ||
df = _read_co2_volumes(ensemble_paths) | ||
fig = px.bar(df, y="ensemble", x="volume", color="containment", title="End-state CO2 containment [m³]", orientation="h") | ||
fig.layout.height = height | ||
fig.layout.legend.title.text = "" | ||
fig.layout.legend.orientation = "h" | ||
fig.layout.yaxis.title = "" | ||
fig.layout.yaxis.tickangle = -90 | ||
fig.layout.xaxis.exponentformat = "power" | ||
fig.layout.xaxis.title = "" | ||
fig.layout.paper_bgcolor = "rgba(0,0,0,0)" | ||
fig.layout.margin.b = 10 | ||
fig.layout.margin.t = 60 | ||
fig.layout.margin.l = 10 | ||
fig.layout.margin.r = 10 | ||
return fig | ||
def realization_paths(ensemble_path) -> Dict[str, str]: | ||
scratch = ScratchEnsemble("tmp", paths=ensemble_path) | ||
return { | ||
r: s.runpath() | ||
for r, s in scratch.realizations.items() | ||
} |
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
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