<jupyter_start><jupyter_text>Airborne observations<jupyter_code>%load_ext autoreload
%autoreload 2
from itertools import product

import numpy as np
import xarray as xr
xr.set_options(display_style='text')

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.colors as colors

import cartopy.crs as ccrs
import seaborn as sns

import datasets
import figure_panels
import obs_aircraft
import util<jupyter_output><empty_output><jupyter_text>Load the aircraft data The data from the aircraft are returned as a `pandas.DataFrame`.<jupyter_code>df = obs_aircraft.open_aircraft_data('obs')
df.head()<jupyter_output>loading obs<jupyter_text>Campaign details<jupyter_code>campaign_info = obs_aircraft.get_campaign_info(clobber=False, lump_orcas=True)

campaign_mon = [c['month'] for c in campaign_info.values()]
I = np.argsort([c['month'] for c in campaign_info.values()])

campaigns = np.array(list(campaign_info.keys()))[I]
time_bound = np.array([c['time_bound'] for c in campaign_info.values()])[I]<jupyter_output>HIPPO-1:
	flights: ['HIPPO-001-006', 'HIPPO-001-007', 'HIPPO-001-008']
	time: 2009-01-20
	year: 2009
	month: 1
	day: 20
	time_bound: ['2009-01-19' '2009-01-24']
	co2_midtrop: 384.0980934046344
	ch4_midtrop: 1735.9877611940308
	sf6_midtrop: 6.44546875
	co2_midtrop_each_sensor: {'co2pfp': 383.83666666666664, 'co2medusa': 384.065, 'co2': 384.0980934046344, 'co2ao2': 384.1803736842106, 'co2oms': 384.4950883838382}
	co2_midtrop_multi_sensor: 384.13504442786996
	co2_midtrop_multi_sensor_std: 0.2130667876906907
HIPPO-2:
	flights: ['HIPPO-002-005', 'HIPPO-002-006', 'HIPPO-002-007']
	time: 2009-11-11
	year: 2009
	month: 11
	day: 11
	time_bound: ['2009-11-09' '2009-11-15']
	co2_midtrop: 385.4305322580645
	ch4_midtrop: 1762.1661757719726
	sf6_midtrop: 6.645344827586209
	co2_midtrop_each_sensor: {'co2pfp': 385.41, 'co2medusa': 385.39267000000007, 'co2': 385.4305322580645, 'co2ao2': 385.4491370558374, 'co2oms': 385.38648337595885}
	co2_midtrop_multi_sensor: 385.4137645379721
	co2_midtrop_multi_sens[...]<jupyter_text>Flight tracks<jupyter_code>ncol = 3
nrow = 3

fig = plt.figure(figsize=(18, 10))

gs_outer = gridspec.GridSpec(
    nrows=nrow, ncols=ncol,
    wspace=0.05, hspace=0.01,
)

for c, (i, j) in enumerate(product(range(nrow), range(ncol))):
    gs_inner = gs_outer[i, j].subgridspec(1, 100, wspace=0.2)
    axMap = fig.add_subplot(gs_inner[0, 60:], projection=ccrs.Gnomonic(central_latitude=-90.0, central_longitude=0.0)) #ccrs.SouthPolarStereo())
    axSex = fig.add_subplot(gs_inner[0, :60])
    
    axMap.coastlines('110m')
    axMap.set_extent([180, -180, -90,  -30], crs=ccrs.PlateCarree())
    axMap.gridlines()
    
    
    df_sub = obs_aircraft.groups_get_dataframe(df, campaigns[c], lump_orcas=True)
    fight_ids = list(df_sub.flight_id.unique())
    datestr = obs_aircraft.campaign_datestr(time_bound[c])
    
    palette_colors = sns.color_palette(figure_panels.sns_palette, len(fight_ids)).as_hex()
        
    for n, flight_id in enumerate(fight_ids):
        df_sub_sub = df_sub.loc[df_sub.flight_id == flight_id]
        axMap.plot(
            df_sub_sub.lon, df_sub_sub.lat, 
            '.',
            markersize=1,
            color=palette_colors[n],
            transform=ccrs.PlateCarree(),
        )

        axSex.plot(
            df_sub_sub.lat, df_sub_sub.alt*1e-3, 
            '.', 
            markersize=1,            
            color=palette_colors[n],                   
        )
        
        axSex.set_ylim((-0.2, 14.8))
        axSex.set_xlim(-87.25, -28.75)
        
        
        if j == 0:
            axSex.set_ylabel('Altitude [km]')
        else:
            axSex.set_yticklabels([])
        
        if i == nrow - 1:
            axSex.set_xlabel('Latitude [°N]')
        else:
            axSex.set_xticklabels([])
    
    axSex.set_title(campaigns[c], loc='left')
    axSex.set_title(datestr, x=1.68, ha='right')
    
    l, b, w, h = axSex.get_position().bounds
    axSex.set_position([l, b+0.034, w*0.99, h*0.72])

util.savefig('flight-tracks')<jupyter_output><empty_output><jupyter_text>Meridional CO2 sections Load latitude-altitude bin-averaged dataset<jupyter_code>ds = datasets.aircraft_sections()
ds<jupyter_output><empty_output><jupyter_text>Visualize sections<jupyter_code>fig, axs = util.canvas(3, 3, 
                       figsize=(16/3, 10/3), 
                       use_gridspec=True, 
                       hspace=0.3, wspace=0.12,
                       width_ratios=[1, 1, 1,],
                      )

for n, i in enumerate(np.argsort(ds.month.values)):
    ax = axs[np.unravel_index(n, (3, 3))]
    
    if not np.isnan(ds.DCO2_binned.isel(time=i)).all():
        co2_ref = campaign_info[ds.campaigns.values[i]]['co2_midtrop_multi_sensor']
        
        vmin, vmax = np.array(figure_panels.co2_anom_bounds) + co2_ref
        divnorm = colors.TwoSlopeNorm(vmin=vmin, vcenter=co2_ref, vmax=vmax)  
        cf = ax.pcolormesh(
            ds.y, ds.z, ds.CO2_binned.isel(time=i),
            norm=divnorm,
            cmap=figure_panels.cmap,
            shading='nearest',
        )
        cs = ax.contour(
            ds.LAT, ds.ALT, ds.THETA.isel(time=i),
            levels=np.arange(255., 350., 10.),
            linewidths=1,
            colors='gray')    
        lb = plt.clabel(cs, fontsize=8, inline=True, fmt='%d')    
        
        cb = plt.colorbar(cf, ax=ax, pad=0.02)
        cb.ax.set_title('ppm', loc='left')
        
    tb = campaign_info[ds.campaigns.values[i]]['time_bound']    
    
    date_str = obs_aircraft.campaign_datestr(tb)
    
    ax.set_title(date_str, loc='right')
    ax.set_title(ds.campaigns.values[i], loc='left')
    ax.set_ylim((0, 10.5))
    ax.set_xlim(-81.25, -28.75)

    if n%ncol == 0:
            ax.set_ylabel('Altitude [km]')

    if n >= (nrow-1) * ncol:
        ax.set_xlabel('Latitude [°N]')

util.savefig(f'aircraft-sections')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1378441907320349, 'fraction_numerical': 0.08999328408327736, 'mean_word_length': 3.0969738651994496, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '214299', 'license': 'MIT', 'n_tokens_mistral': 2725, 'n_tokens_neox': 2355, 'n_words': 357, 'path': 'so-co2-airborne-obs/obs-aircraft.ipynb', 'repo_name': 'mgrover1/so-co2-airborne-obs', 'size': '5956'}