示例#1
0
 def load_vcs_plots(self):
     from packages.uvcdat_cdms.pipeline_helper import CDMSPipelineHelper
     from gui.uvcdat.uvcdatCommons import plotTypes, gmInfos
     from packages.uvcdat_cdms.init import get_canvas
     if not self._registry:
         raise UVCDATInternalError("Plot Registry must have been initialized")
     
     for p in sorted(plotTypes.keys()): 
         #kitem = self.addPlotBar(k)
         if p not in self._plot_list:
             self._plot_list[p] = {}
             self._plot_helpers[p] = CDMSPipelineHelper
         for pl in plotTypes[p]:
             ## Special section here for VCS GMs they have one more layer
             self._plot_list[p][pl] = {}
             for m in get_canvas().listelements(str(pl).lower()):
                 self._plot_list[p][pl][m] = self._registry.add_plot(m,p,
                                                                     None, 
                                                                     None,
                                                                     pl)
                 #FIXME: get the var num from somewhere
                 self._plot_list[p][pl][m].varnum = int(gmInfos[pl]["nSlabs"])
示例#2
0
    def load_vcs_plots(self):
        from packages.uvcdat_cdms.pipeline_helper import CDMSPipelineHelper
        from gui.uvcdat.uvcdatCommons import plotTypes, gmInfos
        from packages.uvcdat_cdms.init import get_canvas
        if not self._registry:
            raise UVCDATInternalError(
                "Plot Registry must have been initialized")

        for p in sorted(plotTypes.keys()):
            #kitem = self.addPlotBar(k)
            if p not in self._plot_list:
                self._plot_list[p] = {}
                self._plot_helpers[p] = CDMSPipelineHelper
            for pl in plotTypes[p]:
                ## Special section here for VCS GMs they have one more layer
                self._plot_list[p][pl] = {}
                for m in get_canvas().listelements(str(pl).lower()):
                    self._plot_list[p][pl][m] = self._registry.add_plot(
                        m, p, None, None, pl)
                    #FIXME: get the var num from somewhere
                    self._plot_list[p][pl][m].varnum = int(
                        gmInfos[pl]["nSlabs"])
