Exemplo n.º 1
0
    def plan_computation( self, model, obs, varid, seasonid, region=None, aux=slice(0,None),
                          names={}, plotparms=None ):
       """Set up for a lat-lon polar contour plot.  Data is averaged over all other axes.
       """
       filetable1, filetable2 = self.getfts(model, obs)
       ft1src = filetable1.source()
       if region is not None:
           regname = str(region)
       else:
           regname = None
       try:
           ft2src = filetable2.source()
       except:
           ft2src = ''
       reduced_varlis = [
           reduced_variable(
               variableid=varid, filetable=filetable1, season=self.season, region=regname,
               reduction_function=(lambda x,vid, region=regname,aux1=aux: reduce2latlon_seasonal(
                       x(latitude=aux1, longitude=(0, 360)), self.season, region, vid=vid ) ) ),
           reduced_variable(
               variableid=varid, filetable=filetable2, season=self.season, region=regname,
               reduction_function=(lambda x,vid, region=regname,aux1=aux: reduce2latlon_seasonal(
                       x(latitude=aux1, longitude=(0, 360)), self.season, region, vid=vid ) ) )
            ]
       self.reduced_variables = { v.id():v for v in reduced_varlis }
       vid1 = rv.dict_id( varid, seasonid, filetable1, region=regname )
       vid2 = rv.dict_id( varid, seasonid, filetable2, region=regname )

       self.derived_variables = {}
       self.single_plotspecs = {
            self.plot1_id: plotspec(
                vid = ps.dict_idid(vid1),
                zvars = [vid1],  zfunc = (lambda z: z),
                plottype = self.plottype,
                source = names.get('model',ft1src),
                file_descr = 'model',
                plotparms = plotparms[src2modobs(ft1src)] ),
            self.plot2_id: plotspec(
                vid = ps.dict_idid(vid2),
                zvars = [vid2],  zfunc = (lambda z: z),
                plottype = self.plottype,
                source = names.get('obs',ft2src),
                file_descr = 'obs',
                plotparms = plotparms[src2obsmod(ft2src)] ),
            self.plot3_id: plotspec(
                vid = ps.dict_id(varid,'diff',seasonid,filetable1,filetable2),
                zvars = [vid1,vid2],  zfunc = aminusb_2ax,
                plottype = self.plottype,
                source = ', '.join([names.get('model',ft1src),names.get('obs',ft2src)]),
                file_descr = 'diff',
                plotparms = plotparms['diff'] )         
            }
       self.composite_plotspecs = {
            self.plotall_id: [ self.plot1_id, self.plot2_id, self.plot3_id]
            }
       self.computation_planned = True
Exemplo n.º 2
0
    def plan_computation( self, model, obs, varnom, seasonid, plotparms ):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        
        self.reduced_variables = {}
        vidAll = {}        
        for FT in [filetable1, filetable2]:
            VIDs = []
            for i in range(1, 13):
                month = cdutil.times.getMonthString(i)
                #pdb.set_trace()
                #create identifiers
                VID = rv.dict_id(varnom, month, FT) #cdutil.times.getMonthIndex(VID[2])[0]-1
                RF = (lambda x, vid=id2str(VID), month = VID[2]:reduce2scalar_seasonal_zonal(x, seasons=cdutil.times.Seasons(month), vid=vid))
                RV = reduced_variable(variableid = varnom, 
                                      filetable = FT, 
                                      season = cdutil.times.Seasons(month), 
                                      reduction_function =  RF)
    
                VID = id2str(VID)
                self.reduced_variables[VID] = RV   
                VIDs += [VID]
            vidAll[FT] = VIDs 
        
        #create the identifiers 
        vidModel = dv.dict_id(varnom, 'model', "", filetable1)
        vidObs   = dv.dict_id(varnom, 'obs',   "", filetable2)
        self.vidModel = id2str(vidModel)
        self.vidObs   = id2str(vidObs)

        #create the derived variables which is the composite of the months
        #pdb.set_trace()
        model = derived_var(vid=self.vidModel, inputs=vidAll[filetable1], func=join_1d_data) 
        obs   = derived_var(vid=self.vidObs,   inputs=vidAll[filetable2], func=join_1d_data) 
        self.derived_variables = {self.vidModel: model, self.vidObs: obs}
        
        #create the plot spec
        self.single_plotspecs = {}

        self.single_plotspecs[self.plot_id] = plotspec(self.plot_id, 
                                                       zvars = [self.vidModel],
                                                       zfunc = (lambda y: y),
                                                       z2vars = [self.vidObs ],
                                                       z2func = (lambda z: z),
                                                       plottype = self.plottype,
                                                       source = ', '.join([ft1src,ft2src]),
                                                       file_descr = '',
                                                       plotparms=plotparms[src2modobs(ft1src)] )


        self.computation_planned = True
Exemplo n.º 3
0
    def plan_computation_normal_contours( self, model, obs, varid, seasonid, aux, plotparms ):
        """Set up for a lat-lon contour plot, as in plot set 5.  Data is averaged over all other
        axes."""
        filetable1, filetable2 = self.getfts(model, obs)
        self.derived_variables = {}
        vars_vec1 = {}
        vars_vec2 = {}
        try:
            if varid=='STRESS' or varid=='SURF_STRESS' or varid=='MOISTURE_TRANSPORT':
                vars1,rvars1,dvars1,var_cont1,vars_vec1,vid_cont1 =\
                    self.STRESS_setup( filetable1, varid, seasonid )
                vars2,rvars2,dvars2,var_cont2,vars_vec2,vid_cont2 =\
                    self.STRESS_setup( filetable2, varid, seasonid )
                if vars1 is None and vars2 is None:
                    raise DiagError("cannot find set6 variables in data 2")
            else:
                logger.error("AMWG plot set 6 does not yet support %s",varid)
                return None
        except Exception as e:
            logger.error("cannot find suitable set6_variables in data for varid= %s",varid)
            logger.exception(" %s ", e)
            return None
        reduced_varlis = []
        vardict1 = {'':'nameless_variable'}
        vardict2 = {'':'nameless_variable'}
        new_reducedvars, needed_derivedvars = self.STRESS_rvs( filetable1, rvars1, seasonid, vardict1 )
        reduced_varlis += new_reducedvars
        self.reduced_variables = { v.id():v for v in reduced_varlis }
        self.STRESS_dvs( filetable1, needed_derivedvars, seasonid, vardict1, vid_cont1, vars_vec1 )
        new_reducedvars, needed_derivedvars = self.STRESS_rvs( filetable2, rvars2, seasonid, vardict2 )
        reduced_varlis += new_reducedvars
        self.STRESS_dvs( filetable2, needed_derivedvars, seasonid, vardict2, vid_cont2, vars_vec2 )
        self.reduced_variables = { v.id():v for v in reduced_varlis }

        self.single_plotspecs = {}
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        vid_vec1 =  vardict1[','.join([vars_vec1[0],vars_vec1[1]])]
        vid_vec11 = vardict1[vars_vec1[0]]
        vid_vec12 = vardict1[vars_vec1[1]]
        vid_vec2 =  vardict2[','.join([vars_vec2[0],vars_vec2[1]])]
        vid_vec21 = vardict2[vars_vec2[0]]
        vid_vec22 = vardict2[vars_vec2[1]]
        plot_type_temp = ['Isofill','Vector'] # can't use self.plottype yet because don't support it elsewhere as a list or tuple <<<<<
        if vars1 is not None:
            # Draw two plots, contour and vector, over one another to get a single plot.
            # Only one needs to plot title,source; but both need source to get the filenames right.
            title = ' '.join([varid,seasonid,'(1)'])

            contplot = plotspec(
                vid = ps.dict_idid(vid_cont1),  zvars = [vid_cont1],  zfunc = (lambda z: z),
                plottype = plot_type_temp[0],
                title = title, source=ft1src,
                plotparms = plotparms[src2modobs(ft1src)] )
            vecplot = plotspec(
                vid = ps.dict_idid(vid_vec1), zvars=[vid_vec11,vid_vec12], zfunc = (lambda z,w: (z,w)),
                plottype = plot_type_temp[1], title1='', title2='', source=ft1src,
                plotparms = plotparms[src2modobs(ft1src)] )
            #self.single_plotspecs[self.plot1_id] = [contplot,vecplot]
            self.single_plotspecs[self.plot1_id+'c'] = contplot
            self.single_plotspecs[self.plot1_id+'v'] = vecplot
        if vars2 is not None:
            # Draw two plots, contour and vector, over one another to get a single plot.
            # Only one needs title,source.
            title = ' '.join([varid,seasonid,'(2)'])
            contplot = plotspec(
                vid = ps.dict_idid(vid_cont2),  zvars = [vid_cont2],  zfunc = (lambda z: z),
                plottype = plot_type_temp[0],
                title = title, source=ft2src,
                plotparms = plotparms[src2obsmod(ft2src)] )
            vecplot = plotspec(
                vid = ps.dict_idid(vid_vec2), zvars=[vid_vec21,vid_vec22], zfunc = (lambda z,w: (z,w)),
                plottype = plot_type_temp[1], title1='', title2='', source=ft2src,
                plotparms = plotparms[src2obsmod(ft2src)] )
            self.single_plotspecs[self.plot2_id+'c'] = contplot
            self.single_plotspecs[self.plot2_id+'v'] = vecplot
        if vars1 is not None and vars2 is not None:
            # First, we need some more derived variables in order to do the contours as a magnitude
            # of the difference vector.
            diff1_vid = dv.dict_id( vid_vec11[1], 'DIFF1', seasonid, filetable1, filetable2 )
            diff1 = derived_var( vid=diff1_vid, inputs=[vid_vec11,vid_vec21], func=aminusb_2ax )
            self.derived_variables[diff1_vid] = diff1
            diff2_vid = dv.dict_id( vid_vec12[1], 'DIFF1', seasonid, filetable1, filetable2 )
            diff2 = derived_var( vid=diff2_vid, inputs=[vid_vec12,vid_vec22], func=aminusb_2ax )
            
            self.derived_variables[diff2_vid] = diff2
            title = ' '.join([varid,seasonid,'diff,mag.diff'])
            #source = underscore_join([ft1src,ft2src]) 
            source = ''

            contplot = plotspec(
                vid = ps.dict_id(var_cont1,'mag.of.diff',seasonid,filetable1,filetable2),
                zvars = [diff1_vid,diff2_vid],  zfunc = abnorm,  # This is magnitude of difference of vectors
                plottype = plot_type_temp[0], title=title, source=source,
                plotparms = plotparms['diff'] )
            #contplot = plotspec(
            #    vid = ps.dict_id(var_cont1,'diff.of.mags',seasonid,filetable1,filetable2),
            #    zvars = [vid_cont1,vid_cont2],  zfunc = aminusb_2ax,  # This is difference of magnitudes.
            #    plottype = plot_type_temp[0], title=title, source=source )
            # This could be done in terms of diff1,diff2, but I'll leave it alone for now...
            vecplot = plotspec(
                vid = ps.dict_id(vid_vec2,'diff',seasonid,filetable1,filetable2),
                zvars = [vid_vec11,vid_vec12,vid_vec21,vid_vec22],
                zfunc = (lambda z1,w1,z2,w2: (aminusb_2ax(z1,z2),aminusb_2ax(w1,w2))),
                plottype = plot_type_temp[1], title1='', title2='',  source=source,
                plotparms = plotparms['diff'] )
            self.single_plotspecs[self.plot3_id+'c'] = contplot
            self.single_plotspecs[self.plot3_id+'v'] = vecplot
        # initially we're not plotting the contour part of the plots....
        self.composite_plotspecs = {
            self.plot1_id: ( self.plot1_id+'c', self.plot1_id+'v' ),
            #self.plot1_id: [ self.plot1_id+'v' ],
            self.plot2_id: ( self.plot2_id+'c', self.plot2_id+'v' ),
            self.plot3_id: ( self.plot3_id+'c', self.plot3_id+'v' ),
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id]
            }
        self.computation_planned = True
