Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions aps/algorithms/APSZoneModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ def __interpretXMLTree(self, ET_Tree, modelFileName, debug_level=Debug.OFF):
mainFaciesTable,
faciesInZone,
gaussFieldsInZone,
self.key_resolution,
self.debug_level,
modelFileName,
self.zone_number,
Expand All @@ -313,7 +312,6 @@ def __interpretXMLTree(self, ET_Tree, modelFileName, debug_level=Debug.OFF):
mainFaciesTable,
faciesInZone,
gaussFieldsInZone,
self.key_resolution,
self.debug_level,
modelFileName,
self.zone_number,
Expand Down
11 changes: 5 additions & 6 deletions aps/algorithms/truncation_rules/Trunc2D_Angle_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(
mainFaciesTable: Optional[APSMainFaciesTable] = None,
faciesInZone: Optional[List[str]] = None,
gaussFieldsInZone: Optional[List[str]] = None,
keyResolution: int = 100,
debug_level: Debug = Debug.OFF,
modelFileName: Optional[str] = None,
zoneNumber: Optional[int] = None,
Expand All @@ -107,7 +106,6 @@ def __init__(
debug_level,
modelFileName,
nGaussFieldsInBackGroundModel=2,
keyResolution=keyResolution,
)
# Variables containing truncations for the 2D truncation map
# The input direction angles can be file names in case trend parameters for these are specified
Expand Down Expand Up @@ -302,7 +300,6 @@ def initialize(
List[List[Union[List[List[Union[str, float]]], List[str]]]]
] = None,
useConstTruncParam: int = True,
keyResolution: int = 100,
debug_level: Debug = Debug.OFF,
) -> None:
"""
Expand Down Expand Up @@ -333,7 +330,7 @@ def initialize(
:return:
"""
# Initialize data structure
self.__init__(keyResolution=keyResolution, debug_level=debug_level)
self.__init__(debug_level=debug_level)

