Exemple #1
0
    def setAxesDesc(self,
                    template='',
                    x='',
                    y='',
                    z='',
                    r='',
                    theta='',
                    phi=''):

        from string import lower
        from gfuncs import error

        if lower(template) == 'ISO 31-11':
            r, theta, phi = 'Radial distance', 'Inclination angle', 'Azimuthal angle'

        elif lower(template) == 'hugin':
            x, y, z = 'Along track', 'Cross track', 'Depth'
            r, theta, phi = 'Range', 'Look angle', 'Slant angle'

        if self.desc == 'Cartesian':
            self.units = (x, y, z)
        elif self.desc == 'Spherical':
            self.units = (r, theta, phi)
        else:
            error(self, 'Unknown coordinate system.')
Exemple #2
0
   def load(self, desc=''):
      db = Configurable.__db__
      
      conf = db.open(type='configuration', mode='r')
      db.close('configuration')
      
      if not desc in conf:
         error(self, 'A configuration with the description \''+desc+'\' does not exist')
         raise Exception('')
         return

#      id = self.getConfId(desc, conf)
#      if id != None:
#         self.__id__ = id
#      else:
#         error(self, 'A configuration with the description \''+desc+'\' does not exist')
               
      # Remove the date and description
      conf[desc].pop('date')
      conf[desc].pop('desc')

      # Open the database
      db_root = db.open(type='system', mode='a')
      
      # Let the fun begin getattr(db_root,'i%d'%self.__id__)
      Configurable.__load__(self, db_root, conf[desc]['s'])
            
      # Close the database
      db.close() 

      Configurable.__refreshEclipse__(self)
Exemple #3
0
    def load(self, desc=''):
        db = Configurable.__db__

        conf = db.open(type='configuration', mode='r')
        db.close('configuration')

        if not desc in conf:
            error(
                self, 'A configuration with the description \'' + desc +
                '\' does not exist')
            raise Exception('')
            return

#      id = self.getConfId(desc, conf)
#      if id != None:
#         self.__id__ = id
#      else:
#         error(self, 'A configuration with the description \''+desc+'\' does not exist')

# Remove the date and description
        conf[desc].pop('date')
        conf[desc].pop('desc')

        # Open the database
        db_root = db.open(type='system', mode='a')

        # Let the fun begin getattr(db_root,'i%d'%self.__id__)
        Configurable.__load__(self, db_root, conf[desc]['s'])

        # Close the database
        db.close()

        Configurable.__refreshEclipse__(self)
Exemple #4
0
    def save(self, node, key, val, type='data'):
        '''
      obj_key      The variable that points to the object being stored
      obj_type     The type of the object being stored
      id      The configuration number being used
      keys         The variables in the object
      vals         and their values
      '''

        # If a groupname is supplied, open/create it and enter that group
        if type == 'group' and pl.is_string_like(key):
            try:
                node = self.h5f.getNode(node, key)
            except:
                node = self.h5f.createGroup(node, key, filters=self.FILTERS)

        # If an id is supplied, make a group for it and enter that group
        elif type == 'id' and pl.is_numlike(key):
            try:
                node = self.h5f.getNode(node, "i%d" % key)
            except:
                node = self.h5f.createGroup(node,
                                            "i%d" % key,
                                            filters=self.FILTERS)

        # When data is supplied, add it (and overwrite any data that was there before)
        elif type == 'data':
            if key == None:
                key = 'None'
            elif not pl.is_string_like(key):
                error(self, 'This should not happen...')

            try:
                self.h5f.removeNode(node, key)
            except:
                pass

            if issubclass(val.__class__, np.ndarray):

                # Empty tuples not supported by pytables. Fix by reshaping to (1,)
                if val.shape == ():
                    val = val.reshape((1, ))

                atom = tb.Atom.from_dtype(val.dtype)
                new_node = self.h5f.createCArray(node,
                                                 key,
                                                 atom,
                                                 val.shape,
                                                 filters=self.FILTERS)
                new_node[:] = val[:]

            else:
                self.h5f.createArray(node, key, val)

        else:
            error(self, 'Hmm? Either \'type\' or \'key\' is of shitty format.')
            node = self.h5f.root

        return node
