Skip to content

Commit 5b8f784

Browse files
centralize statsComputer retrieval
1 parent a0fedff commit 5b8f784

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

smodels/matching/theoryPrediction.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,8 @@ def setStatsComputer(self):
143143
to define a statistical computer (upper limit result or no expected
144144
upper limits), set the computer to 'N/A'.
145145
"""
146-
from smodels.base import runtime
147-
if runtime._experimental["spey"]:
148-
from smodels.statistics.speyTools import SpeyComputer as StatsComputer
149-
else:
150-
from smodels.statistics.statsTools import StatsComputer
146+
from smodels.statistics.statsTools import getStatsComputerModule
147+
StatsComputer = getStatsComputerModule()
151148

152149
if self.dataType() == "upperLimit":
153150
from smodels.base.runtime import experimentalFeature
@@ -527,11 +524,8 @@ def setStatsComputer(self):
527524
if any(tp.statsComputer == 'N/A' for tp in self.theoryPredictions):
528525
computer = 'N/A'
529526
else:
530-
from smodels.base import runtime
531-
if runtime._experimental["spey"]:
532-
from smodels.statistics.speyTools import SpeyComputer as StatsComputer
533-
else:
534-
from smodels.statistics.statsTools import StatsComputer
527+
from smodels.statistics.statsTools import getStatsComputerModule
528+
StatsComputer = getStatsComputerModule()
535529
computer = StatsComputer.forAnalysesComb(self.theoryPredictions, self.deltas_rel)
536530

537531
self._statsComputer = computer

smodels/statistics/statsTools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
"""
1212

13-
__all__ = [ "StatsComputer" ]
13+
__all__ = [ "StatsComputer", "getStatsComputerModule" ]
1414

1515
from typing import Union, Text, Dict, List
1616
from smodels.statistics.exceptions import SModelSStatisticsError as SModelSError
@@ -23,6 +23,17 @@
2323
from smodels.experiment.datasetObj import DataSet,CombinedDataSet
2424
from typing import Union, Text
2525

26+
def getStatsComputerModule():
27+
""" very single convenience function to centralize
28+
switching between our stats code and spey. """
29+
from smodels.base import runtime
30+
if runtime._experimental["spey"]:
31+
from smodels.statistics.speyTools import SpeyComputer as StatsComputer
32+
return StatsComputer
33+
else:
34+
from smodels.statistics.statsTools import StatsComputer
35+
return StatsComputer
36+
2637
class StatsComputer:
2738
__slots__ = [ "nsig", "dataObject", "dataType", "likelihoodComputer", "data",
2839
"upperLimitComputer", "deltas_sys", "allowNegativeSignals" ]

0 commit comments

Comments
 (0)