Exemplo n.º 4
0
    def plan_computation( self, model, obs, varid, seasonid, plotparms ):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        self.computation_planned = False
        #check if there is data to process
        ft1_valid = False
        ft2_valid = False
        if filetable1 is not None and filetable2 is not None:
            #the filetables must contain the variables LWCF and SWCF
            ft10 = filetable1.find_files(self.vars[0])
            ft11 = filetable1.find_files(self.vars[1])
            ft20 = filetable2.find_files(self.vars[0])
            ft21 = filetable2.find_files(self.vars[1])
            ft1_valid = ft10 is not None and ft10!=[] and ft11 is not None and ft11!=[] 
            ft2_valid = ft20 is not None and ft20!=[] and ft21 is not None and ft21!=[]  
        else:
            logger.error("user must specify 2 data files")
            return None
        if not ft1_valid or not ft2_valid:
            return None

        VIDs = {}
        for season in self.seasons:
            for dt, ft in zip(self.datatype, self.filetables):
                
                pair = []
                for var in self.vars:
                    VID = rv.dict_id(var, season, ft)
                    VID = id2str(VID)
                    pair += [VID]
                    if ft == filetable1:
                        RF = ( lambda x, vid=VID:x)
                    else:
                        RF = ( lambda x, vid=VID:x[0])
                    RV = reduced_variable( variableid=var, 
                                           filetable=ft, 
                                           season=cdutil.times.Seasons(season), 
                                           reduction_function=RF)
                    self.reduced_variables[VID] = RV      
                ID = dt + '_' + season
                VIDs[ID] = pair              
                
        #create a line as a derived variable
        self.derived_variables = {}
        xline = cdms2.createVariable([0., 120.])
        xline.id = 'LWCF'
        yline = cdms2.createVariable([0., -120.])
        yline.id = 'SWCF'
        yline.units = 'Wm-2'             
        self.derived_variables['LINE'] = derived_var(vid='LINE',  func=create_yvsx(xline, yline, stride=1))  #inputs=[xline, yline],
        
        self.single_plotspecs = {}
        self.composite_plotspecs[self.plotall_id] = []
        self.compositeTitle = self.vars[0] + ' vs ' + self.vars[1]
        SLICE = slice(0, None, 10) #return every 10th datum
        for plot_id in self.plot_ids:
            title = plot_id
            xVID, yVID = VIDs[plot_id]
            self.single_plotspecs[plot_id] = plotspec(vid = plot_id, 
                                                      zvars=[xVID], 
                                                      zfunc = (lambda x: x.flatten()[SLICE]),
                                                      zrangevars={'xrange':[0., 120.]},
                                                      z2vars = [yVID],
                                                      z2func = (lambda x: x.flatten()[SLICE]),
                                                      z2rangevars={'yrange':[-120., 0.]},
                                                      plottype = 'Scatter', 
                                                      title = title,
                                                      overplotline = False,
                                                      source = ', '.join([ft1src,ft2src]),
                                                      plotparms=plotparms[src2modobs(ft1src)] )
        self.single_plotspecs['DIAGONAL_LINE'] = plotspec(vid = 'LINE_PS', 
                                                          zvars=['LINE'], 
                                                          zfunc = (lambda x: x),
                                                          plottype = 'Yxvsx',
                                                          zlinecolor = 242,
                                                          title='', 
                                                          overplotline = False)

        self.composite_plotspecs = {}
        plotall_id = []
        for plot_id in self.plot_ids:
            ID = plot_id + '_with_line'
            self.composite_plotspecs[ID] =  (plot_id, 'DIAGONAL_LINE' )
            plotall_id += [ID]
        self.composite_plotspecs[self.plotall_id] = plotall_id
        self.computation_planned = True
Exemplo n.º 5
0
    def plan_computation( self, model, obs, varnom, seasonid, region, plotparms ):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        region = interpret_region( region )
        if varnom in filetable1.list_variables_incl_axes():
            vid1 = self.var_from_data( filetable1, varnom, seasonid, region )
        elif varnom in self.common_derived_variables.keys():
            vid1 = self.var_from_cdv( filetable1, varnom, seasonid, region )
        else:
            logger.error( "variable %s cannot be read or computed from data in the filetable %s",
                          varnom, filetable1 )
            return None
        if filetable2 is None:
            vid2 = None
        elif varnom in filetable2.list_variables_incl_axes():
            vid2 = self.var_from_data( filetable2, varnom, seasonid, region )
        elif varnom in self.common_derived_variables.keys():
            vid2 = self.var_from_cdv( filetable2, varnom, seasonid, region )
        else:
            vid2 = None

        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        #vid1 = rv.dict_id(  varnom,seasonid, filetable1, region=region)
        #vid2 = rv.dict_id(  varnom,seasonid, filetable2, region=region)
        self.single_plotspecs = {
            self.plot1_id: plotspec(
                vid = ps.dict_idid(vid1), zvars=[vid1],\
                    zfunc=(lambda z: standardize_and_check_cloud_variable(z)),
                plottype = self.plottype,
                title = ' '.join([varnom,seasonid,str(region),'(1)']),
                source = ft1src,
                file_descr = 'model',
                plotparms = plotparms[src2modobs(ft1src)] ),
            self.plot2_id: plotspec(
                vid = ps.dict_idid(vid2), zvars=[vid2],\
                    zfunc=(lambda z: standardize_and_check_cloud_variable(z)),
                plottype = self.plottype,
                title = ' '.join([varnom,seasonid,str(region),'(2)']),
                source = ft2src,
                file_descr = 'obs',
                plotparms = plotparms[src2obsmod(ft2src)] ),
            self.plot3_id: plotspec(
                vid = ps.dict_id(varnom,'diff',seasonid,filetable1,filetable2,region=region), zvars=[vid1,vid2],
                zfunc=aminusb_2ax, plottype = self.plottype,
                title = ' '.join([varnom,seasonid,str(region),'(1)-(2)']),
                source = ', '.join([ft1src,ft2src]),
                file_descr = 'diff',
                plotparms = plotparms['diff'] )
            }
        self.composite_plotspecs = {
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id ]
            }
        self.computation_planned = True
