Skip to content

Commit

Permalink
Run doctests in fmudesign as part of GH actions
Browse files Browse the repository at this point in the history
- Also added ... notation to doctests to avoid different results on different machines
  • Loading branch information
tommyod authored and dafeda committed Dec 2, 2024
1 parent 28f4058 commit a5f8d0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ jobs:

- name: "Run tests"
run: pytest tests -n logical --durations 5 --ert-integration

- name: "Run doctests on fmudesign"
run: pytest ./src/semeio/fmudesign/ --doctest-modules -v
10 changes: 5 additions & 5 deletions src/semeio/fmudesign/_designsummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def summarize_design(filename, sheetname="DesignSheet01"):
'senstype', 'casename1', 'startreal1', 'endreal1',
'casename2', 'startreal2', 'endreal2']
Example::
>>> from semeio.fmudesign import summarize_design
>>> designname = 'design_filename.xlsx'
>>> designsheet = 'DesignSheet01'
>>> designtable = summarize_design(designname, designsheet)
Example:
>> from semeio.fmudesign import summarize_design
>> designname = 'design_filename.xlsx'
>> designsheet = 'DesignSheet01'
>> designtable = summarize_design(designname, designsheet)
"""

Expand Down
26 changes: 13 additions & 13 deletions src/semeio/fmudesign/_tornado_onebyone.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ def calc_tornadoinput(
* (int): Average response value for realizations in
reference sensitivity.
Example::
>>> import pandas as pd
>>> from semeio.fmudesign import calc_tornadoplot
>>> designtable = pd.read_csv('designsummary.csv')
>>> results = pd.read_csv('resultfile.csv')
>>> response = 'STOIIP_OIL'
>>> selectors = ['ZONE', 'REGION']
>>> selection = [['Nansen','Larsson'], ['SegmentA']]
>>> reference = 'rms_seed'
>>> scale = 'percentage'
>>> cutbyref = True
>>> sortsens = False
>>> (tornadotable, ref_value) = calc_tornadoinput(
Example:
>> import pandas as pd
>> from semeio.fmudesign import calc_tornadoplot
>> designtable = pd.read_csv('designsummary.csv')
>> results = pd.read_csv('resultfile.csv')
>> response = 'STOIIP_OIL'
>> selectors = ['ZONE', 'REGION']
>> selection = [['Nansen','Larsson'], ['SegmentA']]
>> reference = 'rms_seed'
>> scale = 'percentage'
>> cutbyref = True
>> sortsens = False
>> (tornadotable, ref_value) = calc_tornadoinput(
designtable, results, response, selectors,
selection, reference, scale, cutbyref, sortsens)
Expand Down
10 changes: 5 additions & 5 deletions src/semeio/fmudesign/iman_conover.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
Induce correlations
>>> sp.stats.pearsonr(*X.T).statistic
0.06589800321227991
0.065898...
>>> correlation_matrix = np.array([[1, 0.3], [0.3, 1]])
>>> transform = ImanConover(correlation_matrix)
>>> X_transformed = transform(X)
>>> sp.stats.pearsonr(*X_transformed.T).statistic
0.27965286549530805
0.279652...
"""

import numpy as np
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(self, correlation_matrix):
>>> sp.stats.pearsonr(*X.T).statistic
0.0
>>> sp.stats.pearsonr(*X_transformed.T).statistic
0.8164965809277261
0.816496...
Achieving the exact correlation structure might be impossible. For the
input matrix above, there is no permutation of the columns that yields
Expand All @@ -102,7 +102,7 @@ def __init__(self, correlation_matrix):
>>> X = rng.normal(size=(1000, 2))
>>> X_transformed = transform(X)
>>> sp.stats.pearsonr(*X_transformed.T).statistic
0.697701261152449
0.697701...
But if the data are far from normal (here:lognormal), the results are
not as good. This is because correlation is induced in a normal space
Expand All @@ -112,7 +112,7 @@ def __init__(self, correlation_matrix):
>>> X = rng.lognormal(size=(1000, 2))
>>> X_transformed = transform(X)
>>> sp.stats.pearsonr(*X_transformed.T).statistic
0.5925413169604046
0.592541...
"""
if not isinstance(correlation_matrix, np.ndarray):
raise TypeError("Input argument `correlation_matrix` must be NumPy array.")
Expand Down

0 comments on commit a5f8d0b

Please sign in to comment.