Exemplo n.º 1
0
    "d_E", "phase", "cap_phase", "num_peaks", "original_omega"
]
changed_sv_vals = [
    300e-3, 3 * math.pi / 2, 3 * math.pi / 2, 50, RV_param_list["omega"]
]
for key, value in zip(changed_SV_params, changed_sv_vals):
    SV_param_list[key] = value
num_harms = 6
start_harm = 1
SV_simulation_options["method"] = "sinusoidal"
other_values = {
    "filter_val": 0.5,
    "harmonic_range": list(range(start_harm, start_harm + num_harms, 1)),
    "bounds_val": 20000,
}
RV = single_electron(None, RV_param_list, simulation_options, other_values,
                     param_bounds)
SV = single_electron(None, SV_param_list, SV_simulation_options, other_values,
                     param_bounds)
RV.def_optim_list(list(table_names))

SV.def_optim_list([])

SV_simulation_options["no_transient"] = 2 / SV_param_list["omega"]
SV_new = single_electron(None, SV_param_list, SV_simulation_options,
                         other_values, param_bounds)

timeseries = SV_new.test_vals([], "timeseries")
SV_plot_times = SV_new.t_nondim(SV_new.time_vec[SV_new.time_idx])
SV_plot_voltages = SV_new.e_nondim(SV_new.define_voltages()[SV_new.time_idx])

