示例#1
0
 def initialize(self, args, **cfg_args):
     self.configure(**cfg_args)
     (grid_file, data_file, interface, varname, grid_coords,
      var_proc_op) = args
     self.gf = cdms2.open(grid_file) if grid_file else None
     self.df = cdms2.open(data_file)
     self.var = self.getProcessedVariable(varname, var_proc_op)
     self.extractMetadata()
     self.grid = self.var.getGrid()
     self.lev = self.getLevel(self.var)
     lon, lat = self.getLatLon(grid_coords)
     if (id(lon) <> id(None)) and (id(lat) <> id(None)):
         self.time = self.var.getTime()
         z_scale = 0.5
         self.missing_value = self.var.attributes.get('missing_value', None)
         if self.lev == None:
             domain = self.var.getDomain()
             for axis in domain:
                 if PlotType.isLevelAxis(axis[0].id.lower()):
                     self.lev = axis[0]
                     break
         self.computePoints()
         self.setPointHeights(height_var=grid_coords[3], z_scale=z_scale)
         np_var_data_block = self.getDataBlock(self.var).flatten()
         if self.missing_value:
             var_data = numpy.ma.masked_equal(np_var_data_block,
                                              self.missing_value, False)
         else:
             var_data = np_var_data_block
         self.point_data_arrays[self.defvar] = var_data
         self.vrange = (var_data.min(), var_data.max())
         self.var_data_cache[self.iTimeStep] = var_data
         self.metadata['vbounds'] = self.vrange
示例#2
0
 def initialize( self, args, **cfg_args ): 
     self.configure( **cfg_args )
     ( grid_file, data_file, interface, varname, grid_coords, var_proc_op ) = args
     self.gf = cdms2.open( grid_file ) if grid_file else None
     self.df = cdms2.open( data_file )       
     self.var = self.getProcessedVariable( varname, var_proc_op )
     self.extractMetadata()
     self.grid = self.var.getGrid()
     self.lev = self.getLevel(self.var)
     lon, lat = self.getLatLon( grid_coords )  
     if ( id(lon) <> id(None) ) and ( id(lat) <> id(None) ):                                 
         self.time = self.var.getTime()
         z_scale = 0.5
         self.missing_value = self.var.attributes.get( 'missing_value', None )
         if self.lev == None:
             domain = self.var.getDomain()
             for axis in domain:
                 if PlotType.isLevelAxis( axis[0].id.lower() ):
                     self.lev = axis[0]
                     break        
         self.computePoints() 
         self.setPointHeights( height_var=grid_coords[3], z_scale=z_scale )
         np_var_data_block = self.getDataBlock(self.var).flatten()     
         if self.missing_value: var_data = numpy.ma.masked_equal( np_var_data_block, self.missing_value, False )
         else: var_data = np_var_data_block
         self.point_data_arrays[ self.defvar ] = var_data
         self.vrange = ( var_data.min(), var_data.max() ) 
         self.var_data_cache[ self.iTimeStep ] = var_data
         self.metadata['vbounds'] = self.vrange
示例#3
0
    def getLatLon(self, grid_coords, **args):
        data_file = self.df
        grid_file = self.gf
        #         if grid_file:
        #             lat = grid_file['lat']
        #             lon = grid_file['lon']
        #             if PlotType.validCoords( lat, lon ):
        #                 return  self.processCoordinates( lat, lon )
        Var = self.var
        axis_ids = self.getAxisIds(Var)
        if axis_ids:
            try:
                if grid_file:
                    lon = grid_file(axis_ids[0], squeeze=1)
                    lat = grid_file(axis_ids[1], squeeze=1)
                else:
                    lon = data_file(axis_ids[0], squeeze=1)
                    lat = data_file(axis_ids[1], squeeze=1)
            except cdms2.error.CDMSError:
                print >> sys.stderr, "Can't find lat/lon coordinate variables in file(s)."
                return None, None
            if PlotType.validCoords(lat, lon):
                return self.processCoordinates(lat, lon)
        elif hasattr(Var, "stagger"):
            stagger = Var.stagger.strip()
            lat = data_file("XLAT_%s" % stagger, squeeze=1)
            lon = data_file("XLONG_%s" % stagger, squeeze=1)
            if PlotType.validCoords(lat, lon):
                return self.processCoordinates(lat, lon)

        lat = Var.getLatitude()
        lon = Var.getLongitude()
        if PlotType.validCoords(lat, lon):
            return self.processCoordinates(lat.getValue(), lon.getValue())

        lon_coord = grid_coords[0]
        lon = data_file(lon_coord, squeeze=1) if lon_coord else None
        lat_coord = grid_coords[1]
        lat = data_file(lat_coord, squeeze=1) if lat_coord else None
        if PlotType.validCoords(lat, lon):
            return self.processCoordinates(lat, lon)

        axis_ids = []
        longitude_names = ['longitude', 'column longitude']
        latitude_names = ['latitude', 'column latitude']
        for axis_spec in Var.getDomain():
            if not (axis_spec[0].isLevel() or axis_spec[0].isTime()):
                axis_ids.append(axis_spec[0].id)
        for dset in [data_file, grid_file]:
            if dset:
                for cvar_name in dset.variables:
                    cvar = dset[cvar_name]
                    cvar_axis_ids = cvar.getAxisIds()
                    if (len(cvar_axis_ids) == 1) and (cvar_axis_ids[0]
                                                      in axis_ids):
                        if hasattr(cvar, 'long_name'):
                            if (cvar.long_name.lower() in longitude_names):
                                lon = dset(cvar.id, squeeze=1)
                            elif (cvar.long_name.lower() in latitude_names):
                                lat = dset(cvar.id, squeeze=1)
                        if hasattr(cvar, 'standard_name'):
                            if (cvar.standard_name.lower() in longitude_names):
                                lon = dset(cvar.id, squeeze=1)
                            elif (cvar.standard_name.lower()
                                  in latitude_names):
                                lat = dset(cvar.id, squeeze=1)
        if PlotType.validCoords(lat, lon):
            return self.processCoordinates(lat, lon)
        print >> sys.stdout, "Error, Can't find grid axes!"
        return None, None