Exemple #5
0
 def __new__(self, type='rect', **kwargs):
     from gfuncs import error
     if type == 'rect':
         return self.rect(self, kwargs)
     elif type == 'kaiser':
         return self.kaiser(kwargs)
     else:
         error(self, 'The window type %s is not recognised' % type)
Exemple #6
0
    def setAxesUnits(self, x='m', y='m', z='m', r='m', theta='rad', phi='rad'):
        from gfuncs import error

        if self.desc == 'Cartesian':
            self.units = (x, y, z)
        elif self.desc == 'Spherical':
            self.units = (r, theta, phi)
        else:
            error(self, 'Unknown coordinate system.')
Exemple #7
0
 def setAxesUnits(self, x='m',y='m',z='m',r='m',theta='rad',phi='rad'):
    from gfuncs import error
    
    if self.desc == 'Cartesian':
       self.units = (x,y,z)
    elif self.desc == 'Spherical':
       self.units = (r,theta,phi)
    else:
       error(self, 'Unknown coordinate system.')
Exemple #8
0
   def save(self, node, key, val, type='data'):
      '''
      obj_key      The variable that points to the object being stored
      obj_type     The type of the object being stored
      id      The configuration number being used
      keys         The variables in the object
      vals         and their values
      '''
               
      # If a groupname is supplied, open/create it and enter that group
      if type=='group' and pl.is_string_like(key):
         try:
            node = self.h5f.getNode(node, key)
         except:
            node = self.h5f.createGroup(node, key, filters=self.FILTERS)
      
      # If an id is supplied, make a group for it and enter that group
      elif type=='id' and pl.is_numlike(key):
         try:
            node = self.h5f.getNode(node, "i%d"%key)
         except:
            node = self.h5f.createGroup(node, "i%d"%key, filters=self.FILTERS)
      
      # When data is supplied, add it (and overwrite any data that was there before)
      elif type=='data':
         if key == None:
            key = 'None'
         elif not pl.is_string_like(key):
            error(self, 'This should not happen...')
                        
         try:
            self.h5f.removeNode(node, key)
         except:
            pass
         
         
         if issubclass(val.__class__, np.ndarray):
            
            # Empty tuples not supported by pytables. Fix by reshaping to (1,)
            if val.shape == ():
               val = val.reshape((1,))
                      
            atom = tb.Atom.from_dtype(val.dtype)
            new_node = self.h5f.createCArray(node, key, atom, val.shape, filters=self.FILTERS)
            new_node[:] = val[:]
            
         else:
            self.h5f.createArray(node, key, val)

         
      else:
         error(self, 'Hmm? Either \'type\' or \'key\' is of shitty format.')
         node = self.h5f.root
 
      
         
      return node
Exemple #9
0
def delay(system=None, X=None):
   
   # If a system is supplied, attempt to find the relevant parameters
   if system != None:
      try:
         X = system.findAttr('X')
      except:
         error('Unable to find the relevant parameters in supplied system. Aborting.')
         pass
   
   if X==None:
      error('One or more of the required parameters are \'None\'. Aborting.')
      return
Exemple #10
0
 def setAxesDesc(self, template='',
                       x='',y='',z='',
                       r='',theta='',phi=''):
    
    from string import lower
    from gfuncs import error
    
    if lower(template)=='ISO 31-11':
       r,theta,phi = 'Radial distance', 'Inclination angle', 'Azimuthal angle'
    
    elif lower(template)=='hugin':
       x,y,z = 'Along track', 'Cross track', 'Depth'
       r,theta,phi = 'Range', 'Look angle', 'Slant angle'
       
    if self.desc == 'Cartesian':
       self.units = (x,y,z)
    elif self.desc == 'Spherical':
       self.units = (r,theta,phi)
    else:
       error(self, 'Unknown coordinate system.')
