def make_plot(icam, report_center_points=True, **kwargs): q_sampled_mean = np.mean(q_sampled[:, icam, :], axis=-2) def make_tuple(*args): return args data_tuples = \ make_tuple((q_sampled[:,icam,0], q_sampled[:,icam,1], dict(_with = 'points pt 6 ps 0.5', tuplesize = 2)), *get_point_cov_plot_args(q_sampled[:,icam,:], "Observed uncertainty"), *get_cov_plot_args(q_sampled_mean, Var_dq[icam], "Predicted uncertainty"),) if report_center_points: data_tuples += \ ( (q0_baseline, dict(tuplesize = -2, _with = 'points pt 3 ps 3', legend = 'Baseline center point')), (q0_true[args.distances[0]][icam], dict(tuplesize = -2, _with = 'points pt 3 ps 3', legend = 'True center point')), (q_sampled_mean, dict(tuplesize = -2, _with = 'points pt 3 ps 3', legend = 'Sampled mean'))) plot_options = \ dict(square=1, _xrange=(q0_baseline[0]-2,q0_baseline[0]+2), _yrange=(q0_baseline[1]-2,q0_baseline[1]+2), title=f'Uncertainty reprojection distribution for camera {icam}', **kwargs) gp.add_plot_option(plot_options, 'set', ('xtics 1', 'ytics 1')) return data_tuples, plot_options
def makeplots(dohardcopy, processoptions_base): processoptions = copy.deepcopy(processoptions_base) gp.add_plot_option(processoptions, 'set', ('xtics 0.01', 'ytics 0.01')) # The key should use smaller text than the rest of the plot, if possible if 'terminal' in processoptions: m = re.search('font ",([0-9]+)"', processoptions['terminal']) if m is not None: s = int(m.group(1)) gp.add_plot_option( processoptions, 'set', ('xtics 0.01', 'ytics 0.01', f'key font ",{int(s*0.8)}"')) if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_path}--ellipses.{extension}' processoptions['terminal'] = shorter_terminal( processoptions['terminal']) # Hardcopies do things a little differently, to be nicer for docs gp.plot(*subplots, multiplot=f'layout 1,2', unset='grid', **processoptions) else: # Interactive plotting, so no multiplots. Interactive plots for p in subplots: gp.plot(*p[:-1], **p[-1], **processoptions) processoptions = copy.deepcopy(processoptions_base) if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_path}--p0-p1-magnitude-covariance.{extension}' processoptions['title'] = title_covariance gp.plotimage( np.abs(Var_p_joint.reshape(Npoints * 3, Npoints * 3)), square=True, xlabel='Variable index (left point x,y,z; right point x,y,z)', ylabel='Variable index (left point x,y,z; right point x,y,z)', **processoptions) processoptions = copy.deepcopy(processoptions_base) binwidth = np.sqrt(Var_ranges_joint[0]) / 4. equation_range0_observed_gaussian = \ mrcal.fitted_gaussian_equation(x = ranges_sampled[0], binwidth = binwidth, legend = "Idealized gaussian fit to data") equation_range0_predicted_joint_gaussian = \ mrcal.fitted_gaussian_equation(mean = ranges[0], sigma = np.sqrt(Var_ranges_joint[0]), N = len(ranges_sampled[0]), binwidth = binwidth, legend = "Predicted-joint") equation_range0_predicted_calibration_gaussian = \ mrcal.fitted_gaussian_equation(mean = ranges[0], sigma = np.sqrt(Var_ranges_calibration[0]), N = len(ranges_sampled[0]), binwidth = binwidth, legend = "Predicted-calibration") equation_range0_predicted_observations_gaussian = \ mrcal.fitted_gaussian_equation(mean = ranges[0], sigma = np.sqrt(Var_ranges_observations[0]), N = len(ranges_sampled[0]), binwidth = binwidth, legend = "Predicted-observations") if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_path}--range-to-p0.{extension}' processoptions['title'] = title_range0 gp.add_plot_option(processoptions, 'set', 'samples 1000') gp.plot( ranges_sampled[0], histogram=True, binwidth=binwidth, equation_above=(equation_range0_predicted_joint_gaussian, equation_range0_predicted_calibration_gaussian, equation_range0_predicted_observations_gaussian, equation_range0_observed_gaussian), xlabel="Range to the left triangulated point (m)", ylabel="Frequency", **processoptions) processoptions = copy.deepcopy(processoptions_base) binwidth = np.sqrt(Var_distance) / 4. equation_distance_observed_gaussian = \ mrcal.fitted_gaussian_equation(x = distance_sampled, binwidth = binwidth, legend = "Idealized gaussian fit to data") equation_distance_predicted_gaussian = \ mrcal.fitted_gaussian_equation(mean = distance, sigma = np.sqrt(Var_distance), N = len(distance_sampled), binwidth = binwidth, legend = "Predicted") if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_path}--distance-p1-p0.{extension}' processoptions['title'] = title_distance gp.add_plot_option(processoptions, 'set', 'samples 1000') gp.plot(distance_sampled, histogram=True, binwidth=binwidth, equation_above=(equation_distance_predicted_gaussian, equation_distance_observed_gaussian), xlabel="Distance between triangulated points (m)", ylabel="Frequency", **processoptions)
# to evaluate a different world point for each camera q0_baseline = imagersizes[0] / 3. if args.make_documentation_plots is not None: import gnuplotlib as gp if args.make_documentation_plots: for extension in ('pdf', 'svg', 'png', 'gp'): processoptions_output = dict( wait=False, terminal=terminal[extension], _set=extraset[extension], hardcopy= f'{args.make_documentation_plots}--simulated-geometry.{extension}' ) gp.add_plot_option(processoptions_output, 'set', 'xyplane relative 0') mrcal.show_geometry(models_baseline, unset='key', **processoptions_output) else: processoptions_output = dict(wait=True) gp.add_plot_option(processoptions_output, 'set', 'xyplane relative 0') mrcal.show_geometry(models_baseline, unset='key', **processoptions_output) def observed_points(icam): obs_cam = observations_true[ indices_frame_camintrinsics_camextrinsics[:, 1] == icam, ..., :2].ravel()
def makeplots(dohardcopy, processoptions_base): processoptions = copy.deepcopy(processoptions_base) if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_filename}--ellipses.{extension}' processoptions['terminal'] = shorter_terminal(processoptions['terminal']) gp.plot( *subplots, multiplot = f'title "{title_triangulation}" layout 1,2', **processoptions ) processoptions = copy.deepcopy(processoptions_base) if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_filename}--p0-p1-magnitude-covariance.{extension}' processoptions['title'] = title_covariance gp.plotimage( np.abs(Var_p0p1_triangulated), square = True, xlabel = 'Variable index (left point x,y,z; right point x,y,z)', ylabel = 'Variable index (left point x,y,z; right point x,y,z)', **processoptions) processoptions = copy.deepcopy(processoptions_base) binwidth = np.sqrt(Var_range0) / 4. equation_range0_observed_gaussian = \ mrcal.fitted_gaussian_equation(x = range0_sampled, binwidth = binwidth, legend = "Idealized gaussian fit to data") equation_range0_predicted_gaussian = \ mrcal.fitted_gaussian_equation(mean = range0, sigma = np.sqrt(Var_range0), N = len(range0_sampled), binwidth = binwidth, legend = "Predicted") if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_filename}--range-to-p0.{extension}' processoptions['title'] = title_range0 gp.add_plot_option(processoptions, 'set', 'samples 1000') gp.plot(range0_sampled, histogram = True, binwidth = binwidth, equation_above = (equation_range0_predicted_gaussian, equation_range0_observed_gaussian), xlabel = "Range to the left triangulated point (m)", ylabel = "Frequency", **processoptions) processoptions = copy.deepcopy(processoptions_base) binwidth = np.sqrt(Var_distance) / 4. equation_distance_observed_gaussian = \ mrcal.fitted_gaussian_equation(x = distance_sampled, binwidth = binwidth, legend = "Idealized gaussian fit to data") equation_distance_predicted_gaussian = \ mrcal.fitted_gaussian_equation(mean = distance, sigma = np.sqrt(Var_distance), N = len(distance_sampled), binwidth = binwidth, legend = "Predicted") if dohardcopy: processoptions['hardcopy'] = \ f'{args.make_documentation_plots_filename}--distance-p1-p0.{extension}' processoptions['title'] = title_distance gp.add_plot_option(processoptions, 'set', 'samples 1000') gp.plot(distance_sampled, histogram = True, binwidth = binwidth, equation_above = (equation_distance_predicted_gaussian, equation_distance_observed_gaussian), xlabel = "Distance between triangulated points (m)", ylabel = "Frequency", **processoptions)