Python 计算二氧化碳吸收截面:0-30000 千米高度变化
首先,我们需要导入所需的库:/n/npython/nimport numpy as np/nimport matplotlib.pyplot as plt/n/n/n然后,我们需要定义二氧化碳的吸收系数函数。在这个示例中,我们将使用以下公式:/n/n$$/sigma(//nu,T,P) = //frac{N}{P} //sum_{i=1}^{n} S_i(//nu) f_i(T) //left[ 1 - //exp//left(-//frac{h//nu}{kT}//right)//right]$$ /n/n其中:/n/n- $//sigma(//nu,T,P)$ 是在给定温度和压强下的吸收截面/n- $N$ 是二氧化碳的分子数密度/n- $P$ 是压强/n- $S_i(//nu)$ 是第 $i$ 个吸收线的线型函数/n- $f_i(T)$ 是第 $i$ 个吸收线的强度函数/n- $h$ 是普朗克常数/n- $k$ 是玻尔兹曼常数/n/n我们可以将这个公式转化为 Python 代码:/n/npython/ndef sigma(nu, T, P):/n # Constants/n N = 2.6867774e19 # CO2 number density at 1 atm and 300 K/n h = 6.62607004e-34 # Planck's constant/n k = 1.38064852e-23 # Boltzmann constant/n/n # Line parameters/n S = np.array([0.020, 0.067, 0.170, 0.210, 0.080, 0.180, 0.010, 0.120, 0.040, 0.280])/n f = np.array([0.010, 0.070, 0.020, 0.040, 0.060, 0.170, 0.200, 0.130, 0.040, 0.050])/n nu0 = np.array([667.382, 667.385, 667.369, 667.379, 667.381, 667.400, 667.404, 667.415, 667.431, 667.420])/n/n # Calculate absorption cross section/n sigma = np.zeros_like(nu)/n for i in range(len(S)):/n sigma += S[i] * f[i] * (1 - np.exp(-h*nu/(k*T))) / (P * nu0[i]**2) * N/n/n return sigma/n/n/n接下来,我们需要创建一个数组来存储各个高度处的压强和温度值。在这个示例中,我们将使用 US Standard Atmosphere 1976 模型:/n/npython/n# Constants/ng = 9.80665 # Gravitational acceleration/nR = 8.31432 # Universal gas constant/nM = 0.0289644 # Molar mass of dry air/n/n# US Standard Atmosphere 1976/nh = np.arange(0, 30001, 1) # Altitude, m/nT = np.zeros_like(h) # Temperature, K/nP = np.zeros_like(h) # Pressure, Pa/nrho = np.zeros_like(h) # Density, kg/m^3/n/n# Sea level values/nT[0] = 288.15 # K/nP[0] = 101325 # Pa/nrho[0] = P[0] / (R * T[0])/n/n# Calculate values at each altitude/nfor i in range(1, len(h)):/n if h[i] < 11000:/n # Troposphere/n T[i] = T[i-1] - 0.0065 * h[i]/n P[i] = P[i-1] * (T[i] / T[i-1])**(-g*M/(R*0.0065))/n rho[i] = P[i] / (R * T[i])/n elif h[i] < 20000:/n # Lower stratosphere/n T[i] = 216.65 # K/n P[i] = P[i-1] * np.exp(-g*M*(h[i]-11000)/(R*T[i]))/n rho[i] = P[i] / (R * T[i])/n elif h[i] < 32000:/n # Upper stratosphere/n T[i] = 288.65 + 0.001 * (h[i]-20000) # K/n P[i] = P[i-1] * (T[i] / T[i-1])**(-g*M/(R*0.001))/n rho[i] = P[i] / (R * T[i])/n else:/n # Mesosphere and above/n T[i] = 1000 - 2.5 * (h[i] - 32000) # K/n P[i] = P[i-1] * (T[i] / T[i-1])**(-g*M/(R*2.5))/n rho[i] = P[i] / (R * T[i])/n/n/n最后,我们可以使用 sigma 函数计算各个高度处的吸收截面,并将结果绘制成图表:/n/npython/n# Calculate absorption cross section/nnu = 299792458 / np.linspace(1000e-9, 2000e-9, 1000) # Wavelength, m/nsigma_tot = np.zeros_like(h)/nfor i in range(len(h)):/n sigma_tot[i] = sigma(299792458/nu, T[i], P[i]).sum()/n/n# Plot results/nplt.plot(h/1000, sigma_tot)/nplt.xlabel('Altitude (km)')/nplt.ylabel('Absorption cross section (m^2)')/nplt.show()/n/n/n完整代码如下:/n/npython/nimport numpy as np/nimport matplotlib.pyplot as plt/n/ndef sigma(nu, T, P):/n # Constants/n N = 2.6867774e19 # CO2 number density at 1 atm and 300 K/n h = 6.62607004e-34 # Planck's constant/n k = 1.38064852e-23 # Boltzmann constant/n/n # Line parameters/n S = np.array([0.020, 0.067, 0.170, 0.210, 0.080, 0.180, 0.010, 0.120, 0.040, 0.280])/n f = np.array([0.010, 0.070, 0.020, 0.040, 0.060, 0.170, 0.200, 0.130, 0.040, 0.050])/n nu0 = np.array([667.382, 667.385, 667.369, 667.379, 667.381, 667.400, 667.404, 667.415, 667.431, 667.420])/n/n # Calculate absorption cross section/n sigma = np.zeros_like(nu)/n for i in range(len(S)):/n sigma += S[i] * f[i] * (1 - np.exp(-h*nu/(k*T))) / (P * nu0[i]**2) * N/n/n return sigma/n/n# Constants/ng = 9.80665 # Gravitational acceleration/nR = 8.31432 # Universal gas constant/nM = 0.0289644 # Molar mass of dry air/n/n# US Standard Atmosphere 1976/nh = np.arange(0, 30001, 1) # Altitude, m/nT = np.zeros_like(h) # Temperature, K/nP = np.zeros_like(h) # Pressure, Pa/nrho = np.zeros_like(h) # Density, kg/m^3/n/n# Sea level values/nT[0] = 288.15 # K/nP[0] = 101325 # Pa/nrho[0] = P[0] / (R * T[0])/n/n# Calculate values at each altitude/nfor i in range(1, len(h)):/n if h[i] < 11000:/n # Troposphere/n T[i] = T[i-1] - 0.0065 * h[i]/n P[i] = P[i-1] * (T[i] / T[i-1])**(-g*M/(R*0.0065))/n rho[i] = P[i] / (R * T[i])/n elif h[i] < 20000:/n # Lower stratosphere/n T[i] = 216.65 # K/n P[i] = P[i-1] * np.exp(-g*M*(h[i]-11000)/(R*T[i]))/n rho[i] = P[i] / (R * T[i])/n elif h[i] < 32000:/n # Upper stratosphere/n T[i] = 288.65 + 0.001 * (h[i]-20000) # K/n P[i] = P[i-1] * (T[i] / T[i-1])**(-g*M/(R*0.001))/n rho[i] = P[i] / (R * T[i])/n else:/n # Mesosphere and above/n T[i] = 1000 - 2.5 * (h[i] - 32000) # K/n P[i] = P[i-1] * (T[i] / T[i-1])**(-g*M/(R*2.5))/n rho[i] = P[i] / (R * T[i])/n/n# Calculate absorption cross section/nnu = 299792458 / np.linspace(1000e-9, 2000e-9, 1000) # Wavelength, m/nsigma_tot = np.zeros_like(h)/nfor i in range(len(h)):/n sigma_tot[i] = sigma(299792458/nu, T[i], P[i]).sum()/n/n# Plot results/nplt.plot(h/1000, sigma_tot)/nplt.xlabel('Altitude (km)')/nplt.ylabel('Absorption cross section (m^2)')/nplt.show()/n
原文地址: https://www.cveoy.top/t/topic/n0BX 著作权归作者所有。请勿转载和采集!