Exemplo n.º 1
0
	def openFile(self, config_file, readonly = True):
		if self.debug: print '\t\treadARMS.openFile loading config file..'
		if config_file != None:
			try:
				self._config = testReader.getConfig(config_file)
				self.set_config_globals()
				self.set_file_names()
				self.set_preferred_coordinates()
				model_name = str(testReader.get_config_value(self._config,'Reader', 'ModelName'))
				if self.debug: print '\t\t\tresetting model_name attribute to', model_name
				self.globalAttributes['model_name'] = Attribute('model_name', model_name)
			except:
				raise

		if self.debug: print '\t\treadARMS.openFile setting current filename'
		self.current_filename = self.data_file_name
		self.read_ARMS_header(self.header_file_name) #defines variableNames

		if self.debug: print '\t\treadARMS.openFile initializing variable IDs and attributes'
		self.initializeVariableIDs()
		self.initializeVariableAttributeIDs()

		variables = self.variableNames.values()
		readARMS.variables_tuple = collections.namedtuple('Variables', variables) #so interpolate_variables can access it
		self.initializeGlobalAttributeIDs() #why did I comment this out?
		
		return pyKameleon.FileReader.OK
Exemplo n.º 2
0
	def set_preferred_coordinates(self):
		try:
			preferred_coords = testReader.get_config_value(self._config, 'Reader', 'PreferredCoordinates')
			if preferred_coords in ['ARMS', 'CART', 'SPHEXP']:
				self.preferred_coordinates = preferred_coords
			else:
				self.preferred_coordinates = 'ARMS'
		except KeyError:
			self.preferred_coordinates = 'ARMS'
Exemplo n.º 3
0
	def set_file_names(self):
		self.header_file_name = testReader.get_config_value(self._config, 'Files', 'HeaderFile')
		self.data_file_name = testReader.get_config_value(self._config, 'Files', 'DataFile')
Exemplo n.º 4
0
	def read_ARMS_header(self, header_filename):
		"""Read gloabl attributes from file """
		self.header_file = open(header_filename, 'r')

		# get time step
		line = self.header_file.readline().split()
		time = line[0]

		#can get date from config
		date = str(testReader.get_config_value(self._config,'MetaData', 'Date'))
		self.globalAttributes['timestep_time'] = Attribute('timestep_time', date+'T'+time+'.000Z')

		# get grid type
		line = self.header_file.readline().split()
		self.grid_type = line[0]
		self.globalAttributes['grid_type'] = Attribute('grid_type', self.grid_type)

		if self.grid_type == 'Spherical_Exponential':
			components = ['R', 'T', 'P']
		else:
			print self.grid_type, 'not supported!'
			raise Exception("grid type not supported!")
			components = ['x', 'y', 'z'] # just guessing here...

		# get Block sizes
		for i in range(3):
			dim_size, dim_name = self.header_file.readline().split()
			self.globalAttributes[dim_name] = Attribute(dim_name, int(dim_size))


		#initialize variables
		var_num = 0
		
		line = ' '
		while len(line) > 0:
			line = self.header_file.readline().split()
			if len(line) == 0:
				break
			else:
				number_components, var_base_name = line
			
			if int(number_components) == 1:
				self.addVariableName(var_base_name, var_num)

				# get variable units
				val, attr = self.header_file.readline().split() 
				self.variableAttributes[var_base_name]['units'] = Attribute('units', val)

				# get variable scale factor
				val, attr = self.header_file.readline().split()
				self.variableAttributes[var_base_name]['scale_factor'] = Attribute('scale_factor', float(val))

				# get min and max values (what are the valid_min valid_max values???)
				val, attr = self.header_file.readline().split()
				self.variableAttributes[var_base_name]['actual_min'] = Attribute('actual_min', float(val))

				val, attr = self.header_file.readline().split()
				self.variableAttributes[var_base_name]['actual_max'] = Attribute('actual_max', float(val))

				var_num += 1
			else:
				# get variable units
				units, attr = self.header_file.readline().split() 

				# get variable scale factor
				scale_factor, attr = self.header_file.readline().split()


				for i in range(int(number_components)+1):
					if i == int(number_components):
						val, attr = self.header_file.readline().split()
						self.globalAttributes[var_base_name+'_mag_min'] = Attribute(var_base_name+'_mag_min', float(val))

						val, attr = self.header_file.readline().split()
						self.globalAttributes[var_base_name+'_mag_max'] = Attribute(var_base_name+'_mag_max', float(val))

						
					else:
						var_name = var_base_name + '_' + components[i]

						self.addVariableName(var_name, var_num)
						self.variableAttributes[var_name]['units'] = Attribute('units', units)
						self.variableAttributes[var_name]['scale_factor'] = Attribute('scale_factor', float(scale_factor))

						# get min and max values (what are the valid_min valid_max values???)
						val, attr = self.header_file.readline().split()
						self.variableAttributes[var_name]['actual_min'] = Attribute('actual_min', float(val))

						val, attr = self.header_file.readline().split()
						self.variableAttributes[var_name]['actual_max'] = Attribute('actual_max', float(val))

						var_num += 1
