예제 #1
0
def plotObjectives(vars_set, interval, objectives):

    ax = fun_lib.getAxes(vars_set)

    ax.plot(vars_set['time'],
            vars_set['brachial_pressure'] / 133.32,
            label='Brachial pressure mmHg')
    # ax.plot(vars_set['time'], vars_set['V_LV']*1000*1000, label='V_LV ml')
    ax.plot(vars_set['time'], vars_set['CO'] / lpm2SI, label='CO')

    # ax.plot(vars_set['time'], vars_set['TEjection'], label='TEjection')
    # ax.plot(vars_set['time'], vars_set['TFilling'], label='TFilling')

    pack = (objectives, vars_set['time'], ax, interval)
    fun_lib.plotObjectiveTarget(pack, 'BPs', 1 / 133.32)
    # fun_lib.plotObjectiveTarget(pack, 'EDV', 1e6)
    fun_lib.plotObjectiveTarget(pack, 'ESV', 1e6)
    fun_lib.plotObjectiveTarget(pack, 'Ts', 1, verticalalignment='top')
    fun_lib.plotObjectiveTarget(pack, 'Td', 1)
    fun_lib.plotObjectiveTarget(pack, 'Ppa', 1 / 133.32)
    fun_lib.plotObjectiveTarget(pack, 'Ppa_s', 1 / 133.32)
    fun_lib.plotObjectiveTarget(pack, 'Ppa_d', 1 / 133.32)
    fun_lib.plotObjectiveTarget(pack, 'Ppv', 1 / 133.32)
    fun_lib.plotObjectiveLimit(pack, 'CO', 1 / lpm2SI, 'lower')

    total_costs = fun_lib.countTotalWeightedCost(objectives)
    ax.set_title('Exercise costs %.6f' % total_costs)
    ax.set_ylim([0, 165])
예제 #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])
예제 #3
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