Esempio n. 1
0
 def plotMetric(t_val, t_offset, val, baseline, color, showYerr = True, showXerr = True):
     if fun_lib.getObjectiveByName(objectives, val).costFunctionType == fun_lib.CostFunctionType.Ignore:
         return
     val_mean = getTrgtVal(val)*baseline
     val_std = getTrgtVar(val)*baseline if showYerr else None
     t_mean = getTrgtVal(t_val) + t_offset
     t_std = getTrgtVar(t_val) if showXerr else None
     costs_legend.append('%s %.4f\n%s %.4f' % (val, getCost(val), t_val, getCost(t_val)))
     # zorder 3 is a workaround to show errorbars above the plots
     ax.errorbar(t_mean, val_mean, yerr= val_std, xerr=t_std, fmt = color, barsabove = True, zorder=3, linewidth = 2)
Esempio n. 2
0
def plotObjectives(vars_set, interval, objectives):
    if '__plot_axes' in vars_set:
        ax = vars_set['__plot_axes']
    else:
        fig = plt.figure()
        ax = fig.subplots()

    ax.plot(vars_set['time'],
            vars_set['brachial_pressure'] / 133.32,
            label='Brachial pressure mmHg')
    ax.plot(vars_set['time'], vars_set['CO'] * 1000 * 60, label='CO l/min')
    ax.plot(vars_set['time'],
            vars_set['renal_capillary'] / 133.32,
            label='Capillary pressure')
    # ax.plot([vars_set['time'][interval[0]], vars_set['time'][interval[-1]]], [fun_lib.getObjectiveByName(objectives, 'EF').value*100]*2, label='EF')
    ax.plot([vars_set['time'][interval[0]], vars_set['time'][interval[-1]]],
            [fun_lib.getObjectiveByName(objectives, 'PWV').value * 1] * 2,
            label='PWV')

    # bounds
    pack = (objectives, vars_set['time'], ax, interval)
    fun_lib.plotObjectiveTarget(pack, 'BPs', 1 / 133.32)
    fun_lib.plotObjectiveTarget(pack, 'BPd', 1 / 133.32)
    # fun_lib.plotObjectiveTarget(pack,'CO', 1000*60)
    fun_lib.plotObjectiveTarget(pack, 'BPk', 1 / 133.32)
    # fun_lib.plotObjectiveTarget(pack,'EF', 100)
    fun_lib.plotObjectiveTarget(pack, 'HR', 60, verticalalignment='top')
    # fun_lib.plotObjectiveTarget(pack,'Ppa', 1/133.32)
    fun_lib.plotObjectiveTarget(pack, 'Ppas', 1 / 133.32)
    fun_lib.plotObjectiveTarget(pack, 'Ppad', 1 / 133.32)
    fun_lib.plotObjectiveTarget(pack, 'Ppv', 1 / 133.32)
    fun_lib.plotObjectiveLimit(pack,
                               'PWV',
                               1,
                               'lower',
                               verticalalignment='top')

    total_costs = fun_lib.countTotalWeightedCost(objectives)
    ax.set_title('Baseline costs %.6f' % total_costs)
    ax.set_ylim([0, 140])
Esempio n. 3
0
 def getCost(name):
     return fun_lib.getObjectiveByName(objectives, name).cost()
Esempio n. 4
0
 def getObj(name):
     if fun_lib.getObjectiveByName(objectives, name).costFunctionType == fun_lib.CostFunctionType.Ignore:
         return -100
     return fun_lib.getObjectiveByName(objectives, name).value
Esempio n. 5
0
 def getTrgtVar(name):
     return fun_lib.getObjectiveByName(objectives, name).std
Esempio n. 6
0
 def getTrgtVal(name):
     return fun_lib.getObjectiveByName(objectives, name).targetValue
Esempio n. 7
0
 def buildPPObjective(po):
     (name, timeObjName, phase, tolerance, include_in_cost) = po
     o = fun_lib.getObjectiveByName(objectives, timeObjName).value + phase[0]
     i = fun_lib.findLowestIndex(o, time)
     value = ppulse[i]/baseline_pp
     return fun_lib.ObjectiveVar(name, value=value, costFunctionType=include_in_cost, base=baseline_pp, tolerance=1/baseline_pp)
