def boxfill_levels(name): try: box = vcs.getboxfill(str(name)) except: abort(404) minimum, maximum = float(request.args.get("min", 0)), float( request.args.get("max", 0)) levs = box.getlevels(minimum, maximum).tolist() return jsonify(levs)
def boxfill(name): try: box = vcs.getboxfill(str(name)) except: abort(404) box_dict, _ = vcs.utils.dumpToDict(box) box = {} for k, v in box_dict.iteritems(): if v == 1e20: v = None if isinstance(v, (list, tuple)): new_v = [] for val in v: if val == 1e20: new_v.append(None) else: new_v.append(val) v = new_v box[k] = v return jsonify(box)
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
def test_vcs_read_old_scr(self): testfile = os.path.join("uvcdat-testdata", "data", "vcs", "old.scr") Ns = {} for k in vcs.elements.keys(): Ns[k] = len(vcs.elements[k].keys()) vcs.scriptrun(testfile) Ns2 = {} for k in vcs.elements.keys(): Ns2[k] = len(vcs.elements[k].keys()) diffs = { 'projection': 0, 'colormap': 53, 'isofill': 187, 'marker': 0, '3d_dual_scalar': 0, 'texttable': 4, '3d_scalar': 0, 'fillarea': 234, 'font': 0, '3d_vector': 0, '1d': 9, 'template': 43, 'textcombined': 0, 'textorientation': 3, 'xvsy': 0, 'xyvsy': 0, 'isoline': 113, 'boxfill': 239, 'fontNumber': 0, 'line': 21, 'meshfill': 0, 'yxvsx': 9, 'taylordiagram': 0, 'list': 26, 'display': 0, 'vector': 55, 'scatter': 0, "streamline": 0 } for k in vcs.elements.keys(): print "---Checking number of new elements for", k self.assertEqual(diffs[k], Ns2[k] - Ns[k]) gm = vcs.getisofill("pr_time_lat_1") self.assertEqual(gm.ymtics1, "lat5") self.assertTrue(gm.ext_2) self.assertEqual(gm.fillareastyle, "solid") self.assertEqual( gm.fillareacolors, [240, 240, 240, 28, 27, 26, 25, 23, 22, 21, 20, 19, 18, 16]) gm = vcs.getboxfill("lon_lat_mjop05") self.assertEqual(gm.xmtics1, "lon5") self.assertEqual(gm.yticlabels1, "lat20") self.assertEqual(gm.datawc_x1, 30) self.assertEqual(gm.datawc_x2, 210.) self.assertEqual(gm.datawc_y1, -30) self.assertEqual(gm.datawc_y2, 30.) self.assertEqual(gm.level_1, -0.05) self.assertEqual(gm.level_2, 0.05) self.assertEqual(gm.color_1, 18) self.assertEqual(gm.color_2, 219) gm = vcs.getline("red_solid") self.assertEqual(gm.type, ['solid']) self.assertEqual(gm.color, [242]) self.assertEqual(gm.width, [2.0]) gm = vcs.getyxvsx("pr_lsfit_lat") self.assertEqual(gm.xmtics1, "lat5") self.assertEqual(gm.linecolor, 242) self.assertEqual(gm.linewidth, 2.) self.assertEqual(gm.datawc_x1, 30) self.assertEqual(gm.datawc_x2, -30.) self.assertEqual(gm.datawc_y1, -5.) self.assertEqual(gm.datawc_y2, 5.) gm = vcs.getisoline("div_anom") self.assertEqual(gm.xmtics1, "lon5") self.assertEqual(gm.xticlabels1, "lon15") self.assertEqual(gm.linetypes, [ 'dash', 'dash', 'dash', 'dash', 'solid', 'dash', 'dash', 'dash', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid' ]) self.assertEqual(gm.linecolors, [ 241, 241, 241, 241, 242, 241, 241, 241, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]) self.assertEqual(gm.linewidths, [ 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]) gm = vcs.getvector("lon_lat_IO_5") self.assertEqual(gm.xmtics1, "lon5") self.assertEqual(gm.xticlabels1, "lon20") self.assertEqual(gm.linecolor, 242) self.assertEqual(gm.linewidth, 2.) self.assertEqual(gm.scale, 3) self.assertEqual(gm.reference, 5)
import os, sys, cdms2, cdutil, genutil, vcs, testing.regression as regression # This tests if extending the longitude to more than 360 decrees is handled correctly by # proj4. See https://github.com/UV-CDAT/uvcdat/issues/1728 for more information. cdmsfile = cdms2.open(os.path.join(vcs.sample_data, "clt.nc")) clt2 = cdmsfile('clt') clt3 = clt2(latitude=(-90.0, 90.0),squeeze=1,longitude=(-180, 200.0),time=('1979-01', '1988-12'),) canvas = vcs.init() gmBoxfill = vcs.getboxfill('a_robinson_boxfill') kwargs = {} kwargs[ 'cdmsfile' ] = cdmsfile.id kwargs['bg'] = 1 canvas.plot(clt3, gmBoxfill, **kwargs) regression.run(canvas, "test_vcs_robinson_wrap.png")
def testPlot(self): """ displayCellEvent(e: DisplayCellEvent) -> None Display a cell when receive this event """ # FIXME: TEST Widget #widget = QtGui.QLabel("I am a useless widget!") # Add widget to spreadsheet #reference = StandardSheetReference() #sheet = self.get_current_tab_controller().findSheet(reference) #(row, col) = sheet.getFreeCell() #sheet.tabWidget.setCurrentWidget(sheet) #sheet.setCellByWidget(row, col, widget) #from .vtk_classes import QCDATWidget #widget = QCDATWidget() #sheet.setCellByWidget(row, col, widget) # Example getting canvas for first cell in current spreadsheet canvas = self.getCanvas(0,0) # Example uses the corresponding cel widget # this shoud not be neccecary if storing this info externally # Get first cell in active sheet reference = StandardSheetReference() sheet = self.get_current_tab_controller().findSheet(reference) cell = sheet.getCell(0,0) # Set up data and plot import cdms2, vcs cdmsfile = cdms2.open('/usr/local/uvcdat/2.2.0/sample_data/clt.nc') var = clt = cdmsfile('clt') cgm = gmBoxfill = vcs.getboxfill('default') #widget.updateContents(clt, gmBoxfill) # Draw plot on canvas canvas.clear() cell.extraDimsNames=var.getAxisIds()[:-2] cell.extraDimsIndex=[0,]*len(cell.extraDimsNames) cell.extraDimsLen=var.shape[:-2] #if hasattr(self.parent(),"toolBar"): # t = self.parent().toolBar # if hasattr(t,"dimSelector"): # while (t.dimSelector.count()>0): # t.dimSelector.removeItem(0) # t.dimSelector.addItems(self.extraDimsNames) # Plot cmd = "#Now plotting\nvcs_canvas[%i].plot(" % (canvas.canvasid()-1) k1 = cell.prepExtraDims(var) args = [var(**k1)] cmd+="%s(**%s), " % (args[0].id,str(k1)) kwargs = {} file_path = None #for fname in [ var.file, var.filename ]: # if fname and ( os.path.isfile(fname) or fname.startswith('http://') ): # file_path = fname # break #if not file_path and var.url: # file_path = var.url #if file_path: kwargs['cdmsfile'] = file_path #record commands for k in kwargs: cmd+=", %s=%s" % (k, repr(kwargs[k])) cmd+=")" canvas.plot(cgm,*args,**kwargs)
def __init__(self, parent=None): super(TemplateEditor, self).__init__(parent=parent) self._template = None layout = QtGui.QVBoxLayout() self._preview = TemplatePreviewWidget() self._preview.gm = vcs.getboxfill() self._preview.var = cdms2.open(os.path.join(vcs.sample_data, "clt.nc"))["clt"] self._yslider = QtGui.QSlider() self._yslider.setMinimum(0) self._yslider.setMaximum(1000) self._xslider = QtGui.QSlider(QtCore.Qt.Horizontal) self._xslider.setMinimum(0) self._xslider.setMaximum(1000) # Disable until something requests to be moved self._yslider.setEnabled(False) self._xslider.setEnabled(False) self._xslider.sliderMoved.connect(self.move_slider) self._yslider.sliderMoved.connect(self.move_slider) preview_layout = QtGui.QVBoxLayout() preview_h = QtGui.QHBoxLayout() preview_h.addWidget(self._preview) preview_h.addWidget(self._yslider) preview_layout.addLayout(preview_h) preview_layout.addWidget(self._xslider) layout.addLayout(preview_layout) self.move_callback = None editors = QtGui.QTabWidget() self._template_labels = TemplateLabelEditor() self._template_labels.labelUpdated.connect(self.update) self._template_labels.moveLabel.connect(self.start_move) editors.addTab(self._template_labels, "Labels") plot_box = QtGui.QVBoxLayout() self._template_data = DataEditor() self._template_data.boxEdited.connect(self.update) self._template_data.moveBox.connect(self.start_move) self._template_legend = LegendEditor() self._template_legend.boxEdited.connect(self.update) self._template_legend.moveBox.connect(self.start_move) plot_box.addWidget(self._template_data) plot_box.addWidget(self._template_legend) plot_widget = QtGui.QWidget() plot_widget.setLayout(plot_box) editors.addTab(plot_widget, "Plot & Legend") axis_tabs = QtGui.QTabWidget() x1 = AxisEditor("x", 1) x1.axisUpdated.connect(self.update) x2 = AxisEditor("x", 2) x2.axisUpdated.connect(self.update) y1 = AxisEditor("y", 1) y1.axisUpdated.connect(self.update) y2 = AxisEditor("y", 2) y2.axisUpdated.connect(self.update) axis_tabs.addTab(x1, x1.name) axis_tabs.addTab(y1, y1.name) axis_tabs.addTab(x2, x2.name) axis_tabs.addTab(y2, y2.name) self._axes = {"x1": x1, "x2": x2, "y1": y1, "y2": y2} editors.addTab(axis_tabs, "Axes") layout.addWidget(editors) self.setLayout(layout)
def testPlot(self): """ displayCellEvent(e: DisplayCellEvent) -> None Display a cell when receive this event """ # FIXME: TEST Widget #widget = QtGui.QLabel("I am a useless widget!") # Add widget to spreadsheet #reference = StandardSheetReference() #sheet = self.get_current_tab_controller().findSheet(reference) #(row, col) = sheet.getFreeCell() #sheet.tabWidget.setCurrentWidget(sheet) #sheet.setCellByWidget(row, col, widget) #from .vtk_classes import QCDATWidget #widget = QCDATWidget() #sheet.setCellByWidget(row, col, widget) # Example getting canvas for first cell in current spreadsheet canvas = self.getCanvas(0, 0) # Example uses the corresponding cel widget # this shoud not be neccecary if storing this info externally # Get first cell in active sheet reference = StandardSheetReference() sheet = self.get_current_tab_controller().findSheet(reference) cell = sheet.getCell(0, 0) # Set up data and plot import cdms2, vcs cdmsfile = cdms2.open('/usr/local/uvcdat/2.2.0/sample_data/clt.nc') var = clt = cdmsfile('clt') cgm = gmBoxfill = vcs.getboxfill('default') #widget.updateContents(clt, gmBoxfill) # Draw plot on canvas canvas.clear() cell.extraDimsNames = var.getAxisIds()[:-2] cell.extraDimsIndex = [ 0, ] * len(cell.extraDimsNames) cell.extraDimsLen = var.shape[:-2] #if hasattr(self.parent(),"toolBar"): # t = self.parent().toolBar # if hasattr(t,"dimSelector"): # while (t.dimSelector.count()>0): # t.dimSelector.removeItem(0) # t.dimSelector.addItems(self.extraDimsNames) # Plot cmd = "#Now plotting\nvcs_canvas[%i].plot(" % (canvas.canvasid() - 1) k1 = cell.prepExtraDims(var) args = [var(**k1)] cmd += "%s(**%s), " % (args[0].id, str(k1)) kwargs = {} file_path = None #for fname in [ var.file, var.filename ]: # if fname and ( os.path.isfile(fname) or fname.startswith('http://') ): # file_path = fname # break #if not file_path and var.url: # file_path = var.url #if file_path: kwargs['cdmsfile'] = file_path #record commands for k in kwargs: cmd += ", %s=%s" % (k, repr(kwargs[k])) cmd += ")" canvas.plot(cgm, *args, **kwargs)
import os, sys, cdms2, cdutil, genutil, vcs, vcs.testing.regression as regression # This tests if extending the longitude to more than 360 decrees is handled correctly by # proj4. See https://github.com/UV-CDAT/uvcdat/issues/1728 for more information. cdmsfile = cdms2.open(os.path.join(vcs.sample_data, "clt.nc")) clt2 = cdmsfile('clt') clt3 = clt2( latitude=(-90.0, 90.0), squeeze=1, longitude=(-180, 200.0), time=('1979-01', '1988-12'), ) canvas = regression.init() gmBoxfill = vcs.getboxfill('a_robinson_boxfill') kwargs = {} kwargs['cdmsfile'] = cdmsfile.id kwargs['bg'] = 1 canvas.plot(clt3, gmBoxfill, **kwargs) regression.run(canvas, "test_vcs_boxfill_robinson_wrap.png")