コード例 #1
0
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
ファイル: lbl2od.py プロジェクト: jaymz07/spectral-line-fit
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!'
コード例 #3
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()