Esempio n. 8
0
def plotTargetValues(ax, objectives, valsalva_start, valsalva_end, time):
    # plot merged timecourse
    # valsalva_start = 20
    # valsalva_end = 35
    # signal_end = 55
    signal_end = time[-1]
    
    # All targets are relative to baseline, so we have to have that set first
    baseline_bp = fun_lib.getObjectiveByName(objectives, 'baseline_bp').value
    baseline_hr = fun_lib.getObjectiveByName(objectives, 'baseline_hr').value
    baseline_pp = fun_lib.getObjectiveByName(objectives, 'baseline_pp').value

    # just a shortcuts
    def getTrgtVal(name):
        return fun_lib.getObjectiveByName(objectives, name).targetValue
    
    def getTrgtVar(name):
        return fun_lib.getObjectiveByName(objectives, name).std
    
    def getCost(name):
        return fun_lib.getObjectiveByName(objectives, name).cost()

    # color for BP and HR
    c_BP = 'g'
    c_HR = 'c'
    c_PP = 'm'

    # baselines
    ax.errorbar((valsalva_start/2), getTrgtVal('baseline_bp'), yerr=getTrgtVar('baseline_bp'), fmt = c_BP, barsabove = True, zorder=3)
    ax.errorbar((valsalva_start/2), getTrgtVal('baseline_hr'), yerr=getTrgtVar('baseline_hr'), fmt = c_HR, barsabove = True, zorder=3)
    ax.errorbar((valsalva_start/2), getTrgtVal('baseline_pp'), yerr=getTrgtVar('baseline_pp'), fmt = c_PP, barsabove = True, zorder=3)    
    
    # recoveries
    ax.errorbar((signal_end - 2.5), getTrgtVal('ph5_recovery')*baseline_bp, yerr=getTrgtVar('ph5_recovery')*baseline_bp, fmt = c_BP, barsabove = True, zorder=3)
    ax.errorbar((signal_end - 2.5), getTrgtVal('ph5_hr_recovery')*baseline_hr, yerr=getTrgtVar('ph5_hr_recovery')*baseline_hr, fmt = c_HR, barsabove = True, zorder=3)

    # sv lower limit
    if len([o for o in objectives if o.name == 'SV_min_valsalva']) > 0:
        pack = (objectives, time, ax, fun_lib.findInterval(valsalva_start, valsalva_end, time))
        fun_lib.plotObjectiveLimit(pack, 'SV_min_valsalva', 1, 'lower')
        fun_lib.plotObjectiveLimit(pack, 'SV_min_recovery', 1, 'lower')

    costs_legend = []
    def plotMetric(t_val, t_offset, val, baseline, color, showYerr = True, showXerr = True):
        if fun_lib.getObjectiveByName(objectives, val).costFunctionType == fun_lib.CostFunctionType.Ignore:
            return
        val_mean = getTrgtVal(val)*baseline
        val_std = getTrgtVar(val)*baseline if showYerr else None
        t_mean = getTrgtVal(t_val) + t_offset
        t_std = getTrgtVar(t_val) if showXerr else None
        costs_legend.append('%s %.4f\n%s %.4f' % (val, getCost(val), t_val, getCost(t_val)))
        # zorder 3 is a workaround to show errorbars above the plots
        ax.errorbar(t_mean, val_mean, yerr= val_std, xerr=t_std, fmt = color, barsabove = True, zorder=3, linewidth = 2)

    def plotBPMetric(t_val, t_offset, val, color = c_BP):
        plotMetric(t_val, t_offset, val, baseline_bp, color)

    def plotHRMetric(t_val, t_offset, val, color = c_HR):
        plotMetric(t_val, t_offset, val, baseline_hr, color)    

    def plotPPMetric(t_val, t_offset, val, color = c_PP):
        plotMetric(t_val, t_offset, val, baseline_pp, color, showXerr=False)    

    plotBPMetric('t_ph1_peak', valsalva_start, 'ph1_peak')
    plotBPMetric('t_ph2_mean_min', valsalva_start, 'ph2_mean_min')
    plotBPMetric('t_ph2_max', valsalva_end, 'ph2_max')
    plotBPMetric('t_ph4_drop', valsalva_end, 'ph4_drop')
    plotBPMetric('t_ph4_ovrshoot', valsalva_end, 'ph4_ovrshoot')

    plotHRMetric('t_ph1_hr_min', valsalva_start, 'ph1_hr_min')
    plotHRMetric('t_ph4_hr_max', valsalva_end, 'ph4_hr_max')
    plotHRMetric('t_ph4_hr_drop', valsalva_end, 'ph4_hr_drop')

    plotPPMetric('t_ph2_mean_min', valsalva_start, 'pp_ph2_mean_min')
    plotPPMetric('t_ph2_max', valsalva_end, 'pp_ph2_max')
    plotPPMetric('t_ph4_drop', valsalva_end, 'pp_ph4_drop')

    ax.text(0, 60, '\n'.join(costs_legend), 
            horizontalalignment='left', 
            verticalalignment='bottom', fontsize = 8)

    pass