def computeAbsorption(pressure, temperature, gasSpecies, concValues, Line_Data, Mol_Data):
    profs = [
        Profile([0.0], what="altitude", unit="km"),
        Profile([pressure], what="pressure", unit="g/cm/s**2"),
        Profile([temperature], what="temperature", unit="K"),
    ]
    for i in range(0, len(gasSpecies)):
        profs.append(Profile([concValues[i]], what=gasSpecies[i], unit="ppV"))
    atmos = Atmos1D(profs)
    xsMatrix = []
    for i in range(0, len(gasSpecies)):
        # compute cross sections for selected line shape, returns a list with npT dictionaries
        molCrossSections = lbl_xs(
            Line_Data[i],
            Mol_Data[i],
            atmos.p,
            atmos.T,
            xLimits,
            lineShape,
            sampling,
            wingExt,
            nGrids,
            gridRatio,
            nWidths,
            lagrange,
            verbose,
        )
        xsMatrix.append(molCrossSections)

    # compute absorption coefficients, also return uniform, equiidistant wavenumber grid corresponding to most dense cross section

    xOut, absCoeffOut = sum_xsTimesDensity(xsMatrix, atmos.densities, interpolate=interpolate, verbose=verbose)
    return xOut, absCoeffOut[:, 0]
示例#2
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!'
def fitErr(pressures):
    crossSections = []
    sum = np.array([0.0]*len(data['x']))
    for i in range(0,len(Line_Data)):
        factor = pressures[i]/1013500.0/8.31/temperature*6.022*10**23
        crossSections.append(lbl_xs (Line_Data[i], Mol_Data[i], np.array([pressures[i]]), np.array([temperature]), xLimits, lineShape, sampling, wingExt, nGrids, gridRatio, nWidths, lagrange, verbose)[0]  )
        xarr = np.linspace(xMin,xMax,len(crossSections[-1]['y']))
        interp = interp1d(xarr,crossSections[-1]['y']*factor)
        sum = sum + interp(data['x(wn)'])
    
    diff = sum - data['alpha']
    return diff.dot(diff)
示例#4
0
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)

for i in range(0,len(absCoeff[0])):
    plt.plot(vGrid,absCoeff[:,i])
plt.show()
from scipy.optimize import minimize
if(fitScale):
    minResult = minimize(fitErrScale,initialGuess,method='Nelder-Mead')
else:
    minResult = minimize(fitErr,initialGuess,method='Nelder-Mead')

#plot data    
plt.plot(data['x(wn)'],data['alpha'],'ro')
crossSections = []
xplt = np.linspace(xMin,xMax,2000)
interps = []
interpFuncs = []
sum = np.array([0.0]*len(xplt))
for i in range(0,len(Line_Data)):
    factor = minResult['x'][i]/1013500.0/8.31/temperature*6.022*10**23
    crossSections.append(lbl_xs (Line_Data[i], Mol_Data[i], np.array([minResult['x'][i]]), np.array([temperature]), xLimits, lineShape, sampling, wingExt, nGrids, gridRatio, nWidths, lagrange, verbose)[0]  )
    xarr = np.linspace(xMin,xMax,len(crossSections[-1]['y']))
    interp = interp1d(xarr,crossSections[-1]['y']*factor)
    interpFuncs.append(interp)
    interps.append(interp(data['x(wn)']))
if(fitScale):
    A = np.column_stack(interps)
    c, resid,rank,sigma = np.linalg.lstsq(A,data['alpha'])
else:
    c = [1.0]*len(Line_Data)
for i in range(0,len(Line_Data)):
    factor = minResult['x'][i]/1013500.0/8.31/temperature*6.022*10**23
    sum = sum + interpFuncs[i](xplt)*c[i]
    xarr = np.linspace(xMin,xMax,len(crossSections[i]['y']))
    plt.plot(xarr,crossSections[i]['y']*factor*c[i])
#plot total hitran absorbance