Skip to content
9 changes: 3 additions & 6 deletions graphics/AnalyzeStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import logsetup
import multiprocessing as mp
import os
import pandas as pd

from analysis.Analyses import Analyses
import analysis.StatisticsDatabase as sdb
Expand Down Expand Up @@ -66,12 +67,8 @@ def main():
# where each pair is colon delimited, e.g. exp1:long_name_exp1,exp2:long_name_exp2
exps = args.experiments.split(',')

firstCycle = None
lastCycle = None
if args.firstCycle:
firstCycle= dt.datetime.strptime(args.firstCycle, '%Y%m%dT%H')
if args.lastCycle:
lastCycle= dt.datetime.strptime(args.lastCycle, '%Y%m%dT%H')
firstCycle = pd.to_datetime(args.firstCycle)
lastCycle = pd.to_datetime(args.lastCycle)

anconf.adjust_experiments(args.controlExperiment, exps, args.verifySpace, args.verifyType, firstCycle, lastCycle)

Expand Down
62 changes: 33 additions & 29 deletions graphics/analysis/AnalysisBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging
import numpy as np
from pathlib import Path
import plot_utils as pu
import os
import var_utils as vu
import modelsp_utils as mu
Expand Down Expand Up @@ -239,22 +238,26 @@ def initLimits(dmin0=np.NaN, dmax0=np.NaN, d=None):
dmax = np.nanmax(d)
return dmin, dmax


def oneHundredCenteredLimiter(self, dmin0=np.NaN, dmax0=np.NaN, d=None):
dmin, dmax = self.initLimits(dmin0, dmax0, d)
dmin, dmax = self.initLimits(dmin0, dmax0, d)

# update dmax, conditional on dmin
dmax = np.nanmax([dmax, 100.0/(dmin/100.0)])
# Clamp dmin to its "Safety Envelope" (66.7% to 98.0%)
# This prevents division by zero and keeps the plot from being too squashed or too wide.
dmin = np.nanmax([dmin, 66.7])
dmin = np.nanmin([dmin, 98.0])

# set absolute min/max in case there are large outliers
#if np.isfinite(dmin):
dmin = np.nanmax([dmin, 66.7])
dmin = np.nanmin([dmin, 98.0])
# Clamp dmax to its "Safety Envelope" (102.0% to 150.0%)
dmax = np.nanmax([dmax, 102.0])
dmax = np.nanmin([dmax, 150.0])

#if np.isfinite(dmax):
dmax = np.nanmin([dmax, 150.0])
dmax = np.nanmax([dmax, 102.0])
# Symmetry Check
# Since dmin is at least 66.7, 100/(66.7/100) is ~150.
# This will never exceed our 150.0 ceiling.
dmax = np.nanmax([dmax, 100.0 / (dmin / 100.0)])

return dmin, dmax

return dmin, dmax