Exemplo n.º 6
0
    def plan_computation_level_surface( self, model, obs, varnom, seasonid, aux=None, names={}, plotparms=None ):
        filetable1, filetable2 = self.getfts(model, obs)
        """Set up for a lat-lon contour plot, averaged in other directions - except that if the
        variable to be plotted depend on level, it is not averaged over level.  Instead, the value
        at a single specified pressure level, aux, is used. The units of aux are millbars."""
        # In calling reduce_time_seasonal, I am assuming that no variable has axes other than
        # (time, lev,lat,lon).
        # If there were another axis, then we'd need a new function which reduces it as well.
        if not isinstance(aux,Number): return None
        pselect = udunits(aux,'mbar')
        pselect.value=int(pselect.value)
        PSELECT = str(pselect)

        reduced_varlis = [
            reduced_variable(  # var=var(time,lev,lat,lon)
                variableid=varnom, filetable=filetable1, season=self.season,
                reduction_function=(lambda x,vid: reduce_time_seasonal( x, self.season, self.region, vid ) ) ),
            reduced_variable(   # hyam=hyam(lev)
                variableid='hyam', filetable=filetable1, season=self.season,
                reduction_function=(lambda x,vid=None: select_region( x, self.region)) ),
            reduced_variable(   # hybm=hybm(lev)
                variableid='hybm', filetable=filetable1, season=self.season,
                reduction_function=(lambda x,vid=None: select_region( x, self.region)) ),
            reduced_variable(     # ps=ps(time,lat,lon)
                variableid='PS', filetable=filetable1, season=self.season,
                reduction_function=(lambda x,vid: reduce_time_seasonal( x, self.season, self.region, vid ) ) ) ]
        # vid1 = varnom+'_p_1'
        # vidl1 = varnom+'_lp_1'
        vid1 = dv.dict_id(  varnom, 'p', seasonid, filetable1)
        vidl1 = dv.dict_id(varnom, 'lp', seasonid, filetable1)
        self.derived_variables = {
            vid1: derived_var( vid=vid1, inputs =
                               [rv.dict_id(varnom,seasonid,filetable1), rv.dict_id('hyam',seasonid,filetable1),
                                rv.dict_id('hybm',seasonid,filetable1), rv.dict_id('PS',seasonid,filetable1) ],
            #was  vid1: derived_var( vid=vid1, inputs=[ varnom+'_1', 'hyam_1', 'hybm_1', 'PS_1' ],
                               func=verticalize ),
            vidl1: derived_var( vid=vidl1, inputs=[vid1],
                                func=(lambda z,psl=pselect: select_lev(z,psl))) }

        ft1src = filetable1.source()
        #note: the title in the following is parced in customizeTemplate. This is a garbage kludge! Mea culpa. 
        varstr = varnom + '(' + PSELECT + ')'
        self.single_plotspecs = {
            self.plot1_id: plotspec(
                # was vid = varnom+'_1',
                # was zvars = [vid1],  zfunc = (lambda z: select_lev( z, pselect ) ),
                vid = ps.dict_idid(vidl1),
                zvars = [vidl1],  zfunc = (lambda z: z),
                plottype = self.plottype,
                title = ' '.join([varstr, seasonid, 'model', names['model']]),
                title1 = ' '.join([varstr, seasonid, 'model', names['model']]),
                title2 = 'model',
                file_descr = 'model',
                source = names['model'],
                plotparms = plotparms[src2modobs(ft1src)] ) }
           
        if filetable2 is None:
            self.reduced_variables = { v.id():v for v in reduced_varlis }
            self.composite_plotspecs = {
                self.plotall_id: [ self.plot1_id ]
                }
            self.computation_planned = True
            return

        if 'hyam' in filetable2.list_variables() and 'hybm' in filetable2.list_variables():
            # hybrid levels in use, convert to pressure levels
            reduced_varlis += [
                reduced_variable(  # var=var(time,lev,lat,lon)
                    variableid=varnom, filetable=filetable2, season=self.season,
                    reduction_function=(lambda x,vid: reduce_time_seasonal( x, self.season, self.region, vid ) ) ),
                reduced_variable(   # hyam=hyam(lev)
                    variableid='hyam', filetable=filetable2, season=self.season,
                    reduction_function=(lambda x,vid=None: select_region( x, self.region)) ),
                reduced_variable(   # hybm=hybm(lev)
                    variableid='hybm', filetable=filetable2, season=self.season,
                    reduction_function=(lambda x,vid=None: select_region( x, self.region)) ),
                reduced_variable(     # ps=ps(time,lat,lon)
                    variableid='PS', filetable=filetable2, season=self.season,
                    reduction_function=(lambda x,vid: reduce_time_seasonal( x, self.season, self.region, vid ) ) )
                ]
            #vid2 = varnom+'_p_2'
            #vidl2 = varnom+'_lp_2'
            vid2 = dv.dict_id( varnom, 'p', seasonid, filetable2 )
            vid2 = dv.dict_id( vards, 'lp', seasonid, filetable2 )
            self.derived_variables[vid2] = derived_var( vid=vid2, inputs=[
                    rv.dict_id(varnom,seasonid,filetable2), rv.dict_id('hyam',seasonid,filetable2),
                    rv.dict_id('hybm',seasonid,filetable2), rv.dict_id('PS',seasonid,filetable2) ],
                                                        func=verticalize )
            self.derived_variables[vidl2] = derived_var(
                vid=vidl2, inputs=[vid2], func=(lambda z,psl=pselect: select_lev(z,psl) ) )
        else:
            # no hybrid levels, assume pressure levels.
            #vid2 = varnom+'_2'
            #vidl2 = varnom+'_lp_2'
            vid2 = rv.dict_id(varnom,seasonid,filetable2)
            vidl2 = dv.dict_id( varnom, 'lp', seasonid, filetable2 )
            reduced_varlis += [
                reduced_variable(  # var=var(time,lev,lat,lon)
                    variableid=varnom, filetable=filetable2, season=self.season,
                    reduction_function=(lambda x,vid: reduce_time_seasonal( x, self.season, self.region, vid ) ) )
                ]
            self.derived_variables[vidl2] = derived_var(
                vid=vidl2, inputs=[vid2], func=(lambda z,psl=pselect: select_lev(z,psl) ) )
        self.reduced_variables = { v.id():v for v in reduced_varlis }

        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        filterid = ft2src.split('_')[-1] #recover the filter id: kludge
        self.single_plotspecs[self.plot2_id] = plotspec(
                #was vid = varnom+'_2',
                vid = ps.dict_idid(vidl2),
                zvars = [vidl2],  zfunc = (lambda z: z),
                plottype = self.plottype,
                title = ' '.join([varstr,seasonid,'observation',names['obs']]),
                title1 = ' '.join([varstr, seasonid, 'observation',names['obs']]),
                title2 = 'observation',
                file_descr = 'obs',
                source = names['obs'],
                plotparms = plotparms[src2obsmod(ft2src)] )
        self.single_plotspecs[self.plot3_id] = plotspec(
                #was vid = varnom+'_diff',
                vid = ps.dict_id(varnom,'diff',seasonid,filetable1,filetable2),
                zvars = [vidl1,vidl2],  zfunc = aminusb_2ax,
                plottype = self.plottype,
                title = ' '.join([varstr,seasonid,'difference']),
                title1 = ' '.join([varstr, seasonid, 'difference']),
                title2 = 'difference',
                file_descr = 'diff',
                plotparms = plotparms['diff'] )
#                zerocontour=-1 )
        self.composite_plotspecs = {
            self.plotall_id: [ self.plot1_id, self.plot2_id, self.plot3_id ]
            }
        self.computation_planned = True
Exemplo n.º 7
0
    def plan_computation_normal_contours( self, model, obs, varnom, seasonid, aux=None, names={}, plotparms=None ):
        filetable1, filetable2 = self.getfts(model, obs)

        """Set up for a lat-lon contour plot, as in plot set 5.  Data is averaged over all other
        axes."""
        if varnom in filetable1.list_variables():
            vid1,vid1var = self.vars_normal_contours(
                filetable1, varnom, seasonid, aux=None )
        elif varnom in self.common_derived_variables.keys():
            vid1,vid1var = self.vars_commdervar_normal_contours(
                filetable1, varnom, seasonid, aux=None )
        else:
            logger.error("variable %s not found in and cannot be computed from %s",varnom, filetable1)
            return None
        if filetable2 is not None and varnom in filetable2.list_variables():
            vid2,vid2var = self.vars_normal_contours(
                filetable2, varnom, seasonid, aux=None )
        elif varnom in self.common_derived_variables.keys():
            vid2,vid2var = self.vars_commdervar_normal_contours(
                filetable2, varnom, seasonid, aux=None )
        else:
            vid2,vid2var = None,None
        self.single_plotspecs = {}
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        all_plotnames = []

        if filetable1 is not None:
            if vid1 is not None:
                self.single_plotspecs[self.plot1_id] = plotspec(
                    vid = ps.dict_idid(vid1),
                    zvars = [vid1],  zfunc = (lambda z: z),
                    plottype = self.plottype,
                    title = ' '.join([varnom, seasonid, 'model']),
                    title1 = ' '.join([varnom, seasonid, 'model']),
                    title2 = 'model',
                    file_descr = 'model',
                    source = names['model'], 
                    plotparms = plotparms[src2modobs(ft1src)])
                all_plotnames.append(self.plot1_id)
                
            if vid1var is not None:
                self.single_plotspecs[self.plot1var_id] = plotspec(
                    vid = ps.dict_idid(vid1var),
                    zvars = [vid1var],  zfunc = (lambda z: z),
                    plottype = self.plottype,
                    title = ' '.join([varnom, seasonid, 'model variance']),
                    title1 = ' '.join([varnom, seasonid, 'model variance']),
                    title2 = 'model variance',
                    file_descr = 'model variance',
                    source = names['model'],
                    plotparms = plotparms[src2modobs(ft1src)] )
                all_plotnames.append(self.plot1var_id)
                
        if filetable2 is not None and vid2 is not None:
            self.single_plotspecs[self.plot2_id] = plotspec(
                vid = ps.dict_idid(vid2),
                zvars = [vid2],  zfunc = (lambda z: z),
                plottype = self.plottype,
                title = ' '.join([varnom, seasonid, 'obs']),
                title1 = ' '.join([varnom, seasonid, 'obs']),
                title2 = "observation",
                file_descr = "obs",
                source = names['obs'], 
                plotparms = plotparms[src2obsmod(ft2src)] )
            all_plotnames.append(self.plot2_id)
            
        if filetable1 is not None and filetable2 is not None and vid1 is not None and vid2 is not None:
            self.single_plotspecs[self.plot3_id] = plotspec(
                vid = ps.dict_id(varnom,'diff',seasonid,filetable1,filetable2),
                zvars = [vid1,vid2],  zfunc = aminusb_2ax,
                plottype = self.plottype,
                title = ' '.join([varnom, seasonid, 'difference']),
                title1 = ' '.join([varnom, seasonid, 'difference']),
                title2 = 'difference',
                file_descr = 'diff',
                plotparms = plotparms['diff'] )
            all_plotnames.append(self.plot3_id)

        if len(all_plotnames)>0:
            self.composite_plotspecs = {
                self.plotall_id: all_plotnames
                }
        else:
            self.composite_plotspecs = {}
        self.computation_planned = True
