示例#1
0
    def open_script(self):
        filePath = QtGui.QFileDialog.getOpenFileName(self,
                                                     u"Open Script",
                                                     "/",
                                                     u"CDAT Scripts (*.py)"
                                                     )
        if filePath[0] == u"":
            return
        if os.path.exists(filePath[0]) is False:
            return

        script = import_script(filePath[0])

        self.var.load(script.variables.values())

        rows, cols = script.rows, script.columns
        num_canvases = script.num_canvases

        cells = self.ss.load(rows, cols, num_canvases)

        canvases = [cell.canvas for cell in cells]
        displays = script.plot(canvases)

        # Now we need to sync up the plotters with the displays
        for cell, display_plots in zip(cells, displays):
            cell.load(display_plots)
示例#2
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)
示例#3
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)
示例#4
0
def test_load_script(canvas):
    dirpath = os.path.dirname(__file__)
    load_file = os.path.join(dirpath, "data", "clt_u_v_iso.py")
    script = import_script(load_file)

    assert script.path == load_file
    assert script.rows == 1
    assert script.columns == 1
    assert script.num_canvases == 1
    assert len(script.files) == 1
    assert type(script.files[0]) == FileMetadataWrapper
    assert len(script.variables) == 3
    for var_id, variable in script.variables.iteritems():
        assert var_id == variable.id
        assert type(variable) == VariableMetadataWrapper
    assert len(script.graphics_methods) == 1
    assert len(script.templates) == 3
示例#5
0
def test_load_script(canvas):
    dirpath = os.path.dirname(__file__)
    load_file = os.path.join(dirpath, "data", "clt_u_v_iso.py")
    script = import_script(load_file)

    assert script.path == load_file
    assert script.rows == 1
    assert script.columns == 1
    assert script.num_canvases == 1
    assert len(script.files) == 1
    assert type(script.files[0]) == FileMetadataWrapper
    assert len(script.variables) == 3
    for var_id, variable in script.variables.iteritems():
        assert var_id == variable.id
        assert type(variable) == VariableMetadataWrapper
    assert len(script.graphics_methods) == 1
    assert len(script.templates) == 3
示例#6
0
def test_save_and_load_script(tmpdir):
    save_file = tmpdir.join("simple_vis.py")

    # File shouldn't exist
    assert save_file.exists() is False

    path = str(save_file.realpath())
    pm = PlotManager(mocks.PlotInfo)
    pm.graphics_method = vcs.getboxfill("default")
    pm.template = vcs.gettemplate('default')

    f = cdms2.open(vcs.sample_data + "/clt.nc")
    fmw = FileMetadataWrapper(f)
    clt = fmw["clt"]

    pm.variables = [clt.var, None]
    mocks.PlotInfo.canvas.close()

    export_script(path, [clt], [[pm]])

    # Make sure the file now exists
    assert save_file.exists()
    # Import it
    obj = import_script(path)

    # Now we make sure that everything was preserved correctly
    assert obj.path == path
    assert obj.rows == 1
    assert obj.columns == 1
    assert obj.num_canvases == 1
    assert len(obj.files) == 1
    assert type(obj.files[0]) == FileMetadataWrapper
    assert len(obj.variables) == 1
    for var_id, variable in obj.variables.iteritems():
        assert var_id == variable.id
        assert type(variable) == VariableMetadataWrapper
    assert len(obj.graphics_methods) == 1
    assert len(obj.templates) == 1
示例#7
0
def test_save_and_load_script(tmpdir):
    save_file = tmpdir.join("simple_vis.py")

    # File shouldn't exist
    assert save_file.exists() is False

    path = str(save_file.realpath())
    pm = PlotManager(mocks.PlotInfo)
    pm.graphics_method = vcs.getboxfill("default")
    pm.template = vcs.gettemplate('default')

    f = cdms2.open(vcs.sample_data + "/clt.nc")
    fmw = FileMetadataWrapper(f)
    clt = fmw["clt"]

    pm.variables = [clt.var, None]
    mocks.PlotInfo.canvas.close()

    export_script(path, [clt], [[pm]])

    # Make sure the file now exists
    assert save_file.exists()
    # Import it
    obj = import_script(path)

    # Now we make sure that everything was preserved correctly
    assert obj.path == path
    assert obj.rows == 1
    assert obj.columns == 1
    assert obj.num_canvases == 1
    assert len(obj.files) == 1
    assert type(obj.files[0]) == FileMetadataWrapper
    assert len(obj.variables) == 1
    for var_id, variable in obj.variables.iteritems():
        assert var_id == variable.id
        assert type(variable) == VariableMetadataWrapper
    assert len(obj.graphics_methods) == 1
    assert len(obj.templates) == 1
示例#8
0
    def open_script(self):
        filePath = QtGui.QFileDialog.getOpenFileName(self, u"Open Script", "/",
                                                     u"CDAT Scripts (*.py)")
        if filePath[0] == u"":
            return
        if os.path.exists(filePath[0]) is False:
            return

        script = import_script(filePath[0])

        self.var.load(script.variables.values())

        rows, cols = script.rows, script.columns
        num_canvases = script.num_canvases

        cells = self.ss.load(rows, cols, num_canvases)

        canvases = [cell.canvas for cell in cells]
        displays = script.plot(canvases)

        # Now we need to sync up the plotters with the displays
        for cell, display_plots in zip(cells, displays):
            cell.load(display_plots)