Example #1
0
 def setPlotMethod(self, plot_type, plot_method):
     method = vcs.getgraphicsmethod(plot_type, plot_method)
     if method:
         self._plot.graphics_method = method
         return True
     else:
         return False
Example #2
0
 def setgraphicsmethod(self, typeName, name, nameValueMap):
     gm = vcs.getgraphicsmethod(typeName, name)
     for k in nameValueMap:
         if k == "name":
             continue
         if nameValueMap[k] == 100000000000000000000:
             nameValueMap[k] = 1e20
         if nameValueMap[k] == -100000000000000000000:
             nameValueMap[k] = -1e20
         if isinstance(nameValueMap[k], list):
             conv = []
             for v in nameValueMap[k]:
                 if v == 100000000000000000000:
                     conv.append(1e20)
                 elif v == -100000000000000000000:
                     conv.append(-1e20)
                 else:
                     conv.append(v)
             nameValueMap[k] = conv
         if hasattr(gm, k):
             try:
                 setattr(gm, k, nameValueMap[k])
             except:
                 print "Could not set attribute %s on graphics method [%s,%s]" %\
                   (k, typeName, name)
Example #3
0
 def setPlotMethod(self, plot_type, plot_method):
     method = vcs.getgraphicsmethod(plot_type, plot_method)
     if method:
         self._plot.graphics_method = method
         return True
     else:
         return False
Example #4
0
    def activate(self, obj, display):
        if self.target is not None and self.shift() == False:
            self.deactivate(self.target)

        self.toolbar.hide()

        if display.g_type == "fillarea":
            editor = editors.fillarea.FillEditor(self.interactor, obj, self.clicked_info, self)
        elif display.g_type == "line":
            editor = editors.line.LineEditor(self.interactor, obj, self.clicked_info, self)
        elif display.g_type == "marker":
            editor = editors.marker.MarkerEditor(self.interactor, obj, self.clicked_info, display, self)
        elif display.g_type == "text":
            editor = editors.text.TextEditor(self.interactor, obj, self.clicked_info, display, self)
        else:
            if is_box(obj):
                if obj.member == "legend":
                    editor = editors.legend.LegendEditor(self.interactor, t(display.template), self)
                elif obj.member == "data":
                    editor = editors.data.DataEditor(self.interactor, vcs.getgraphicsmethod(display.g_type, display.g_name), t(display.template), self)
                else:
                    editor = editors.box.BoxEditor(self.interactor, obj, self)
            else:
                if is_label(obj):
                    editor = editors.label.LabelEditor(self.interactor, obj, display, self)
                elif is_point(obj):
                    editor = editors.point.PointEditor(self.interactor, obj, self)
                else:
                    editor = None

        if self.target:
            self.target.add_target(editor)
        else:
            self.target = editor
Example #5
0
 def getgraphicsmethod(self, typeName, name):
     """Returns the graphics method object"""
     typeName = str(typeName)
     name = str(name)
     gm = vcs.getgraphicsmethod(typeName, name)
     if (gm is None):
         raise ValueError('Cannot find graphics method [%s, %s]' % (typeName, name))
     propertyNames = [i for i in gm.__slots__ if not i[0] == '_' and hasattr(gm, i)]
     properties = {k:getattr(gm, k) for k in propertyNames}
     return properties
Example #6
0
 def getgraphicsmethod(self, typeName, name):
     """Returns the graphics method object"""
     typeName = str(typeName)
     name = str(name)
     gm = vcs.getgraphicsmethod(typeName, name)
     if (gm is None):
         raise ValueError('Cannot find graphics method [%s, %s]' %
                          (typeName, name))
     propertyNames = [i for i in gm.__slots__ if not i[0] == '_']
     properties = {k: getattr(gm, k) for k in propertyNames}
     return properties
Example #7
0
    def editGM(self):
        gm_type = self.gm_type_combo.currentText()
        gm_name = self.gm_instance_combo.currentText()

        gm = vcs.getgraphicsmethod(gm_type, gm_name)
        if self.gm_editor:
            self.gm_editor.reject()
            self.gm_editor.deleteLater()
        self.gm_editor = BoxfillDialog(gm, self.var_combos[0].currentObj(), self.template_combo.currentObj())
        self.gm_editor.createdGM.connect(self.makeGraphicsMethod)
        self.gm_editor.editedGM.connect(self.editGraphicsMethod)
        self.gm_editor.show()
        self.gm_editor.raise_()