Exemplo n.º 8
0
    def plan_computation(self, model, obs, varnom, seasonid, plotparms):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''

        self.reduced_variables = {}
        vidAll = {}
        for FT in [filetable1, filetable2]:
            VIDs = []
            for i in range(1, 13):
                month = cdutil.times.getMonthString(i)
                #pdb.set_trace()
                #create identifiers
                VID = rv.dict_id(varnom, month,
                                 FT)  #cdutil.times.getMonthIndex(VID[2])[0]-1
                RF = (lambda x, vid=id2str(VID), month=VID[2]:
                      reduce2scalar_seasonal_zonal(
                          x, seasons=cdutil.times.Seasons(month), vid=vid))
                RV = reduced_variable(variableid=varnom,
                                      filetable=FT,
                                      season=cdutil.times.Seasons(month),
                                      reduction_function=RF)

                VID = id2str(VID)
                self.reduced_variables[VID] = RV
                VIDs += [VID]
            vidAll[FT] = VIDs

        #create the identifiers
        vidModel = dv.dict_id(varnom, 'model', "", filetable1)
        vidObs = dv.dict_id(varnom, 'obs', "", filetable2)
        self.vidModel = id2str(vidModel)
        self.vidObs = id2str(vidObs)

        #create the derived variables which is the composite of the months
        #pdb.set_trace()
        model = derived_var(vid=self.vidModel,
                            inputs=vidAll[filetable1],
                            func=join_1d_data)
        obs = derived_var(vid=self.vidObs,
                          inputs=vidAll[filetable2],
                          func=join_1d_data)
        self.derived_variables = {self.vidModel: model, self.vidObs: obs}

        #create the plot spec
        self.single_plotspecs = {}

        self.single_plotspecs[self.plot_id] = plotspec(
            self.plot_id,
            zvars=[self.vidModel],
            zfunc=(lambda y: y),
            z2vars=[self.vidObs],
            z2func=(lambda z: z),
            plottype=self.plottype,
            source=', '.join([ft1src, ft2src]),
            file_descr='',
            plotparms=plotparms[src2modobs(ft1src)])

        self.computation_planned = True
Exemplo n.º 9
0
    def plan_computation(self, model, obs, varid, seasonid, plotparms):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        self.computation_planned = False
        #check if there is data to process
        ft1_valid = False
        ft2_valid = False
        if filetable1 is not None and filetable2 is not None:
            #the filetables must contain the variables LWCF and SWCF
            ft10 = filetable1.find_files(self.vars[0])
            ft11 = filetable1.find_files(self.vars[1])
            ft20 = filetable2.find_files(self.vars[0])
            ft21 = filetable2.find_files(self.vars[1])
            ft1_valid = ft10 is not None and ft10!=[] and ft11 is not None and ft11!=[]
            ft2_valid = ft20 is not None and ft20!=[] and ft21 is not None and ft21!=[]
        else:
            logger.error("user must specify 2 data files")
            return None
        if not ft1_valid or not ft2_valid:
            return None

        VIDs = {}
        for season in self.seasons:
            for dt, ft in zip(self.datatype, self.filetables):

                pair = []
                for var in self.vars:
                    VID = rv.dict_id(var, season, ft)
                    VID = id2str(VID)
                    pair += [VID]
                    if ft == filetable1:
                        RF = (lambda x, vid=VID: x)
                    else:
                        RF = (lambda x, vid=VID: x[0])
                    RV = reduced_variable(variableid=var,
                                          filetable=ft,
                                          season=cdutil.times.Seasons(season),
                                          reduction_function=RF)
                    self.reduced_variables[VID] = RV
                ID = dt + '_' + season
                VIDs[ID] = pair

        #create a line as a derived variable
        self.derived_variables = {}
        xline = cdms2.createVariable([0., 120.])
        xline.id = 'LWCF'
        yline = cdms2.createVariable([0., -120.])
        yline.id = 'SWCF'
        yline.units = 'Wm-2'
        self.derived_variables['LINE'] = derived_var(
            vid='LINE', func=create_yvsx(xline, yline,
                                         stride=1))  #inputs=[xline, yline],

        self.single_plotspecs = {}
        self.composite_plotspecs[self.plotall_id] = []
        self.compositeTitle = self.vars[0] + ' vs ' + self.vars[1]
        SLICE = slice(0, None, 10)  #return every 10th datum
        for plot_id in self.plot_ids:
            title = plot_id
            xVID, yVID = VIDs[plot_id]
            self.single_plotspecs[plot_id] = plotspec(
                vid=plot_id,
                zvars=[xVID],
                zfunc=(lambda x: x.flatten()[SLICE]),
                zrangevars={'xrange': [0., 120.]},
                z2vars=[yVID],
                z2func=(lambda x: x.flatten()[SLICE]),
                z2rangevars={'yrange': [-120., 0.]},
                plottype='Scatter',
                title=title,
                overplotline=False,
                source=', '.join([ft1src, ft2src]),
                plotparms=plotparms[src2modobs(ft1src)])
        self.single_plotspecs['DIAGONAL_LINE'] = plotspec(vid='LINE_PS',
                                                          zvars=['LINE'],
                                                          zfunc=(lambda x: x),
                                                          plottype='Yxvsx',
                                                          zlinecolor=242,
                                                          title='',
                                                          overplotline=False)

        self.composite_plotspecs = {}
        plotall_id = []
        for plot_id in self.plot_ids:
            ID = plot_id + '_with_line'
            self.composite_plotspecs[ID] = (plot_id, 'DIAGONAL_LINE')
            plotall_id += [ID]
        self.composite_plotspecs[self.plotall_id] = plotall_id
        self.computation_planned = True
Exemplo n.º 10
0
    def plan_computation(self, model, obs, varid, seasonid, names, plotparms):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1_hyam = filetable1.find_files('hyam')
        if filetable2 is None:
            ft2_hyam = None
        else:
            ft2_hyam = filetable2.find_files('hyam')
        hybrid1 = ft1_hyam is not None and ft1_hyam != [
        ]  # true iff filetable1 uses hybrid level coordinates
        hybrid2 = ft2_hyam is not None and ft2_hyam != [
        ]  # true iff filetable2 uses hybrid level coordinates
        #print hybrid1, hybrid2
        #retrieve the 1d and 2d reduction function; either lat & levlat or lon & levlon
        RF_1d, RF_2d = self.reduction_functions[self.number]
        rf_id = self.rf_ids[self.number]

        #print RF_1d
        #print RF_2d
        if hybrid1:
            reduced_variables_1 = self.reduced_variables_hybrid_lev(
                filetable1, varid, seasonid, RF1=identity, RF2=identity)
        else:
            reduced_variables_1 = self.reduced_variables_press_lev(filetable1,
                                                                   varid,
                                                                   seasonid,
                                                                   RF2=RF_2d)
        if hybrid2:
            reduced_variables_2 = self.reduced_variables_hybrid_lev(
                filetable2, varid, seasonid, RF1=identity, RF2=identity)
        else:
            reduced_variables_2 = self.reduced_variables_press_lev(filetable2,
                                                                   varid,
                                                                   seasonid,
                                                                   RF2=RF_2d)
        reduced_variables_1.update(reduced_variables_2)
        self.reduced_variables = reduced_variables_1

        self.derived_variables = {}
        if hybrid1:
            # >>>> actually last arg of the derived var should identify the coarsest level, not nec. 2
            # Note also that it is dangerous to use input data from two filetables (though necessary here) - it
            # can badly mess things up if derive() assigns to the new variable a filetable which is not the
            # main source of the data, meaning its axes.  It gets the filetable from the first input listed here.
            vid1 = dv.dict_id(varid, rf_id, seasonid, filetable1)
            self.derived_variables[vid1] = derived_var(
                vid=vid1,
                inputs=[
                    rv.dict_id(varid, seasonid, filetable1),
                    rv.dict_id('hyam', seasonid, filetable1),
                    rv.dict_id('hybm', seasonid, filetable1),
                    rv.dict_id('PS', seasonid, filetable1),
                    rv.dict_id(varid, seasonid, filetable2)
                ],
                func=(lambda T, hyam, hybm, ps, level_src, seasonid=
                      seasonid, varid=varid: RF_2d(verticalize(
                          T, hyam, hybm, ps, level_src),
                                                   season=seasonid,
                                                   vid=varid)))
        else:
            vid1 = rv.dict_id(varid, seasonid, filetable1)
        if hybrid2:
            # >>>> actually last arg of the derived var should identify the coarsest level, not nec. 2
            vid2 = dv.dict_id(varid, rf_id, seasonid, filetable2)
            self.derived_variables[vid2] = derived_var(
                vid=vid2,
                inputs=[
                    rv.dict_id(varid, seasonid, filetable2),
                    rv.dict_id('hyam', seasonid, filetable2),
                    rv.dict_id('hybm', seasonid, filetable2),
                    rv.dict_id('PS', seasonid, filetable2),
                    rv.dict_id(varid, seasonid, filetable2)
                ],
                func=(lambda T, hyam, hybm, ps, level_src, seasonid=
                      seasonid, varid=varid: RF_2d(verticalize(
                          T, hyam, hybm, ps, level_src),
                                                   season=seasonid,
                                                   vid=varid)))
        else:
            vid2 = rv.dict_id(varid, seasonid, filetable2)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        self.single_plotspecs = {
            self.plot1_id:
            plotspec(vid=ps.dict_idid(vid1),
                     zvars=[vid1],
                     zfunc=(lambda z: z),
                     plottype=self.plottype,
                     title=' '.join([varid, seasonid, '(1)']),
                     file_descr='model',
                     source=names['model'],
                     plotparms=plotparms[src2modobs(ft1src)]),
            self.plot2_id:
            plotspec(vid=ps.dict_idid(vid2),
                     zvars=[vid2],
                     zfunc=(lambda z: z),
                     plottype=self.plottype,
                     title=' '.join([varid, seasonid, '(2)']),
                     file_descr='obs',
                     source=names['obs'],
                     plotparms=plotparms[src2obsmod(ft2src)]),
            self.plot3_id:
            plotspec(vid=ps.dict_id(varid, 'diff', seasonid, filetable1,
                                    filetable2),
                     zvars=[vid1, vid2],
                     zfunc=aminusb_2ax,
                     plottype=self.plottype,
                     title=' '.join([varid, seasonid, '(1)-(2)']),
                     file_descr='diff',
                     source=', '.join([names['model'], names['obs']]),
                     plotparms=plotparms['diff'])
        }
        self.composite_plotspecs = {
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id]
        }
        self.computation_planned = True
