Skip to content

Commit 1dc3246

Browse files
committed
Added modelbound variable extraction helper fun on context
1 parent ffba2b7 commit 1dc3246

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

RMK_support/remkit_context.py

+24
Original file line numberDiff line numberDiff line change
@@ -848,3 +848,27 @@ def addTermDiagnostics(self, *args: Variable):
848848
model + "_" + term, [pair], self.variables[model + "_" + term]
849849
)
850850
)
851+
852+
def extractMBVar(
853+
self, model: mc.Model, mbVar: Variable, resultVarName: str, priority=4
854+
):
855+
"""Extract a modelbound variable from a model and add it to the context
856+
857+
Args:
858+
model (mc.Model): Model to extract from
859+
mbVar (Variable): Variable to extract
860+
resultVarName (str): Variable name to extract to
861+
priority (int, optional): Manipulator priority. Defaults to 4.
862+
"""
863+
kwargs = mbVar.kwargs
864+
if "derivation" in kwargs:
865+
del kwargs["derivation"]
866+
if "derivationArgs" in kwargs:
867+
del kwargs["derivationArgs"]
868+
kwargs["isDerived"] = True
869+
newVar = Variable(resultVarName, mbVar.grid, **kwargs)
870+
871+
self.manipulators.add(
872+
MBDataExtractor(resultVarName, model, mbVar, newVar, priority)
873+
)
874+
self.variables.add(newVar)

RMK_support/tests/test_remkit_context.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ def test_wrapper(grid: Grid):
397397

398398
# Modelbound data extractor
399399

400-
mbExtract = MBDataExtractor("mbExtract", model, dModelbound, priority=1).dict()
400+
rk.extractMBVar(model, dModelbound, dModelbound.name, priority=1)
401+
402+
mbExtract = rk.manipulators[dModelbound.name].dict()
401403

402404
assert mbExtract == {
403405
"type": "modelboundDataExtractor",

0 commit comments

Comments
 (0)