示例#3
0
    def displayCell(self, res30, row, column, sheet="Sheet 1", dropInfo=True):
        """Display result into one cell defined by row/col args"""
        import pdb
        projectController = self.parent().get_current_project_controller()
        if dropInfo:
            projectController.get_sheet_widget(sheet).deleteCell(row, column)
        projectController.enable_animation = False  # I (JfP) don't know why I need this, it didn't
        # used to be necessary.
        if res30 is None:
            return
        if not hasattr(
                res30, 'presentation'
        ) or res30.presentation is None or res30.presentation is "text":
            return
        pvars = res30.vars
        labels = res30.labels
        title = res30.title
        presentation = res30.presentation
        Gtype = res30.type
        if Gtype == "Taylor":
            Gtype = "Taylordiagram"

        pm = projectController.plot_manager
        VCS_LIST = pm._plot_list["VCS"]
        gm = res30.presentation
        from packages.uvcdat_cdms.init import get_canvas, get_gm_attributes, original_gm_attributes
        from gui.uvcdat.uvcdatCommons import gmInfos

        if False:  # standard diagnostics prints:
            print "pvars:", [p.id for p in pvars]
            print "labels:", labels
            print "title:", title
            print "presentation:", presentation
            print "x min,max:", getattr(presentation, 'datawc_x1',
                                        None), getattr(presentation,
                                                       'datawc_x2', None)
            print "y min,max:", getattr(presentation, 'datawc_y1',
                                        None), getattr(presentation,
                                                       'datawc_y2', None)
            print "res", res30.type

        #define where to drag and drop
        import cdms2
        from packages.uvcdat_cdms.init import CDMSVariable
        from core.utils import InstanceObject
        from metrics.frontend.uvcdat import diagnostics_template
        tm = diagnostics_template()  # template name is 'diagnostic'
        if dropInfo:
            tmplDropInfo = ('diagnostic', sheet, row, column)
            projectController.template_was_dropped(tmplDropInfo)

        if Gtype == 'Vector':
            pvars = pvars[0]
        for varindex, V in enumerate(pvars):
            if Gtype != 'Vector':
                V.title = title  # VCS looks the title of the variable, not the plot.
                V.long_name = V.title  # VCS overrides title with long_name!

            # Until I know better storing vars in tempfile....
            f = tempfile.NamedTemporaryFile()
            filename = f.name
            f.close()
            value = 0
            cdms2.setNetcdfShuffleFlag(value)  ## where value is either 0 or 1
            cdms2.setNetcdfDeflateFlag(value)  ## where value is either 0 or 1
            cdms2.setNetcdfDeflateLevelFlag(
                value)  ## where value is a integer between 0 and 9 included
            fd = cdms2.open(filename, "w")
            fd.write(V)
            fd.close()
            cdmsFile = cdms2.open(filename)
            #define name of variable to appear in var widget
            if Gtype == 'Vector':
                name_in_var_widget = V[0].id
            else:
                name_in_var_widget = V.id
            #get uri if exists
            url = None
            if hasattr(cdmsFile, 'uri'):
                url = cdmsFile.uri
            #create vistrails module
            cdmsVar = CDMSVariable(filename=cdmsFile.id,
                                   url=url,
                                   name=name_in_var_widget,
                                   varNameInFile=name_in_var_widget)  #V.id)
            #get variable widget and project controller
            definedVariableWidget = self.parent().dockVariable.widget()
            #add variable to display widget and controller
            definedVariableWidget.addVariable(V)
            projectController.add_defined_variable(cdmsVar)

            # simulate drop variable
            varDropInfo = (name_in_var_widget, sheet, row, column)
            projectController.variable_was_dropped(varDropInfo)

            # Trying to add method to plot list....
            #from gui.application import get_vistrails_application
            #_app = get_vistrails_application()
            #d = _app.uvcdatWindow.dockPlot
            # simulate drop plot

            G = VCS_LIST[Gtype]
            if not gm.name in G.keys():
                G[gm.name] = pm._registry.add_plot(gm.name, "VCS", None, None,
                                                   Gtype)
                G[gm.name].varnum = int(gmInfos[Gtype]["nSlabs"])

            #add initial attributes to global dict
            canvas = get_canvas()
            method_name = "get" + Gtype.lower()
            attributes = get_gm_attributes(Gtype)

            attrs = {}
            for attr in attributes:
                attrs[attr] = getattr(gm, attr)
            original_gm_attributes[Gtype][gm.name] = InstanceObject(**attrs)

            if Gtype in ["Scatter", "Vector"] and varindex == 0:
                #to plot a scatter plot or vector plot, requires both axes passed to plotspec.
                #so dont plot the 1st one until the 2nd variable is processed.
                pass
            else:
                # simulate drop plot
                plot = projectController.plot_manager.new_plot(
                    'VCS', Gtype, gm.name)
                #plot = projectController.plot_manager.new_plot('VCS', Gtype, "default" )
                plotDropInfo = (plot, sheet, row, column)
                projectController.plot_was_dropped(plotDropInfo)
    def displayCell(self,res30,row,column,sheet="Sheet 1"):
        """Display result into one cell defined by row/column args"""
        global original_gm_attributes
        projectController = self.parent().get_current_project_controller()
        projectController.clear_cell(sheet,row,column) # There's no visible clearing!
        #...This is necessary to make the cell internally clear; without it the new plot
        # will be overlaid over the old plot.  But this isn't enough to give you a blank cell
        if res30 is None:
            return
        pvars = res30.vars
        labels = res30.labels
        title = res30.title
        presentation = res30.presentation
        print "pvars:",[p.id for p in pvars]
        print "labels:",labels
        print "title:",title
        print "presentation:",presentation
        print "x min,max:",presentation.datawc_x1, presentation.datawc_x2
        print "y min,max:",presentation.datawc_y1, presentation.datawc_y2
        print "res",res30.type
        #define where to drag and drop
        import cdms2
        from packages.uvcdat_cdms.init import CDMSVariable
        for V in pvars:
            # Until I know better storing vars in tempfile....
            f = tempfile.NamedTemporaryFile()
            filename = f.name
            f.close()
            fd = cdms2.open(filename,"w")
            fd.write(V)
            fd.close()
            cdmsFile = cdms2.open(filename)
            #define name of variable to appear in var widget
            name_in_var_widget = V.id
            #get uri if exists
            url = None
            if hasattr(cdmsFile, 'uri'):
                url = cdmsFile.uri
            #create vistrails module
            cdmsVar = CDMSVariable(filename=cdmsFile.id, url=url, name=name_in_var_widget,
                                    varNameInFile=V.id)

            #get variable widget and project controller
            definedVariableWidget = self.parent().dockVariable.widget()

            #add variable to display widget and controller
            definedVariableWidget.addVariable(V)
            projectController.add_defined_variable(cdmsVar)

            # simulate drop variable
            varDropInfo = (name_in_var_widget, sheet, row, column)
            projectController.variable_was_dropped(varDropInfo)

            # Trying to add method to plot list....
            #from gui.application import get_vistrails_application
            #_app = get_vistrails_application()
            #d = _app.uvcdatWindow.dockPlot
            # simulate drop plot
            pm = projectController.plot_manager
            #print pm._plot_list.keys()
            V=pm._plot_list["VCS"]
            #print V.keys()
            gm = res30.presentation
            from gui.uvcdat.uvcdatCommons import gmInfos
            Gtype = res30.type
            G = V[Gtype]
            #print "G:",G.keys()
            #print get_canvas().listelements(Gtype.lower())
            if not gm.name in G.keys():
                G[gm.name] = pm._registry.add_plot(gm.name,"VCS",None,None,Gtype)
                G[gm.name].varnum = int(gmInfos[Gtype]["nSlabs"])
                
            #add initial attributes to global dict
            canvas = get_canvas()
            method_name = "get"+Gtype.lower()
            attributes = get_gm_attributes(Gtype)

            attrs = {}
            for attr in attributes:
                attrs[attr] = getattr(gm,attr)
            original_gm_attributes[Gtype][gm.name] = InstanceObject(**attrs)
                
            plot = projectController.plot_manager.new_plot('VCS', Gtype, gm.name )
            #plot = projectController.plot_manager.new_plot('VCS', Gtype, "default" )
            plotDropInfo = (plot, sheet, row, column)
            projectController.plot_was_dropped(plotDropInfo)