Exemplo n.º 11
0
    def plan_computation( self, model, obs, varid, seasonid, plotparms ):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        self.computation_planned = False
        #check if there is data to process
        ft1_valid = False
        ft2_valid = False
        if filetable1 is not None and filetable2 is not None:
            ft1 = filetable1.find_files(varid)
            ft2 = filetable2.find_files(varid)
            ft1_valid = ft1 is not None and ft1!=[]    # true iff filetable1 uses hybrid level coordinates
            ft2_valid = ft2 is not None and ft2!=[]    # true iff filetable2 uses hybrid level coordinates
        else:
            logger.error("user must specify 2 data files")
            return None
        if not ft1_valid or not ft2_valid:
            return None

        #generate identifiers
        vid1 = rv.dict_id(varid, self._s1, filetable1)
        vid2 = rv.dict_id(varid, self._s2, filetable2)
        vid3 = dv.dict_id(varid, 'SeasonalDifference', self._seasonid, filetable1)#, ft2=filetable2)

        #setup the reduced variables
        vid1_season = cdutil.times.Seasons(self._s1)
        if vid1_season is None:
            vid1_season = seasonsyr
        vid2_season = cdutil.times.Seasons(self._s2)
        if vid2_season is None:
            vid2_season = seasonsyr

        rv_1 = reduced_variable(variableid=varid, filetable=filetable1, season=vid1_season,
                                reduction_function=( lambda x, vid=vid1: reduce2latlon_seasonal(x, vid1_season, self.region, vid=vid)) )
        
        rv_2 = reduced_variable(variableid=varid, filetable=filetable2, season=vid2_season,
                                reduction_function=( lambda x, vid=vid2: reduce2latlon_seasonal(x, vid2_season, self.region, vid=vid)) )
                                               
        self.reduced_variables = {rv_1.id(): rv_1, rv_2.id(): rv_2}  

        #create the derived variable which is the difference        
        self.derived_variables = {}
        self.derived_variables[vid3] = derived_var(vid=vid3, inputs=[vid1, vid2], func=aminusb_2ax) 
            
        self.single_plotspecs = {
            self.plot1_id: plotspec(
                vid = ps.dict_idid(vid1), 
                zvars=[vid1], 
                zfunc = (lambda z: z),
                plottype = self.plottype,
                source = ft1src,
                file_descr = 'model',
                plotparms = plotparms[src2modobs(ft1src)] ),
            self.plot2_id: plotspec(
                vid = ps.dict_idid(vid2), 
                zvars=[vid2], 
                zfunc = (lambda z: z),
                plottype = self.plottype,
                source = ft2src,
                file_descr = 'obs',
                plotparms = plotparms[src2obsmod(ft2src)] ),
            self.plot3_id: plotspec(
                vid = ps.dict_idid(vid3), 
                zvars = [vid3],
                zfunc = (lambda x: x), 
                plottype = self.plottype,
                source = ', '.join([ft1src,ft2src]),
                file_descr = 'diff',
                plotparms = plotparms['diff'] )
            }

        self.composite_plotspecs = {
            self.plotall_id: [ self.plot1_id, self.plot2_id, self.plot3_id ]
            }
        # ...was self.composite_plotspecs = { self.plotall_id: self.single_plotspecs.keys() }
        self.computation_planned = True
Exemplo n.º 12
0
    def plan_computation_level_surface(self,
                                       model,
                                       obs,
                                       varnom,
                                       seasonid,
                                       aux=None,
                                       names={},
                                       plotparms=None):
        filetable1, filetable2 = self.getfts(model, obs)
        """Set up for a lat-lon contour plot, averaged in other directions - except that if the
        variable to be plotted depend on level, it is not averaged over level.  Instead, the value
        at a single specified pressure level, aux, is used. The units of aux are millbars."""
        # In calling reduce_time_seasonal, I am assuming that no variable has axes other than
        # (time, lev,lat,lon).
        # If there were another axis, then we'd need a new function which reduces it as well.
        if not isinstance(aux, Number): return None
        pselect = udunits(aux, 'mbar')
        pselect.value = int(pselect.value)
        PSELECT = str(pselect)

        reduced_varlis = [
            reduced_variable(  # var=var(time,lev,lat,lon)
                variableid=varnom,
                filetable=filetable1,
                season=self.season,
                reduction_function=(lambda x, vid: reduce_time_seasonal(
                    x, self.season, self.region, vid))),
            reduced_variable(  # hyam=hyam(lev)
                variableid='hyam',
                filetable=filetable1,
                season=self.season,
                reduction_function=(
                    lambda x, vid=None: select_region(x, self.region))),
            reduced_variable(  # hybm=hybm(lev)
                variableid='hybm',
                filetable=filetable1,
                season=self.season,
                reduction_function=(
                    lambda x, vid=None: select_region(x, self.region))),
            reduced_variable(  # ps=ps(time,lat,lon)
                variableid='PS',
                filetable=filetable1,
                season=self.season,
                reduction_function=(lambda x, vid: reduce_time_seasonal(
                    x, self.season, self.region, vid)))
        ]
        # vid1 = varnom+'_p_1'
        # vidl1 = varnom+'_lp_1'
        vid1 = dv.dict_id(varnom, 'p', seasonid, filetable1)
        vidl1 = dv.dict_id(varnom, 'lp', seasonid, filetable1)
        self.derived_variables = {
            vid1:
            derived_var(
                vid=vid1,
                inputs=[
                    rv.dict_id(varnom, seasonid, filetable1),
                    rv.dict_id('hyam', seasonid, filetable1),
                    rv.dict_id('hybm', seasonid, filetable1),
                    rv.dict_id('PS', seasonid, filetable1)
                ],
                #was  vid1: derived_var( vid=vid1, inputs=[ varnom+'_1', 'hyam_1', 'hybm_1', 'PS_1' ],
                func=verticalize),
            vidl1:
            derived_var(vid=vidl1,
                        inputs=[vid1],
                        func=(lambda z, psl=pselect: select_lev(z, psl)))
        }

        ft1src = filetable1.source()
        #note: the title in the following is parced in customizeTemplate. This is a garbage kludge! Mea culpa.
        varstr = varnom + '(' + PSELECT + ')'
        self.single_plotspecs = {
            self.plot1_id:
            plotspec(
                # was vid = varnom+'_1',
                # was zvars = [vid1],  zfunc = (lambda z: select_lev( z, pselect ) ),
                vid=ps.dict_idid(vidl1),
                zvars=[vidl1],
                zfunc=(lambda z: z),
                plottype=self.plottype,
                title=' '.join([varstr, seasonid, 'model', names['model']]),
                title1=' '.join([varstr, seasonid, 'model', names['model']]),
                title2='model',
                file_descr='model',
                source=names['model'],
                plotparms=plotparms[src2modobs(ft1src)])
        }

        if filetable2 is None:
            self.reduced_variables = {v.id(): v for v in reduced_varlis}
            self.composite_plotspecs = {self.plotall_id: [self.plot1_id]}
            self.computation_planned = True
            return

        if 'hyam' in filetable2.list_variables(
        ) and 'hybm' in filetable2.list_variables():
            # hybrid levels in use, convert to pressure levels
            reduced_varlis += [
                reduced_variable(  # var=var(time,lev,lat,lon)
                    variableid=varnom,
                    filetable=filetable2,
                    season=self.season,
                    reduction_function=(lambda x, vid: reduce_time_seasonal(
                        x, self.season, self.region, vid))),
                reduced_variable(  # hyam=hyam(lev)
                    variableid='hyam',
                    filetable=filetable2,
                    season=self.season,
                    reduction_function=(
                        lambda x, vid=None: select_region(x, self.region))),
                reduced_variable(  # hybm=hybm(lev)
                    variableid='hybm',
                    filetable=filetable2,
                    season=self.season,
                    reduction_function=(
                        lambda x, vid=None: select_region(x, self.region))),
                reduced_variable(  # ps=ps(time,lat,lon)
                    variableid='PS',
                    filetable=filetable2,
                    season=self.season,
                    reduction_function=(lambda x, vid: reduce_time_seasonal(
                        x, self.season, self.region, vid)))
            ]
            #vid2 = varnom+'_p_2'
            #vidl2 = varnom+'_lp_2'
            vid2 = dv.dict_id(varnom, 'p', seasonid, filetable2)
            vid2 = dv.dict_id(vards, 'lp', seasonid, filetable2)
            self.derived_variables[vid2] = derived_var(
                vid=vid2,
                inputs=[
                    rv.dict_id(varnom, seasonid, filetable2),
                    rv.dict_id('hyam', seasonid, filetable2),
                    rv.dict_id('hybm', seasonid, filetable2),
                    rv.dict_id('PS', seasonid, filetable2)
                ],
                func=verticalize)
            self.derived_variables[vidl2] = derived_var(
                vid=vidl2,
                inputs=[vid2],
                func=(lambda z, psl=pselect: select_lev(z, psl)))
        else:
            # no hybrid levels, assume pressure levels.
            #vid2 = varnom+'_2'
            #vidl2 = varnom+'_lp_2'
            vid2 = rv.dict_id(varnom, seasonid, filetable2)
            vidl2 = dv.dict_id(varnom, 'lp', seasonid, filetable2)
            reduced_varlis += [
                reduced_variable(  # var=var(time,lev,lat,lon)
                    variableid=varnom,
                    filetable=filetable2,
                    season=self.season,
                    reduction_function=(lambda x, vid: reduce_time_seasonal(
                        x, self.season, self.region, vid)))
            ]
            self.derived_variables[vidl2] = derived_var(
                vid=vidl2,
                inputs=[vid2],
                func=(lambda z, psl=pselect: select_lev(z, psl)))
        self.reduced_variables = {v.id(): v for v in reduced_varlis}

        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        filterid = ft2src.split('_')[-1]  #recover the filter id: kludge
        self.single_plotspecs[self.plot2_id] = plotspec(
            #was vid = varnom+'_2',
            vid=ps.dict_idid(vidl2),
            zvars=[vidl2],
            zfunc=(lambda z: z),
            plottype=self.plottype,
            title=' '.join([varstr, seasonid, 'observation', names['obs']]),
            title1=' '.join([varstr, seasonid, 'observation', names['obs']]),
            title2='observation',
            file_descr='obs',
            source=names['obs'],
            plotparms=plotparms[src2obsmod(ft2src)])
        self.single_plotspecs[self.plot3_id] = plotspec(
            #was vid = varnom+'_diff',
            vid=ps.dict_id(varnom, 'diff', seasonid, filetable1, filetable2),
            zvars=[vidl1, vidl2],
            zfunc=aminusb_2ax,
            plottype=self.plottype,
            title=' '.join([varstr, seasonid, 'difference']),
            title1=' '.join([varstr, seasonid, 'difference']),
            title2='difference',
            file_descr='diff',
            plotparms=plotparms['diff'])
        #                zerocontour=-1 )
        self.composite_plotspecs = {
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id]
        }
        self.computation_planned = True