Exemple #11
0
   def loadConf(self, conf, *args):
      
      # Check the supplied object type
      if conf.__class__.__name__ != 'Config':
         error(self, 'Supplied object is not of type \'Config\'')
         return
      
      # Process the optional arguments
#      default_opts = {}
#      opts = processArgs(args, default_opts)
      
      ok_list = ''
      fail_list = ''
      has_id = False
      
      # Iterate over all class instance variables
      for key,val in self.__dict__.iteritems():
         
         # If the variable is another configurable class, call its loadConf()
         if issubclass(val.__class__, Configurable):
            val.loadConf(conf)
         else:
            
            # Check that a configuration record exists for this class
            self_name = self.__class__.__name__
            if not conf.has_key(self_name):
               warning(self, 'This class has no conf-record.')
            
            # If it exists, retrieve the data
            else:
               if conf[self_name].has_key(key):
                  setattr(self, key, conf[self_name][key])
                  ok_list += ' '+key
                  if key == 'id':
                     has_id = True
               else:
                  fail_list += ' '+key
      
      warning(self,'')
      print '    OK: '+ok_list
      print '    NA: '+fail_list#   '+self_name+': '+key
Exemple #12
0
    def loadConf(self, conf, *args):

        # Check the supplied object type
        if conf.__class__.__name__ != 'Config':
            error(self, 'Supplied object is not of type \'Config\'')
            return

        # Process the optional arguments
#      default_opts = {}
#      opts = processArgs(args, default_opts)

        ok_list = ''
        fail_list = ''
        has_id = False

        # Iterate over all class instance variables
        for key, val in self.__dict__.iteritems():

            # If the variable is another configurable class, call its loadConf()
            if issubclass(val.__class__, Configurable):
                val.loadConf(conf)
            else:

                # Check that a configuration record exists for this class
                self_name = self.__class__.__name__
                if not conf.has_key(self_name):
                    warning(self, 'This class has no conf-record.')

                # If it exists, retrieve the data
                else:
                    if conf[self_name].has_key(key):
                        setattr(self, key, conf[self_name][key])
                        ok_list += ' ' + key
                        if key == 'id':
                            has_id = True
                    else:
                        fail_list += ' ' + key

        warning(self, '')
        print '    OK: ' + ok_list
        print '    NA: ' + fail_list  #   '+self_name+': '+key
Exemple #13
0
    def open(self, type='system', mode='r'):

        if type == 'system':

            # Make sure the file is not open, and return the root node
            if not self.db_open:
                self.h5f = tb.openFile(self.DATABASE_FILE, mode=mode)
                self.db_open = True
                return self.h5f.getNode(self.h5f.root)
            else:
                error(self, 'System database is already open. Close it first.')

        elif type == 'configuration':

            # Create the file if it does not exist
            if not os.path.exists(self.CONFIGURATION_FILE):
                self.cf = open(self.CONFIGURATION_FILE, mode='w')
                empty_dict = {}
                pickle.dump(empty_dict, self.cf)
                self.cf.close()

            # Make sure the file is not already open, then return the file pointer
            if not self.conf_open:
                self.cf = open(self.CONFIGURATION_FILE, mode=mode)
                self.conf_open = True
                if mode == 'r':
                    try:
                        return pickle.load(self.cf)
                    except:
                        info(
                            self, 'Loaded empty file \'' +
                            self.CONFIGURATION_FILE + '\'')
                        return {}
            else:
                error(self, 'System database is already open. Close it first.')

        else:
            error(self, 'Database type \'' + type + '\' is unknown.')
