#Tables and functions for doing polynomial fit to OLR(rh, CO2,T) from ClimateUtilities import * # needed for polint and interpolation object import math #%-------------Table:Cubic fit to (T-275)---------------------------------------------------- #%**Layout: Make sure this table comes after the corresponding figure #%Y = M0 + M1*x + ... M8*x\u8\n + M9*x\u9 #\begin{table} #\begin{tabular}{lcccc} #$CO_2$ , $a_o$ , $a_1$ , $a_2$ , $a_3$ \\ CO2Vals = [10.,100.,1000.,10000.,100000.] logCO2Vals = [math.log(co2) for co2 in CO2Vals] fitTcoeffs = [] #10ppmv fitTcoeffs.append([ 258.56, 2.5876,-0.0059165,-0.00013402]) #100ppmv fitTcoeffs.append([246.13, 2.5056,-0.0034095,-0.00010672 ]) #1000ppmv fitTcoeffs.append([232.51, 2.3815,-0.0015855 ,-8.3397e-05]) #10000ppmv fitTcoeffs.append([ 215.74,2.1915,0.00056634,-5.0508e-05]) #100000ppmv fitTcoeffs.append([189.06,1.8554,0.0044094,1.0735e-05]) #\end{tabular} #\caption{Coefficients for polynomial fit $OLR = a_o + a_1 x + a_2 x^2 + a_3 x^3$, #where $x = T_g - 275$. Calculation carried out with $rh = .5$.} #\label{table:OLRvsTfit} #\end{table} #%--------------------------------------------------------------------------------------------- #%--------Table:Cubic fit to ln(co2/300)------------------------------------------------------- #%**Layout: Make sure this table comes after the corresponding figure #\begin{table} #\begin{tabular}{lcccc} #$rh$ , $a_o$ , $a_1$ , $a_2$ , $a_3$ \\ rhVals = [0.,.1,.5,1.] fitCO2coeffs = [] #Dry fitCO2coeffs.append([313.8,-6.275,-0.36107 ,-0.019467]) #.1 fitCO2coeffs.append([277.28,-5.9416 ,-0.35596 ,-0.020237]) #.5 fitCO2coeffs.append([259.52,-5.5332 ,-0.33915 ,-0.018932]) #Saturated fitCO2coeffs.append([249.1,-5.183,-0.32187,-0.017367]) #\end{tabular} #\caption{Coefficients for polynomial fit $OLR = a_o + a_1 x + a_2 x^2 + a_3 x^3$, #where $x = \ln (CO_2/100)$, with $CO_2$ in $ppmv$. Calculation carried out with $T_g = 280K$ for #the indicated moisture conditions.} #\label{table:OLRvsCO2fit} #\end{table} #%------------------------------------------------------------ #Utility to evaluate polynomial def evalPoly(coeffs,x): sum = coeffs[-1] for i in range(2,len(coeffs)+1): sum = x*sum + coeffs[-i] return sum #CO2 in ppmv def OLRT(CO2,T): x = T-275. y = math.log(CO2) #interpolate coefficients coeffs = [] for i in range(len(fitTcoeffs[0])): a = [fitTcoeffs[j][i] for j in range(len(logCO2Vals))] coeffs.append(polint(logCO2Vals,a,y)) #Evaluate the polynomial return evalPoly(coeffs,x) #CO2 in ppmv def OLRCO2(rh,CO2): x = math.log(CO2/100.) y = rh #Note, some kind of log-linear fit would be better #interpolate coefficients coeffs = [] for i in range(len(fitCO2coeffs[0])): a = [fitCO2coeffs[j][i] for j in range(len(rhVals))] coeffs.append(polint(rhVals,a,y)) #Evaluate the polynomial #print coeffs return evalPoly(coeffs,x) co2List = [10.**(i/4.) for i in range(21)] olr = [OLRT(co2,280.) for co2 in co2List]