Exemple #1
0
    def __init__(self):
        """default pyFileReader constructor

		This initializer calls the base class initializer.
		The variables dictionary is initialized here and is expected to be populated by the subclassing reader.
		"""
        super(pyFileReader, self).__init__()
        self.variables = {}  #created in subclass
        self.variableIDs = {}  #maps from variable string names to long ids
        self.variableNames = {}  #maps from long ids to string names
        self.globalAttributes = OrderedDict(
        )  #maps from attribute str names to global attribute objects
        self.globalAttributeNames = {}  #maps from ids to str names
        self.globalAttributeIDs = {}  #maps from str names to ids
        self.variableAttributes = {
        }  #maps from variable str names to dictionaries of variable attributes
        self.variableAttributeNames = {}  #maps from attribute IDs to name
        self.variableAttributeIDs = {}  #maps from attribute names to IDs
        self.globalAttributes['model_name'] = Attribute(
            'model_name', 'python_base_model')
        self.globalAttributes['python_model'] = Attribute('python_model', 1)
        self.debug = False
        self.missing_value = -256. * -256. * -256. * -256. * -256.  #same as ccmc::defaults::missingValue
        self.dummy_variable = pyKameleon.vectorFloat()
        self.dummy_variable.append(0)
Exemple #2
0
	def getVariable(self, variable, startIndex = None, count = None):
		'''copy float variable into memory'''
		var_name = self.getVariableName(variable)
		if self.debug: print "\tpyFileReader.getVariable returning variable", var_name
		if self.variables[var_name] is None:
			self.variables[var_name] = pyKameleon.vectorFloat()
			self.variables[var_name].extend(self.file_tree['variables'][var_name]['data'].flatten())
		return self.variables[var_name]
 def getVariable(self, variable, startIndex=None, count=None):
     '''copy float variable into memory'''
     var_name = self.getVariableName(variable)
     if self.debug:
         print "\tpyFileReader.getVariable returning variable", var_name
     if self.variables[var_name] is None:
         self.variables[var_name] = pyKameleon.vectorFloat()
         self.variables[var_name].extend(
             self.file_tree['variables'][var_name]['data'].flatten())
     return self.variables[var_name]
Exemple #4
0
def fillRandom(type='float', count=30):
    import random
    if type == 'float':
        vector = pyKameleon.vectorFloat()
        for i in range(count):
            vector.append(random.random())
        return vector
    if type == 'int':
        vector = pyKameleon.vectorInt()
        for i in range(count):
            vector.append(int(5 * random.random()))
        return vector
Exemple #5
0
def fillRandom(type = 'float', count = 30):
	import random
	if type == 'float':
		vector = pyKameleon.vectorFloat()
		for i in range(count):
			vector.append(random.random())
		return vector
	if type == 'int':
		vector = pyKameleon.vectorInt()
		for i in range(count):
			vector.append(int(5*random.random()))
		return vector
Exemple #6
0
def read_binary_file(variable_file):
    """ Reads an rcm binary file. All RCM data files include a label for each record before the variable data
		This is RCM's definition of the label structure (bytes sum to 240):
		    TYPE :: label_def
		       INTEGER (iprec)   :: intg (20)
		       REAL (rprec)      :: real (20)
		       CHARACTER(LEN=80) :: char  
		       """

    # dt = numpy.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])

    f = open()
    x = numpy.fromfile()

    vector = pyKameleon.vectorFloat()

    return vector
    '''
Exemple #7
0
def read_binary_file(variable_file):
	""" Reads an rcm binary file. All RCM data files include a label for each record before the variable data
		This is RCM's definition of the label structure (bytes sum to 240):
		    TYPE :: label_def
		       INTEGER (iprec)   :: intg (20)
		       REAL (rprec)      :: real (20)
		       CHARACTER(LEN=80) :: char  
		       """


	# dt = numpy.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])

	f = open()
	x = numpy.fromfile()

	vector = pyKameleon.vectorFloat()

	return vector

	'''
Exemple #8
0
	def __init__(self):
		"""default pyFileReader constructor

		This initializer calls the base class initializer.
		The variables dictionary is initialized here and is expected to be populated by the subclassing reader.
		""" 
		super(pyFileReader, self).__init__()
		self.variables = {} #created in subclass
		self.variableIDs = {} #maps from variable string names to long ids
		self.variableNames = {} #maps from long ids to string names
		self.globalAttributes = OrderedDict() #maps from attribute str names to global attribute objects
		self.globalAttributeNames = {} #maps from ids to str names
		self.globalAttributeIDs = {} #maps from str names to ids
		self.variableAttributes = {} #maps from variable str names to dictionaries of variable attributes
		self.variableAttributeNames = {} #maps from attribute IDs to name
		self.variableAttributeIDs = {} #maps from attribute names to IDs
		self.globalAttributes['model_name']  = Attribute('model_name', 'python_base_model')
		self.globalAttributes['python_model'] = Attribute('python_model',1)
		self.debug = False
		self.missing_value = -256.*-256.*-256.*-256.*-256. #same as ccmc::defaults::missingValue
		self.dummy_variable = pyKameleon.vectorFloat()
		self.dummy_variable.append(0)
def readVariableFromFile(filename, variable):
	vector = pyKameleon.vectorFloat()
	for i in range(30):
		vector.append(random.random())

	return vector
Exemple #10
0
def readVariableFromFile(filename, variable):
	vector = pyKameleon.vectorFloat()
	for i in range(30):
		vector.append(random.random())

	return vector