Exemple #14
0
   def open(self, type='system', mode='r'):

      
      if type == 'system':
         
         # Make sure the file is not open, and return the root node
         if not self.db_open:
            self.h5f = tb.openFile( self.DATABASE_FILE, mode=mode )
            self.db_open = True
            return self.h5f.getNode( self.h5f.root )
         else:
            error(self, 'System database is already open. Close it first.')
            
      elif type == 'configuration':
         
         # Create the file if it does not exist
         if not os.path.exists(self.CONFIGURATION_FILE):
            self.cf = open( self.CONFIGURATION_FILE, mode='w' )
            empty_dict = {}
            pickle.dump(empty_dict,self.cf)
            self.cf.close()
         
         # Make sure the file is not already open, then return the file pointer
         if not self.conf_open:
            self.cf = open( self.CONFIGURATION_FILE, mode=mode )
            self.conf_open = True
            if mode == 'r':
               try:
                  return pickle.load(self.cf)
               except:
                  info(self, 'Loaded empty file \''+self.CONFIGURATION_FILE+'\'')
                  return {}
         else:
            error(self, 'System database is already open. Close it first.')
                  
      else:
         error(self, 'Database type \''+type+'\' is unknown.')
Exemple #15
0
 def flush(self):
     if self.db_open == True:
         self.h5f.flush()
     else:
         error(self, 'Flushing not supported for this db-type.')
Exemple #16
0
def W(p=None, w=None, k=None, fc=100e3, c=1480, N=500):
   
   if p==None:
      error('\'p\' are missing. Aborting.')
      return
   
   if k!=None:
      k_abs = k
   
   elif p!=None and fc!=None and c!=None:
      k_abs = 2*pi*fc/c
      
   else:
      error('Either \'k\', or \'c\' and \'fc\' must be supplied. Aborting.')
      return
   
   

   theta       = np.linspace(-0.5,0.5,N)*pi
   
   k           = Coordinate(r=k_abs, theta=theta, phi=None)
   
   def compute_W(ax,ay,az, w):
      Wx          = dot( ax, w )
      Wy          = dot( ay, w )
      Wz          = dot( az, w )

      Wxyz = vstack((Wx,Wy,Wz)).T
      
      return Wxyz
   
#   pT = p.T.copy()
   ax = exp(1j*outer( k[:,0], p[:,0]))
   ay = exp(1j*outer( k[:,1], p[:,1]))
   az = exp(1j*outer( k[:,2], p[:,2]))
   
   if type(w) == list:
      W = []
      for wi in w:
         W.append(compute_W(ax,ay,az, wi))
   elif is_np_array_type(w.__class__):
      if w.ndim == 1:
         W = []
         W.append( compute_W(ax,ay,az,w) )
      elif w.ndim == 2:
         W1 = compute_W(ax,ay,az,w[0])
         W = np.zeros((w.shape[0],W1.shape[0],W1.shape[1]),dtype=W1.dtype)
         W[0] = W1
         for i in range(1,w.shape[0]):
            W[i] = compute_W(ax,ay,az, w[i])
      elif w.ndim == 3:
         W1 = compute_W(ax,ay,az,w[0,0]) # Not exactly efficient, but shouldn't be noticeable
         W = np.zeros((w.shape[0],w.shape[1],W1.shape[0],W1.shape[1]),dtype=W1.dtype)
         for i in range(0,w.shape[0]):
            for j in range(0,w.shape[1]):
               W[i,j] = compute_W(ax,ay,az, w[i,j])
         
      else:
         print 'EE: Not implemented.'
      
   else:
      W = []
      W.append( compute_W(ax,ay,az,w) )
      
  
   return W
Exemple #17
0
 def dump(self, data):
    if self.conf_open == True:
       pickle.dump(data, self.cf)
    else:
       error(self, 'This db-type does not support dumping.')
Exemple #18
0
 def dump(self, data):
     if self.conf_open == True:
         pickle.dump(data, self.cf)
     else:
         error(self, 'This db-type does not support dumping.')
Exemple #19
0
 def flush(self):
    if self.db_open == True:
       self.h5f.flush()
    else:
       error(self, 'Flushing not supported for this db-type.')