Exemplo n.º 13
0
    def plan_computation_normal_contours(self,
                                         model,
                                         obs,
                                         varnom,
                                         seasonid,
                                         aux=None,
                                         names={},
                                         plotparms=None):
        filetable1, filetable2 = self.getfts(model, obs)
        """Set up for a lat-lon contour plot, as in plot set 5.  Data is averaged over all other
        axes."""
        if varnom in filetable1.list_variables():
            vid1, vid1var = self.vars_normal_contours(filetable1,
                                                      varnom,
                                                      seasonid,
                                                      aux=None)
        elif varnom in self.common_derived_variables.keys():
            vid1, vid1var = self.vars_commdervar_normal_contours(filetable1,
                                                                 varnom,
                                                                 seasonid,
                                                                 aux=None)
        else:
            logger.error(
                "variable %s not found in and cannot be computed from %s",
                varnom, filetable1)
            return None
        if filetable2 is not None and varnom in filetable2.list_variables():
            vid2, vid2var = self.vars_normal_contours(filetable2,
                                                      varnom,
                                                      seasonid,
                                                      aux=None)
        elif varnom in self.common_derived_variables.keys():
            vid2, vid2var = self.vars_commdervar_normal_contours(filetable2,
                                                                 varnom,
                                                                 seasonid,
                                                                 aux=None)
        else:
            vid2, vid2var = None, None
        self.single_plotspecs = {}
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        all_plotnames = []

        if filetable1 is not None:
            if vid1 is not None:
                self.single_plotspecs[self.plot1_id] = plotspec(
                    vid=ps.dict_idid(vid1),
                    zvars=[vid1],
                    zfunc=(lambda z: z),
                    plottype=self.plottype,
                    title=' '.join([varnom, seasonid, 'model']),
                    title1=' '.join([varnom, seasonid, 'model']),
                    title2='model',
                    file_descr='model',
                    source=names['model'],
                    plotparms=plotparms[src2modobs(ft1src)])
                all_plotnames.append(self.plot1_id)

            if vid1var is not None:
                self.single_plotspecs[self.plot1var_id] = plotspec(
                    vid=ps.dict_idid(vid1var),
                    zvars=[vid1var],
                    zfunc=(lambda z: z),
                    plottype=self.plottype,
                    title=' '.join([varnom, seasonid, 'model variance']),
                    title1=' '.join([varnom, seasonid, 'model variance']),
                    title2='model variance',
                    file_descr='model variance',
                    source=names['model'],
                    plotparms=plotparms[src2modobs(ft1src)])
                all_plotnames.append(self.plot1var_id)

        if filetable2 is not None and vid2 is not None:
            self.single_plotspecs[self.plot2_id] = plotspec(
                vid=ps.dict_idid(vid2),
                zvars=[vid2],
                zfunc=(lambda z: z),
                plottype=self.plottype,
                title=' '.join([varnom, seasonid, 'obs']),
                title1=' '.join([varnom, seasonid, 'obs']),
                title2="observation",
                file_descr="obs",
                source=names['obs'],
                plotparms=plotparms[src2obsmod(ft2src)])
            all_plotnames.append(self.plot2_id)

        if filetable1 is not None and filetable2 is not None and vid1 is not None and vid2 is not None:
            self.single_plotspecs[self.plot3_id] = plotspec(
                vid=ps.dict_id(varnom, 'diff', seasonid, filetable1,
                               filetable2),
                zvars=[vid1, vid2],
                zfunc=aminusb_2ax,
                plottype=self.plottype,
                title=' '.join([varnom, seasonid, 'difference']),
                title1=' '.join([varnom, seasonid, 'difference']),
                title2='difference',
                file_descr='diff',
                plotparms=plotparms['diff'])
            all_plotnames.append(self.plot3_id)

        if len(all_plotnames) > 0:
            self.composite_plotspecs = {self.plotall_id: all_plotnames}
        else:
            self.composite_plotspecs = {}
        self.computation_planned = True
Exemplo n.º 14
0
    def plan_computation_normal_contours(self, model, obs, varid, seasonid,
                                         aux, plotparms):
        """Set up for a lat-lon contour plot, as in plot set 5.  Data is averaged over all other
        axes."""
        filetable1, filetable2 = self.getfts(model, obs)
        self.derived_variables = {}
        vars_vec1 = {}
        vars_vec2 = {}
        try:
            if varid == 'STRESS' or varid == 'SURF_STRESS' or varid == 'MOISTURE_TRANSPORT':
                vars1,rvars1,dvars1,var_cont1,vars_vec1,vid_cont1 =\
                    self.STRESS_setup( filetable1, varid, seasonid )
                vars2,rvars2,dvars2,var_cont2,vars_vec2,vid_cont2 =\
                    self.STRESS_setup( filetable2, varid, seasonid )
                if vars1 is None and vars2 is None:
                    raise DiagError("cannot find set6 variables in data 2")
            else:
                logger.error("AMWG plot set 6 does not yet support %s", varid)
                return None
        except Exception as e:
            logger.error(
                "cannot find suitable set6_variables in data for varid= %s",
                varid)
            logger.exception(" %s ", e)
            return None
        reduced_varlis = []
        vardict1 = {'': 'nameless_variable'}
        vardict2 = {'': 'nameless_variable'}
        new_reducedvars, needed_derivedvars = self.STRESS_rvs(
            filetable1, rvars1, seasonid, vardict1)
        reduced_varlis += new_reducedvars
        self.reduced_variables = {v.id(): v for v in reduced_varlis}
        self.STRESS_dvs(filetable1, needed_derivedvars, seasonid, vardict1,
                        vid_cont1, vars_vec1)
        new_reducedvars, needed_derivedvars = self.STRESS_rvs(
            filetable2, rvars2, seasonid, vardict2)
        reduced_varlis += new_reducedvars
        self.STRESS_dvs(filetable2, needed_derivedvars, seasonid, vardict2,
                        vid_cont2, vars_vec2)
        self.reduced_variables = {v.id(): v for v in reduced_varlis}

        self.single_plotspecs = {}
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        vid_vec1 = vardict1[','.join([vars_vec1[0], vars_vec1[1]])]
        vid_vec11 = vardict1[vars_vec1[0]]
        vid_vec12 = vardict1[vars_vec1[1]]
        vid_vec2 = vardict2[','.join([vars_vec2[0], vars_vec2[1]])]
        vid_vec21 = vardict2[vars_vec2[0]]
        vid_vec22 = vardict2[vars_vec2[1]]
        plot_type_temp = [
            'Isofill', 'Vector'
        ]  # can't use self.plottype yet because don't support it elsewhere as a list or tuple <<<<<
        if vars1 is not None:
            # Draw two plots, contour and vector, over one another to get a single plot.
            # Only one needs to plot title,source; but both need source to get the filenames right.
            title = ' '.join([varid, seasonid, '(1)'])

            contplot = plotspec(vid=ps.dict_idid(vid_cont1),
                                zvars=[vid_cont1],
                                zfunc=(lambda z: z),
                                plottype=plot_type_temp[0],
                                title=title,
                                source=ft1src,
                                plotparms=plotparms[src2modobs(ft1src)])
            vecplot = plotspec(vid=ps.dict_idid(vid_vec1),
                               zvars=[vid_vec11, vid_vec12],
                               zfunc=(lambda z, w: (z, w)),
                               plottype=plot_type_temp[1],
                               title1='',
                               title2='',
                               source=ft1src,
                               plotparms=plotparms[src2modobs(ft1src)])
            #self.single_plotspecs[self.plot1_id] = [contplot,vecplot]
            self.single_plotspecs[self.plot1_id + 'c'] = contplot
            self.single_plotspecs[self.plot1_id + 'v'] = vecplot
        if vars2 is not None:
            # Draw two plots, contour and vector, over one another to get a single plot.
            # Only one needs title,source.
            title = ' '.join([varid, seasonid, '(2)'])
            contplot = plotspec(vid=ps.dict_idid(vid_cont2),
                                zvars=[vid_cont2],
                                zfunc=(lambda z: z),
                                plottype=plot_type_temp[0],
                                title=title,
                                source=ft2src,
                                plotparms=plotparms[src2obsmod(ft2src)])
            vecplot = plotspec(vid=ps.dict_idid(vid_vec2),
                               zvars=[vid_vec21, vid_vec22],
                               zfunc=(lambda z, w: (z, w)),
                               plottype=plot_type_temp[1],
                               title1='',
                               title2='',
                               source=ft2src,
                               plotparms=plotparms[src2obsmod(ft2src)])
            self.single_plotspecs[self.plot2_id + 'c'] = contplot
            self.single_plotspecs[self.plot2_id + 'v'] = vecplot
        if vars1 is not None and vars2 is not None:
            # First, we need some more derived variables in order to do the contours as a magnitude
            # of the difference vector.
            diff1_vid = dv.dict_id(vid_vec11[1], 'DIFF1', seasonid, filetable1,
                                   filetable2)
            diff1 = derived_var(vid=diff1_vid,
                                inputs=[vid_vec11, vid_vec21],
                                func=aminusb_2ax)
            self.derived_variables[diff1_vid] = diff1
            diff2_vid = dv.dict_id(vid_vec12[1], 'DIFF1', seasonid, filetable1,
                                   filetable2)
            diff2 = derived_var(vid=diff2_vid,
                                inputs=[vid_vec12, vid_vec22],
                                func=aminusb_2ax)

            self.derived_variables[diff2_vid] = diff2
            title = ' '.join([varid, seasonid, 'diff,mag.diff'])
            #source = underscore_join([ft1src,ft2src])
            source = ''

            contplot = plotspec(
                vid=ps.dict_id(var_cont1, 'mag.of.diff', seasonid, filetable1,
                               filetable2),
                zvars=[diff1_vid, diff2_vid],
                zfunc=abnorm,  # This is magnitude of difference of vectors
                plottype=plot_type_temp[0],
                title=title,
                source=source,
                plotparms=plotparms['diff'])
            #contplot = plotspec(
            #    vid = ps.dict_id(var_cont1,'diff.of.mags',seasonid,filetable1,filetable2),
            #    zvars = [vid_cont1,vid_cont2],  zfunc = aminusb_2ax,  # This is difference of magnitudes.
            #    plottype = plot_type_temp[0], title=title, source=source )
            # This could be done in terms of diff1,diff2, but I'll leave it alone for now...
            vecplot = plotspec(
                vid=ps.dict_id(vid_vec2, 'diff', seasonid, filetable1,
                               filetable2),
                zvars=[vid_vec11, vid_vec12, vid_vec21, vid_vec22],
                zfunc=(lambda z1, w1, z2, w2:
                       (aminusb_2ax(z1, z2), aminusb_2ax(w1, w2))),
                plottype=plot_type_temp[1],
                title1='',
                title2='',
                source=source,
                plotparms=plotparms['diff'])
            self.single_plotspecs[self.plot3_id + 'c'] = contplot
            self.single_plotspecs[self.plot3_id + 'v'] = vecplot
        # initially we're not plotting the contour part of the plots....
        self.composite_plotspecs = {
            self.plot1_id: (self.plot1_id + 'c', self.plot1_id + 'v'),
            #self.plot1_id: [ self.plot1_id+'v' ],
            self.plot2_id: (self.plot2_id + 'c', self.plot2_id + 'v'),
            self.plot3_id: (self.plot3_id + 'c', self.plot3_id + 'v'),
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id]
        }
        self.computation_planned = True
