def __init__(self, field, *, cmap=None, norm=None, limit_func=None, auto_redraw=True, interpolation=None, window_title=None, aspect='equal', tofile=None): from xray_vision.backend.mpl.cross_section_2d import CrossSection import matplotlib.pyplot as plt self.tofile = tofile super().__init__() fig = plt.figure() self.field = field self._plot_norm = norm # the None field is supposed to be norm self.cs = CrossSection(fig, cmap, None, limit_func, auto_redraw, interpolation) # not supported feature but do anyway... # need to set aspect ratio!!!! # (get rid of xray vision in the future...) self.cs._im_ax.set_aspect(aspect) if window_title: self.cs._fig.canvas.set_window_title(window_title) self.cs._fig.show()
def _show_image(light, title): from xray_vision.backend.mpl.cross_section_2d import CrossSection options = dict(cmap='gray', interpolation='nearest') fig = plt.figure() cs = CrossSection(fig) cs.update_image(light) # fig, axes = plt.subplots(1, 1, figsize=(4, 4)) # axes.imshow(light, **options) cs._ax_h.set_title(title)
def __init__(self, field, *, fs=None): from xray_vision.backend.mpl.cross_section_2d import CrossSection import matplotlib.pyplot as plt super().__init__() self.field = field fig = plt.figure() self.cs = CrossSection(fig) self.cs._fig.show() if fs is None: import filestore.api as fs self.fs = fs
def __init__(self, field, *, db=None, cmap=None, norm=None, limit_func=None, auto_redraw=True, interpolation=None, window_title=None): from xray_vision.backend.mpl.cross_section_2d import CrossSection import matplotlib.pyplot as plt super().__init__((field, ), db=db) fig = plt.figure() self.field = field self.cs = CrossSection(fig, cmap, norm, limit_func, auto_redraw, interpolation) if window_title: self.cs._fig.canvas.set_window_title(window_title) self.cs._fig.show()
def descriptor(self, doc): self.fields = [ k for k, v in doc["data_keys"].items() if len(v["shape"]) == 2 or (len(v["shape"]) == 3 and len( [dim for dim in v["shape"] if dim > 0]) == 2) ] data_keys = doc["data_keys"] if self.aspect is None: aspects = [] for field in self.fields: aspect_ratio = data_keys[field]["shape"][0] / data_keys[field][ "shape"][1] if any(s == -1 for s in data_keys[field]["shape"]): aspects.append('auto') elif aspect_ratio > 1.25 or aspect_ratio < .75: aspects.append('auto') else: aspects.append('equal') else: aspects = [self.aspect] * len(self.fields) from xray_vision.backend.mpl.cross_section_2d import CrossSection import matplotlib.pyplot as plt # only make new figure for new data otherwise use old data for field, asp in zip(self.fields, aspects): if field in self.cs_dict and plt.fignum_exists( self.cs_dict[field]._fig.number): continue fig = plt.figure(field) cs = CrossSection( fig, self.cmap, self.norm, self.limit_func, self.auto_redraw, self.interpolation, aspect=asp, ) cs._fig.canvas.set_window_title(field) cs._fig.show() self.cs_dict[field] = cs
def __init__(self, field): super().__init__() self.field = field fig = plt.figure() self.cs = CrossSection(fig) self.cs._fig.show()
def cli(): import argparse parser = argparse.ArgumentParser(description='Plot image based on input file') parser.add_argument('-d', '--dat_file', dest='dat_file', default='', help ='input .dat file') parser.add_argument('-g', '--graph', dest='graph', default='', help='create graph', action='store_true') parser.add_argument('-vp', '--vert_pos', dest='vert_pos', default='', help='input vertical slice position', type=str) parser.add_argument('-hp', '--horiz_pos', dest='horiz_pos', default='', help='input horizontal slice position', type=str) parser.add_argument('-vl', '--vert_label', dest='vert_label', default='', help='input vertical label string', type=str) parser.add_argument('-hl', '--horiz_label', dest='horiz_label', default='', help='input horizontal label string', type=str) parser.add_argument('-e', '--extent_labels', dest='extent_labels', default=None, help='input extent labels for image ranges', nargs='+', type=int) parser.add_argument('-t', '--title', dest='title',default=None, help='input title', type=str) args = parser.parse_args() initial_data = {'photon': {}, 'horizontal': {}, 'vertical': {},} matrix = [[]] try: get_parameters(initial_data, file_name=args.dat_file) except: print('no data file found - specify with (-d <filename>)') quit() horizontal = initial_data['horizontal']['points'] vertical = initial_data['vertical']['points'] if args.graph and args.dat_file: import matplotlib.pyplot as plt from xray_vision.backend.mpl.cross_section_2d import CrossSection img = np.loadtxt(args.dat_file) img = img.reshape((vertical, horizontal)) fig = plt.figure() kwargs = {'fig': fig} if args.vert_pos: if args.vert_pos == 'right': args.vert_pos = 'right' kwargs['vert_loc'] = args.vert_pos if args.horiz_pos: if args.horiz_pos == 'bottom': args.horiz_pos = 'bottom' kwargs['horiz_loc'] = args.horiz_pos if args.vert_label: kwargs['vert_label'] = args.vert_label if args.horiz_label: kwargs['horiz_label'] = args.horiz_label if args.extent_labels: kwargs['extent_labels'] = args.extent_labels if args.title: kwargs['title'] = args.title cs = CrossSection(**kwargs) cs.update_image(img) plt.show() else: if args.dat_file: file = args.dat_file matrix = populate_matrix_smart(matrix, horizontal, vertical, data_file=file) print(initial_data)
if args.horiz_pos: if args.horiz_pos == 'bottom': args.horiz_pos = 'bottom' kwargs['horiz_loc'] = args.horiz_pos if args.vert_label: kwargs['vert_label'] = args.vert_label if args.horiz_label: kwargs['horiz_label'] = args.horiz_label if args.extent_labels: kwargs['extent_labels'] = args.extent_labels cs = CrossSection(**kwargs) cs.update_image(img) plt.show() else: matrix = populate_matrix_smart(matrix, horizontal, vertical) fig = plt.figure(figsize=(8, 10)) title = f'After Propagation (E={initial_data["photon"]["initial_energy"]} {initial_data["photon"]["units"]})' axis_data = [ initial_data['horizontal']['axis_label'] + " [µm]", initial_data['vertical']['axis_label'] + " [µm]", "Intensity " + initial_data['intensity'] ] cs = CrossSection(fig, horiz_loc='top', vert_loc='right',