Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fmudesign #658

Closed
wants to merge 113 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
0a54934
Add singlesens
tralsos Sep 7, 2018
57d0791
Changed style for documentation, added examples
Sep 10, 2018
c32f24a
Changes to plot in webviz instead of webportal
Sep 26, 2018
0b98b8f
Handling when no reals in sensitivity are ok. Handling of integer sel…
Oct 15, 2018
3e3197e
Added first version of code for automatic generation of design matrices
Oct 15, 2018
6a45a2a
Added example to docs
Oct 15, 2018
b585feb
Defaultvalues added automatically, and some minor changes
Oct 16, 2018
021b043
Documentation in yaml config, plus start on correlations
Oct 17, 2018
115db1a
Added mc with correlations
Oct 18, 2018
03dab18
Added seed sensitivity
Oct 26, 2018
5360844
Adding excel configuration for design matrix and options for backgrou…
Nov 13, 2018
f48dc68
Documentation and bug fixing
Nov 15, 2018
2216786
fixes for issues #20 and #21, plus added bin/fmudesign
Nov 20, 2018
c31d163
check for destination in fmudesignrunner
Nov 20, 2018
2866488
More checks for distribution parameters #21, and destination folder f…
Nov 20, 2018
59c05a6
added discrete uniform
Nov 20, 2018
483b74a
improving docs
Nov 21, 2018
7168623
Added more options for creation of design matrix, and senstype ref.
Dec 10, 2018
7c4294f
Tuning the siteinstall in Makefile
Nov 20, 2018
4292a9f
bugfix
Dec 13, 2018
8bb4338
Allowing constant RMS_SEED, plus improving error handling for distrib…
Dec 20, 2018
da5da87
Fix for issue #19, plus converting some dist_params to floats
Dec 21, 2018
5be1d54
Fixes for issue #27 accept variations of sheet names in excel config
Jan 2, 2019
87c622a
Fix for issue #26, missing default value should give error.
Jan 2, 2019
d7e4547
Added reading seeds from external file, issue #18
Jan 3, 2019
7105f97
add command line options for sheetnames
berland Jan 7, 2019
ac9b2a7
fixed weights for discrete dist
Feb 6, 2019
9d59872
Fix for all None values in sensitivity for calc_tornadoinput
Feb 6, 2019
a5830d3
Removed on_demand for pandas.ExcelFile
Feb 7, 2019
07ecab7
Added pert distribution
tralsos Feb 22, 2019
9518de7
Solve bug in input arguments handling
berland Apr 4, 2019
4eb4374
Create output directories if needed
berland Apr 4, 2019
4f705db
Fix for issue #38 in readin corr matrix
Apr 16, 2019
1a99cd1
Implemented request #37. fmudesign to report number of realizations g…
Apr 16, 2019
926bb35
Solves #39, move RMS_SEED column first
Apr 23, 2019
4f7b57e
Improved error message for seed sensitivity
May 6, 2019
509793f
Error message for missing input in scenario sensitivity.
May 6, 2019
79da1b6
Fix for issue #42, bug in reading correlation matrix for nackground p…
Jun 24, 2019
eefdd73
Reorganisation of code to allow for several correlation matrices per …
Aug 12, 2019
2a424b4
Minor changes in error message
Aug 12, 2019
347d9fc
Adding functionallity for dependent parameters. Issue #47
Dec 11, 2019
596f8d0
bugfix dependencies for numbers
Dec 12, 2019
dfd78f9
wip: avoid webviz dependency and depreciation warning
berland Dec 11, 2019
e5ebad8
Add link to webviz-subsurface
berland Dec 12, 2019
63eaeb8
Catch ModuleNotFoundError for Python3
berland Dec 18, 2019
5e358b3
Minor changes for python 3
Dec 19, 2019
1e964bf
Revert "Merge branch 'singlesens' into 'master'"
tralsos Dec 19, 2019
ccc4f81
Fix for outputname equal to inputname (part of #45), plus some modifi…
Dec 19, 2019
c0f605b
Fix for fmudesign output filename not ending with .xlsx
Dec 19, 2019
9963b37
Missing dot. Updating example input
Dec 19, 2019
2107f2a
Make destination optional
berland Dec 20, 2019
90e092d
Make optional import py2 compatible
berland Feb 12, 2020
9face1f
Add seed (#10)
Mar 13, 2020
6c91f8a
Make fmu.tools independent of fmu.config (#17)
berland Mar 13, 2020
097df70
Repo setup (#28)
jcrivenaes Mar 24, 2020
7727b67
Report closest semi-definite correlation matrix (#30)
tralsos Mar 24, 2020
2addc4a
Blacken everything (#31)
berland Apr 14, 2020
f040a6e
Added warning for duplicate default values (#35)
tralsos Apr 14, 2020
a2cec78
Added checks for duplicate sensname and senstivities of more than one…
tralsos Apr 14, 2020
f5f513a
Strip spaces in parameter names, solve Excel user errors (#38)
berland May 18, 2020
40fcf3a
Give error message on missing repeats (#44)
berland Jul 1, 2020
5975838
Add black and flake8 to CI (#48)
berland Jul 6, 2020
c3fed1a
Qcforward add perf (#53)
jcrivenaes Aug 27, 2020
a71b7ed
Deploy docs to github pages (#78)
berland Nov 30, 2020
e13304e
Remove dependency to old webviz (#67)
Dec 1, 2020
58b8b16
Cleanup python2 remnants design matrix generator (#82)
berland Dec 8, 2020
be776dd
Compatibility with xlrd 1.2 and 2.0, and pandas 1.x (#94)
tralsos Jan 7, 2021
2579963
Sort test data into directories pr. tool (#96)
berland Jan 8, 2021
dcd6d3a
Solve pylint issue for sensitivites (#98)
berland Feb 9, 2021
1a73fcf
Add tests for background values in fmudesign (#107)
berland Mar 8, 2021
4bd7ff4
Test multiple Pandas version. (#118)
berland Mar 15, 2021
985faa8
Black with newest colour of black (#132)
berland May 14, 2021
89f342f
Add type hinting to some modules, enforce in CI
berland May 27, 2021
85f4147
Fix recurrent testing errors (#170)
jcrivenaes Mar 2, 2022
cd6873a
Correct files for mypy and isort issues
jcrivenaes Jan 19, 2023
8393a59
Change "...".format() to f"..." using flynt tool
jcrivenaes Jan 19, 2023
7a59d92
Add encoding key to all file i/o
jcrivenaes Jan 19, 2023
b3676c3
Update to black==23.1.0
mferrera Feb 6, 2023
f469aa0
replace xlswriter (#182)
tralsos Apr 17, 2023
031cb22
replace comparison of floats with numpy.isclose (#184)
tralsos Aug 2, 2023
4796a3e
Lint with isort
mferrera Nov 3, 2023
9f4a837
fix bug for uncorrelated symmetric pert disstrbutions
Nov 22, 2023
a5c9845
Move to ruff (#203)
tnatt Feb 19, 2024
415521c
Update ruff format (#206)
Mar 4, 2024
9f5e519
TST: let tests work when in RoxEnv
jcrivenaes Apr 4, 2024
65d831f
ENH: add library for general Sw in a 3D grid
jcrivenaes Apr 5, 2024
f66bcb0
STY: Update to new ruff
mferrera Jun 28, 2024
72a6e31
STY: Update to latest ruff (#214)
tnatt Aug 19, 2024
f9d48f9
FIX: avoid issues with new version of sphinx
jcrivenaes Oct 7, 2024
7be6618
Test properties in test_generate_onebyone
dafeda Oct 21, 2024
a527e64
Remove skipif old pandas is used
dafeda Oct 21, 2024
2aaf5f0
Extend test_generate_full_mc to test dependent params
dafeda Oct 22, 2024
1a97913
import numpy as np
dafeda Oct 22, 2024
d31fe83
Test drawing correlated normals
dafeda Oct 22, 2024
736b020
Test that sampling normal with bad params raises errors
dafeda Oct 21, 2024
47d09c4
Simplify if in _check_dist_params_normal
dafeda Oct 21, 2024
063011e
Return early if bad status in draw_values_normal
dafeda Oct 21, 2024
e78d33f
Remove init of distribution to None
dafeda Oct 21, 2024
143c1f9
Do validation once in draw_values_normal
dafeda Oct 21, 2024
7834a15
Add Metadata sheet
dafeda Oct 28, 2024
aafec96
Simplify draw_values_uniform and add tests
dafeda Oct 28, 2024
7a83379
Add snapshot test
dafeda Oct 30, 2024
097ebcd
Use RandomState instead of global random seed
dafeda Oct 30, 2024
814c892
Pass rng to background and add test
dafeda Oct 31, 2024
133d2b1
Remove some future warnings when running fmudesign
dafeda Oct 31, 2024
3e91645
Remove setter for defaultvalues
dafeda Oct 31, 2024
7fd5412
Test that vars are correlated (#245)
dafeda Nov 4, 2024
aa3136a
Simplify draw_values_lognormal and add tests
dafeda Nov 5, 2024
23152c0
Remove _add_webviz_tornado_onebyone
dafeda Nov 8, 2024
4b035d4
Deprecate calc_tornadoinput
dafeda Nov 8, 2024
e2f1867
Do not sample from multivariate_normal in test
dafeda Nov 8, 2024
6d40c49
Refactor and test summarize design
dafeda Nov 18, 2024
4d86161
Remove old seed deprecation warning
dafeda Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/semeio/fmudesign/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Used for pre and processing of ert sensitivities, such as
setting up design matrix to run single sensitivities with ERT and
post processing of results to create input for a tornado plot.
Output of this module can be used in custom standalone applications.
"""

from fmu.tools.sensitivities._designsummary import summarize_design
from fmu.tools.sensitivities._excel2dict import excel2dict_design, inputdict_to_yaml
from fmu.tools.sensitivities._tornado_onebyone import calc_tornadoinput
from fmu.tools.sensitivities.create_design import DesignMatrix

__all__ = [
"summarize_design",
"calc_tornadoinput",
"DesignMatrix",
"excel2dict_design",
"inputdict_to_yaml",
]
127 changes: 127 additions & 0 deletions src/semeio/fmudesign/_designsummary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""Module for summarizing design set up for one by one sensitivities"""

import pandas as pd


def _get_sensitivity_type(senscase: str) -> str:
"""Determine sensitivity type based on the case name"""
sensitivity_types = {"p10_p90": "mc", "ref": "ref", "skip": "skip"}
return sensitivity_types.get(senscase.lower(), "scalar")


def summarize_design(filename, sheetname="DesignSheet01"):
"""
Summarizes the design set up for one by one sensitivities
specified in a design matrix on standard fmu format.

Args:
filename (str): Path to excel or csv file containting designmatrix
for one by one sensitivities on standard FMU format.
sheetname (str): Name of sheet in excel workbook which
contains the designmatrix (only for excel input). Defaults to
'DesignSheet01'.

Returns:
pd.DataFrame: Summary of sensitivities,
corresponding realisation numbers,
senstype('mc' or 'scalar')
and senscase (name of high and low cases).
Each row represents one sensitivity
with 1-2 cases (low/high).
Column names are ['sensno', 'sensname',
'senstype', 'casename1', 'startreal1', 'endreal1',
'casename2', 'startreal2', 'endreal2']

Example::
>>> from fmu.tools.sensitivities import summarize_design
>>> designname = 'design_filename.xlsx'
>>> designsheet = 'DesignSheet01'
>>> designtable = summarize_design(designname, designsheet)

"""

# Read design matrix
if str(filename).endswith(".xlsx"):
dgn = pd.read_excel(filename, sheetname, engine="openpyxl")
# Drop empty rows or columns that have been read in
# due to having background colour/formatting
dgn.dropna(axis=0, how="all", inplace=True)
dgn = dgn.loc[:, ~dgn.columns.str.contains("^Unnamed")]
elif str(filename).endswith(".csv"):
dgn = pd.read_csv(filename)
else:
raise ValueError(
"Design matrix must be on Excel or csv format"
" and filename must end with .xlsx or .csv"
)

# Initialize results DataFrame with same columns
designsummary = pd.DataFrame(
columns=[
"sensno",
"sensname",
"senstype",
"casename1",
"startreal1",
"endreal1",
"casename2",
"startreal2",
"endreal2",
]
)

# Get unique sensitivity names in order of appearance
sensnames = dgn["SENSNAME"].unique()

sensno = 0
for sensname in sensnames:
sens_group = dgn[dgn["SENSNAME"] == sensname].copy()
# Get cases in order of appearance
cases = sens_group.drop_duplicates("SENSCASE")[["SENSCASE"]].values.flatten()

# Skip if first case type is 'skip'
# The "skip" option was added when creating tornado plots
# with calc_tornadoinput.
# It allowed manual exclusion of sensitivities from tornado plots by changing
# SENSCASE to "skip" in the design matrix after running the experiment.
# This would exclude the sensitivity from both the
# *designsummary table and the tornado plot.
# calc_tornadoinput is deprecated so this can be removed once
# calc_tornadoinput is removed.
senstype = _get_sensitivity_type(cases[0])
if senstype == "skip":
continue

# First case
case1_data = sens_group[sens_group["SENSCASE"] == cases[0]]
casename1 = cases[0]
startreal1 = case1_data["REAL"].min()
endreal1 = case1_data["REAL"].max()

# Handle second case if it exists
if len(cases) > 1:
case2_data = sens_group[sens_group["SENSCASE"] == cases[1]]
casename2 = cases[1]
startreal2 = case2_data["REAL"].min()
endreal2 = case2_data["REAL"].max()
else:
casename2 = None
startreal2 = None
endreal2 = None

# Add row to results
designsummary.loc[sensno] = [
sensno,
sensname,
senstype,
casename1,
startreal1,
endreal1,
casename2,
startreal2,
endreal2,
]

sensno += 1

return designsummary
Loading
Loading