if self._debug_level >= Debug.VERY_VERBOSE:
print(f'--- Call the initialize function in {self._className}')
Expand Down Expand Up @@ -797,7 +794,9 @@ def __defineIntersectionFromProb(

return outputPolyA, outputPolyB, closestPolygon

def setTruncRule(self, faciesProb: List[float], cellIndx: int = 0) -> None:
def setTruncRule(
self, faciesProb: List[float], cellIndx: int = 0, resolution: int = 100
) -> None:
"""
Description:
Input: Facies names, direction angles for facies boundary lines and facies probabilities.
Expand All @@ -811,7 +810,7 @@ def setTruncRule(self, faciesProb: List[float], cellIndx: int = 0) -> None:
if self._isFaciesProbEqualOne(faciesProb):
return

faciesProbRoundOff = self._makeRoundOffFaciesProb(faciesProb)
faciesProbRoundOff = self._makeRoundOffFaciesProb(faciesProb, resolution)
sumProb = faciesProbRoundOff.sum()
if np.abs(sumProb - 1.0) > 0.00001:
print(
Expand Down
16 changes: 7 additions & 9 deletions aps/algorithms/truncation_rules/Trunc2D_Base_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def __init__(
debug_level: Debug = Debug.OFF,
modelFileName: Optional[str] = None,
nGaussFieldsInBackGroundModel: int = 2,
keyResolution: int = 100,
) -> None:
"""
Initialize the data structure for empty object.
Expand Down Expand Up @@ -218,15 +217,9 @@ def __init__(
# between two polygons and the algorithm is not able to define in which polygon the point is located.
self._nCountShiftBoundary = 0

# The key resolution is a resolution of how to round off facies probability.
# The facies probability rounded off is used as key to classify which grid cells have the same facies
# probability and can be treated simultaneously when looking up facies in the truncation cubes.
self._keyResolution = 100

self._className = self.__class__.__name__
self._gaussFieldsInZone = []
self._debug_level = debug_level
self._keyResolution = keyResolution
self._nGaussFieldsInBackGroundModel = nGaussFieldsInBackGroundModel

if trRuleXML is not None:
Expand Down Expand Up @@ -1451,18 +1444,23 @@ def _makeKey(faciesProbRoundOff) -> Tuple[float, ...]:
key = tuple(faciesProbRoundOff)
return key

def _makeRoundOffFaciesProb(self, facies_prob):
def _makeRoundOffFaciesProb(self, facies_prob, resolution: int = 100):
"""Calculate round off of facies probabilities and adjusted
so that the round off values also are close to normalised
Resolution is set to 100 if input is not positive. The case that memoization is turned off
corresponds to input resolution = 0 and in this case 100 is always used.

:param facies_prob: The Facies probabilities to use
:param resolution: The key resolution is a resolution of how to round off facies probability.
The facies probability rounded off is used as key to classify which grid cells
have the same facies probability and can be treated simultaneously when looking
up facies in the truncation cubes.
"""
if len(facies_prob) == 0:
warn('The facies probabilities are empty')
return facies_prob
# A value of 0 or negative indicates that memoization is turned off.
# Anyway the probabilities will be rounded off to nearest 1/100.
resolution = 100 if self._keyResolution <= 0 else self._keyResolution
delta = 1.0 / resolution
facies_prob = (facies_prob * resolution + 0.5).astype(int) * delta
sum_prob = facies_prob.sum()
Expand Down
15 changes: 9 additions & 6 deletions aps/algorithms/truncation_rules/Trunc2D_Cubic_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def __init__(
mainFaciesTable: Optional[APSMainFaciesTable] = None,
faciesInZone: Optional[List[str]] = None,
gaussFieldsInZone: Optional[List[str]] = None,
keyResolution: int = 100,
debug_level: Debug = Debug.OFF,
modelFileName: Optional[str] = None,
zoneNumber: Optional[int] = None,
Expand Down Expand Up @@ -147,7 +146,6 @@ def __init__(
debug_level,
modelFileName,
nGaussFieldsInBackGroundModel=2,
keyResolution=keyResolution,
)
# Variables containing truncations for the 2D truncation map
self.__truncStructure = []
Expand Down Expand Up @@ -505,7 +503,9 @@ def useConstTruncModelParam(self):
# there are no model parameters for the truncation model (except facies probability)
return True

def setTruncRule(self, faciesProb: List[float], cellIndx: int = 0) -> None:
def setTruncRule(
self, faciesProb: List[float], cellIndx: int = 0, resolution: int = 100
) -> None:
"""
Calculate how truncation map is to be divided into polygons or threshold values.
This function must be called each time the facies probability changes, so it must
Expand All @@ -516,6 +516,10 @@ def setTruncRule(self, faciesProb: List[float], cellIndx: int = 0) -> None:
:param faciesProb: Probability for each facies.
:param cellIndx: Is not used here , but may be used in other algorithms where there are
model parameters that may vary from cell to cell in the 3D modelling grid.
:param resolution: The key resolution is a resolution of how to round off facies probability.
The facies probability rounded off is used as key to classify which grid cells
have the same facies probability and can be treated simultaneously when looking
up facies in the truncation cubes.
"""

# Call common functions from base class
Expand All @@ -525,7 +529,7 @@ def setTruncRule(self, faciesProb: List[float], cellIndx: int = 0) -> None:
if self._isFaciesProbEqualOne(faciesProb):
return

faciesProbRoundOff = self._makeRoundOffFaciesProb(faciesProb)
faciesProbRoundOff = self._makeRoundOffFaciesProb(faciesProb, resolution)
sumProb = faciesProbRoundOff.sum()
if np.abs(sumProb - 1.0) > 0.00001:
print(
Expand Down Expand Up @@ -1179,7 +1183,6 @@ def initialize(
alphaFieldNameForBackGroundFacies: List[str],
truncStructureList: CubicTruncationRuleStructureType,
overlayGroups: Optional[OverlayGroupType] = None,
keyResolution: int = 100,
debug_level: Debug = Debug.OFF,
) -> None:
"""
Expand All @@ -1199,7 +1202,7 @@ def initialize(
overlayGroups - List of overlay facies with associated alphaFields and probability fractions.
"""
# Initialize (base) class variables
self.__init__(keyResolution=keyResolution, debug_level=debug_level)
self.__init__(debug_level=debug_level)

if self._debug_level >= Debug.VERY_VERBOSE:
print(f'--- Call the initialize function in {self._className}')
Expand Down
8 changes: 0 additions & 8 deletions aps/tests/test_Trunc2D_Angle_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def interpretXMLModelFileAndWrite(
fTable,
faciesInZone,
gaussFieldsInZone,
keyResolution,
debug_level=Debug.OFF,
):
# Read test model file with truncation rule into xml tree
Expand All @@ -59,7 +58,6 @@ def interpretXMLModelFileAndWrite(
mainFaciesTable,
faciesInZone,
gaussFieldsInZone,
keyResolution,
debug_level=debug_level,
modelFileName=modelFileName,
)
Expand Down Expand Up @@ -91,7 +89,6 @@ def createTrunc(
truncStructure,
overlayGroups,
useConstTruncParam,
keyResolution,
debug_level=Debug.OFF,
):
mainFaciesTable = APSMainFaciesTable(facies_table=fTable)
Expand All @@ -106,7 +103,6 @@ def createTrunc(
truncStructure,
overlayGroups,
useConstTruncParam,
keyResolution,
debug_level,
)

Expand All @@ -125,7 +121,6 @@ def initialize_write_read(
truncStructure,
overlayGroups,
useConstTruncParam,
keyResolution,
debug_level=Debug.OFF,
):
file1 = outputModelFileName1
Expand All @@ -141,7 +136,6 @@ def initialize_write_read(
truncStructure,
overlayGroups,
useConstTruncParam,
keyResolution,
debug_level,
)
inputFile = file1
Expand All @@ -157,7 +151,6 @@ def initialize_write_read(
fTable,
faciesInZone,
gaussFieldsInZone,
keyResolution,
debug_level,
)

Expand Down Expand Up @@ -435,7 +428,6 @@ def test_non_cubic_truncation_rule(
truncStructure=truncation_rule,
overlayGroups=overlay_groups,
useConstTruncParam=USE_CONST_TRUNC_PARAM,
keyResolution=KEYRESOLUTION,
debug_level=Debug.OFF,
)
nGaussFields = truncRule.getNGaussFieldsInModel()
Expand Down
3 changes: 0 additions & 3 deletions aps/tests/test_Trunc2D_Cubic_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

from aps.algorithms.APSMainFaciesTable import APSMainFaciesTable
from aps.algorithms.truncation_rules import Trunc2D_Cubic
from aps.tests.constants import (
KEYRESOLUTION,
)
from aps.tests.helpers import (
apply_truncations,
apply_truncations_vectorized,
Expand Down