def zeroCenteredPercentDifference(self,
experiment,
Expand Down Expand Up @@ -292,23 +295,24 @@ def zeroCenteredLabeler(self):
#return '100 x (EXP-'+self.cntrlExpName+') / \n'+self.cntrlExpName+''
#return '100 x (EXP-CONTROL)/\nCONTROL'


def zeroCenteredLimiter(self, dmin0=np.NaN, dmax0=np.NaN, d=None):
dmin, dmax = self.initLimits(dmin0, dmax0, d)
dmin, dmax = self.initLimits(dmin0, dmax0, d)

# update dmax, conditional on dmin
#dmax = np.nanmax([dmax, 100.0/((100.0+dmin)/100.0) - 100.0])
dmax = np.nanmax([dmax, 1.0/dmin])
# Ensures we always see at least -2.0 to +2.0
dmin = np.nanmin([dmin, -2.0])
dmax = np.nanmax([dmax, 2.0])

# set absolute min/max in case there are large outliers
#if np.isfinite(dmin):
dmin = np.nanmax([dmin, -33.3])
dmin = np.nanmin([dmin, -2.0])
# Prevents one bad observation from squishing the whole plot
dmin = np.nanmax([dmin, -33.3])
dmax = np.nanmin([dmax, 50.0])

#if np.isfinite(dmax):
dmax = np.nanmin([dmax, 50.0])
dmax = np.nanmax([dmax, 2.0])
# Symmetry (Optional/Legacy logic)
# With dmin clamped to -2.0, this maxes at 0.5.
# It won't override the 2.0 floor, but it's safe to keep.
dmax = np.nanmax([dmax, 1.0 / np.abs(dmin)])

return dmin, dmax
return dmin, dmax


def binMethodFile(self, binMethod, before = True):
Expand Down Expand Up @@ -357,7 +361,7 @@ def statPlotAttributes(self, diagnosticGroup, statName,
truncateDiagnostics = ommDiagnostics+mmoDiagnostics
diagnosticGroup_ = diagnosticGroup
#for diag in truncateDiagnostics:
# if pu.prepends(diag, diagnosticGroup_) or pu.postpends(diag, diagnosticGroup_):
# if diagnosticGroup_.startswith(diag) or diagnosticGroup_.endswith(diag):
# diagnosticGroup_ = diag

allDiagnosticNames_ = deepcopy(allDiagnosticNames)
Expand Down Expand Up @@ -395,18 +399,18 @@ def statPlotAttributes(self, diagnosticGroup, statName,
centralValue = None

#for diag in truncateDiagnostics:
# if pu.prepends(diag, cntrlDiagnosticName) or pu.postpends(diag, cntrlDiagnosticName):
# if cntrlDiagnosticName.startswith(diag) or cntrlDiagnosticName.endswith(diag):
# cntrlDiagnosticName = diag
# for idiag, adiag in enumerate(allDiagnosticNames_):
# if pu.prepends(diag, adiag) or pu.postpends(diag, adiag):
# if adiag.startswith(diag) or adiag.endswith(diag):
# allDiagnosticNames_[idiag] = diag

oneCenteredRatioDiagPrefixes = ['CRx', 'CRy', 'InnovationRatio', 'SRx', 'SRy', 'OENI']
allOneCenteredDiagnostics = statName not in ['Count', 'Mean', 'Skew', 'ExcessKurtosis']
for diag in allDiagnosticNames_:
oneCentered = False
for diagPrefix in oneCenteredRatioDiagPrefixes:
oneCentered = oneCentered or pu.prepends(diagPrefix, diag)
oneCentered = oneCentered or diag.startswith(diagPrefix)
allOneCenteredDiagnostics = allOneCenteredDiagnostics and oneCentered
if allOneCenteredDiagnostics:
centralValue = 1.
Expand All @@ -419,7 +423,7 @@ def statPlotAttributes(self, diagnosticGroup, statName,
# for diag in allDiagnosticNames_:
# logScaled = False
# for diagPrefix in logScaledDiagPrefixes:
# logScaled = logScaled or pu.prepends(diagPrefix, diag)
# logScaled = logScaled or diag.startswith(diagPrefix)
# allLogScaledDiagnostics = allLogScaledDiagnostics and logScaled
# if allLogScaledDiagnostics:
# logScale = True and not isDifferencePlot
Expand Down
4 changes: 2 additions & 2 deletions graphics/analysis/BinValAxisStatsComposite.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def analyze_(self, workers = None):
varMapLoc.append((varName, varLabel))

nsubplots = nVarsLoc
nxplots = np.int(np.ceil(np.sqrt(nsubplots)))
nxplots = int(np.ceil(np.sqrt(nsubplots)))
while nsubplots%nxplots > 0 and nsubplots%nxplots / nxplots <= 0.5: nxplots += 1
nyplots = np.int(np.ceil(np.true_divide(nsubplots, nxplots)))
nyplots = int(np.ceil(np.true_divide(nsubplots, nxplots)))

ptLoc = {}

Expand Down
Loading