Example #8
0
    def activate(self, obj, display):
        if self.target is not None and self.shift() == False:
            self.deactivate(self.target)

        self.toolbar.hide()

        if display.g_type == "fillarea":
            editor = editors.fillarea.FillEditor(self.interactor, obj,
                                                 self.clicked_info, self)
        elif display.g_type == "line":
            editor = editors.line.LineEditor(self.interactor, obj,
                                             self.clicked_info, self)
        elif display.g_type == "marker":
            editor = editors.marker.MarkerEditor(self.interactor, obj,
                                                 self.clicked_info, display,
                                                 self)
        elif display.g_type == "text":
            editor = editors.text.TextEditor(self.interactor, obj,
                                             self.clicked_info, display, self)
        else:
            if is_box(obj):
                if obj.member == "legend":
                    editor = editors.legend.LegendEditor(
                        self.interactor, t(display.template), self)
                elif obj.member == "data":
                    editor = editors.data.DataEditor(
                        self.interactor,
                        vcs.getgraphicsmethod(display.g_type, display.g_name),
                        t(display.template), self)
                else:
                    editor = editors.box.BoxEditor(self.interactor, obj, self)
            else:
                if is_label(obj):
                    editor = editors.label.LabelEditor(self.interactor, obj,
                                                       display, self)
                elif is_point(obj):
                    editor = editors.point.PointEditor(self.interactor, obj,
                                                       self)
                else:
                    editor = None

        if self.target:
            self.target.add_target(editor)
        else:
            self.target = editor
Example #9
0
    def testBoxfillPickFrame(self):
        f = cdms2.open(os.path.join(cdat_info.get_sampledata_path(), "ta_ncep_87-6-88-4.nc"))
        ta = f("ta")
        u = self.clt("u")
        v = self.clt("v")

        f = cdms2.open(os.path.join(cdat_info.get_sampledata_path(), "sampleCurveGrid4.nc"))
        mesh = f("sample")
        grd = mesh.getGrid()
        sh = list(mesh.shape)
        print("NESFG SHAPE:",sh)
        sh.insert(0,12)
        axes = mesh.getAxisList()
        mesh = cdms2.MV2.resize(mesh, sh)
        mesh.setGrid(grd)
        ax = mesh.getAxis(0)
        ax.units = "months since 2019"
        ax.id = "time"
        ax.designateTime()
        for i, ax in enumerate(axes):
            mesh.setAxis(1+i, ax)
        mesh[3] = mesh[3]*3.
        gm_types = ["vector", "streamline", "meshfill", "1d", "boxfill", "isofill"]
        for gm_type in gm_types:
            # skip first time and second level on second time
            gm = vcs.getgraphicsmethod(gm_type)
            if gm_type in ["vector", "streamline"]:
                data1 = u
                data2 = v
                frame = 1
            elif gm_type == "meshfill":
                data1 = mesh
                data2 = None
                frame = 3
            else:
                data1 = ta
                data2 = None
                frame = 43
                if gm_type == "1d":
                    frame = 193
                elif gm_type == "isofill":
                    frame = -1
            self.x.clear()
            self.x.plot(data1, data2, gm, frame=frame, bg=self.bg)
            self.checkImage("test_vcs_pick_frame_{}.png".format(gm_type))
Example #10
0
 def generate_sliders(self, debug):
     dimensions = set()
     funcs = []
     widgets = []
     for disp_name in self._parent.display_names:
         disp = vcs.elements["display"][disp_name]
         gm_info = vcs.graphicsmethodinfo(
             vcs.getgraphicsmethod(disp.g_type, disp.g_name))
         data = disp.array[0]
         if data is None:
             continue
         for dim in data.getAxisList(
         )[:-gm_info["dimensions_used_on_plot"]]:
             units = getattr(dim, "units", None)
             if (dim.id, units, dim[0], dim[-1]) not in dimensions:
                 if dim.isTime():
                     values = dim.asComponentTime()
                 else:
                     values = [
                         "{}{}".format(value, units) for value in dim[:]
                     ]
                 slider = ipywidgets.IntSlider(value=0,
                                               min=0,
                                               max=len(dim) - 1,
                                               step=1,
                                               description='{}'.format(
                                                   dim.id),
                                               disabled=False,
                                               continuous_update=False,
                                               orientation='horizontal',
                                               readout=True,
                                               readout_format='d')
                 label = ipywidgets.Label(str(values[0]))
                 label.values = values
                 box = ipywidgets.HBox([slider, label])
                 widgets.append(box)
                 funcs.append(
                     partial(self.handle_slider_change, name=dim.id))
             dimensions.add((dim.id, units, dim[0], dim[-1]))
     for i, wdgt in enumerate(widgets):
         slider = wdgt.children[0]
         slider.observe(partial(funcs[i], widgets=widgets), names="value")
     if debug:
         IPython.display.display(self._parent._display_target_out)
     return widgets
