def read_cross_sections_xy (file, commentChar):
	""" Read one cross section file (xy ascii format; typically one molecule, several p,T pairs). """
	# initialize list of cross sections to be returned
	xsList = []
	# read entire cross section file (incl. commented header lines)
	try:
		xyData, comments = readDataAndComments(file,commentChar)
	except:
		raise SystemExit, 'ERROR:  reading cross section file failed (check format etc!?!)\n' + repr(file)

	# parse comment header and extract some infos
	need = ('pressure', 'temperature', 'molecule')
	headerDict = parse_file_header (comments, need)

	npT = xyData.shape[1]-1
	xLimits = Interval(xyData[0,0], xyData[-1,0])
	for l in range(1,npT+1):
		xsList.append({'molecule': headerDict['molecule'],  'x': xLimits,  'y': xyData[:,l]})

	pValues, pUnit = headerDict['pressure'][0], headerDict['pressure'][1]
	pValues = unitConversion (pValues, 'pressure', pUnit)
	if len(pValues)==npT:
		for l in range(npT): xsList[l]['p'] = pValues[l]

	TValues, TUnit = headerDict['temperature'][0], headerDict['temperature'][1]
	TValues = unitConversion (TValues, 'temperature', TUnit)
	if len(TValues)==npT:
		for l in range(npT): xsList[l]['T'] = TValues[l]

	return xsList
Example #2
0
def read_line_file (lineFile, xLimits=None, airWidth=0.1, wingExt=0.0, molecule=None,  commentChar='#'):
	""" Read a simple line parameter list and return a dictionary:  lines and some attributes. """

	# wavenumber interval to be searched
	if xLimits:
		xLow, xHigh = xLimits.limits()
	else:
		xLow, xHigh = 0.0, 0.0

	# read entire line file and return a dictionary
	lines, comments = readDataAndComments (lineFile,commentChar)
	# if there is just a single line in the dataset, a 1dim array is returned
	lines = np.atleast_2d (lines)

	# parse comment header and extract some infos
	Line_Data = parse_file_header (comments, ['molecule','format','pressure','temperature'])

	# check if molecule is specified  (and consistent if specified in file and on command line)
	if molecule and Line_Data.has_key('molecule'):
		if not molecule==Line_Data['molecule']:
			raise SystemExit, 'ERROR:  inconsistent molecule specification!   ' + \
			                  repr(molecule) + ' <--> ' + repr(Line_Data['molecule'])
	elif Line_Data.has_key('molecule'):
		pass
	elif molecule:
		Line_Data['molecule'] = molecule
	else:
		print 'lineFile: ', lineFile
		raise SystemExit, 'ERROR:  molecule not specified (neither in line list header nor as command option)!'

	# also need reference pressure and temperature
	if Line_Data.has_key('temperature'):
		# remove unit spec 'Kelvin'
		Line_Data['temperature'] = float(split(Line_Data['temperature'])[0])
	else:
		raise SystemExit, 'ERROR:  reference temperature of line parameters not given!'
	if Line_Data.has_key('pressure'):
		try:    # remove unit spec 'millibar' and return pressure in cgs units!
			value_unit = split(Line_Data['pressure'])
			Line_Data['pressure'] = unitConversion(float(value_unit[0]), 'pressure', value_unit[1])
		except StandardError,errMsg: 
			raise SystemExit, str(errMsg) + '\nparsing pressure spec in line file failed ' + repr(Line_Data['pressure'])