def activate(self, display, actor, key): if self.target is not None and self.shift() is False: self.deactivate(self.target) self.toolbar.hide() if display.g_type == "marker": l = display.backend[key] # Actor is actually a group of VTK objects index = l.index(actor) editor = editors.marker.MarkerEditor(self.interactor, vcs.getmarker(display.g_name), index, display, self) elif display.g_type == "text": l = display.backend[key] index = l.index(actor) editor = editors.text.TextEditor(self.interactor, vcs.gettext(display.g_name), index, display, self) elif is_label(key): obj = get_attribute(display, key) editor = editors.label.LabelEditor(self.interactor, obj, display, self) else: editor = None if self.target: self.target.add_target(editor) else: self.target = editor
def activate(self, display, actor, key): if self.target is not None and self.shift() is False: self.deactivate(self.target) self.toolbar.hide() if display.g_type == "marker": l = display.backend[key] # Actor is actually a group of VTK objects index = l.index(actor) editor = editors.marker.MarkerEditor(self.interactor, vcs.getmarker(display.g_name), index, display, self) elif display.g_type == "text": l = display.backend[key] index = l.index(actor) editor = editors.text.TextEditor(self.interactor, vcs.gettext(display.g_name), index, display, self) elif is_label(key): obj = get_attribute(display, key) editor = editors.label.LabelEditor(self.interactor, obj, display, self) else: editor = None if self.target: self.target.add_target(editor) else: self.target = editor
def in_display_plot(self, point, dp): #Normalize the point x, y = point w, h = self.interactor.GetRenderWindow().GetSize() if x > 1 or y > 1: point = (x / float(w), y / float(h)) x, y = point if dp.g_type == "fillarea": fill = vcs.getfillarea(dp.g_name) info = editors.fillarea.inside_fillarea(fill, *point) if info is not None: self.clicked_info = info return fill elif dp.g_type == "line": l = vcs.getline(dp.g_name) # Uses screen_height to determine how much buffer space there is around the line info = editors.line.inside_line(l, *point, screen_height=h) if info is not None: self.clicked_info = info return l elif dp.g_type == "marker": m = vcs.getmarker(dp.g_name) info = editors.marker.inside_marker(m, point[0], point[1], w, h) if info is not None: self.clicked_info = info return m elif dp.g_type == "text": tc = vcs.gettextcombined(dp.g_name) info = editors.text.inside_text(tc, point[0], point[1], w, h) if info is not None: self.clicked_info = info return tc else: fudge = 5 / float(w) return in_template(point, t(dp.template), dp, (w, h), fudge=fudge)
def in_display_plot(self, point, dp): #Normalize the point x, y = point w, h = self.interactor.GetRenderWindow().GetSize() if x > 1 or y > 1: point = (x / float(w), y / float(h)) x, y = point if dp.g_type == "fillarea": fill = vcs.getfillarea(dp.g_name) info = editors.fillarea.inside_fillarea(fill, *point) if info is not None: self.clicked_info = info return fill elif dp.g_type == "line": l = vcs.getline(dp.g_name) # Uses screen_height to determine how much buffer space there is around the line info = editors.line.inside_line(l, *point, screen_height=h) if info is not None: self.clicked_info = info return l elif dp.g_type == "marker": m = vcs.getmarker(dp.g_name) info = editors.marker.inside_marker(m, point[0], point[1], w, h) if info is not None: self.clicked_info = info return m elif dp.g_type == "text": tc = vcs.gettextcombined(dp.g_name) info = editors.text.inside_text(tc, point[0], point[1], w, h) if info is not None: self.clicked_info = info return tc else: fudge = 5 / float(w) return in_template(point, t(dp.template), dp, (w, h), fudge=fudge)
def test_vcs_read_old_2(self): testfile = os.path.join("uvcdat-testdata", "data", "vcs", "old_2.scr") Ns = {} Es = {} for k in list(vcs.elements.keys()): Ns[k] = len(list(vcs.elements[k].keys())) Es[k] = vcs.listelements(k) vcs.scriptrun(testfile) Ns2 = {} for k in list(vcs.elements.keys()): Ns2[k] = len(list(vcs.elements[k].keys())) diffs = { 'projection': 0, 'colormap': 4, 'isofill': 102, 'marker': 15, '3d_dual_scalar': 0, 'texttable': 1, '3d_scalar': 0, 'fillarea': 404, 'font': 0, '3d_vector': 0, '1d': 19, 'template': 128, 'textcombined': 0, 'textorientation': 0, 'xvsy': 0, 'xyvsy': 15, 'isoline': 3, 'boxfill': 3, 'fontNumber': 0, 'line': 16, 'meshfill': 0, 'yxvsx': 17, 'taylordiagram': 1, 'list': 68, 'display': 0, 'vector': 5, 'scatter': 2, "streamline": 0 } for k in list(vcs.elements.keys()): print("Cheking number of new elements for", k) self.assertEqual(diffs[k], Ns2[k] - Ns[k]) gm = vcs.getmarker("navy") self.assertEqual(gm.type, ['dot']) self.assertEqual(gm.size, [2]) self.assertEqual(gm.color, [250]) gm = vcs.getisofill("AMIP2_psl") self.assertEqual( gm.levels, [[-1e+20, 97000.0], [97000.0, 97500.0], [97500.0, 98000.0], [98000.0, 98500.0], [98500.0, 99000.0], [99000.0, 99500.0], [99500.0, 100000.0], [100000.0, 100500.0], [100500.0, 101000.0], [101000.0, 101500.0], [101500.0, 102000.0], [102000.0, 102500.0], [102500.0, 103000.0], [103000.0, 103500.0], [103500.0, 104000.0], [104000.0, 1e+20]]) self.assertTrue(gm.ext_2) self.assertEqual(gm.ymtics1, "lat5") self.assertEqual(gm.fillareastyle, "solid") self.assertEqual( gm.fillareacolors, [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 35, 36])
def marker(name): try: gm = vcs.getmarker(str(name)) except: abort(404) return jsonify(vcs.utils.dumpToDict(gm)[0])
def spaghetti_plot(variables, template=None, min_y=None, max_y=None, left_label=None, right_label=None, tick_sides=None, line="default", marker="default", x_labels="*", y_labels="*", canvas=None): """ This file is ready to be imported by your scripts, and you can just call this function. Sample usage is below. variables: List of variables to plot template: The template to use as the base for the plot. min_y: If you want to adjust the y axis bounds, you can set a minimum value. Will be derived from data if not specified. max_y: If you want to adjust the y axis bounds, you can set a maximum value. Will be derived from data if not specified. left_label: Text to put on the left Y axis right_label: Text to put on the right Y axis tick_sides: A list of "left" or "right" values indicating which side of the chart you want the variable axes to be displayed. line: A line object or name of a line object used to describe the lines plotted. Set to None to hide. marker: A marker object or name of a marker object used to describe the markers plotted. Set to None to hide. x_labels: Dictionary for setting axis tick labels y_labels: Dictionary for setting axis tick labels """ if canvas is None: canvas = vcs.init() if isinstance(template, (str, unicode)): template = vcs.gettemplate(template) if template is None: # Use our custom default template for 1ds template = vcs.createtemplate() # Shrink the template a bit template.scale(.78, "x") template.move(.02, "x") template.yname.x = .01 template.data.y1 = .1 template.box1.y1 = .1 ticlen = template.xtic1.y2 - template.xtic1.y1 template.xtic1.y1 = template.data.y1 template.xtic1.y2 = template.xtic1.y1 + ticlen template.xtic2.priority = 0 template.xlabel1.y = template.xtic1.y2 - .01 template.legend.x1 = template.data.x2 + (1 - template.data.x2) / 3. template.legend.x2 = .95 template.legend.y1 = template.data.y1 template.legend.y2 = template.data.y2 template.yname.y = (template.data.y1 + template.data.y2) / 2. template.xname.y = template.xlabel1.y - .05 # The labels don't make any sense with multiple values; hide them. template.min.priority = 0 template.max.priority = 0 template.mean.priority = 0 template.dataname.priority = 0 templates = EzTemplate.oneD(len(variables), template=template) templates.x = canvas if tick_sides is None: tick_sides = ["left"] * len(variables) clean_ticks = [] for t in tick_sides: if t.lower() not in ('left', 'right'): raise ValueError( "tick_sides must be a list of 'left' or 'right' values; found '%s'." % t) clean_ticks.append(t.lower()) tick_sides = clean_ticks if len(tick_sides) < len(variables): tick_sides += tick_sides[-1:] * len(variables) # Store min/max per side for appropriate scaling min_vals = {"left": min_y, "right": min_y} if min_y is None: for i, var in enumerate(variables): v_min = min(var) min_y = min_vals[tick_sides[i]] if min_y is None or min_y > v_min: min_vals[tick_sides[i]] = v_min max_vals = {"left": max_y, "right": max_y} if max_y is None: for i, var in enumerate(variables): v_max = max(var) max_y = max_vals[tick_sides[i]] if max_y is None or max_y < v_max: max_vals[tick_sides[i]] = v_max if isinstance(line, (str, unicode)): line = vcs.getline(line) if isinstance(marker, (str, unicode)): marker = vcs.getmarker(marker) to_pad = [] if line is not None: widths = line.width to_pad.append(widths) styles = line.type to_pad.append(styles) colors = line.color to_pad.append(colors) if marker is not None: markers = marker.type to_pad.append(markers) marker_colors = marker.color to_pad.append(marker_colors) marker_sizes = marker.size to_pad.append(marker_sizes) for padded in to_pad: if len(padded) < len(variables): padded += padded[-1:] * (len(variables) - len(padded)) for n in range(len(variables)): gm = vcs.create1d() if line is not None: gm.line = styles[n] gm.linewidth = widths[n] gm.linecolor = colors[n] else: gm.linewidth = 0 if marker is not None: gm.marker = markers[n] gm.markersize = marker_sizes[n] gm.markercolor = marker_colors[n] else: gm.marker = None gm.datawc_y1 = min_vals[tick_sides[n]] gm.datawc_y2 = max_vals[tick_sides[n]] template = templates.get(n) gm.xticlabels1 = x_labels if tick_sides[n] == "left": if tick_sides.index("left") == n: template.ylabel1.priority = 1 if left_label is not None: template.yname.priority = 0 left_text = vcs.createtext( Tt_source=template.yname.texttable, To_source=template.yname.textorientation) left_text.x = template.yname.x left_text.y = template.yname.y left_text.string = [left_label] templates.x.plot(left_text) else: template.ylabel1.priority = 0 template.yname.priority = 0 template.ylabel2.priority = 0 gm.yticlabels1 = y_labels gm.yticlabels2 = "" else: template.ylabel1.priority = 0 if tick_sides.index("right") == n: template.ylabel2.priority = 1 if right_label is not None: right_text = vcs.createtext( Tt_source=template.yname.texttable, To_source=template.yname.textorientation) right_text.x = template.data.x2 + (template.data.x1 - template.yname.x) right_text.y = template.yname.y right_text.string = [right_label] templates.x.plot(right_text) else: template.ylabel2.priority = 0 gm.yticlabels1 = "" gm.yticlabels2 = y_labels if n != 0: template.xlabel1.priority = 0 template.xname.priority = 0 var = variables[n] templates.x.plot(var, gm, template) return templates.x
def spaghetti_plot(variables, template=None, min_y=None, max_y=None, left_label=None, right_label=None, tick_sides=None, line="default", marker="default", x_labels="*", y_labels="*", canvas=None): """ This file is ready to be imported by your scripts, and you can just call this function. Sample usage is below. variables: List of variables to plot template: The template to use as the base for the plot. min_y: If you want to adjust the y axis bounds, you can set a minimum value. Will be derived from data if not specified. max_y: If you want to adjust the y axis bounds, you can set a maximum value. Will be derived from data if not specified. left_label: Text to put on the left Y axis right_label: Text to put on the right Y axis tick_sides: A list of "left" or "right" values indicating which side of the chart you want the variable axes to be displayed. line: A line object or name of a line object used to describe the lines plotted. Set to None to hide. marker: A marker object or name of a marker object used to describe the markers plotted. Set to None to hide. x_labels: Dictionary for setting axis tick labels y_labels: Dictionary for setting axis tick labels """ if canvas is None: canvas = vcs.init() if isinstance(template, (str, unicode)): template = vcs.gettemplate(template) if template is None: # Use our custom default template for 1ds template = vcs.createtemplate() # Shrink the template a bit template.scale(.78, "x") template.move(.02, "x") template.yname.x = .01 template.data.y1 = .1 template.box1.y1 = .1 ticlen = template.xtic1.y2 - template.xtic1.y1 template.xtic1.y1 = template.data.y1 template.xtic1.y2 = template.xtic1.y1 + ticlen template.xtic2.priority = 0 template.xlabel1.y = template.xtic1.y2 - .01 template.legend.x1 = template.data.x2 + (1 - template.data.x2) / 3. template.legend.x2 = .95 template.legend.y1 = template.data.y1 template.legend.y2 = template.data.y2 template.yname.y = (template.data.y1 + template.data.y2)/2. template.xname.y = template.xlabel1.y - .05 # The labels don't make any sense with multiple values; hide them. template.min.priority = 0 template.max.priority = 0 template.mean.priority = 0 template.dataname.priority = 0 templates = EzTemplate.oneD(len(variables), template=template) templates.x = canvas if tick_sides is None: tick_sides = ["left"] * len(variables) clean_ticks = [] for t in tick_sides: if t.lower() not in ('left', 'right'): raise ValueError("tick_sides must be a list of 'left' or 'right' values; found '%s'." % t) clean_ticks.append(t.lower()) tick_sides = clean_ticks if len(tick_sides) < len(variables): tick_sides += tick_sides[-1:] * len(variables) # Store min/max per side for appropriate scaling min_vals = {"left": min_y, "right": min_y} if min_y is None: for i, var in enumerate(variables): v_min = min(var) min_y = min_vals[tick_sides[i]] if min_y is None or min_y > v_min: min_vals[tick_sides[i]] = v_min max_vals = {"left": max_y, "right": max_y} if max_y is None: for i, var in enumerate(variables): v_max = max(var) max_y = max_vals[tick_sides[i]] if max_y is None or max_y < v_max: max_vals[tick_sides[i]] = v_max if isinstance(line, (str, unicode)): line = vcs.getline(line) if isinstance(marker, (str, unicode)): marker = vcs.getmarker(marker) to_pad = [] if line is not None: widths = line.width to_pad.append(widths) styles = line.type to_pad.append(styles) colors = line.color to_pad.append(colors) if marker is not None: markers = marker.type to_pad.append(markers) marker_colors = marker.color to_pad.append(marker_colors) marker_sizes = marker.size to_pad.append(marker_sizes) for padded in to_pad: if len(padded) < len(variables): padded += padded[-1:] * (len(variables) - len(padded)) for n in range(len(variables)): gm = vcs.create1d() if line is not None: gm.line = styles[n] gm.linewidth = widths[n] gm.linecolor = colors[n] else: gm.linewidth = 0 if marker is not None: gm.marker = markers[n] gm.markersize = marker_sizes[n] gm.markercolor = marker_colors[n] else: gm.marker = None gm.datawc_y1 = min_vals[tick_sides[n]] gm.datawc_y2 = max_vals[tick_sides[n]] template = templates.get(n) gm.xticlabels1 = x_labels if tick_sides[n] == "left": if tick_sides.index("left") == n: template.ylabel1.priority = 1 if left_label is not None: template.yname.priority = 0 left_text = vcs.createtext(Tt_source=template.yname.texttable, To_source=template.yname.textorientation) left_text.x = template.yname.x left_text.y = template.yname.y left_text.string = [left_label] templates.x.plot(left_text) else: template.ylabel1.priority = 0 template.yname.priority = 0 template.ylabel2.priority = 0 gm.yticlabels1 = y_labels gm.yticlabels2 = "" else: template.ylabel1.priority = 0 if tick_sides.index("right") == n: template.ylabel2.priority = 1 if right_label is not None: right_text = vcs.createtext(Tt_source=template.yname.texttable, To_source=template.yname.textorientation) right_text.x = template.data.x2 + (template.data.x1 - template.yname.x) right_text.y = template.yname.y right_text.string = [right_label] templates.x.plot(right_text) else: template.ylabel2.priority = 0 gm.yticlabels1 = "" gm.yticlabels2 = y_labels if n != 0: template.xlabel1.priority = 0 template.xname.priority = 0 var = variables[n] templates.x.plot(var, gm, template) return templates.x