plot_height = max(75 * num_harms, 450)
Exemplo n.º 2
0
def apply_slider_changes(n_clicks, *inputs):
    states = inputs[:-2]
    table_data = inputs[-2]
    drop_down_opts = inputs[-1]
    for i in range(0, len(states)):
        if states[i] is not None:
            val = states[i]
            val = min(val, param_bounds[table_names[i]][1])
            val = max(val, param_bounds[table_names[i]][0])
            RV.dim_dict[RV.optim_list[i]] = val
            SV.dim_dict[RV.optim_list[i]] = val
    SV.dim_dict["original_gamma"] = SV.dim_dict["gamma"]
    RV.dim_dict["original_gamma"] = RV.dim_dict["gamma"]
    SV.dim_dict["original_omega"] = SV.dim_dict["omega"]
    SV.simulation_options["no_transient"] = 2 / SV.dim_dict["omega"]
    RV.simulation_options["no_transient"] = 2 / RV.dim_dict["omega"]
    SV.simulation_options["optim_list"] = []
    RV.simulation_options["optim_list"] = []
    SV.dim_dict["d_E"] = (SV.dim_dict["E_reverse"] -
                          SV.dim_dict["E_start"]) / 2
    RV.dim_dict["d_E"] = (RV.dim_dict["E_reverse"] -
                          RV.dim_dict["E_start"]) / 4
    RV_new = single_electron(None, RV.dim_dict, RV.simulation_options,
                             RV.other_values, param_bounds)
    SV_new = single_electron(None, SV.dim_dict, SV.simulation_options,
                             SV.other_values, param_bounds)
    params = []
    ramped_layout = go.Layout(height=plot_height)
    harmonic_layout = go.Layout(height=plot_height // num_harms,
                                margin={
                                    "pad": 0,
                                    "b": 0,
                                    "t": 0
                                })
    r_tab_labels = ["r_time", "r_volt", "r_volt_time", "r_fft"]
    s_tab_labels = ["s_time", "s_volt", "s_volt_time", "s_r_fft"]
    if n_clicks > 0:

        timeseries = RV_new.i_nondim(RV_new.test_vals(params, "timeseries"))
        RV_plot_times = RV_new.t_nondim(RV_new.time_vec[RV_new.time_idx])
        RV_plot_voltages = RV_new.e_nondim(
            RV_new.define_voltages()[RV_new.time_idx])
        for q in range(0, len(table_data)):
            table_data[q]["Value"] = RV_new.dim_dict[table_data[q]
                                                     ["Parameter"]]
        SV_timeseries = SV_new.i_nondim(SV_new.test_vals(params, "timeseries"))
        SV_plot_voltages = SV_new.e_nondim(
            SV_new.define_voltages()[SV_new.time_idx])
        SV_plot_times = SV_new.t_nondim(SV_new.time_vec[SV_new.time_idx])
        r_harms = harmonics(list(range(start_harm, start_harm + num_harms)),
                            RV_new.dim_dict["omega"], 0.05)
        s_harms = harmonics(list(range(start_harm, start_harm + num_harms)),
                            SV_new.dim_dict["omega"], 0.05)
        SV_harmonics = s_harms.generate_harmonics(SV_plot_times,
                                                  SV_timeseries,
                                                  hanning=False)
        ramped_harmonics = r_harms.generate_harmonics(RV_plot_times,
                                                      timeseries,
                                                      hanning=True)
        r_one_tail_len = (len(r_harms.exposed_f) // 2) + 1
        s_one_tail_len = (len(s_harms.exposed_f) // 2) + 1
        r_freqs = r_harms.exposed_f[:r_one_tail_len]
        r_fft = abs(r_harms.exposed_Y[:r_one_tail_len])
        s_freqs = s_harms.exposed_f[:s_one_tail_len]
        s_fft = np.real(s_harms.exposed_Y[:s_one_tail_len])
        r_x_args = [RV_plot_times, RV_plot_voltages, RV_plot_times, r_freqs]
        r_y_args = [timeseries, timeseries, RV_plot_voltages, r_fft]
        s_x_args = [SV_plot_times, SV_plot_voltages, SV_plot_times, s_freqs]
        s_y_args = [SV_timeseries, SV_timeseries, SV_plot_voltages, s_fft]
        r_right_plots = {}
        s_right_plots = {}
        for i in range(0, len(r_tab_labels)):
            r_right_plots[r_tab_labels[i]] = {
                "data": [
                    {
                        "x": r_x_args[i],
                        "y": r_y_args[i],
                        "type": "line",
                        "name": "Ramped",
                        "render_mode": "webgl"
                    },
                ],
                "layout":
                ramped_layout,
            }
            s_right_plots[s_tab_labels[i]] = {
                "data": [
                    {
                        "x": s_x_args[i],
                        "y": s_y_args[i],
                        "type": "line",
                        "name": "Ramped",
                        "render_mode": "webgl"
                    },
                ],
                "layout":
                ramped_layout,
            }

        return_arg = [r_right_plots]
        for i in range(0, num_harms):
            return_arg.append({
                "data": [
                    {
                        "x": RV_plot_times,
                        "y": np.abs(ramped_harmonics[i, :]),
                        "type": "line",
                        "name": "Ramped_harm" + str(i),
                        "render_mode": "webgl"
                    },
                ],
                "layout":
                harmonic_layout,
            })
        return_arg.append(s_right_plots)
        for i in range(0, num_harms):
            return_arg.append({
                "data": [
                    {
                        "x": SV_plot_voltages,
                        "y": np.real(SV_harmonics[i, :]),
                        "type": "line",
                        "name": "sv_harm" + str(i),
                        "render_mode": "webgl"
                    },
                ],
                "layout":
                harmonic_layout,
            })
        return_arg.append(table_data)
        return return_arg

    empty_r_plots = dict(
        zip(r_tab_labels, [{
            "layout": ramped_layout
        }] * len(r_tab_labels)))
    empty_s_plots = dict(
        zip(s_tab_labels, [{
            "layout": ramped_layout
        }] * len(s_tab_labels)))
    return [empty_r_plots] + [{
        "layout": harmonic_layout
    }] * (num_harms) + [empty_s_plots] + [{
        "layout": harmonic_layout
    }] * (num_harms) + [table_data]
def apply_slider_changes(n_clicks, *inputs):
    #start=time.time()
    slider_input_len=len(table_names)
    states=inputs[:slider_input_len]
    table_data=inputs[slider_input_len]
    drop_down_opts=inputs[slider_input_len+1]
    disp_bins=inputs[slider_input_len+2]
    freeze_buttons=inputs[slider_input_len+3]
    adaptive_buttons=inputs[slider_input_len+4]
    plot_buttons=inputs[slider_input_len+5]
    #print(disp_bins, freeze_buttons, adaptive_buttons)
    dispersion_optim_list=[]
    if drop_down_opts is not None:
        dispersion_groups={"E_0":["E0_mean", "E0_std"], "k_0":["k0_shape", "k0_scale"], "alpha":["alpha_mean", "alpha_std"]}
        dispersion_associations={"E0_mean":"E_0", "E0_std":"E_0", "E0_skew":"E_0", "k0_shape":"k_0", "k0_scale":"k_0", "alpha_mean":"alpha", "alpha_std":"alpha"}
        dispersed_params=list(set([dispersion_associations[key] for key in drop_down_opts if key in dispersion_associations.keys()]))
        if len(dispersed_params)!=0:
            dispersion=True
            for key in dispersed_params:
                dispersion_optim_list+=dispersion_groups[key]
        else:
            dispersion=False
            params=[]
    else:
        dispersion=False
        params=[]
    for i in range(0, len(states)):
        if states[i] is not None:
            val=states[i]
            val=min(val, param_bounds[table_names[i]][1])
            val=max(val, param_bounds[table_names[i]][0])
            RV.dim_dict[RV.optim_list[i]]=val
            SV.dim_dict[RV.optim_list[i]]=val
            DCV.dim_dict[RV.optim_list[i]]=val
    SV.dim_dict["original_gamma"]=SV.dim_dict["gamma"]
    RV.dim_dict["original_gamma"]=RV.dim_dict["gamma"]
    DCV.dim_dict["original_gamma"]=DCV.dim_dict["gamma"]
    SV.dim_dict["original_omega"]=SV.dim_dict["omega"]
    SV.simulation_options["no_transient"]=2/SV.dim_dict["omega"]
    RV.simulation_options["no_transient"]=2/RV.dim_dict["omega"]
    DCV.simulation_options["no_transient"]=False
    SV.simulation_options["optim_list"]=[]
    RV.simulation_options["optim_list"]=[]
    DCV.simulation_options["optim_list"]=[]
    SV.dim_dict["d_E"]=(SV.dim_dict["E_reverse"]-SV.dim_dict["E_start"])/2
    RV.dim_dict["d_E"]=(RV.dim_dict["E_reverse"]-RV.dim_dict["E_start"])/4
    RV_new=single_electron(None, RV.dim_dict, RV.simulation_options, RV.other_values, param_bounds)
    SV_new=single_electron(None, SV.dim_dict, SV.simulation_options, SV.other_values, param_bounds)
    DCV_new=single_electron(None, DCV.dim_dict, DCV.simulation_options, DCV.other_values, param_bounds)
    if dispersion==True:
        #print(dispersion_optim_list)
        RV_new.simulation_options["dispersion_bins"]=[disp_bins]
        SV_new.simulation_options["dispersion_bins"]=[disp_bins]
        DCV_new.simulation_options["dispersion_bins"]=[disp_bins]
        in_table=dict(zip(dispersion_optim_list, [False]*len(dispersion_optim_list)))
        RV_new.def_optim_list(dispersion_optim_list)
        SV_new.def_optim_list(dispersion_optim_list)
        DCV_new.def_optim_list(dispersion_optim_list)
        params=[RV.dim_dict[param] for param in dispersion_optim_list]
    ramped_layout=go.Layout(height=plot_height)
    harmonic_layout=go.Layout(height=plot_height//num_harms, margin={"pad":0, "b":0, "t":0})
    r_tab_labels=["r_time", "r_volt", "r_volt_time", "r_fft"]
    s_tab_labels=["s_time", "s_volt", "s_volt_time", "s_r_fft"]
    d_tab_labels=["d_time", "d_volt", "d_volt_time"]
    if n_clicks>0:


        deletion_idx=[]
        if dispersion==False:
            table_data=table_init
        for q in range(0, len(table_data)):
            table_data[q]["Value"]=RV_new.dim_dict[table_data[q]["Parameter"]]
            if dispersion==True:
                if table_data[q]["Parameter"] in dispersion_optim_list:
                    in_table[table_data[q]["Parameter"]]=True
                if table_data[q]["Parameter"] in dispersed_params:
                    deletion_idx.append(q)

        if dispersion==True:
            for q in range(0, len(dispersion_optim_list)):
                if in_table[dispersion_optim_list[q]]==False:
                    table_data.append({"Parameter":dispersion_optim_list[q], "Value":RV_new.dim_dict[dispersion_optim_list[q]]})
            for q in range(0, len(deletion_idx)):
                del table_data[deletion_idx[q]]

        if "r_freeze" in freeze_buttons:
            if "r_scipy" in adaptive_buttons:
                RV_new.update_params(params)
                V=RV.e_nondim(RV_new.define_voltages())
                w0=[0, 0, V[0]]
                wsol = odeint(RV_new.current_ode_sys, w0, RV.time_vec, rtol=1e-6, atol=1e-6)
                timeseries=RV_new.i_nondim(wsol[:,0][RV_new.time_idx])
                RV_plot_voltages=V[RV_new.time_idx]
                RV_plot_times=RV_new.t_nondim(RV.time_vec[RV_new.time_idx])
            else:
                timeseries=RV_new.i_nondim(RV_new.test_vals(params, "timeseries"))
                RV_plot_times=RV_new.t_nondim(RV_new.time_vec[RV_new.time_idx])
                RV_plot_voltages=RV_new.e_nondim(RV_new.define_voltages()[RV_new.time_idx])
            r_harms=harmonics(list(range(start_harm, start_harm+num_harms)), RV_new.dim_dict["omega"], 0.05)
            ramped_harmonics=r_harms.generate_harmonics(RV_plot_times, timeseries, hanning=True)
            r_one_tail_len=(len(r_harms.exposed_f)//2)+1
            r_freqs=r_harms.exposed_f[:r_one_tail_len]
            r_fft=abs(r_harms.exposed_Y[:r_one_tail_len])

            if "no_decimation" in plot_buttons:
                r_x_args=[RV_plot_times, RV_plot_voltages, RV_plot_times[0::10], r_freqs]
                r_y_args=[timeseries, timeseries, RV_plot_voltages[0::10], r_fft]
            elif "ramped_rdp" in plot_buttons:
                simped_line=np.array(rdp_lines.rdp_controller(RV_plot_times, timeseries, max(timeseries)/5))
                sorted_idx=np.argsort(simped_line[:,0])
                simped_times=simped_line[:,0][sorted_idx]
                simped_timeseries=simped_line[:,1][sorted_idx]
                r_x_args=[simped_times, RV_plot_voltages[0::10], RV_plot_times[0::10], decimate(r_freqs, 10)]
                r_y_args=[simped_timeseries, timeseries[0::10], RV_plot_voltages[0::10], decimate(r_fft, 10)]
            elif "decimation" in plot_buttons:
                r_x_args=[x[0::10] for x in [RV_plot_times, RV_plot_voltages, RV_plot_times, r_freqs]]
                r_y_args=[x[0::10] for x in [timeseries, timeseries, RV_plot_voltages, r_fft]]

        if "s_freeze" in freeze_buttons:
            if "s_scipy" in adaptive_buttons:
                SV_new.update_params(params)
                V=SV.e_nondim(SV_new.define_voltages())
                C=SV_new.test_vals(params, "timeseries")
                w0=[0, 0, V[0]]
                wsol = odeint(SV_new.current_ode_sys, w0, SV.time_vec, rtol=1e-6, atol=1e-6)
                SV_timeseries=SV_new.i_nondim(wsol[:,0][SV_new.time_idx])
                SV_plot_voltages=V[SV_new.time_idx]
                SV_plot_times=SV_new.t_nondim(SV.time_vec[SV_new.time_idx])
            else:
                SV_timeseries=SV_new.i_nondim(SV_new.test_vals(params, "timeseries"))
                SV_plot_voltages=SV_new.e_nondim(SV_new.define_voltages()[SV_new.time_idx])
                SV_plot_times=SV_new.t_nondim(SV_new.time_vec[SV_new.time_idx])
            s_harms=harmonics(list(range(start_harm, start_harm+num_harms)), SV_new.dim_dict["omega"], 0.05)
            SV_harmonics=s_harms.generate_harmonics(SV_plot_times, SV_timeseries, hanning=False)
            s_one_tail_len=(len(s_harms.exposed_f)//2)+1
            s_freqs=s_harms.exposed_f[:s_one_tail_len]
            s_fft=np.real(s_harms.exposed_Y[:s_one_tail_len])
            s_x_args=[SV_plot_times, SV_plot_voltages, SV_plot_times, s_freqs]
            s_y_args=[SV_timeseries, SV_timeseries, SV_plot_voltages, s_fft]
        if "d_freeze" in freeze_buttons:
            if "d_scipy" in adaptive_buttons:
                DCV_new.update_params(params)
                V=DCV.e_nondim(DCV_new.define_voltages())
                w0=[0, 0, V[0]]
                wsol = odeint(DCV_new.current_ode_sys, w0, DCV.time_vec, rtol=1e-6, atol=1e-6)
                DCV_timeseries=DCV_new.i_nondim(wsol[:,0][DCV_new.time_idx])
                DCV_plot_voltages=V[DCV_new.time_idx]
                DCV_plot_times=DCV_new.t_nondim(DCV.time_vec[DCV_new.time_idx])
            else:
                DCV_timeseries=DCV_new.i_nondim(DCV_new.test_vals(params, "timeseries"))
                DCV_plot_voltages=DCV_new.e_nondim(DCV_new.define_voltages()[DCV_new.time_idx])
                DCV_plot_times=DCV_new.t_nondim(DCV_new.time_vec[DCV_new.time_idx])
            d_x_args=[running_reduction(x, 10) for x in [DCV_plot_times, DCV_plot_voltages, DCV_plot_times]]
            d_y_args=[running_reduction(x, 10) for x in [DCV_timeseries, DCV_timeseries, DCV_plot_voltages]]
        x_labels=["Time(s)", "Voltage(V)", "Time(s)", "Frequency(Hz)"]
        y_labels=["Current(A)", "Current(A)", "Voltage(V)", "Magnitude"]
        r_right_plots={}
        s_right_plots={}
        d_right_plots={}

        for i in range(0, len(r_tab_labels)):
            if "r_freeze" not in freeze_buttons:
                r_x_plot=[]
                r_y_plot=[]
            else:
                r_x_plot=r_x_args[i]
                r_y_plot=r_y_args[i]
            r_right_plots[r_tab_labels[i]]={"data": [
                {"x":r_x_plot, "y":r_y_plot , "type": "scattergl", "name":"Current sim", "render_mode":"webgl"},
            ],
            "layout": {"height":plot_height, "xaxis":{"title":{"text":x_labels[i]}}, "yaxis":{"title":{"text":y_labels[i]}}},
            }

            if "s_freeze" not in freeze_buttons:
                s_x_plot=[]
                s_y_plot=[]
            else:
                s_x_plot=s_x_args[i]
                s_y_plot=s_y_args[i]
            s_right_plots[s_tab_labels[i]]={"data": [
                {"x":s_x_plot, "y": s_y_plot, "type": "scattergl", "name": "Current sim", "render_mode":"webgl"},
            ],
            "layout": {"height":plot_height, "xaxis":{"title":{"text":x_labels[i]}}, "yaxis":{"title":{"text":y_labels[i]}}},
            }
            if i<len(d_tab_labels):
                if "d_freeze" not in freeze_buttons:
                    d_x_plot=[]
                    d_y_plot=[]
                else:
                    d_x_plot=d_x_args[i]
                    d_y_plot=d_y_args[i]
                d_right_plots[d_tab_labels[i]]={"data": [
                    {"x":d_x_plot, "y": d_y_plot, "type": "scattergl", "name": "Current sim", "render_mode":"webgl"},
                ],
                "layout": {"height":plot_height, "xaxis":{"title":{"text":x_labels[i]}}, "yaxis":{"title":{"text":y_labels[i]}}},
                }

        harmonics_dict={"ramped":{}, "sinusoidal":{}}
        for i in range(0, num_harms):
            xlabel=""
            ylabel=""
            b=0
            if i==(num_harms-1):
                xlabel="Time(s)"
                b=30
            if i==num_harms//2:
                ylabel="Current(A)"
            if "r_freeze" not in freeze_buttons:
                r_x_plot=[]
                r_y_plot=[]
            else:
                r_x_plot=RV_plot_times
                r_y_plot=np.abs(ramped_harmonics[i,:][0::10])
            harmonics_dict["ramped"]["ramped_harm_"+str(i)]={"data": [
                {"x":r_x_plot, "y":r_y_plot , "type": "line", "name": None, "render_mode":"webgl"},
            ],
            "layout": {"height":plot_height//num_harms, "margin":{"pad":0, "b":b, "t":5},"xaxis":{"title":{"text":xlabel}}, "yaxis":{"title":{"text":ylabel}} },
            }
        for i in range(0, num_harms):
            xlabel=""
            ylabel=""
            b=0
            if i==(num_harms-1):
                xlabel="Voltage(V)"
                b=40
            if i==num_harms//2:
                ylabel="Current(A)"
            if "s_freeze" not in freeze_buttons:
                s_x_plot=[]
                s_y_plot=[]
            else:
                s_x_plot=SV_plot_voltages
                s_y_plot=np.real(SV_harmonics[i,:])
            harmonics_dict["sinusoidal"]["sinusoidal_harm_"+str(i)]=({"data": [
                {"x":s_x_plot, "y": s_y_plot, "type": "line", "name": None, "render_mode":"webgl"},
            ],
            "layout": {"height":plot_height//num_harms, "margin":{"pad":0, "b":b, "t":5},"xaxis":{"title":{"text":xlabel}}, "yaxis":{"title":{"text":ylabel}} },
            })
        #print("simulation_time", time.time()-start)
        return [r_right_plots]+[s_right_plots]+[d_right_plots]+[harmonics_dict]+[table_data]

    empty_r_plots=dict(zip(r_tab_labels, [{"layout": ramped_layout}]*len(r_tab_labels)))
    empty_s_plots=dict(zip(s_tab_labels, [{"layout": ramped_layout}]*len(s_tab_labels)))
    empty_d_plots=dict(zip(d_tab_labels, [{"layout": ramped_layout}]*len(d_tab_labels)))
    harmonics_dict={"ramped":{}, "sinusoidal":{}}
    for i in range(0, num_harms):
        harmonics_dict["ramped"]["ramped_harm_"+str(i)]={"layout":harmonic_layout}
        harmonics_dict["sinusoidal"]["sinusoidal_harm_"+str(i)]={"layout":harmonic_layout}

    return [empty_r_plots]+[empty_s_plots]+[empty_d_plots]+[harmonics_dict]+[table_data]
Exemplo n.º 4
0
def apply_slider_changes(n_clicks, drop_down_opts, disp_bins, freeze_buttons,
                         adaptive_buttons, plot_buttons, exp_id,
                         *slider_params):
    for exp in ["ramped", "sinusoidal", "dcv"]:
        if exp in exp_id:
            experiment_type = exp
            exp_class = class_dict[exp]
    if (n_clicks > 0) and (experiment_type + "_freeze" in freeze_buttons):
        if drop_down_opts is not None:
            dispersion_groups = {
                "E_0": ["E0_mean", "E0_std"],
                "k_0": ["k0_shape", "k0_scale"],
                "alpha": ["alpha_mean", "alpha_std"]
            }
            dispersion_associations = {
                "E0_mean": "E_0",
                "E0_std": "E_0",
                "E0_skew": "E_0",
                "k0_shape": "k_0",
                "k0_scale": "k_0",
                "alpha_mean": "alpha",
                "alpha_std": "alpha"
            }
            dispersed_params = list(
                set([
                    dispersion_associations[key] for key in drop_down_opts
                    if key in dispersion_associations.keys()
                ]))
            if len(dispersed_params) != 0:
                dispersion = True
                for key in dispersed_params:
                    dispersion_optim_list += dispersion_groups[key]
            else:
                dispersion = False
                params = []
        else:
            dispersion = False
            params = []
        for i in range(0, len(slider_params)):
            if slider_params[i] is not None:
                val = slider_params[i]
                val = min(val, param_bounds[table_names[i]][1])
                val = max(val, param_bounds[table_names[i]][0])
                exp_class.dim_dict[RV.optim_list[i]] = val
        exp_class.dim_dict["original_gamma"] = exp_class.dim_dict["gamma"]
        exp_class.simulation_options["optim_list"] = []
        if experiment_type == "sinusoidal":
            exp_class.dim_dict["original_omega"] = exp_class.dim_dict["omega"]
            exp_class.simulation_options[
                "no_transient"] = 2 / exp_class.dim_dict["omega"]
            exp_class.dim_dict["d_E"] = (exp_class.dim_dict["E_reverse"] -
                                         exp_class.dim_dict["E_start"]) / 2
        elif experiment_type == "ramped":
            exp_class.simulation_options[
                "no_transient"] = 2 / exp_class.dim_dict["omega"]
            exp_class.dim_dict["d_E"] = (exp_class.dim_dict["E_reverse"] -
                                         RV.dim_dict["E_start"]) / 4
        elif experiment_type == "dcv":
            exp_class.simulation_options["no_transient"] = False
        new_class = single_electron(None, exp_class.dim_dict,
                                    exp_class.simulation_options,
                                    exp_class.other_values, param_bounds)
        if dispersion == True:
            new_class.simulation_options["dispersion_bins"] = [disp_bins]
            new_class.def_optim_list(dispersion_optim_list)
            params = [
                new_class.dim_dict[param] for param in dispersion_optim_list
            ]
        if experiment_type + "_scipy" in adaptive_buttons and dispersion == False:
            new_class.update_params(params)
            V = new_class.e_nondim(new_class.define_voltages())
            w0 = [0, 0, V[0]]
            wsol = odeint(new_class.current_ode_sys,
                          w0,
                          new_class.time_vec,
                          rtol=1e-6,
                          atol=1e-6)
            timeseries = new_class.i_nondim(wsol[:, 0][new_class.time_idx])
            plot_voltages = V[new_class.time_idx]
            plot_times = new_class.t_nondim(
                new_class.time_vec[new_class.time_idx])
        else:
            timeseries = new_class.i_nondim(
                new_class.test_vals(params, "timeseries"))
            plot_times = new_class.t_nondim(
                new_class.time_vec[new_class.time_idx])
            plot_voltages = new_class.e_nondim(
                new_class.define_voltages()[new_class.time_idx])
        if experiment_type != "dcv":
            harms = harmonics(list(range(start_harm, start_harm + num_harms)),
                              new_class.dim_dict["omega"], 0.05)
            if experiment_type == "ramped":
                experiment_harmonics = harms.generate_harmonics(plot_times,
                                                                timeseries,
                                                                hanning=True)
            elif experiment_type == "sinusoidal":
                experiment_harmonics = harms.generate_harmonics(plot_times,
                                                                timeseries,
                                                                hanning=False)
            one_tail_len = (len(harms.exposed_f) // 2) + 1
            freqs = harms.exposed_f[:one_tail_len]
            fft = abs(harms.exposed_Y[:one_tail_len])
            if experiment_type == "ramped":
                if "no_decimation" in plot_buttons:
                    plot_list = [[plot_times, timeseries],
                                 [plot_voltages, timeseries],
                                 [plot_times[0::10], plot_voltages[0::10]],
                                 [freqs, fft]]
                elif "ramped_rdp" in plot_buttons:
                    simped_line = np.array(
                        rdp_lines.rdp_controller(plot_times, timeseries,
                                                 max(timeseries) / 5))
                    sorted_idx = np.argsort(simped_line[:, 0])
                    simped_times = simped_line[:, 0][sorted_idx]
                    simped_timeseries = simped_line[:, 1][sorted_idx]
                    plot_list = [[simped_times, simped_timeseries],
                                 [plot_voltages[0::10], timeseries[0::10]],
                                 [plot_times[0::10], plot_voltages[0::10]],
                                 [freqs, fft]]
                elif "decimation" in plot_buttons:
                    plot_list = [[plot_times[0::10], timeseries[0::10]],
                                 [plot_voltages[0::10], timeseries[0::10]],
                                 [plot_times[0::10], plot_voltages[0::10]],
                                 [freqs[0::10], fft[0::10]]]
            else:
                plot_list = [[plot_times, timeseries],
                             [plot_voltages, timeseries],
                             [plot_times, plot_voltages], [freqs, fft]]
        else:
            plot_list = [[plot_times[0::10], timeseries[0::10]],
                         [plot_voltages[0::10], timeseries[0::10]],
                         [plot_times[0::10], plot_voltages[0::10]]]

        non_harm_plots = [{
            "figure_object": {
                "data": [{
                    "x": plot_list[i][0],
                    "y": plot_list[i][1],
                    "type": "scattergl",
                    "name": "Current sim",
                    "render_mode": "webgl"
                }],
                "layout": {
                    "height": plot_height,
                    "xaxis": {
                        "title": {
                            "text": labels[experiment_type]["x"][i]
                        }
                    },
                    "yaxis": {
                        "title": {
                            "text": labels[experiment_type]["y"][i]
                        }
                    }
                },
            },
            "parameters": dict(zip(RV.optim_list, slider_params))
        } for i in range(0, len(plot_list))]
        return_arg = non_harm_plots
        if experiment_type != "dcv":
            for i in range(0, num_harms):
                xlabel = ""
                ylabel = ""
                b = 0
                if i == (num_harms - 1):
                    xlabel = "Time(s)"
                    b = 30
                if i == num_harms // 2:
                    ylabel = "Current(A)"

                if experiment_type == "ramped":
                    x_plot = plot_times
                    y_plot = np.abs(experiment_harmonics[i, :][0::10])
                else:
                    x_plot = plot_voltages
                    y_plot = np.real(experiment_harmonics[i, :])
                return_arg.append({
                    "data": [
                        {
                            "x": x_plot,
                            "y": y_plot,
                            "type": "line",
                            "name": "Current sim",
                            "render_mode": "webgl"
                        },
                    ],
                    "layout": {
                        "height": plot_height // num_harms,
                        "margin": {
                            "pad": 0,
                            "b": b,
                            "t": 5
                        },
                        "xaxis": {
                            "title": {
                                "text": xlabel
                            }
                        },
                        "yaxis": {
                            "title": {
                                "text": ylabel
                            }
                        }
                    },
                })
        return return_arg
    else:
        if experiment_type == "dcv":
            return [{
                "figure_object": {
                    "layout": ramped_layout
                }
            }] * len(labels["dcv"]["y"])
        else:
            return [{
                "figure_object": {
                    "layout": ramped_layout
                }
            }] * len(labels["ramped"]["y"]) + [{
                "layout": harmonic_layout
            }] * (num_harms)
Exemplo n.º 5
0
    'CdlE3': [-0.001, 0.001],
    'gamma': [1e-11, 1e-9],
    'k_0': [10, 1e3],
    'alpha': [0.35, 0.65],
    "cap_phase": [0, 2 * math.pi],
    "E0_mean": [0.15, 0.3],
    "E0_std": [0.001, 0.2],
    "k0_shape": [0, 5],
    "k0_loc": [0, 1e4],
    "k0_scale": [0, 1e4],
    "k0_range": [1e2, 1e4],
    'phase': [0, 2 * math.pi]
}
noramp_test = single_electron(file_name=None,
                              dim_paramater_dictionary=param_list,
                              simulation_options=simulation_options,
                              other_values=other_values,
                              param_bounds=param_bounds)
noramp_test.def_optim_list([
    "E0_mean", "E0_std", "k_0", "Ru", "Cdl", "CdlE1", "CdlE2", "gamma",
    'omega', "cap_phase", "phase", "alpha"
])
#test simulation with some random params within bounds
random_params = np.random.rand(len(noramp_test.optim_list))
#changes numbers distributed according to U(0,1) to position within bound
random_params = noramp_test.change_norm_group(random_params, "un_norm")
#Simulate using sinusoidal parameters
test_sim = noramp_test.test_vals(random_params, "timeseries", test=False)
test_voltage = noramp_test.define_voltages()
#time, voltage and current are returned in non-dimensional form, so need to redimensionalise
dim_current = noramp_test.i_dim(test_sim)
Exemplo n.º 6
0
def apply_slider_changes(n_clicks, *inputs):
    slider_input_len=len(table_names)
    states=inputs[:slider_input_len]
    table_data=inputs[slider_input_len]
    drop_down_opts=inputs[slider_input_len+1]
    r_button, s_button, d_button=inputs[slider_input_len+2:]

    for i in range(0, len(states)):
        if states[i] is not None:
            val=states[i]
            val=min(val, param_bounds[table_names[i]][1])
            val=max(val, param_bounds[table_names[i]][0])
            RV.dim_dict[RV.optim_list[i]]=val
            SV.dim_dict[RV.optim_list[i]]=val
    SV.dim_dict["original_gamma"]=SV.dim_dict["gamma"]
    RV.dim_dict["original_gamma"]=RV.dim_dict["gamma"]
    SV.dim_dict["original_omega"]=SV.dim_dict["omega"]
    SV.simulation_options["no_transient"]=2/SV.dim_dict["omega"]
    RV.simulation_options["no_transient"]=2/RV.dim_dict["omega"]
    SV.simulation_options["optim_list"]=[]
    RV.simulation_options["optim_list"]=[]
    SV.dim_dict["d_E"]=(SV.dim_dict["E_reverse"]-SV.dim_dict["E_start"])/2
    RV.dim_dict["d_E"]=(RV.dim_dict["E_reverse"]-RV.dim_dict["E_start"])/4
    RV_new=single_electron(None, RV.dim_dict, RV.simulation_options, RV.other_values, param_bounds)
    SV_new=single_electron(None, SV.dim_dict, SV.simulation_options, SV.other_values, param_bounds)

    params=[]
    ramped_layout=go.Layout(height=plot_height)
    harmonic_layout=go.Layout(height=plot_height//num_harms, margin={"pad":0, "b":0, "t":0})
    if n_clicks>0:
        for q in range(0, len(table_data)):
            table_data[q]["Value"]=RV_new.dim_dict[table_data[q]["Parameter"]]


        ramped_x_val, ramped_y_val, r_timeseries, r_times=plot_args(RV_new, r_button, params, "r")
        sinusoidal_x_val, sinusoidal_y_val, s_timeseries, s_times, s_volts=plot_args(SV_new, s_button, params, "s")
        #SPACEFORDCV
        if r_button!="r_x_volt_time":
            r_harms=harmonics(list(range(start_harm, start_harm+num_harms)), RV_new.dim_dict["omega"], 0.05)
            ramped_harmonics=r_harms.generate_harmonics(r_times[0::10], r_timeseries[0::10], hanning=True)
        else:
            ramped_harmonics=np.zeros((num_harms, len(r_timeseries)))
        if s_button!="s_x_volt_time":
            s_harms=harmonics(list(range(start_harm, start_harm+num_harms)), SV_new.dim_dict["omega"], 0.05)
            SV_harmonics=s_harms.generate_harmonics(s_times, s_timeseries, hanning=False)
        else:
            SV_harmonics=np.zeros((num_harms, len(s_timeseries)))


        return_arg=[{"data": [
            {"x":ramped_x_val, "y": ramped_y_val, "type": "line", "name": "Ramped", "render_mode":"webgl"},
        ],
        "layout": ramped_layout,
        }]
        for i in range(0, num_harms):
            return_arg.append({"data": [
                {"x":r_times, "y": np.abs(ramped_harmonics[i,:]), "type": "line", "name": "Ramped_harm"+str(i), "render_mode":"webgl"},
            ],
            "layout": harmonic_layout,
            })
        return_arg.append({"data": [
            {"x":sinusoidal_x_val, "y": sinusoidal_y_val, "type": "line", "name": "SV", "render_mode":"webgl"},
        ],
        "layout": ramped_layout,
        })

        for i in range(0, num_harms):
            return_arg.append({"data": [
                {"x":s_volts, "y": np.real(SV_harmonics[i,:]), "type": "line", "name": "sv_harm"+str(i), "render_mode":"webgl"},
            ],
            "layout": harmonic_layout,
            })
        return_arg.append(table_data)
        return return_arg


    return [{"layout": ramped_layout}]+[{"layout": harmonic_layout}]*(num_harms)+[{"layout": ramped_layout}]+[{"layout": harmonic_layout}]*(num_harms)+[table_data]
Exemplo n.º 7
0
}
param_bounds = {
    'E_0': [-0.1, -0.04],
    'omega':
    [0.95 * param_list['omega'],
     1.05 * param_list['omega']],  #8.88480830076,  #    (frequency Hz)
    'Ru': [0, 2e3],  #     (uncompensated resistance ohms)
    'Cdl': [0, 1e-3],  #(capacitance parameters)
    'CdlE1': [-0.05, 0.05],  #0.000653657774506,
    'CdlE2': [-0.05, 0.05],  #0.000245772700637,
    'CdlE3': [-0.05, 0.05],  #1.10053945995e-06,
    'gamma':
    [0.1 * param_list["original_gamma"], 8 * param_list["original_gamma"]],
    'k_0': [0, 7e3],  #(reaction rate s-1)
    'alpha': [0.498, 0.502],
    "cap_phase": [0.8 * 3 * math.pi / 2, 1.2 * 3 * math.pi / 2],
    "E0_mean": [-0.1, -0.04],
    "E0_std": [1e-4, 0.1],
    "E0_skew": [-10, 10],
    "alpha_mean": [0.4, 0.65],
    "alpha_std": [1e-3, 0.3],
    "k0_shape": [0, 1],
    "k0_scale": [0, 1e4],
    'phase': [0.8 * 3 * math.pi / 2, 1.2 * 3 * math.pi / 2],
}
eis = single_electron(None, param_list, simulation_options, other_values,
                      param_bounds)
curr = eis.test_vals([], "timeseries")
plt.plot(eis.define_voltages(transient=True), curr)
plt.show()