Example #11
0
def test_save_loaded_script(tmpdir):
    _ = vcs.init()
    dirpath = os.path.dirname(__file__)
    load_file = os.path.join(dirpath, "data", "clt_u_v_iso.py")
    save_file = tmpdir.join("clt_u_v_iso.py")

    loaded = import_script(load_file)

    canvases = [vcs.init() for _ in range(loaded.num_canvases)]
    canvas_displays = loaded.plot(canvases)
    for canvas in canvases:
        canvas.close()

    plot_managers = []
    for display_group in canvas_displays:
        pm_group = []
        for display in display_group:
            pm = PlotManager(mocks.PlotInfo)
            # Determine which of the graphics methods created in loaded
            gm = vcs.getgraphicsmethod(display.g_type, display.g_name)
            pm.graphics_method = closest(gm, loaded.graphics_methods)
            pm.template = vcs.gettemplate(display._template_origin)
            pm.variables = display.array
            pm_group.append(pm)
        plot_managers.append(pm_group)
    mocks.PlotInfo.canvas.close()

    export_script(str(save_file), loaded.variables.values(), plot_managers)

    saved = import_script(str(save_file))

    assert saved.rows == loaded.rows
    assert saved.columns == loaded.columns
    assert saved.num_canvases == loaded.num_canvases
    assert len(saved.files) == len(loaded.files)
    assert saved.files[0].id == loaded.files[0].id
    assert len(saved.variables) == len(loaded.variables)

    for save_var, load_var in zip(saved.variables.values(),
                                  loaded.variables.values()):
        assert save_var.id == load_var.id

    assert len(saved.graphics_methods) == len(loaded.graphics_methods)
    assert len(saved.templates) == len(loaded.templates)
Example #12
0
def test_save_loaded_script(tmpdir):
    _ = vcs.init()
    dirpath = os.path.dirname(__file__)
    load_file = os.path.join(dirpath, "data", "clt_u_v_iso.py")
    save_file = tmpdir.join("clt_u_v_iso.py")

    loaded = import_script(load_file)

    canvases = [vcs.init() for _ in range(loaded.num_canvases)]
    canvas_displays = loaded.plot(canvases)
    for canvas in canvases:
        canvas.close()

    plot_managers = []
    for display_group in canvas_displays:
        pm_group = []
        for display in display_group:
            pm = PlotManager(mocks.PlotInfo)
            # Determine which of the graphics methods created in loaded
            gm = vcs.getgraphicsmethod(display.g_type, display.g_name)
            pm.graphics_method = closest(gm, loaded.graphics_methods)
            pm.template = vcs.gettemplate(display._template_origin)
            pm.variables = display.array
            pm_group.append(pm)
        plot_managers.append(pm_group)
    mocks.PlotInfo.canvas.close()

    export_script(str(save_file), loaded.variables.values(), plot_managers)

    saved = import_script(str(save_file))

    assert saved.rows == loaded.rows
    assert saved.columns == loaded.columns
    assert saved.num_canvases == loaded.num_canvases
    assert len(saved.files) == len(loaded.files)
    assert saved.files[0].id == loaded.files[0].id
    assert len(saved.variables) == len(loaded.variables)

    for save_var, load_var in zip(saved.variables.values(), loaded.variables.values()):
        assert save_var.id == load_var.id

    assert len(saved.graphics_methods) == len(loaded.graphics_methods)
    assert len(saved.templates) == len(loaded.templates)
Example #13
0
 def setGraphicsMethod(self, gm):
     if (isinstance(gm, list)):
         self._plot.graphics_method = vcs.getgraphicsmethod(gm[0], gm[1])
         return
     for t in vcs.listelements():
         if len(vcs.listelements(t)):
             o = vcs.elements[t].values()[0]
             if hasattr(o, "g_name"):
                 if o.g_name == gm["g_name"]:
                     break
     else:
         return False
     my_gm = vcs.creategraphicsmethod(t)
     for k in gm:
         if k == "name":
             continue
         if gm[k] == 100000000000000000000:
             gm[k] = 1e20
         if gm[k] == -100000000000000000000:
             gm[k] = -1e20
         if isinstance(gm[k], list):
             conv = []
             for v in gm[k]:
                 if v == 100000000000000000000:
                     conv.append(1e20)
                 elif v == -100000000000000000000:
                     conv.append(-1e20)
                 else:
                     conv.append(v)
             gm[k] = conv
         if hasattr(my_gm, k):
             try:
                 setattr(my_gm, k, gm[k])
             except:
                 print "Could not set attribute %s on graphics method of type %s" % (
                     k, t)
     if "ext_1" in gm:
         my_gm.ext_1 = gm["ext_1"]
     if "ext_2" in gm:
         my_gm.ext_2 = gm["ext_2"]
     self._plot.graphics_method = my_gm