Exemplo n.º 15
0
    def plan_computation( self, model, obs, varid, seasonid, names, plotparms ):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1_hyam = filetable1.find_files('hyam')
        if filetable2 is None:
            ft2_hyam = None
        else:
            ft2_hyam = filetable2.find_files('hyam')
        hybrid1 = ft1_hyam is not None and ft1_hyam!=[]    # true iff filetable1 uses hybrid level coordinates
        hybrid2 = ft2_hyam is not None and ft2_hyam!=[]    # true iff filetable2 uses hybrid level coordinates
        #print hybrid1, hybrid2
        #retrieve the 1d and 2d reduction function; either lat & levlat or lon & levlon
        RF_1d, RF_2d = self.reduction_functions[self.number]
        rf_id = self.rf_ids[self.number]
        
        #print RF_1d
        #print RF_2d
        if hybrid1:
            reduced_variables_1 = self.reduced_variables_hybrid_lev(
                filetable1, varid, seasonid, RF1=identity, RF2=identity )
        else:
            reduced_variables_1 = self.reduced_variables_press_lev( filetable1, varid, seasonid, RF2=RF_2d)
        if hybrid2:
            reduced_variables_2 = self.reduced_variables_hybrid_lev(
                filetable2, varid, seasonid, RF1=identity, RF2=identity )
        else:
            reduced_variables_2 = self.reduced_variables_press_lev( filetable2, varid, seasonid, RF2=RF_2d )
        reduced_variables_1.update( reduced_variables_2 )
        self.reduced_variables = reduced_variables_1

        self.derived_variables = {}
        if hybrid1:
            # >>>> actually last arg of the derived var should identify the coarsest level, not nec. 2
            # Note also that it is dangerous to use input data from two filetables (though necessary here) - it
            # can badly mess things up if derive() assigns to the new variable a filetable which is not the
            # main source of the data, meaning its axes.  It gets the filetable from the first input listed here.
            vid1=dv.dict_id(varid,rf_id,seasonid,filetable1)
            self.derived_variables[vid1] = derived_var(
                vid=vid1, inputs=[rv.dict_id(varid,seasonid,filetable1), rv.dict_id('hyam',seasonid,filetable1),
                                  rv.dict_id('hybm',seasonid,filetable1), rv.dict_id('PS',seasonid,filetable1),
                                  rv.dict_id(varid,seasonid,filetable2) ],
                func=(lambda T, hyam, hybm, ps, level_src, seasonid=seasonid, varid=varid:
                                 RF_2d( verticalize(T,hyam,hybm,ps,level_src), season=seasonid, vid=varid ) )
                )
        else:
            vid1 = rv.dict_id(varid,seasonid,filetable1)
        if hybrid2:
            # >>>> actually last arg of the derived var should identify the coarsest level, not nec. 2
            vid2=dv.dict_id(varid,rf_id,seasonid,filetable2)
            self.derived_variables[vid2] = derived_var(
                vid=vid2, inputs=[rv.dict_id(varid,seasonid,filetable2),
                                  rv.dict_id('hyam',seasonid,filetable2),
                                  rv.dict_id('hybm',seasonid,filetable2),
                                  rv.dict_id('PS',seasonid,filetable2),
                                  rv.dict_id(varid,seasonid,filetable2) ],
                func=(lambda T, hyam, hybm, ps, level_src, seasonid=seasonid, varid=varid:
                                 RF_2d( verticalize(T,hyam,hybm,ps,level_src), season=seasonid, vid=varid ) )
                )
        else:
            vid2 = rv.dict_id(varid,seasonid,filetable2)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        self.single_plotspecs = {
            self.plot1_id: plotspec(
                vid = ps.dict_idid(vid1), zvars=[vid1], zfunc=(lambda z: z),
                plottype = self.plottype,
                title = ' '.join([varid,seasonid,'(1)']),
                file_descr = 'model',
                source = names['model'],
                plotparms = plotparms[src2modobs(ft1src)] ),
            self.plot2_id: plotspec(
                vid = ps.dict_idid(vid2), zvars=[vid2], zfunc=(lambda z: z),
                plottype = self.plottype,
                title = ' '.join([varid,seasonid,'(2)']),
                file_descr = 'obs',
                source = names['obs'],
                plotparms = plotparms[src2obsmod(ft2src)] ),
            self.plot3_id: plotspec(
                vid = ps.dict_id(varid,'diff',seasonid,filetable1,filetable2), zvars=[vid1,vid2],
                zfunc=aminusb_2ax, plottype = self.plottype,
                title = ' '.join([varid,seasonid,'(1)-(2)']),
                file_descr = 'diff',
                source = ', '.join([names['model'],names['obs']]),
                plotparms = plotparms['diff'] )
            }
        self.composite_plotspecs = {
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id ]
            }
        self.computation_planned = True
Exemplo n.º 16
0
    def plan_computation(self,
                         model,
                         obs,
                         varid,
                         seasonid,
                         region=None,
                         aux=slice(0, None),
                         names={},
                         plotparms=None):
        """Set up for a lat-lon polar contour plot.  Data is averaged over all other axes.
       """
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        if region is not None:
            regname = str(region)
        else:
            regname = None
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        reduced_varlis = [
            reduced_variable(
                variableid=varid,
                filetable=filetable1,
                season=self.season,
                region=regname,
                reduction_function=(lambda x, vid, region=regname, aux1=aux:
                                    reduce2latlon_seasonal(x(
                                        latitude=aux1, longitude=(0, 360)),
                                                           self.season,
                                                           region,
                                                           vid=vid))),
            reduced_variable(
                variableid=varid,
                filetable=filetable2,
                season=self.season,
                region=regname,
                reduction_function=(lambda x, vid, region=regname, aux1=aux:
                                    reduce2latlon_seasonal(x(
                                        latitude=aux1, longitude=(0, 360)),
                                                           self.season,
                                                           region,
                                                           vid=vid)))
        ]
        self.reduced_variables = {v.id(): v for v in reduced_varlis}
        vid1 = rv.dict_id(varid, seasonid, filetable1, region=regname)
        vid2 = rv.dict_id(varid, seasonid, filetable2, region=regname)

        self.derived_variables = {}
        self.single_plotspecs = {
            self.plot1_id:
            plotspec(vid=ps.dict_idid(vid1),
                     zvars=[vid1],
                     zfunc=(lambda z: z),
                     plottype=self.plottype,
                     source=names.get('model', ft1src),
                     file_descr='model',
                     plotparms=plotparms[src2modobs(ft1src)]),
            self.plot2_id:
            plotspec(vid=ps.dict_idid(vid2),
                     zvars=[vid2],
                     zfunc=(lambda z: z),
                     plottype=self.plottype,
                     source=names.get('obs', ft2src),
                     file_descr='obs',
                     plotparms=plotparms[src2obsmod(ft2src)]),
            self.plot3_id:
            plotspec(vid=ps.dict_id(varid, 'diff', seasonid, filetable1,
                                    filetable2),
                     zvars=[vid1, vid2],
                     zfunc=aminusb_2ax,
                     plottype=self.plottype,
                     source=', '.join([
                         names.get('model', ft1src),
                         names.get('obs', ft2src)
                     ]),
                     file_descr='diff',
                     plotparms=plotparms['diff'])
        }
        self.composite_plotspecs = {
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id]
        }
        self.computation_planned = True
