def run_sp_model_example(q, k, t, b, c, d, show_plot=False): """ Run the SP model example and the inverse to show how a synthetic curve can be obtained :param q: :param k: :param t: :param b: :param c: :param d: :return: """ dT = sp_model_nominal(q, k, t, b, c, d) dT_synth0, t0 = cut_to_zero(dT, t) dt = t0[1] - t0[0] kdet, bdet, tth, dT_sig_pro = sp_model_signal_inv(dT_synth0, t0, dt, q, output_model_array=True, cutoff=0.5, filter=False) dT_sig_pro_comp = dT_sp_model_signal(q, kdet, tth, bdet) dT_sig_pro_comp_diff = dT_sig_pro - dT_sig_pro_comp kd, bd, cd, dd = obtain_sp_vars_from_curve(q, t0, dT_synth0, kdet) dT_comp = sp_model_nominal(q, kd, t0, bd, cd, dd) dT_comp_diff = dT_synth0 - dT_comp fig = plt.figure(num=None, figsize=SQUARE_FIGSIZE) # (a) ax = fig.add_subplot(2, 2, 1) # ax.set_xlabel('Time (s)') ticklabels_off_x() ax.set_ylabel(create_label('$\Delta T$', 'K')) ax.plot(t0, dT_synth0, color=MODELLED_COLOR, linewidth=4, label='Forward') ax.plot(t0, dT_comp, color='grey', ls='dashed', label='Inverse') ax.legend() ax.set_title('(a)', loc='center') # (b) ax = fig.add_subplot(2, 2, 2) # ax.set_xlabel('Time (s)') ticklabels_off_x() ax.set_ylabel(create_label('$\Delta T \hspace{1}$ Forward - Inverse', 'K')) ax.plot(t0, dT_comp_diff, color=GREY_COLOR, label='Difference', ls='solid') ax.legend() ax.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax.set_title('(b)', loc='center') # (c) ax = fig.add_subplot(2, 2, 3) ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta \Gamma _{5} \hspace{0.3} (\hspace{0.3} t \hspace{0.3})$', '')) ax.plot(tth, dT_sig_pro_comp, color=MODELLED_COLOR, linewidth=4, label='Forward (Processed)') ax.plot(tth, dT_sig_pro, color='grey', ls='dashed', label='Theoretical') ax.set_title('(c)', loc='center') ax.legend() # (d) ax = fig.add_subplot(2, 2, 4) ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta \Gamma _{5} \hspace{0.3} (\hspace{0.3} t \hspace{0.3}) \hspace{1}$ ' 'Forward - Inverse', 'K')) ax.plot(tth, dT_sig_pro_comp_diff, color=GREY_COLOR, ls='solid') ax.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax.set_title('(d)', loc='center') plt.tight_layout() plt.savefig(FIG_PATH + SP_SYNTH_FILENAME_EXAMPLE + PLOT_EXTENSION) if show_plot: plt.show()
def run_dp_model_inv_test(show_plot=False, run_full=False): """ Run the SP model inverse test to show an example of the reconstruction :param show_plot: True to show the plot :param run_full: True to run the reconstruction over the heating and cooling curve False to run the reconstruction over only the heating curve :return: """ ################################################ # MAIN ################################################ q = 45 k = 5.2 theta_m = 0.59 theta_o = 9.2e-3 theta_w = 0.40 C = get_volumetric_heat_capacity(theta_m, theta_o, theta_w) alpha = get_alpha_k_C(k, C) r0 = 6e-3 fs = 12 t0 = 0 max_delta_r = 5.0e-3 timestep = 1 / fs t_heat = 8 # 8 seconds for heating (when working with the full curve) if run_full: t1 = 60*3 # 3 minutes for heating and cooling else: t1 = 8 # 8 seconds for heating # create the time vector t = np.arange(t0, t1, timestep) # required since t0 = 0 and this cannot be used since Ei(x=0) is not defined rstep = length(t)-1 ########################################################### # LINEAR CHANGE (INCREASE) ########################################################### print('Computing for linear increase in r(t)...') r = r0 + np.linspace(0, max_delta_r, rstep) dT_dual, dT_dual_fixed, r_det_mm, r_mm, r_t_det_diff, tt = \ run_plot_output(alpha, fs, k, q, r0, run_full, t_heat, t, r) ########################################################### # LINEAR CHANGE (DECREASE) ########################################################### print('Computing for linear decrease in r(t)...') rdec = r[::-1] r0_dec = rdec[0] dT_dual_dec, dT_dual_fixed_dec, r_det_mm_dec, r_mm_dec, r_t_det_diff_dec, tt = \ run_plot_output(alpha, fs, k, q, r0_dec, run_full, t_heat, t, rdec) ########################################################### # RANDOM WALK ########################################################### print('Computing for Brownian random walk in r(t)...') nr = length(r) rb = brownian_noise_norm(nr, r0, r0 + max_delta_r) rb0 = rb[0] dT_dual_bn, dT_dual_fixed_bn, r_det_mm_bn, r_mm_bn, r_t_det_diff_bn, tt = \ run_plot_output(alpha, fs, k, q, rb0, run_full, t_heat, t, rb) ########################################################### # FIGURES ########################################################### print('DONE COMPUTING, RUNNING FIGURES') fig = plt.figure(num=None, figsize=LARGE_SQUARE_FIGSIZE) # INCREASE # (a) ax = fig.add_subplot(3, 3, 1) ax.plot(tt, dT_dual_fixed, label='DP Fixed Radius', color='orange') ax.plot(tt, dT_dual, label='DP Variable Radius', color="cornflowerblue") # ax.set_xlabel('Time (s)') ticklabels_off_x() ax.set_ylabel(create_label('$\Delta T \hspace{1}$', 'K')) ax.legend() ax.set_title('(a)', loc='center') # (b) ax = fig.add_subplot(3, 3, 2) ax.plot(tt, r_mm, color=MODELLED_COLOR, linewidth=4, label='Forward') ax.plot(tt, r_det_mm, color='grey', ls='dashed', label='Inverse') ax.set_ylabel(create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})$', 'mm')) # ax.set_xlabel('Time (s)') ticklabels_off_x() ax.legend() ax.set_title('(b)', loc='center') # (c) ax = fig.add_subplot(3, 3, 3) ax.plot(tt, r_t_det_diff, color='grey', label='difference') ax.set_ylabel(create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})\hspace{1}$ Forward -\n Inverse', 'mm')) # ax.set_xlabel('Time (s)') ticklabels_off_x() ax.set_title('(c)', loc='center') # DECREASE # (d) ax = fig.add_subplot(3, 3, 4) ax.plot(tt, dT_dual_fixed_dec, label='DP Fixed Radius', color='orange') ax.plot(tt, dT_dual_dec, label='DP Variable Radius', color="cornflowerblue") ticklabels_off_x() # ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta T \hspace{1}$', 'K')) # ax.legend() ax.set_title('(d)', loc='center') # (e) ax = fig.add_subplot(3, 3, 5) ax.plot(tt, r_mm_dec, color=MODELLED_COLOR, linewidth=4, label='Forward') ax.plot(tt, r_det_mm_dec, color='grey', ls='dashed', label='Inverse') ax.set_ylabel(create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})$', 'mm')) ticklabels_off_x() # ax.set_xlabel('Time (s)') # ax.legend() ax.set_title('(e)', loc='center') # (f) ax = fig.add_subplot(3, 3, 6) ax.plot(tt, r_t_det_diff_dec, color='grey', label='difference') ax.set_ylabel(create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})\hspace{1}$ Forward -\n Inverse', 'mm')) ticklabels_off_x() # ax.set_xlabel('Time (s)') ax.set_title('(f)', loc='center') # RANDOM WALK # (g) ax = fig.add_subplot(3, 3, 7) ax.plot(tt, dT_dual_fixed_bn, label='DP Fixed Radius', color='orange') ax.plot(tt, dT_dual_bn, label='DP Variable Radius', color="cornflowerblue") ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta T \hspace{1}$', 'K')) # ax.legend() ax.set_title('(g)', loc='center') # (h) ax = fig.add_subplot(3, 3, 8) ax.plot(tt, r_mm_bn, color=MODELLED_COLOR, linewidth=4, label='Forward') ax.plot(tt, r_det_mm_bn, color='grey', ls='dashed', label='Inverse') ax.set_ylabel(create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})$', 'mm')) ax.set_xlabel('Time (s)') ylim = list(ax.get_ylim()) ylim[1] += 0.20*(ylim[1]-ylim[0]) ax.set_ylim(ylim) ax.legend() ax.set_title('(h)', loc='center') # (i) ax = fig.add_subplot(3, 3, 9) ax.plot(tt, r_t_det_diff_bn, color='grey', label='difference') ax.set_ylabel(create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})\hspace{1}$ Forward -\n Inverse', 'mm')) ax.set_xlabel('Time (s)') ax.set_title('(i)', loc='center') # SHOW AND SAVE FIGURE plt.tight_layout() plt.savefig(FIG_PATH + DP_SYNTH_FILENAME_EXAMPLE + PLOT_EXTENSION) if show_plot: plt.show()
def plot_main_all_data(show_plot=False): print('Loading data...') experiments = pickle.load(open(DATA_PICKLE_FILE_VEC, "rb")) theta_nom_sand, rho_nom_sand, theta_sig_sand, rho_sig_sand, \ alpha_det_sand, alpha_sig_sand, k_det_sand, kdet_sig_sand, kdet_linear_sand, \ qav_vec_sand, qknown_vec_sand = experiments[SAND_NAME] theta_nom_peat, rho_nom_peat, theta_sig_peat, rho_sig_peat, \ alpha_det_peat, alpha_sig_peat, k_det_peat, kdet_sig_peat, kdet_linear_peat, \ qav_vec_peat, qknown_vec_peat \ = experiments[PEAT_NAME] print('Done loading data...') # first sequence of experiments ns = length(theta_nom_sand) xs = np.linspace(1, ns, ns) # second sequence of experiments nnp = length(theta_nom_peat) xp = np.linspace(xs[-1] + 1, xs[-1] + nnp, nnp) ################################################################# fig = plt.figure(num=None, figsize=SQUARE_FIGSIZE) lim_theta = [0, 1.0] lim_rho = [400, 2500] # (a) theta_sand ax = fig.add_subplot(2, 2, 1) ax.plot(xs, theta_nom_sand, 's', label='Heating and Cooling DP') ax.plot(xs, theta_sig_sand, 'o', label='Signal Processing SP and DP') ax.axhline(THETA_NOMINAL_SAND, linestyle='--', label='Nominal Value', color='gray') ax.set_ylim(lim_theta) set_x_axis_integer() ax.set_ylabel(create_label(r'$\theta_w$', '')) ticklabels_off_x() ax.legend() ax.set_title('(a)', loc='left') # (b) theta_peat ax = fig.add_subplot(2, 2, 2) ax.plot(xp, theta_nom_peat, 's', label='Heating and Cooling DP') ax.plot(xp, theta_sig_peat, 'o', label='Signal Processing SP and DP') ax.axhline(THETA_NOMINAL_PEAT, linestyle='--', label='Nominal Value', color='gray') ax.set_ylim(lim_theta) ticklabels_off_y() ticklabels_off_x() set_x_axis_integer() ax.set_title('(b)', loc='left') # (c) density of sand ax = fig.add_subplot(2, 2, 3) ax.plot(xs, rho_nom_sand, 's', label='Heating and Cooling DP') ax.plot(xs, rho_sig_sand, 'o', label='Signal Processing SP and DP') ax.axhline(DENSITY_NOMINAL_SAND, linestyle='--', label='Nominal Value', color='gray') ax.set_ylim(lim_rho) set_x_axis_integer() ax.set_ylabel(create_label(r'$\rho$', 'kg m^-3')) ax.set_xlabel('Experiment #') ax.set_title('(c)', loc='left') # (d) density of peat ax = fig.add_subplot(2, 2, 4) ax.plot(xp, rho_nom_peat, 's', label='Heating and Cooling DP') ax.plot(xp, rho_sig_peat, 'o', label='Signal Processing SP and DP') ax.axhline(DENSITY_NOMINAL_PEAT, linestyle='--', label='Nominal Value', color='gray') ax.set_ylim(lim_rho) ticklabels_off_y() set_x_axis_integer() ax.set_xlabel('Experiment #') ax.set_title('(d)', loc='left') plt.tight_layout() plt.savefig(FIG_PATH + PLOTS_ALL_THETA_RHO_FILENAME + PLOT_EXTENSION) if show_plot: block = False plt.show(block) ########################################################################### lim_k = [0, 9] lim_a = [1e-7, 6e-6] fig = plt.figure(num=None, figsize=SQUARE_FIGSIZE) # (a) k for sand ax = fig.add_subplot(2, 2, 1) ax.plot(xs, k_det_sand, 's', label='Heating and Cooling DP') ax.plot(xs, kdet_sig_sand, 'o', label='Signal Processing SP') ax.plot(xs, kdet_linear_sand, '^', label='Late-Time SP') ax.set_ylim(lim_k) set_x_axis_integer() ax.set_ylabel(create_label(r'$k$', 'W m^-1 K^-1')) ticklabels_off_x() ax.legend() ax.set_title('(a)', loc='center') # (b) alpha for sand ax = fig.add_subplot(2, 2, 3) ax.plot(xs, alpha_det_sand, 's', label='Heating and Cooling DP') ax.plot(xs, alpha_sig_sand, 'o', label='Signal Processing SP and DP') ax.set_ylim(lim_a) set_x_axis_integer() set_y_scientific() ax.set_ylabel(create_label(r'$\alpha$', 'm^2 s^-1')) ax.set_xlabel('Experiment #') ax.set_title('(c)', loc='center') ax.legend() # (c) k for peat ax = fig.add_subplot(2, 2, 2) ax.plot(xp, k_det_peat, 's', label='Heating and Cooling DP') ax.plot(xp, kdet_sig_peat, 'o', label='Signal Processing SP') ax.plot(xp, kdet_linear_peat, '^', label='Late-Time SP') ax.set_ylim(lim_k) set_x_axis_integer() ticklabels_off_x() ticklabels_off_y() ax.set_title('(b)', loc='center') # (d) alpha for peat ax = fig.add_subplot(2, 2, 4) ax.plot(xp, alpha_det_peat, 's', label='Heating and Cooling DP') ax.plot(xp, alpha_sig_peat, 'o', label='Signal Processing SP') set_x_axis_integer() set_y_scientific() ax.set_ylim(lim_a) ticklabels_off_y() ax.set_xlabel('Experiment #') ax.set_title('(d)', loc='center') plt.tight_layout() plt.savefig(FIG_PATH + PLOTS_ALL_THERMAL_FILENAME + PLOT_EXTENSION) if show_plot: block = True plt.show(block)
def run_test_calibration_k(show_plot): path = '../hpp-data/hpp-formatted-data/calibration/July-12-2017/' dec_places = 2 # number of decimal places to have result t_cold = T_COLD_BEGIN # time at beginning which is cold t_heat = T_HEAT_CAL # seconds heating (s) t_total = TIME_TOTAL_CAL # 3 minutes for entire test fs = FS_SAMPLE # sampling rate (Hz) k_assumed = K_WATER # thermal conductivity of water (W m^-1 K^-1) rho = RHO_WATER_AGAR # density of agar gel water (kg m^-3) c = HEAT_CAPACITY_WATER # heat capacity of water (J kg^-1 K^-1) filt = 'both' # filter both SP and DP downsample = 'dp' # downsample DP fs_down = DOWNSAMPLE_DP # 1 second downsample filt_cutoff = DP_LOWPASS_FILTER_CUT # lowpass filter cutoff frequency start_string = CAL_BEGIN # start calibration string additional_text = NO_TEXT # additional text Hstart = 80 # starting value for H qlist = Q_VAL_CAL_LIST # list of q values during calibration kout_dp_heating_vec = [] kout_dp_heating_cooling_vec = [] kout_sp_late_time_vec = [] kout_sp_all_vec = [] kout_signal_vec = [] kout_signal_curve_fit_vec = [] for q in qlist: print('q = ', q) kout_dp_heating, kout_dp_heating_cooling, kout_sp_late_time, _tlinear, kout_sp_all, \ kout_signal, bdet_signal, kout_signal_curve_fit = \ test_calibration_k(path, start_string, additional_text, downsample, filt, filt_cutoff, fs, fs_down, q, t_cold, t_heat, t_total, k_assumed, Hstart) kout_dp_heating_vec.append(kout_dp_heating) kout_dp_heating_cooling_vec.append(kout_dp_heating_cooling) kout_sp_late_time_vec.append(kout_sp_late_time) kout_sp_all_vec.append(kout_sp_all) kout_signal_vec.append(kout_signal) kout_signal_curve_fit_vec.append(kout_signal_curve_fit) # DONE qlist = np.asarray(qlist) kout_dp_heating_vec = np.asarray(kout_dp_heating_vec) kout_dp_heating_cooling_vec = np.asarray(kout_dp_heating_cooling_vec) kout_sp_late_time_vec = np.asarray(kout_sp_late_time_vec) kout_sp_all_vec = np.asarray(kout_sp_all_vec) kout_signal_vec = np.asarray(kout_signal_vec) kout_signal_curve_fit_vec = np.asarray(kout_signal_curve_fit_vec) ed = EasyDump(TABLE_PATH + K_PLOT_TABLE_FILENAME + TABLE_EXT, 2) ed.open() # COMPUTE RMSE AND MB FOR ALL EXPERIMENTS rmse_kout_dp_heating = compute_rmse(k_assumed, kout_dp_heating_vec) mb_kout_dp_heating = compute_mb(k_assumed, kout_dp_heating_vec) pd_kout_dp_heating = compute_percentage_diff(k_assumed, kout_dp_heating_vec) ed.write(rmse_kout_dp_heating, 'rmse_kout_dp_heating') ed.write(mb_kout_dp_heating, 'mb_kout_dp_heating') ed.write(pd_kout_dp_heating, 'pd_kout_dp_heating') rmse_kout_dp_heating_cooling = compute_rmse(k_assumed, kout_dp_heating_cooling_vec) mb_kout_dp_heating_cooling = compute_mb(k_assumed, kout_dp_heating_cooling_vec) pd_kout_dp_heating_cooling = compute_percentage_diff( k_assumed, kout_dp_heating_cooling_vec) ed.write(rmse_kout_dp_heating_cooling, 'rmse_kout_dp_heating_cooling') ed.write(mb_kout_dp_heating_cooling, 'mb_kout_dp_heating_cooling') ed.write(pd_kout_dp_heating_cooling, 'pd_kout_dp_heating_cooling') rmse_kout_sp_late_time = compute_rmse(k_assumed, kout_sp_late_time_vec) mb_kout_sp_late_time = compute_mb(k_assumed, kout_sp_late_time_vec) pd_kout_sp_late_time = compute_percentage_diff(k_assumed, kout_sp_late_time_vec) ed.write(rmse_kout_sp_late_time, 'rmse_kout_sp_late_time') ed.write(mb_kout_sp_late_time, 'mb_kout_sp_late_time') ed.write(pd_kout_sp_late_time, 'pd_kout_sp_late_time') rmse_kout_sp_all = compute_rmse(k_assumed, kout_sp_all_vec) mb_kout_sp_all = compute_mb(k_assumed, kout_sp_all_vec) pd_kout_sp_all = compute_percentage_diff(k_assumed, kout_sp_all_vec) ed.write(rmse_kout_sp_all, 'rmse_kout_sp_all') ed.write(mb_kout_sp_all, 'mb_kout_sp_all') ed.write(pd_kout_sp_all, 'pd_kout_sp_all') rmse_kout_signal = compute_rmse(k_assumed, kout_signal_vec) mb_kout_signal = compute_mb(k_assumed, kout_signal_vec) pd_kout_signal = compute_percentage_diff(k_assumed, kout_signal_vec) ed.write(rmse_kout_signal, 'rmse_kout_signal') ed.write(mb_kout_signal, 'mb_kout_signal') ed.write(pd_kout_signal, 'pd_kout_signal') rmse_kout_signal_curve_fit = compute_rmse(k_assumed, kout_signal_curve_fit_vec) mb_kout_signal_curve_fit = compute_mb(k_assumed, kout_signal_curve_fit_vec) pd_kout_signal_curve_fit = compute_percentage_diff( k_assumed, kout_signal_curve_fit_vec) ed.write(rmse_kout_signal_curve_fit, 'rmse_kout_signal_curve_fit') ed.write(mb_kout_signal_curve_fit, 'mb_kout_signal_curve_fit') ed.write(pd_kout_signal_curve_fit, 'pd_kout_signal_curve_fit') # close the file ed.close() # need to trim outliers elem = kout_dp_heating_vec < 100 qq = qlist[elem] kout_dp_heating_vec_trim = kout_dp_heating_vec[elem] elem = kout_dp_heating_vec_trim > 0.01 qq = qq[elem] kout_dp_heating_vec_trim = kout_dp_heating_vec_trim[elem] fig = plt.figure(num=None) nx = 6 ax = fig.add_subplot(1, 1, 1) ax.plot(qq, kout_dp_heating_vec_trim, "o", label='Heating DP', color='orange') ax.plot(qlist, kout_dp_heating_cooling_vec, "v", label='Heating and Cooling DP') ax.plot(qlist, kout_sp_late_time_vec, "s", label='Late-Time SP') ax.plot(qlist, kout_sp_all_vec, "^", label='Late-Time SP (all data)') ax.plot(qlist, kout_signal_vec, "*", label='Signal Processing SP', color="yellowgreen") ax.plot(qlist, kout_signal_curve_fit_vec, "h", label='Signal Processing SP with Curve-Fitting') ax.set_ylim([-0.1, 7]) set_xlim_linear(qlist[0], qlist[-1], nx) ax.set_xlim([qlist[0] - 3, qlist[-1] + 3]) ax.set_xlabel(create_label('$q$', 'W \hspace{0.1} m^-1')) ax.set_ylabel(create_label('$k$', 'W \hspace{0.1} m^-1 \hspace{0.1} K^-1')) ax.axhline(y=k_assumed, color="silver", linestyle='dashed', label='Assumed Value') ax.legend(loc='upper left') plt.tight_layout() plt.savefig(FIG_PATH + K_PLOT_FILENAME + PLOT_EXTENSION) if show_plot: # show the plot for purposes of debugging plt.show()
def plot_oat(show=False): """ Plot for sensitivity analysis :return: """ # load in the data from the dictionary file print('Loading in the data...') dictionary = pickle.load(open(SENSITIVITY_ANALYSIS_VEC_FILE, "rb")) print('DONE loading in the data.') ####################################################################################### # RADIUS rvec_sand, theta_nom_rmsd_vec_sand_radius, theta_nom_mb_vec_sand_radius, rho_nom_rmse_vec_sand_radius, \ rho_nom_mb_vec_sand_radius, theta_sig_rmsd_vec_sand_radius, theta_sig_mb_vec_sand_radius, \ rho_sig_rmse_vec_sand_radius, rho_sig_mb_vec_sand_radius = dictionary[SAND_RADIUS] rvec_peat, theta_nom_rmsd_vec_peat_radius, theta_nom_mb_vec_peat_radius, rho_nom_rmse_vec_peat_radius, \ rho_nom_mb_vec_peat_radius, theta_sig_rmsd_vec_peat_radius, theta_sig_mb_vec_peat_radius, \ rho_sig_rmse_vec_peat_radius, rho_sig_mb_vec_peat_radius = dictionary[PEAT_RADIUS] # ORGANIC CONTENT dvec_sand_theta_o, theta_nom_rmsd_vec_sand_theta_o, theta_nom_mb_vec_sand_theta_o, rho_nom_rmse_vec_sand_theta_o, \ rho_nom_mb_vec_sand_theta_o, theta_sig_rmsd_vec_sand_theta_o, theta_sig_mb_vec_sand_theta_o, \ rho_sig_rmse_vec_sand_theta_o, rho_sig_mb_vec_sand_theta_o = dictionary[SAND_ORGANIC] dvec_peat_theta_o, theta_nom_rmsd_vec_peat_theta_o, theta_nom_mb_vec_peat_theta_o, rho_nom_rmse_vec_peat_theta_o, \ rho_nom_mb_vec_peat_theta_o, theta_sig_rmsd_vec_peat_theta_o, theta_sig_mb_vec_peat_theta_o, \ rho_sig_rmse_vec_peat_theta_o, rho_sig_mb_vec_peat_theta_o = dictionary[PEAT_ORGANIC] # MINERAL CONTENT (dvec_sand_theta_m, theta_nom_rmsd_vec_sand_theta_m, theta_nom_mb_vec_sand_theta_m, rho_nom_rmse_vec_sand_theta_m, rho_nom_mb_vec_sand_theta_m, theta_sig_rmsd_vec_sand_theta_m, theta_sig_mb_vec_sand_theta_m, rho_sig_rmse_vec_sand_theta_m, rho_sig_mb_vec_sand_theta_m) = dictionary[SAND_MINERAL] (dvec_peat_theta_m, theta_nom_rmsd_vec_peat_theta_m, theta_nom_mb_vec_peat_theta_m, rho_nom_rmse_vec_peat_theta_m, rho_nom_mb_vec_peat_theta_m, theta_sig_rmsd_vec_peat_theta_m, theta_sig_mb_vec_peat_theta_m, rho_sig_rmse_vec_peat_theta_m, rho_sig_mb_vec_peat_theta_m) = dictionary[PEAT_MINERAL] # TIME SHIFT (dvec_sand_time, theta_nom_rmsd_vec_sand_time, theta_nom_mb_vec_sand_time, rho_nom_rmse_vec_sand_time, rho_nom_mb_vec_sand_time, theta_sig_rmsd_vec_sand_time, theta_sig_mb_vec_sand_time, rho_sig_rmse_vec_sand_time, rho_sig_mb_vec_sand_time) = dictionary[SAND_TIME] (dvec_peat_time, theta_nom_rmsd_vec_peat_time, theta_nom_mb_vec_peat_time, rho_nom_rmse_vec_peat_time, rho_nom_mb_vec_peat_time, theta_sig_rmsd_vec_peat_time, theta_sig_mb_vec_peat_time, rho_sig_rmse_vec_peat_time, rho_sig_mb_vec_peat_time) = dictionary[PEAT_TIME] ####################################################################################### # There will be two plots: # plot theta (3 x 2 = 6) # plot rho (3 x 2 = 6) ######################### # THETA ONLY ######################### fig = plt.figure(num=None, figsize=VLONG_FIGSIZE) colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] # (a) ax = fig.add_subplot(4, 2, 1) ax.plot(rvec_sand, theta_nom_rmsd_vec_sand_radius, label='Heating and Cooling DP Sand') ax.plot(rvec_sand, theta_sig_rmsd_vec_sand_radius, label='Signal Processing SP and DP Sand') ax.plot(rvec_peat, theta_nom_rmsd_vec_peat_radius, label='Heating and Cooling DP Peat') ax.plot(rvec_peat, theta_sig_rmsd_vec_peat_radius, label='Signal Processing SP and DP Peat') ax.set_xlabel(create_label('$r$', 'mm')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\theta$', '')) ax.set_title('(a)', loc='center') ax.set_ylim([0, 4]) ax.legend() # (b) # sand and peat MB for radius ax = fig.add_subplot(4, 2, 2) ax.plot(rvec_sand, theta_nom_mb_vec_sand_radius, label='Heating and Cooling DP Sand') ax.plot(rvec_sand, theta_sig_mb_vec_sand_radius, label='Signal Processing SP and DP Sand') ax.plot(rvec_peat, theta_nom_mb_vec_peat_radius, label='Heating and Cooling DP Peat') ax.plot(rvec_peat, theta_sig_mb_vec_peat_radius, label='Signal Processing SP and DP Peat') ax.set_xlabel(create_label('$r$', 'mm')) ax.set_ylabel(create_label(r'MB$\hspace{1}\theta$', '')) ax.set_title('(b)', loc='center') # (c) # sand and peat RMSD for theta_o ax = fig.add_subplot(4, 2, 3) ax.plot(dvec_sand_theta_o, theta_nom_rmsd_vec_sand_theta_o) ax.plot(dvec_sand_theta_o, theta_sig_rmsd_vec_sand_theta_o) ax.plot(dvec_peat_theta_o, theta_nom_rmsd_vec_peat_theta_o) ax.plot(dvec_peat_theta_o, theta_sig_rmsd_vec_peat_theta_o) ax.set_xlabel(create_label(r'$\theta_o$', '')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\theta$', '')) ax.set_title('(c)', loc='center') # (d) # sand and peat MB for theta_o ax = fig.add_subplot(4, 2, 4) ax.plot(dvec_sand_theta_o, theta_nom_mb_vec_sand_theta_o) ax.plot(dvec_sand_theta_o, theta_sig_mb_vec_sand_theta_o) ax.plot(dvec_peat_theta_o, theta_nom_mb_vec_peat_theta_o) ax.plot(dvec_peat_theta_o, theta_sig_mb_vec_peat_theta_o) ax.set_xlabel(create_label(r'$\theta_o$', '')) ax.set_ylabel(create_label(r'MB$\hspace{1}\theta$', '')) ax.set_title('(d)', loc='center') # (e) # sand and peat RMSD for theta_m ax = fig.add_subplot(4, 2, 5) ax.plot(dvec_sand_theta_m, theta_nom_rmsd_vec_sand_theta_m) ax.plot(dvec_sand_theta_m, theta_sig_rmsd_vec_sand_theta_m) ax.plot(dvec_peat_theta_m, theta_nom_rmsd_vec_peat_theta_m) ax.plot(dvec_peat_theta_m, theta_sig_rmsd_vec_peat_theta_m) ax.set_xlabel(create_label(r'$\theta_m$', '')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\theta$', '')) ax.set_title('(e)', loc='center') # (f) # sand and peat MB for theta_m ax = fig.add_subplot(4, 2, 6) ax.plot(dvec_sand_theta_m, theta_nom_mb_vec_sand_theta_m) ax.plot(dvec_sand_theta_m, theta_sig_mb_vec_sand_theta_m) ax.plot(dvec_peat_theta_m, theta_nom_mb_vec_peat_theta_m) ax.plot(dvec_peat_theta_m, theta_sig_mb_vec_peat_theta_m) ax.set_xlabel(create_label(r'$\theta_m$', '')) ax.set_ylabel(create_label(r'MB$\hspace{1}\theta$', '')) ax.set_title('(f)', loc='center') # (g) # time ax = fig.add_subplot(4, 2, 7) # ax.plot(dvec_sand_time, theta_nom_rmsd_vec_sand_time) ax.plot(dvec_sand_time, theta_sig_rmsd_vec_sand_time, color=colors[1]) # ax.plot(dvec_sand_time, theta_nom_rmsd_vec_peat_time) ax.plot(dvec_sand_time, theta_sig_rmsd_vec_peat_time, color=colors[3]) ax.set_xlabel(create_label(r'$t_a$', 's')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\theta$', '')) ax.set_title('(g)', loc='center') # (h) ax = fig.add_subplot(4, 2, 8) # ax.plot(dvec_sand_time, theta_nom_mb_vec_sand_time) ax.plot(dvec_sand_time, theta_sig_mb_vec_sand_time, color=colors[1]) # ax.plot(dvec_sand_time, theta_nom_mb_vec_peat_time) ax.plot(dvec_sand_time, theta_sig_mb_vec_peat_time, color=colors[3]) ax.set_xlabel(create_label(r'$t_a$', 's')) ax.set_ylabel(create_label(r'MB$\hspace{1}\theta$', '')) ax.set_title('(h)', loc='center') plt.tight_layout() block = False plt.savefig(OAT_SENSITIVITY_FIG_NAME_THETA) if show: plt.show(block) ######################### # RHO ONLY ######################### fig = plt.figure(num=None, figsize=VLONG_FIGSIZE) # (a) ax = fig.add_subplot(4, 2, 1) ax.plot(rvec_sand, rho_nom_rmse_vec_sand_radius, label='Heating and Cooling DP Sand') ax.plot(rvec_sand, rho_sig_rmse_vec_sand_radius, label='Signal Processing SP and DP Sand') ax.plot(rvec_peat, rho_nom_rmse_vec_peat_radius, label='Heating and Cooling DP Peat') ax.plot(rvec_peat, rho_sig_rmse_vec_peat_radius, label='Signal Processing SP and DP Peat') ax.set_xlabel(create_label('$r$', 'mm')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(a)', loc='center') ax.legend() # (b) # sand and peat MB for radius ax = fig.add_subplot(4, 2, 2) ax.plot(rvec_sand, rho_nom_mb_vec_sand_radius, label='Heating and Cooling DP Sand') ax.plot(rvec_sand, rho_sig_mb_vec_sand_radius, label='Signal Processing SP and DP Sand') ax.plot(rvec_peat, rho_nom_mb_vec_peat_radius, label='Heating and Cooling DP Peat') ax.plot(rvec_peat, rho_sig_mb_vec_peat_radius, label='Signal Processing SP and DP Peat') ax.set_xlabel(create_label('$r$', 'mm')) ax.set_ylabel(create_label(r'MB$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(b)', loc='center') ax.set_ylim([None, 20000]) # (c) # sand and peat RMSD for theta_o ax = fig.add_subplot(4, 2, 3) ax.plot(dvec_sand_theta_o, rho_nom_rmse_vec_sand_theta_o) ax.plot(dvec_sand_theta_o, rho_sig_rmse_vec_sand_theta_o) ax.plot(dvec_peat_theta_o, rho_nom_rmse_vec_peat_theta_o) ax.plot(dvec_peat_theta_o, rho_sig_rmse_vec_peat_theta_o) ax.set_xlabel(create_label(r'$\theta_o$', '')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(c)', loc='center') # (d) # sand and peat MB for theta_o ax = fig.add_subplot(4, 2, 4) ax.plot(dvec_sand_theta_o, rho_nom_mb_vec_sand_theta_o) ax.plot(dvec_sand_theta_o, rho_sig_mb_vec_sand_theta_o) ax.plot(dvec_peat_theta_o, rho_nom_mb_vec_peat_theta_o) ax.plot(dvec_peat_theta_o, rho_sig_mb_vec_peat_theta_o) ax.set_xlabel(create_label(r'$\theta_o$', '')) ax.set_ylabel(create_label(r'MB$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(d)', loc='center') # (e) # sand and peat RMSD for theta_m ax = fig.add_subplot(4, 2, 5) ax.plot(dvec_sand_theta_m, rho_nom_rmse_vec_sand_theta_m) ax.plot(dvec_sand_theta_m, rho_sig_rmse_vec_sand_theta_m) ax.plot(dvec_peat_theta_m, rho_nom_rmse_vec_peat_theta_m) ax.plot(dvec_peat_theta_m, rho_sig_rmse_vec_peat_theta_m) ax.set_xlabel(create_label(r'$\theta_m$', '')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(e)', loc='center') # (f) # sand and peat MB for theta_m ax = fig.add_subplot(4, 2, 6) ax.plot(dvec_sand_theta_m, rho_nom_mb_vec_sand_theta_m) ax.plot(dvec_sand_theta_m, rho_sig_mb_vec_sand_theta_m) ax.plot(dvec_peat_theta_m, rho_nom_mb_vec_peat_theta_m) ax.plot(dvec_peat_theta_m, rho_sig_mb_vec_peat_theta_m) ax.set_xlabel(create_label(r'$\theta_m$', '')) ax.set_ylabel(create_label(r'MB$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(f)', loc='center') # (g) # time ax = fig.add_subplot(4, 2, 7) # ax.plot(dvec_sand_time, rho_nom_rmse_vec_sand_time) ax.plot(dvec_sand_time, rho_sig_rmse_vec_sand_time, color=colors[1]) # ax.plot(dvec_sand_time, rho_nom_rmse_vec_peat_time) ax.plot(dvec_sand_time, rho_sig_rmse_vec_peat_time, color=colors[3]) ax.set_xlabel(create_label(r'$t_a$', 's')) ax.set_ylabel(create_label(r'RMSD$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(g)', loc='center') # (h) # time ax = fig.add_subplot(4, 2, 8) # ax.plot(dvec_sand_time, rho_nom_mb_vec_sand_time) ax.plot(dvec_sand_time, rho_sig_mb_vec_sand_time, color=colors[1]) # ax.plot(dvec_sand_time, rho_nom_mb_vec_peat_time) ax.plot(dvec_sand_time, rho_sig_mb_vec_peat_time, color=colors[3]) ax.set_xlabel(create_label(r'$t_a$', 's')) ax.set_ylabel(create_label(r'MB$\hspace{1}\rho$', 'kg m^-3')) ax.set_title('(h)', loc='center') plt.tight_layout() block = True plt.savefig(OAT_SENSITIVITY_FIG_NAME_RHO) if show: plt.show()
def run_example_signal_processing_figure(theta_known, density_known, path, start_string, additional_text, q, t_heat, t_total, end_trim_time, fname, show_plot=False): """ Run the example signal processing to construct a figure :param path: :param start_string: :param additional_text: :param q: :param t_heat: :param t_total: :param end_trim_time: :param fname: :return: """ theta_w_nom, rho_nom, theta_w_sig, rho_sig, \ t2_trim1, delta_T2_trim1, dT_synth_nom, dT_synth_sig, \ cut_time, t2_trim1_cut, r_t_heating_cooling, \ alpha_det, alpha_sig, k_det, kdet_sig, \ t1_trim_heating1, delta_T1_trim_heating1, dT_synth_sp, \ delta_T1_trim, t1_trim, \ tlinear, kdet_linear, qav = \ recomp_theta_rho_additional(path, start_string, additional_text, q, t_heat, t_total, end_trim_time) fig = plt.figure(num=None, figsize=HLONG_FIGSIZE_M) # (a) Single Probe ax = fig.add_subplot(1, 3, 1) ax.plot(t1_trim, delta_T1_trim, label='Measured', color=MEASURED_COLOR) ax.plot(t1_trim_heating1, dT_synth_sp, label='Modelled', color=MODELLED_COLOR) ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta T \hspace{1}$', 'K')) ylim = list(ax.get_ylim()) ylim[1] += 0.20 * (ylim[1] - ylim[0]) ax.set_ylim(ylim) ax.legend(loc='best') ax.set_title('(a)', loc='left') # (b) Dual Probe ax = fig.add_subplot(1, 3, 2) ax.plot(t2_trim1, delta_T2_trim1, label='Measured', color=MEASURED_COLOR) ax.plot(t2_trim1, dT_synth_nom, label='Modelled', color=MODELLED_COLOR) ax.axvline(cut_time, linestyle='--', label='Peak Time', color=MODELLED_COLOR) ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta T \hspace{1}$', 'K')) ylim = list(ax.get_ylim()) ylim[1] += 0.20 * (ylim[1] - ylim[0]) ax.set_ylim(ylim) ax.legend(loc='best') ax.set_title('(b)', loc='left') # (d) r(t) ax = fig.add_subplot(1, 3, 3) ax.plot(t2_trim1_cut, r_t_heating_cooling / 1.0e-3, label='Effective Radius', color='grey') ax.legend(loc='upper left') ax.set_ylabel( create_label('$r\hspace{0.3}(\hspace{0.3}t\hspace{0.3})$', 'mm')) ax.set_xlabel('Time (s)') ylim = list(ax.get_ylim()) ylim[1] += 0.20 * (ylim[1] - ylim[0]) ax.set_ylim(ylim) ax.set_title('(c)', loc='left') plt.tight_layout() plt.savefig(FIG_PATH + fname + PLOT_EXTENSION) # compute percentage differences pd_theta_sig = float_round( compute_percentage_diff(theta_known, theta_w_sig), NOM_DP) pd_theta_nom = float_round( compute_percentage_diff(theta_known, theta_w_nom), NOM_DP) diff_theta_sig = float_round(theta_known - theta_w_sig, NOM_DP) diff_theta_nom = float_round(theta_known - theta_w_nom, NOM_DP) pd_rho_sig = float_round(compute_percentage_diff(density_known, rho_sig), NOM_DP) pd_rho_nom = float_round(compute_percentage_diff(density_known, rho_nom), NOM_DP) diff_rho_sig = float_round(density_known - rho_sig, NOM_DP) diff_rho_nom = float_round(density_known - rho_nom, NOM_DP) # create HTML table to show values tab = PrettyTable() tab.field_names = [ "Type", "Signal Hybrid SP and DP", "DP nominal", "late-time SP nominal" ] tab.add_row([ "k", float_round(kdet_sig, NOM_DP), float_round(k_det, NOM_DP), float_round(kdet_linear, NOM_DP) ]) tab.add_row([ "alpha", float_round(alpha_sig, NOM_DP), float_round(alpha_det, NOM_DP), None ]) tab.add_row([ "theta_w", float_round(theta_w_sig, NOM_DP), float_round(theta_w_nom, NOM_DP), None ]) tab.add_row([ "rho", float_round(rho_sig, NOM_DP), float_round(rho_nom, NOM_DP), None ]) print(tab) # create HTML table with differences tabd = PrettyTable() tabd.field_names = [ "Type", "PD Signal (%)", "Diff signal", "PD nom (%)", "Diff nom" ] tabd.add_row([ "theta_w", float_round(pd_theta_sig, NOM_DP), float_round(diff_theta_sig, NOM_DP), float_round(pd_theta_nom, NOM_DP), float_round(diff_theta_nom, NOM_DP) ]) tabd.add_row([ "rho", float_round(pd_rho_sig, NOM_DP), float_round(diff_rho_sig, NOM_DP), float_round(pd_rho_nom, NOM_DP), float_round(diff_rho_nom, NOM_DP) ]) print(tabd) # save out the tables to HTML file print('Saving tables....') with open(TABLE_PATH + fname + '-table1' + HTML_EXT, 'w') as f: f.write(tab.get_html_string()) f.close() with open(TABLE_PATH + fname + '-table2' + HTML_EXT, 'w') as f: f.write(tabd.get_html_string()) f.close() print('DONE saving tables...') if show_plot: plt.show()
def run_k_q_example(start_string, additional_text, downsample, filt, filt_cutoff, fs, fs_down, path, q, t_cold, t_heat, t_total, show, fn): use_assumed_q = False use_step_detector_q = True I, Rw, T1, T2, Vout, dV, dac_code, delta_T1, delta_T1_trim, delta_T1_trim_heating, \ delta_T2, delta_T2_trim, num, qav, qprime, step_q_tfirst, step_q_tsecond, t1, t1_trim, \ t1_trim_heating, t2, t2_trim, ypk, t, rmse_q_calc, mb_q_calc, pd_q_calc, t2_trim_heating, \ delta_T2_trim_heating = \ initial_compute_hpp(start_string, additional_text, downsample, filt, filt_cutoff, fs, fs_down, path, q, t_cold, t_heat, t_total, use_assumed_q, use_step_detector_q) t1_trim_heating1, delta_T1_trim_heating1 = curve_time_trim(t1_trim_heating, delta_T1_trim_heating) dt = t1_trim_heating1[1] - t1_trim_heating1[0] # late-time model entire = False return_all = True tlinear, kdet, bdet, t_tlinear0, dT_tlinear0 = sp_model_late_time_inv(delta_T1_trim_heating1, t1_trim_heating1, dt, qav, entire, return_all) tlog = np.log(t1_trim_heating1) dT_sp_synth = sp_model_late_time(qav, kdet, t_tlinear0, bdet) rmse_sp = compute_rmse(dT_tlinear0, dT_sp_synth) mb_sp = compute_mb(dT_tlinear0, dT_sp_synth) pd_sp = compute_percentage_diff(dT_tlinear0, dT_sp_synth) # signal processing model kdet_sig, bdet_sig, tth, dT2_h = sp_model_signal_inv(delta_T1_trim_heating1, t1_trim_heating1, dt, q, output_model_array=True) bout, cout, dout = sp_model_nominal_get_b_c_d(delta_T1_trim_heating1, t1_trim_heating1, q, kdet_sig) print('SP output:') print('kdet = ', kdet) print('bout = ', bout) print('cout = ', cout) print('dout = ', dout) # synthetic signal processing for comparison dT_model_sig_synth = dT_sp_model_signal(qav, kdet_sig, tth, bdet_sig) rmse_sp_sig = compute_rmse(dT2_h, dT_model_sig_synth) mb_sp_sig = compute_mb(dT2_h, dT_model_sig_synth) pd_sp_sig = compute_percentage_diff(dT2_h, dT_model_sig_synth) fig = plt.figure(num=None, figsize=HSQUARE_FIGSIZE) is_scientific = True use_pd = True # (a) ax = fig.add_subplot(1, 2, 1) ax.plot(tlog, delta_T1_trim_heating1, color=MEASURED_COLOR, label='Measured') ax.plot(np.log(t_tlinear0), dT_sp_synth, color=MODELLED_COLOR, label='Modelled') ax.axvline(x=np.log(tlinear), linestyle=':', color=MODELLED_COLOR, label='Linear\nSection') place_rmse_mb_pd_on_plot(rmse_sp, mb_sp, pd_sp, 'K', 1, 'center left', is_scientific, use_pd) ax.legend(loc='best') ax.set_xlabel(r'$\mathrm{log}(t)$') ax.set_ylabel(create_label('$\Delta T$', 'K')) ylim = list(ax.get_ylim()) ylim[1] += 0.40*(ylim[1]-ylim[0]) ax.set_ylim(ylim) ax.set_title('(a)', loc='left') # (b) ax = fig.add_subplot(1, 2, 2) ax.plot(tth, dT2_h, color=MEASURED_COLOR, label='signal') ax.plot(tth, dT_model_sig_synth, color=MODELLED_COLOR, label='model') ax.set_xlabel('Time (s)') ax.set_ylabel(create_label('$\Delta \Gamma_{5} \hspace{0.3} (\hspace{0.3}t\hspace{0.3})$', '')) place_rmse_mb_pd_on_plot(rmse_sp_sig, mb_sp_sig, pd_sp_sig, 'K', 1, 'lower right', is_scientific, use_pd) ax.set_title('(b)', loc='left') plt.tight_layout() plt.savefig(FIG_PATH + fn + PLOT_EXTENSION) if show: plt.show()