Importing and Plotting of Averaging Kernels from GGG and TCCON

Generate a dictionary for storage of averaging kernels


In [1]:
%pylab inline
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection

aks = {}
szas={}
wins = ['co2_6220', 'co2_6339']
own_akdir = '~/ggg/ak/'
tccon_ak_filename = 'lamont_co2.out'
runlog_fname = '~/ggg/runlogs/gnd/xxxxxx.grl'


Populating the interactive namespace from numpy and matplotlib

Reading and interpolate in TCCON (Lamont) Averaging Kernels

Read in Lamont averaging kernels and create a series of interpolated AK's from them in steps of 1 degree solar zenith angle.


In [2]:
tccon_ak = np.recfromtxt(tccon_ak_filename, skip_header=3, 
                         names = ['pressure', '10', '15', '20', '25', '30', '35', '40', 
                                  '45', '50', '55', '60', '65', '70', '75', '80', '85'])
aks['tccon']={}
aks['tccon']['pressure'] = tccon_ak['pressure']
aks['tccon']['level'] = np.array(range(71))

szalist = np.array([10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85])
szas['tccon'] = []

interpolated_sza = range(10,86)

for sza in interpolated_sza:
    szas['tccon'].append(sza)
    if sza in szalist:
        ak = tccon_ak[str(sza)]
    else:
        lower_sza = szalist[szalist<sza][-1]
        upper_sza = szalist[szalist>sza][0]
        ak = tccon_ak[str(lower_sza)]+((tccon_ak[str(upper_sza)]-tccon_ak[str(lower_sza)])*
                                       (np.float(sza)-np.float(lower_sza))/(np.float(upper_sza)-np.float(lower_sza)))
    aks['tccon'][str(sza)] = np.array(ak)

szas['tccon'] = np.array(szas['tccon'])

Reading in Ny-Ålesund Averaging Kernels

Reading in averaging Kernels generated by GGG. This assumes the .aks-files are in folder 'own_akdir' (defined above) in a subdirectory with the name of the corresponding retrieval window.

First, define function to read in runlog and another one to find the solar zenith angle 'ASZA' for a given spectrum name in the runlog.


In [3]:
def read_runlog(filename):
    try:
    # specify runlog column names
        nam = ['Spectrum', 'Year', 'Day', 'Hour', 'oblat', 'oblon', 'obalt', 'ASZA', 'POFF', 'AZIM', 'OSDS', 'OPD', 'FOVI', 'FOVO', 'AMAL', 'IFIRST', 'ILAST', 'DELTA_NU', 'POINTER', 'BPW', 'ZOFF', 'SNR', 'APF', 'tins', 'pins', 'hins', 'tout', 'pout', 'hout', 'sia', 'fvsi', 'wspd', 'wdir', 'lasf', 'wavtkr', 'aipl']
        # specify column formats
        form=[]
        for i in range(len(nam)): form.append('f8')
        form[0]='|S30'
        form[22]='|S3'
        runlog=np.recfromtxt(filename, skip_header=3, dtype={'names':nam, 'formats':form}, delimiter=(59,4,4,8,8,9,8,8,7,8,7,7,6,6,6,9,9,15,9,3,6,5,3,6,8,5,6,8,5,7,7,6,6,10,7,7))
        for i in enumerate(runlog.Spectrum):
            runlog.Spectrum[i[0]]=i[1].strip()
    # read runlog file into temporary recarray: runlog
        return runlog
    except:
        pass

def get_sza_from_runlog(runlog, fname):
    try:
        return runlog['ASZA'][runlog['Spectrum']==fname][0]
    except: 
        return np.nan

In [9]:
runlog = read_runlog(runlog_fname)

for win in wins:
    aks[win] = {}
    szas[win] = {}
    for akf in os.listdir(os.path.join(own_akdir,win)):
        if akf[-4:]=='.aks':
            aks[win][akf[1:-4]] = np.recfromtxt(os.path.join(own_akdir,win,akf), 
                                                      skip_header=3, names=['level', 'ak', 'pressure'], missing='NaN')
        else: pass
    szas[win] = np.array([get_sza_from_runlog(runlog, fname) for fname in aks[win].keys()])

We generated a dictionary for each retrieval window within the dictionary 'aks', which contains, for each filename found in 'own_akdir', a numpy record array with the spectrum specific averaging kernel information.

Plotting TCCON Lamont Kernels


In [10]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title(r'Lamont CO$_2$ Averaging Kernels')
ax.set_xlim(0,1.5)
ax.set_ylim(1000,0)
line_segments = LineCollection([list(zip(aks['tccon'][str(sza)], aks['tccon']['pressure'])) for sza in szas['tccon']])
line_segments.set_array(szas['tccon'])
ax.add_collection(line_segments)
axcb = fig.colorbar(line_segments)
axcb.set_label('solar zenith angle / deg')


Plotting self-generated Kernels


In [24]:
for win in wins:
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_title(r'CO$_2$ Averaging Kernels for window '+win)
    ax.set_xlim(0,1.5)
    ax.set_ylim(1000,0)
    line_segments = LineCollection([list(zip(aks[win][fname]['ak'], aks[win][fname]['pressure']*1013.25)) for fname in aks[win].keys()])
    line_segments.set_array(szas[win])
    ax.add_collection(line_segments)
    axcb = fig.colorbar(line_segments)
    axcb.set_label('solar zenith angle / deg')