Exemplo n.º 17
0
    def plan_computation(self, model, obs, varid, seasonid, plotparms):
        filetable1, filetable2 = self.getfts(model, obs)
        ft1src = filetable1.source()
        try:
            ft2src = filetable2.source()
        except:
            ft2src = ''
        self.computation_planned = False
        #check if there is data to process
        ft1_valid = False
        ft2_valid = False
        if filetable1 is not None and filetable2 is not None:
            ft1 = filetable1.find_files(varid)
            ft2 = filetable2.find_files(varid)
            ft1_valid = ft1 is not None and ft1 != [
            ]  # true iff filetable1 uses hybrid level coordinates
            ft2_valid = ft2 is not None and ft2 != [
            ]  # true iff filetable2 uses hybrid level coordinates
        else:
            logger.error("user must specify 2 data files")
            return None
        if not ft1_valid or not ft2_valid:
            return None

        #generate identifiers
        vid1 = rv.dict_id(varid, self._s1, filetable1)
        vid2 = rv.dict_id(varid, self._s2, filetable2)
        vid3 = dv.dict_id(varid, 'SeasonalDifference', self._seasonid,
                          filetable1)  #, ft2=filetable2)

        #setup the reduced variables
        vid1_season = cdutil.times.Seasons(self._s1)
        if vid1_season is None:
            vid1_season = seasonsyr
        vid2_season = cdutil.times.Seasons(self._s2)
        if vid2_season is None:
            vid2_season = seasonsyr

        rv_1 = reduced_variable(
            variableid=varid,
            filetable=filetable1,
            season=vid1_season,
            reduction_function=(lambda x, vid=vid1: reduce2latlon_seasonal(
                x, vid1_season, self.region, vid=vid)))

        rv_2 = reduced_variable(
            variableid=varid,
            filetable=filetable2,
            season=vid2_season,
            reduction_function=(lambda x, vid=vid2: reduce2latlon_seasonal(
                x, vid2_season, self.region, vid=vid)))

        self.reduced_variables = {rv_1.id(): rv_1, rv_2.id(): rv_2}

        #create the derived variable which is the difference
        self.derived_variables = {}
        self.derived_variables[vid3] = derived_var(vid=vid3,
                                                   inputs=[vid1, vid2],
                                                   func=aminusb_2ax)

        self.single_plotspecs = {
            self.plot1_id:
            plotspec(vid=ps.dict_idid(vid1),
                     zvars=[vid1],
                     zfunc=(lambda z: z),
                     plottype=self.plottype,
                     source=ft1src,
                     file_descr='model',
                     plotparms=plotparms[src2modobs(ft1src)]),
            self.plot2_id:
            plotspec(vid=ps.dict_idid(vid2),
                     zvars=[vid2],
                     zfunc=(lambda z: z),
                     plottype=self.plottype,
                     source=ft2src,
                     file_descr='obs',
                     plotparms=plotparms[src2obsmod(ft2src)]),
            self.plot3_id:
            plotspec(vid=ps.dict_idid(vid3),
                     zvars=[vid3],
                     zfunc=(lambda x: x),
                     plottype=self.plottype,
                     source=', '.join([ft1src, ft2src]),
                     file_descr='diff',
                     plotparms=plotparms['diff'])
        }

        self.composite_plotspecs = {
            self.plotall_id: [self.plot1_id, self.plot2_id, self.plot3_id]
        }
        # ...was self.composite_plotspecs = { self.plotall_id: self.single_plotspecs.keys() }
        self.computation_planned = True
Exemplo n.º 18
0
 def plan_computation(self, model, obs, varid, seasonid, plotparms):
     filetable1, filetable2 = self.getfts(model, obs)
     # CAM variables needed for heat transport: (SOME ARE SUPERFLUOUS <<<<<<)
     # FSNS, FLNS, FLUT, FSNTOA, FLNT, FSNT, SHFLX, LHFLX,
     self.reduced_variables = {
         'FSNS_1':
         reduced_variable(variableid='FSNS',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=(lambda x, vid: x)),
         'FSNS_ANN_latlon_1':
         reduced_variable(variableid='FSNS',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'FLNS_1':
         reduced_variable(variableid='FLNS',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=(lambda x, vid: x)),
         'FLNS_ANN_latlon_1':
         reduced_variable(variableid='FLNS',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'FLUT_ANN_latlon_1':
         reduced_variable(variableid='FLUT',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'FSNTOA_ANN_latlon_1':
         reduced_variable(variableid='FSNTOA',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'FLNT_1':
         reduced_variable(variableid='FLNT',
                          filetable=filetable1,
                          reduction_function=(lambda x, vid: x)),
         'FLNT_ANN_latlon_1':
         reduced_variable(variableid='FLNT',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'FSNT_1':
         reduced_variable(variableid='FSNT',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=(lambda x, vid: x)),
         'FSNT_ANN_latlon_1':
         reduced_variable(variableid='FSNT',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'QFLX_1':
         reduced_variable(variableid='QFLX',
                          filetable=filetable1,
                          reduction_function=(lambda x, vid: x)),
         'SHFLX_1':
         reduced_variable(variableid='SHFLX',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=(lambda x, vid: x)),
         'SHFLX_ANN_latlon_1':
         reduced_variable(variableid='SHFLX',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'LHFLX_ANN_latlon_1':
         reduced_variable(variableid='LHFLX',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon),
         'OCNFRAC_ANN_latlon_1':
         reduced_variable(variableid='OCNFRAC',
                          filetable=filetable1,
                          season=self.season,
                          reduction_function=reduce2latlon)
     }
     self.derived_variables = {
         'CAM_HEAT_TRANSPORT_ALL_1':
         derived_var(vid='CAM_HEAT_TRANSPORT_ALL_1',
                     inputs=[
                         'FSNS_ANN_latlon_1', 'FLNS_ANN_latlon_1',
                         'FLUT_ANN_latlon_1', 'FSNTOA_ANN_latlon_1',
                         'FLNT_ANN_latlon_1', 'FSNT_ANN_latlon_1',
                         'SHFLX_ANN_latlon_1', 'LHFLX_ANN_latlon_1',
                         'OCNFRAC_ANN_latlon_1'
                     ],
                     outputs=[
                         'atlantic_heat_transport',
                         'pacific_heat_transport', 'indian_heat_transport',
                         'global_heat_transport'
                     ],
                     func=oceanic_heat_transport),
         'NCEP_OBS_HEAT_TRANSPORT_ALL_2':
         derived_var(vid='NCEP_OBS_HEAT_TRANSPORT_ALL_2',
                     inputs=[],
                     outputs=('latitude', [
                         'atlantic_heat_transport',
                         'pacific_heat_transport', 'indian_heat_transport',
                         'global_heat_transport'
                     ]),
                     func=(lambda: ncep_ocean_heat_transport(filetable2)))
     }
     ft1src = filetable1.source()
     try:
         ft2src = filetable2.source()
     except:
         ft2src = ''
     self.single_plotspecs = {
         'CAM_NCEP_HEAT_TRANSPORT_GLOBAL':
         plotspec(vid='CAM_NCEP_HEAT_TRANSPORT_GLOBAL',
                  zvars=['CAM_HEAT_TRANSPORT_ALL_1'],
                  zfunc=(lambda y: y[3]),
                  z2vars=['NCEP_OBS_HEAT_TRANSPORT_ALL_2'],
                  z2func=(lambda z: z[1][3]),
                  plottype=self.plottype,
                  title='CAM and NCEP HEAT_TRANSPORT GLOBAL',
                  file_descr='',
                  source=ft1src,
                  more_id='Global',
                  plotparms=plotparms[src2modobs(ft1src)]),
         'CAM_NCEP_HEAT_TRANSPORT_PACIFIC':
         plotspec(vid='CAM_NCEP_HEAT_TRANSPORT_PACIFIC',
                  zvars=['CAM_HEAT_TRANSPORT_ALL_1'],
                  zfunc=(lambda y: y[0]),
                  z2vars=['NCEP_OBS_HEAT_TRANSPORT_ALL_2'],
                  z2func=(lambda y: y[1][0]),
                  plottype=self.plottype,
                  title='CAM and NCEP HEAT_TRANSPORT PACIFIC',
                  file_descr='',
                  source=ft1src,
                  more_id='Pacific',
                  plotparms=plotparms[src2modobs(ft1src)]),
         'CAM_NCEP_HEAT_TRANSPORT_ATLANTIC':
         plotspec(vid='CAM_NCEP_HEAT_TRANSPORT_ATLANTIC',
                  zvars=['CAM_HEAT_TRANSPORT_ALL_1'],
                  zfunc=(lambda y: y[1]),
                  z2vars=['NCEP_OBS_HEAT_TRANSPORT_ALL_2'],
                  z2func=(lambda y: y[1][1]),
                  plottype=self.plottype,
                  title='CAM and NCEP HEAT_TRANSPORT ATLANTIC',
                  file_descr='',
                  source=ft1src,
                  more_id='Atlantic',
                  plotparms=plotparms[src2modobs(ft1src)]),
         'CAM_NCEP_HEAT_TRANSPORT_INDIAN':
         plotspec(vid='CAM_NCEP_HEAT_TRANSPORT_INDIAN',
                  zvars=['CAM_HEAT_TRANSPORT_ALL_1'],
                  zfunc=(lambda y: y[2]),
                  z2vars=['NCEP_OBS_HEAT_TRANSPORT_ALL_2'],
                  z2func=(lambda y: y[1][2]),
                  plottype=self.plottype,
                  title='CAM and NCEP HEAT_TRANSPORT INDIAN',
                  file_descr='',
                  source=ft1src,
                  more_id='Indian',
                  plotparms=plotparms[src2modobs(ft1src)]),
     }
     self.composite_plotspecs = {
         'CAM_NCEP_HEAT_TRANSPORT_ALL': [
             'CAM_NCEP_HEAT_TRANSPORT_GLOBAL',
             'CAM_NCEP_HEAT_TRANSPORT_PACIFIC',
             'CAM_NCEP_HEAT_TRANSPORT_ATLANTIC',
             'CAM_NCEP_HEAT_TRANSPORT_INDIAN'
         ]
     }
     self.computation_planned = True