Example #14
0
    def setGraphicsMethod(self, gm):
        if (isinstance(gm, list)):
            self._plot.graphics_method = vcs.getgraphicsmethod(gm[0], gm[1])
            return
        for t in vcs.listelements():
            if len(vcs.listelements(t)):
                o = list(vcs.elements[t].values())[0]
                if hasattr(o, "g_name"):
                    if o.g_name == gm["g_name"]:
                        break
        else:
            return False

        my_gm = vcs.creategraphicsmethod(t)
        updateGraphicsMethodProps(gm, my_gm)

        if "ext_1" in gm:
            my_gm.ext_1 = gm["ext_1"]
        if "ext_2" in gm:
            my_gm.ext_2 = gm["ext_2"]
        self._plot.graphics_method = my_gm
Example #15
0
    def plot(self):
        if self.variables is None:
            raise ValueError("No variables specified")

        if self.dp is not None:
            # Set the slabs appropriately
            self.dp.array[0] = self.variables[0]
            self.dp.array[1] = self.variables[1]

            # Update the template
            self.dp._template_origin = self.template.name

            # Update the graphics method
            self.dp.g_name = self.graphics_method.name
            self.dp.g_type = vcs.graphicsmethodtype(self.graphics_method)

            # Update the canvas
            self.canvas.update()

        else:
            args = []
            for var in self.variables:
                if var is not None:
                    args.append(var)
            if self.template is not None:
                args.append(self.template.name)
            else:
                args.append("default")
            if self.graphics_method is not None:
                args.append(vcs.graphicsmethodtype(self.graphics_method))
                args.append(self.graphics_method.name)
            self.dp = self.canvas.plot(*args)
            if self.template is None:
                self._template = vcs.gettemplate(self.dp._template_origin)
            if self.graphics_method is None:
                self._gm = vcs.getgraphicsmethod(self.dp.g_type,
                                                 self.dp.g_name)
Example #16
0
    def plot(self):
        if self.variables is None:
            raise ValueError("No variables specified")

        if self.dp is not None:
            # Set the slabs appropriately
            self.dp.array[0] = self.variables[0]
            self.dp.array[1] = self.variables[1]

            # Update the template
            self.dp._template_origin = self.template.name

            # Update the graphics method
            self.dp.g_name = self.graphics_method.name
            self.dp.g_type = vcs.graphicsmethodtype(self.graphics_method)

            # Update the canvas
            self.canvas.update()

        else:
            args = []
            for var in self.variables:
                if var is not None:
                    args.append(var)
            if self.template is not None:
                args.append(self.template.name)
            else:
                args.append("default")
            if self.graphics_method is not None:
                args.append(vcs.graphicsmethodtype(self.graphics_method))
                args.append(self.graphics_method.name)
            self.dp = self.canvas.plot(*args)
            if self.template is None:
                self._template = vcs.gettemplate(self.dp._template_origin)
            if self.graphics_method is None:
                self._gm = vcs.getgraphicsmethod(self.dp.g_type, self.dp.g_name)
Example #17
0
def diff_gm(gm):
    base = vcs.getgraphicsmethod(vcs.graphicsmethodtype(gm), "default")
    return diff(gm, base)
Example #18
0
 def load(self, display):
     self.dp = display
     self._gm = vcs.getgraphicsmethod(display.g_type, display.g_name)
     self._vars = display.array
     self._template = vcs.gettemplate(display._template_origin)
Example #19
0
    def updateGM(self, index):
        gm_type = self.gm_type_combo.currentText()
        gm_name = self.gm_instance_combo.currentText()

        gm = vcs.getgraphicsmethod(gm_type, gm_name)
        self.current_plot.graphics_method = gm
Example #20
0
def diff_gm(gm):
    base = vcs.getgraphicsmethod(vcs.graphicsmethodtype(gm), "default")
    return diff(gm, base)
Example #21
0
 def setgraphicsmethod(self, typeName, name, nameValueMap):
     """Retrieves the graphics method of type 'typeName' with the name 'name' and applies the values in nameValueMap to it"""
     gm = vcs.getgraphicsmethod(typeName, name)
     updateGraphicsMethodProps(nameValueMap, gm)
Example #22
0
 def load(self, display):
     self.dp = display
     self._gm = vcs.getgraphicsmethod(display.g_type, display.g_name)
     self._vars = display.array
     self._template = vcs.gettemplate(display._template_origin)