def plot_statistics(statistics, prefix='', degrees_per_bin=5, cutoff_anom=None, cutoff_non_anom=None): range_width = 1 range_min = flex.min(statistics.dose) - range_width range_max = flex.max(statistics.dose) n_steps = 2 + int((range_max - range_min) - range_width) x = flex.double_range(n_steps) * range_width + range_min x *= degrees_per_bin dpi = 300 import matplotlib matplotlib.use('Agg') from matplotlib import pyplot as plt try: plt.style.use('ggplot') except AttributeError: pass line1, = plt.plot(x, statistics.ieither_completeness, label='Unique reflections') line2, = plt.plot(x, statistics.iboth_completeness, label='Bijvoet pairs') if cutoff_non_anom is not None: plt.plot([cutoff_non_anom, cutoff_non_anom], plt.ylim(), c=line1.get_color(), linestyle='dashed') if cutoff_anom is not None: plt.plot([cutoff_anom, cutoff_anom], plt.ylim(), c=line2.get_color(), linestyle='dotted') plt.xlim(0, plt.xlim()[1]) plt.xlabel('Scan angle (degrees)') plt.ylabel('Completeness (%)') plt.ylim(0, 1) plt.legend(loc='lower right', fontsize='small') plt.savefig('%scompleteness_vs_scan_angle.png' %prefix, dpi=dpi) plt.clf() line1, = plt.plot(x[1:], 100 * statistics.frac_new_ref, label='Unique reflections') line2, = plt.plot(x[1:], 100 * statistics.frac_new_pairs, label='Bijvoet pairs') ylim = plt.ylim() if cutoff_non_anom is not None: plt.plot([cutoff_non_anom, cutoff_non_anom], ylim, c=line1.get_color(), linestyle='dashed') if cutoff_anom is not None: plt.plot([cutoff_anom, cutoff_anom], ylim, c=line2.get_color(), linestyle='dotted') plt.ylim(ylim) plt.xlim(0, plt.xlim()[1]) plt.xlabel('Scan angle (degrees)') plt.ylabel('% new reflections per degree') plt.legend(loc='upper right', fontsize='small') plt.savefig('%spercent_new_reflections_vs_scan_angle.png' %prefix, dpi=dpi) plt.clf()
def save_plots(params, raw, smoothed, suffix=""): """Create plots for the centroid analysis results for a single experiment. Overlay raw and smoothed periodograms""" # draw vertical lines at frequencies corresponding to periods of 54, 36 and 18 # degrees if params.plot.mark_periods is not None: vlines = [1.0 / e for e in params.plot.mark_periods] else: vlines = [] import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt nblocks = raw["nblocks"] block_size = raw["block_size"] phistart = raw["phi_range"][0] block_centres = (block_size * flex.double_range(nblocks) + phistart + block_size / 2.0) # X residuals plot plt.figure(1) plt.subplot(211) plt.plot(block_centres, 1000.0 * raw["av_x_resid_per_block"]) plt.xlabel("phi (degrees)") plt.ylabel("x residuals per block (microns)") # X periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots px = dat["x_periodogram"] if px is None: continue sample_freq = 1.0 / dat["block_size"] freq = px.freq * sample_freq (line, ) = plt.semilogy(freq, px.spec) for vline in vlines: plt.axvline(x=vline, color="r") x_interval = smoothed["x_interval"] if x_interval: x_freq = 1.0 / x_interval plt.axvline(x=x_freq, color="c") plt.text( 0.2, 0.9, "interval width: {0:.3f}".format(x_interval), transform=line.axes.transAxes, color="c", ) plt.xlabel("frequency") plt.ylabel("spectrum") # write them out fname = "x-residual-analysis" + suffix + "." + params.output.format print("Saving {0}".format(fname)) plt.savefig(fname) # Y residuals plot plt.figure(2) plt.subplot(211) plt.plot(block_centres, 1000.0 * raw["av_y_resid_per_block"]) plt.xlabel("phi (degrees)") plt.ylabel("y residuals per block (microns)") # Y periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots py = dat["y_periodogram"] if py is None: continue sample_freq = 1.0 / dat["block_size"] freq = py.freq * sample_freq (line, ) = plt.semilogy(freq, py.spec) for vline in vlines: plt.axvline(x=vline, color="r") y_interval = smoothed["y_interval"] if y_interval: y_freq = 1.0 / y_interval plt.axvline(x=y_freq, color="c") plt.text( 0.2, 0.9, "interval width: {0:.3f}".format(y_interval), transform=line.axes.transAxes, color="c", ) plt.xlabel("frequency") plt.ylabel("spectrum") # write them out fname = "y-residual-analysis" + suffix + "." + params.output.format print("Saving {0}".format(fname)) plt.savefig(fname) # phi residuals plot plt.figure(3) plt.subplot(211) plt.plot(block_centres, 1000.0 * raw["av_phi_resid_per_block"]) plt.xlabel("phi (degrees)") plt.ylabel("phi residuals per block (mrad)") # phi periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots pz = dat["phi_periodogram"] if pz is None: continue sample_freq = 1.0 / dat["block_size"] freq = pz.freq * sample_freq (line, ) = plt.semilogy(freq, pz.spec) for vline in vlines: plt.axvline(x=vline, color="r") phi_interval = smoothed["phi_interval"] if phi_interval: phi_freq = 1.0 / phi_interval plt.axvline(x=phi_freq, color="c") plt.text( 0.2, 0.9, "interval width: {0:.3f}".format(phi_interval), transform=line.axes.transAxes, color="c", ) plt.xlabel("frequency") plt.ylabel("spectrum") # write them out fname = "phi-residual-analysis" + suffix + "." + params.output.format print("Saving {0}".format(fname)) plt.savefig(fname) return
def save_plots(params, raw, smoothed, suffix=''): """Create plots for the centroid analysis results for a single experiment. Overlay raw and smoothed periodograms""" # draw vertical lines at frequencies corresponding to periods of 54, 36 and 18 # degrees if params.plot.mark_periods is not None: vlines = [1./e for e in params.plot.mark_periods] else: vlines = [] import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt nblocks = raw['nblocks'] block_size = raw['block_size'] phistart = raw['phi_range'][0] block_centres = block_size * flex.double_range(nblocks) + phistart + block_size/2.0 # X residuals plot plt.figure(1) plt.subplot(211) plt.plot(block_centres, 1000. * raw['av_x_resid_per_block']) plt.xlabel('phi (degrees)') plt.ylabel('x residuals per block (microns)') # X periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots px = dat['x_periodogram'] if px is None: continue sample_freq = 1./dat['block_size'] freq = px.freq * sample_freq line, = plt.semilogy(freq, px.spec) for vline in vlines: plt.axvline(x=vline, color='r') x_interval = smoothed['x_interval'] if x_interval: x_freq = 1./x_interval plt.axvline(x=x_freq, color='c') plt.text(0.2, 0.9, 'interval width: {0:.3f}'.format(x_interval), transform=line.axes.transAxes, color='c') plt.xlabel('frequency') plt.ylabel('spectrum') # write them out fname = 'x-residual-analysis' + suffix + '.' + params.output.format print("Saving {0}".format(fname)) plt.savefig(fname) # Y residuals plot plt.figure(2) plt.subplot(211) plt.plot(block_centres, 1000. * raw['av_y_resid_per_block']) plt.xlabel('phi (degrees)') plt.ylabel('y residuals per block (microns)') # Y periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots py = dat['y_periodogram'] if py is None: continue sample_freq = 1./dat['block_size'] freq = py.freq * sample_freq line, = plt.semilogy(freq, py.spec) for vline in vlines: plt.axvline(x=vline, color='r') y_interval = smoothed['y_interval'] if y_interval: y_freq = 1./y_interval plt.axvline(x=y_freq, color='c') plt.text(0.2, 0.9, 'interval width: {0:.3f}'.format(y_interval), transform=line.axes.transAxes, color='c') plt.xlabel('frequency') plt.ylabel('spectrum') # write them out fname = 'y-residual-analysis' + suffix + '.' + params.output.format print("Saving {0}".format(fname)) plt.savefig(fname) # phi residuals plot plt.figure(3) plt.subplot(211) plt.plot(block_centres, 1000. * raw['av_phi_resid_per_block']) plt.xlabel('phi (degrees)') plt.ylabel('phi residuals per block (mrad)') # phi periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots pz = dat['phi_periodogram'] if pz is None: continue sample_freq = 1./dat['block_size'] freq = pz.freq * sample_freq line, = plt.semilogy(freq, pz.spec) for vline in vlines: plt.axvline(x=vline, color='r') phi_interval = smoothed['phi_interval'] if phi_interval: phi_freq = 1./phi_interval plt.axvline(x=phi_freq, color='c') plt.text(0.2, 0.9, 'interval width: {0:.3f}'.format(phi_interval), transform=line.axes.transAxes, color='c') plt.xlabel('frequency') plt.ylabel('spectrum') # write them out fname = 'phi-residual-analysis' + suffix + '.' + params.output.format print("Saving {0}".format(fname)) plt.savefig(fname) return
def plot_statistics( statistics, prefix="", degrees_per_bin=5, cutoff_anom=None, cutoff_non_anom=None ): range_width = 1 range_min = flex.min(statistics.dose) - range_width range_max = flex.max(statistics.dose) n_steps = 2 + int((range_max - range_min) - range_width) x = flex.double_range(n_steps) * range_width + range_min x *= degrees_per_bin dpi = 300 import matplotlib matplotlib.use("Agg") from matplotlib import pyplot as plt try: plt.style.use("ggplot") except AttributeError: pass (line1,) = plt.plot(x, statistics.ieither_completeness, label="Unique reflections") (line2,) = plt.plot(x, statistics.iboth_completeness, label="Bijvoet pairs") if cutoff_non_anom is not None: plt.plot( [cutoff_non_anom, cutoff_non_anom], plt.ylim(), c=line1.get_color(), linestyle="dashed", ) if cutoff_anom is not None: plt.plot( [cutoff_anom, cutoff_anom], plt.ylim(), c=line2.get_color(), linestyle="dotted", ) plt.xlim(0, plt.xlim()[1]) plt.xlabel("Scan angle (degrees)") plt.ylabel("Completeness (%)") plt.ylim(0, 1) plt.legend(loc="lower right", fontsize="small") plt.savefig("%scompleteness_vs_scan_angle.png" % prefix, dpi=dpi) plt.clf() (line1,) = plt.plot( x[1:], 100 * statistics.frac_new_ref, label="Unique reflections" ) (line2,) = plt.plot(x[1:], 100 * statistics.frac_new_pairs, label="Bijvoet pairs") ylim = plt.ylim() if cutoff_non_anom is not None: plt.plot( [cutoff_non_anom, cutoff_non_anom], ylim, c=line1.get_color(), linestyle="dashed", ) if cutoff_anom is not None: plt.plot( [cutoff_anom, cutoff_anom], ylim, c=line2.get_color(), linestyle="dotted" ) plt.ylim(ylim) plt.xlim(0, plt.xlim()[1]) plt.xlabel("Scan angle (degrees)") plt.ylabel("% new reflections per degree") plt.legend(loc="upper right", fontsize="small") plt.savefig("%spercent_new_reflections_vs_scan_angle.png" % prefix, dpi=dpi) plt.clf()
def save_plots(raw, smoothed, suffix='', vlines=None): """Create plots for the centroid analysis results for a single experiment. Overlay raw and smoothed periodograms""" if vlines is None: vlines = [] import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt nblocks = raw['nblocks'] block_size = raw['block_size'] phistart = raw['phi_range'][0] block_centres = block_size * flex.double_range(nblocks) + phistart + block_size/2.0 # X residuals plot plt.figure(1) plt.subplot(211) plt.plot(block_centres, 1000. * raw['av_x_resid_per_block']) plt.xlabel('phi (degrees)') plt.ylabel('x residuals per block (microns)') # X periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots px = dat['x_periodogram'] sample_freq = 1./dat['block_size'] freq = px.freq * sample_freq line, = plt.semilogy(freq, px.spec) for vline in vlines: plt.axvline(x=vline, color='r') x_interval = smoothed['x_interval'] if x_interval: x_freq = 1./x_interval plt.axvline(x=x_freq, color='c') plt.text(0.2, 0.9, 'interval width: {0:.3f}'.format(x_interval), transform=line.axes.transAxes, color='c') plt.xlabel('frequency') plt.ylabel('spectrum') # write them out fname = 'x-residual-analysis' + suffix + '.png' print "Saving {0}".format(fname) plt.savefig(fname) # Y residuals plot plt.figure(2) plt.subplot(211) plt.plot(block_centres, 1000. * raw['av_y_resid_per_block']) plt.xlabel('phi (degrees)') plt.ylabel('y residuals per block (microns)') # Y periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots py = dat['y_periodogram'] sample_freq = 1./dat['block_size'] freq = py.freq * sample_freq line, = plt.semilogy(freq, py.spec) for vline in vlines: plt.axvline(x=vline, color='r') y_interval = smoothed['y_interval'] if y_interval: y_freq = 1./y_interval plt.axvline(x=y_freq, color='c') plt.text(0.2, 0.9, 'interval width: {0:.3f}'.format(y_interval), transform=line.axes.transAxes, color='c') plt.xlabel('frequency') plt.ylabel('spectrum') # write them out fname = 'y-residual-analysis' + suffix + '.png' print "Saving {0}".format(fname) plt.savefig(fname) # phi residuals plot plt.figure(3) plt.subplot(211) plt.plot(block_centres, 1000. * raw['av_phi_resid_per_block']) plt.xlabel('phi (degrees)') plt.ylabel('phi residuals per block (mrad)') # phi periodogram plt.subplot(212) for dat in [raw, smoothed]: # overlay raw and smoothed periodogram plots pz = dat['phi_periodogram'] sample_freq = 1./dat['block_size'] freq = pz.freq * sample_freq line, = plt.semilogy(freq, pz.spec) for vline in vlines: plt.axvline(x=vline, color='r') phi_interval = smoothed['phi_interval'] if phi_interval: phi_freq = 1./phi_interval plt.axvline(x=phi_freq, color='c') plt.text(0.2, 0.9, 'interval width: {0:.3f}'.format(phi_interval), transform=line.axes.transAxes, color='c') plt.xlabel('frequency') plt.ylabel('spectrum') # write them out fname = 'phi-residual-analysis' + suffix + '.png' print "Saving {0}".format(fname) plt.savefig(fname) return