Exemplo n.º 5
0
 def set_file_names(self):
     self.header_file_name = testReader.get_config_value(
         self._config, 'Files', 'HeaderFile')
     self.data_file_name = testReader.get_config_value(
         self._config, 'Files', 'DataFile')
Exemplo n.º 6
0
    def read_ARMS_header(self, header_filename):
        """Read gloabl attributes from file """
        self.header_file = open(header_filename, 'r')

        # get time step
        line = self.header_file.readline().split()
        time = line[0]

        #can get date from config
        date = str(
            testReader.get_config_value(self._config, 'MetaData', 'Date'))
        self.globalAttributes['timestep_time'] = Attribute(
            'timestep_time', date + 'T' + time + '.000Z')

        # get grid type
        line = self.header_file.readline().split()
        self.grid_type = line[0]
        self.globalAttributes['grid_type'] = Attribute('grid_type',
                                                       self.grid_type)

        if self.grid_type == 'Spherical_Exponential':
            components = ['R', 'T', 'P']
        else:
            print self.grid_type, 'not supported!'
            raise Exception("grid type not supported!")
            components = ['x', 'y', 'z']  # just guessing here...

        # get Block sizes
        for i in range(3):
            dim_size, dim_name = self.header_file.readline().split()
            self.globalAttributes[dim_name] = Attribute(
                dim_name, int(dim_size))

        #initialize variables
        var_num = 0

        line = ' '
        while len(line) > 0:
            line = self.header_file.readline().split()
            if len(line) == 0:
                break
            else:
                number_components, var_base_name = line

            if int(number_components) == 1:
                self.addVariableName(var_base_name, var_num)

                # get variable units
                val, attr = self.header_file.readline().split()
                self.variableAttributes[var_base_name]['units'] = Attribute(
                    'units', val)

                # get variable scale factor
                val, attr = self.header_file.readline().split()
                self.variableAttributes[var_base_name][
                    'scale_factor'] = Attribute('scale_factor', float(val))

                # get min and max values (what are the valid_min valid_max values???)
                val, attr = self.header_file.readline().split()
                self.variableAttributes[var_base_name][
                    'actual_min'] = Attribute('actual_min', float(val))

                val, attr = self.header_file.readline().split()
                self.variableAttributes[var_base_name][
                    'actual_max'] = Attribute('actual_max', float(val))

                var_num += 1
            else:
                # get variable units
                units, attr = self.header_file.readline().split()

                # get variable scale factor
                scale_factor, attr = self.header_file.readline().split()

                for i in range(int(number_components) + 1):
                    if i == int(number_components):
                        val, attr = self.header_file.readline().split()
                        self.globalAttributes[var_base_name +
                                              '_mag_min'] = Attribute(
                                                  var_base_name + '_mag_min',
                                                  float(val))

                        val, attr = self.header_file.readline().split()
                        self.globalAttributes[var_base_name +
                                              '_mag_max'] = Attribute(
                                                  var_base_name + '_mag_max',
                                                  float(val))

                    else:
                        var_name = var_base_name + '_' + components[i]

                        self.addVariableName(var_name, var_num)
                        self.variableAttributes[var_name]['units'] = Attribute(
                            'units', units)
                        self.variableAttributes[var_name][
                            'scale_factor'] = Attribute(
                                'scale_factor', float(scale_factor))

                        # get min and max values (what are the valid_min valid_max values???)
                        val, attr = self.header_file.readline().split()
                        self.variableAttributes[var_name][
                            'actual_min'] = Attribute('actual_min', float(val))

                        val, attr = self.header_file.readline().split()
                        self.variableAttributes[var_name][
                            'actual_max'] = Attribute('actual_max', float(val))

                        var_num += 1