コード例 #1
0
ファイル: test_save_load.py プロジェクト: CDAT/cdatgui
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)
コード例 #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 save_script(self):
        filePath = QtGui.QFileDialog.getSaveFileName(self, u"Save Script", "/",
                                                     u"CDAT Scripts (*.py)")

        rows, columns = self.ss.getRowsAndColumns()
        cells = []
        plotters = []
        for r in range(rows):
            for c in range(columns):
                cell = self.ss.getCell(r, c)
                cells.append(cell)
                plotters.append(cell.getPlotters()[:-1])

        var_manager = manager()
        all_files = var_manager.files.values()
        all_variables = {}
        for f in all_files:
            for var in f.vars:
                all_variables[var.data_key()] = var

        used_variables = []
        # Now that we have all variables sorted out, let's grab relevant ones
        for pgroup in plotters:
            for plotter in pgroup:
                if plotter.can_plot() is False:
                    continue
                for v in plotter.variables:
                    if v is None:
                        continue
                    v_key = v.id

                    if v_key in all_variables:
                        used_variables.append(all_variables[v_key])
                        del all_variables[v_key]

        export_script(filePath[0],
                      used_variables,
                      plotters,
                      rows=rows,
                      columns=columns)
コード例 #4
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
コード例 #5
0
ファイル: test_save_load.py プロジェクト: CDAT/cdatgui
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
コード例 #6
0
ファイル: main_menu.py プロジェクト: sampsonbryce/cdatgui
    def save_script(self):
        filePath = QtGui.QFileDialog.getSaveFileName(self, u"Save Script", "/",
                                                     u"CDAT Scripts (*.py)")

        rows, columns = self.ss.getRowsAndColumns()
        cells = []
        plotters = []
        for r in range(rows):
            for c in range(columns):
                cell = self.ss.getCell(r, c)
                cells.append(cell)
                plotters.append(cell.getPlotters()[:-1])

        var_manager = manager()
        all_files = var_manager.files.values()
        all_variables = {}
        for f in all_files:
            for var in f.vars:
                all_variables[var.data_key()] = var

        used_variables = []
        # Now that we have all variables sorted out, let's grab relevant ones
        for pgroup in plotters:
            for plotter in pgroup:
                if plotter.can_plot() is False:
                    continue
                for v in plotter.variables:
                    if v is None:
                        continue
                    v_key = v.id

                    if v_key in all_variables:
                        used_variables.append(all_variables[v_key])
                        del all_variables[v_key]

        export_script(filePath[0], used_variables, plotters,
                      rows=rows, columns=columns)