示例#4
0
 def getPointsLayout(self):
     return PlotType.getPointsLayout(self.grid)
示例#5
0
    def getLatLon( self, grid_coords, **args ):
        data_file = self.df
        grid_file = self.gf
#         if grid_file:
#             lat = grid_file['lat']
#             lon = grid_file['lon']
#             if PlotType.validCoords( lat, lon ): 
#                 return  self.processCoordinates( lat, lon )
        Var = self.var        
        axis_ids = self.getAxisIds( Var )
        if axis_ids:
            try:
                if grid_file:
                    lon = grid_file( axis_ids[0], squeeze=1 )
                    lat = grid_file( axis_ids[1], squeeze=1 )  
                else:
                    lon = data_file( axis_ids[0], squeeze=1 )
                    lat = data_file( axis_ids[1], squeeze=1 )  
            except cdms2.error.CDMSError:
                print>>sys.stderr, "Can't find lat/lon coordinate variables in file(s)."
                return None, None
            if PlotType.validCoords( lat, lon ): 
                return  self.processCoordinates( lat, lon )
        elif hasattr( Var, "stagger" ):
            stagger = Var.stagger.strip()
            lat = data_file( "XLAT_%s" % stagger, squeeze=1 )  
            lon = data_file( "XLONG_%s" % stagger, squeeze=1 )
            if PlotType.validCoords( lat, lon ): 
                return  self.processCoordinates( lat, lon )

        lat = Var.getLatitude()  
        lon = Var.getLongitude()
        if PlotType.validCoords( lat, lon ): 
            return  self.processCoordinates( lat.getValue(), lon.getValue() )
        
        lon_coord = grid_coords[0] 
        lon = data_file( lon_coord, squeeze=1 ) if lon_coord else None
        lat_coord = grid_coords[1] 
        lat = data_file( lat_coord, squeeze=1 )  if lat_coord else None 
        if PlotType.validCoords( lat, lon ): 
            return  self.processCoordinates( lat, lon )   
        
        axis_ids = []
        longitude_names = [ 'longitude', 'column longitude' ]
        latitude_names = [ 'latitude', 'column latitude' ]
        for axis_spec in Var.getDomain():
            if not ( axis_spec[0].isLevel() or axis_spec[0].isTime() ):
                axis_ids.append( axis_spec[0].id ) 
        for dset in [ data_file, grid_file ]:
            if dset:
                for cvar_name in dset.variables:
                    cvar = dset[ cvar_name ]
                    cvar_axis_ids = cvar.getAxisIds()
                    if ( len( cvar_axis_ids ) == 1 ) and ( cvar_axis_ids[0] in axis_ids ):
                        if hasattr( cvar, 'long_name' ):
                            if ( cvar.long_name.lower() in longitude_names ):
                                lon = dset( cvar.id, squeeze=1 )   
                            elif ( cvar.long_name.lower() in latitude_names ):
                                lat = dset( cvar.id, squeeze=1 )   
                        if hasattr( cvar, 'standard_name' ):
                            if ( cvar.standard_name.lower() in longitude_names ):
                                lon = dset( cvar.id, squeeze=1 )   
                            elif ( cvar.standard_name.lower() in latitude_names ):
                                lat = dset( cvar.id, squeeze=1 )   
        if PlotType.validCoords( lat, lon ): 
            return  self.processCoordinates( lat, lon ) 
        print>>sys.stdout, "Error, Can't find grid axes!"  
        return None, None
示例#6
0
 def getPointsLayout( self ):
     return PlotType.getPointsLayout( self.grid )