Beispiel #1
0
def _lbl2od_ (atmFile, lineFiles, outFile=None, commentChar='#', zToA=None,
              lineShape='Voigt',
	      xLimits=None, airWidth=0.1, sampling=5.0, wingExt=5.0, interpolate='3', nGrids=2, gridRatio=0, nWidths=25.0,
	      mode='d', quad='T', nanometer=False, yOnly=False, flipUpDown=False, plot=False, verbose=False):

	# parse file header and retrieve molecule names
	species = [grep_from_header(file,'molecule') for file in lineFiles]			
	
	#print 'lbl2od for',  len(species), ' molecules:', join(species)

	# read atmospheric data from file,  returns an instance
	atmos = Atmos1D(get_profile_list (atmFile, commentChar, ['z', 'p', 'T']+species, verbose))
	# optinally remove high altitudes 
	if zToA: atmos=reGridAtmos1d(atmos,zToA)
	#print '\n', atmFile, '   ==> atmos\n', atmos
	# vertical column densities
	vcd = atmos.vcd()
	#print str('   vcd [molec/cm**2]' + 20*' '+len(atmos.gases)*'%10.4g') % tuple(vcd)

	# interpolation method used in multigrid algorithms: only Lagrange!
	if   interpolate in 'bBsScC':  lagrange=4
	elif interpolate in 'qQ':      lagrange=3
	elif interpolate in 'lL':      lagrange=2
	else:                          lagrange=int(interpolate)

	# loop over molecules:  read its line parameters (and some other data like mass) and compute cross sections for all p,T
	xsMatrix = []
	for file in lineFiles:
		# read a couple of lines and convert to actual pressure and temperature
		Line_Data, Mol_Data = get_lbl_data (file, xLimits, airWidth, wingExt, commentChar=commentChar)
		# compute cross sections for selected line shape, returns a list with npT dictionaries
		molCrossSections = lbl_xs (Line_Data, Mol_Data, atmos.p, atmos.T, xLimits, lineShape,
					   sampling, wingExt, nGrids, gridRatio, nWidths, lagrange, verbose)
		xsMatrix.append(molCrossSections)
	# for xss in xsMatrix: print 'xs', type(xss), len(xss), [(xs.get('molecule'),len(xs.get('y'))) for xs in xss]

	# compute absorption coefficients, also return uniform, equiidistant wavenumber grid corresponding to most dense cross section
	vGrid, absCoeff = sum_xsTimesDensity (xsMatrix, atmos.densities, interpolate=interpolate, verbose=verbose)

	# integrate absorption coefficients along line of sight
	optDepth = integral_acTimesDistance (absCoeff, atmos.z, quad, mode, verbose)

	# save optical depth
	if outFile and os.path.splitext(outFile)[1].lower() in ('.nc', '.ncdf', '.netcdf'):
		save_optDepth_netcdf (vGrid, optDepth, outFile, atmos, nanometer)
	else:
		save_optDepth_xy (vGrid, optDepth, outFile, atmos, nanometer, yOnly, flipUpDown, commentChar)

	if plot:
		try:
			from pylab import plot, semilogy, show
			if mode in 'cdr':
				for j in range(optDepth.shape[1]):  semilogy (vGrid, optDepth[:,j])
				show()
			else:
				plot (vGrid, optDepth); show()
		except ImportError:
			raise SystemExit, 'ERROR --- lbl2od:  matplotlib not available, no quicklook!'
        if len(molData) > 0:
            moles[mol] = molData
        mol = split[0]
        molData = {}
    if len(split) == 5:
        molData[split[0]] = {
            "abundance": float(split[1]),
            "Q(296K)": float(split[2]),
            "gj": float(split[3]),
            "mass": float(split[4]),
        }

moles[mol] = molData

# parse file header and retrieve molecule names
species = [grep_from_header(file, "molecule") for file in lineFiles]

print "lbl2od for", len(species), " molecules:", join(species)


# interpolation method used in multigrid algorithms: only Lagrange!
if interpolate in "bBsScC":
    lagrange = 4
elif interpolate in "qQ":
    lagrange = 3
elif interpolate in "lL":
    lagrange = 2
else:
    lagrange = int(interpolate)

# loop over molecules:  read its line parameters (and some other data like mass) and compute cross sections for all p,T