Skip to content
Snippets Groups Projects
Select Git revision
  • 85c889d9aa95d53ee9cf43b8d2589a2e04a1da4d
  • master default protected
  • use_flight_altitude
  • distribute
4 results

__init__.py

Blame
  • pca-read-test.ipynb 210.08 KiB
    In [1]:
    import cris_pca_red.rd_pca_red_file as red_file
    In [2]:
    d, gpc = red_file.rd_pca_red_file('input/SNDR.J1.CRIS.20240312T0512.m06.g053.PCA_RED.std.v0_2_0.W.240312174418.nc', 'anc/SNDRGBLPCv2.J1.CRIS.20180325T0000.20190324T2354.L1B.v03_08_nznorm1_latwt1_qc2.nc')
    In [3]:
    d['rad_lw'].shape
    Out [3]:
    (45, 30, 9, 717)
    In [4]:
    d['rad_mw'].shape
    Out [4]:
    (45, 30, 9, 869)
    In [5]:
    d['rad_sw'].shape
    Out [5]:
    (45, 30, 9, 637)
    In [6]:
    from bokeh.io import push_notebook, output_notebook
    from bokeh.layouts import row
    from bokeh.models import Div
    from bokeh.plotting import figure, show
    import ipywidgets as wdgt
    output_notebook()
    Out [6]:
    Out [6]:
    In [7]:
    x1 = d['wnum_lw']
    x2 = d['wnum_mw']
    x3 = d['wnum_sw']
    y1 = d['rad_lw'][23,15].squeeze()
    y2 = d['rad_mw'][23,15].squeeze()
    y3 = d['rad_sw'][23,15].squeeze()
    yn = min(y1.shape[0], y2.shape[0], y3.shape[0])
    
    fig = figure(title='Radiance Reconstruction Test', height=600, width=1000)  
            #, x_range = (0., 100.,0, y_range=(0.,100.))
    line1 = fig.line(x1, y1[0], color='#ff4444')
    line2 = fig.line(x2, y2[0], color='#44ff44')
    line3 = fig.line(x3, y3[0], color='#4444ff')
    fig.xaxis.axis_label = 'wnum'
    fig.yaxis.axis_label = 'radiance'
    
    def _update(dex):
        line1.data_source.data['y'] = y1[dex]
        line2.data_source.data['y'] = y2[dex]
        line3.data_source.data['y'] = y3[dex]
        fig.title.text = str(dex)
        push_notebook()
    
    hnd = show(fig, notebook_handle=True)
    wdgt.interact(_update, dex=(0, yn, 1))
    
    Out [7]:
    Out [7]:
    Out [7]:
    interactive(children=(IntSlider(value=4, description='dex', max=9), Output()), _dom_classes=('widget-interact'…
    Out [7]:
    <function __main__._update(dex)>
    In [8]:
    d['rad_lw'].shape, d['rad_mw'].shape, d['rad_sw'].shape
    Out [8]:
    ((45, 30, 9, 717), (45, 30, 9, 869), (45, 30, 9, 637))
    In [9]:
    from scipy.io.matlab import loadmat
    In [10]:
    tru = loadmat('truth/SNDR.J1.CRIS.20240312T0512.m06.g053.mat')
    In [11]:
    tru.keys()
    Out [11]:
    dict_keys(['__header__', '__version__', '__globals__', 'info', 'local_pc_eig', 'local_pc_mean', 'global_pc_score', 'local_pc_score', 'pca_red', 'pca_qc', 'rad_outlier', 'None', 'obs_time_tai93', 'lat', 'lon', 'lat_bnds', 'lon_bnds', 'land_frac', 'sol_zen', 'sat_zen', 'sat_azi', 'asc_flag', 'mean_anom_wrt_equat', 'rad_lw_qc', 'rad_mw_qc', 'rad_sw_qc', 'scan_sweep_dir', 'for_num', 'fov_num', 'wnum_lw', 'wnum_mw', 'wnum_sw', 'wnum_all', 'nz_norm', 'rad_lw', 'rad_mw', 'rad_sw', '__function_workspace__'])
    In [12]:
    d.keys()
    Out [12]:
    dict_keys(['local_pc_eig', 'local_pc_mean', 'global_pc_score', 'local_pc_score', 'pca_red', 'pca_qc', 'rad_outlier', 'obs_time_tai93', 'lat', 'lon', 'lat_bnds', 'lon_bnds', 'land_frac', 'sol_zen', 'sat_zen', 'sat_azi', 'asc_flag', 'mean_anom_wrt_equat', 'rad_lw_qc', 'rad_mw_qc', 'rad_sw_qc', 'scan_sweep_dir', 'for_num', 'fov_num', 'wnum_lw', 'wnum_mw', 'wnum_sw', 'wnum_all', 'nz_norm', 'rad_lw', 'rad_mw', 'rad_sw'])
    In [13]:
    tru['rad_lw'].shape
    Out [13]:
    (717, 9, 30, 45)
    In [14]:
    import numpy as np
    In [15]:
    np.all(tru['rad_lw'][:,0,0,0].squeeze() == d['rad_lw'][0,0,0,:])
    Out [15]:
    True
    In [16]:
    mlw = tru['rad_lw']
    mlw = np.swapaxes(mlw, 1, 2)
    mlw = np.swapaxes(mlw, 0, 3)
    mlw.shape
    Out [16]:
    (45, 30, 9, 717)
    In [17]:
    np.all(mlw[0,0,0,:].squeeze() == d['rad_lw'][0,0,0,:])
    Out [17]:
    True
    In [18]:
    np.all(mlw==d['rad_lw'])
    Out [18]:
    True
    In [19]:
    mlw[0,0,0,25:40]
    Out [19]:
    array([54.89318708, 54.4612455 , 53.80879517, 52.73572163, 52.11093211,
           68.74785291, 71.79915418, 62.47005973, 58.80166808, 56.43533306,
           51.63145986, 56.01718675, 51.57781785, 53.06464813, 55.38478631])
    In [20]:
    def baltam(x):
        "reverse axis order for radiance 4D arrays"
        return np.swapaxes( np.swapaxes(x, 1, 2), 0, 3 )
    In [21]:
    tlw = baltam(tru['rad_lw'])
    tmw = baltam(tru['rad_mw'])
    tsw = baltam(tru['rad_sw'])
    plw = d['rad_lw']
    pmw = d['rad_mw']
    psw = d['rad_sw']
    In [22]:
    np.all(tmw == pmw)
    Out [22]:
    True
    In [23]:
    np.all(tsw == psw)
    Out [23]:
    True
    In [24]:
    np.all(tlw == plw)
    Out [24]:
    True
    In [25]:
    tlw.shape, tmw.shape, tsw.shape
    Out [25]:
    ((45, 30, 9, 717), (45, 30, 9, 869), (45, 30, 9, 637))
    In [26]:
    x1 = d['wnum_lw']
    x2 = d['wnum_mw']
    x3 = d['wnum_sw']
    y1 = tlw[23,15].squeeze()
    y2 = tmw[23,15].squeeze()
    y3 = tsw[23,15].squeeze()
    yn = min(y1.shape[0], y2.shape[0], y3.shape[0])
    
    fig = figure(title='Radiance Reconstruction Test', height=600, width=1000)  
            #, x_range = (0., 100.,0, y_range=(0.,100.))
    line1 = fig.line(x1, y1[0], color='#ff4444')
    line2 = fig.line(x2, y2[0], color='#44ff44')
    line3 = fig.line(x3, y3[0], color='#4444ff')
    fig.xaxis.axis_label = 'wnum'
    fig.yaxis.axis_label = 'radiance'
    
    def _update(dex):
        line1.data_source.data['y'] = y1[dex]
        line2.data_source.data['y'] = y2[dex]
        line3.data_source.data['y'] = y3[dex]
        fig.title.text = str(dex)
        push_notebook()
    
    hnd = show(fig, notebook_handle=True)
    wdgt.interact(_update, dex=(0, yn, 1))
    
    Out [26]:
    Out [26]:
    Out [26]:
    interactive(children=(IntSlider(value=4, description='dex', max=9), Output()), _dom_classes=('widget-interact'…
    Out [26]:
    <function __main__._update(dex)>
    In [27]:
    x1 = d['wnum_mw']
    x2 = d['wnum_mw']
    x3 = d['wnum_mw']
    y1 = pmw[23,15].squeeze()
    y2 = tmw[23,15].squeeze()
    y3 = y1 - y2
    # y3 = d['rad_sw'][23,15].squeeze()
    yn = min(y1.shape[0], y2.shape[0], y3.shape[0])
    print(max(abs(y3.ravel())))
    
    fig = figure(title='Radiance Reconstruction Test', height=600, width=1000)  
            #, x_range = (0., 100.,0, y_range=(0.,100.))
    line1 = fig.line(x1, y1[0], color='#ff4444')
    line2 = fig.line(x2, y2[0], color='#44ff44')
    line3 = fig.line(x3, y3[0], color='#4444ff')
    fig.xaxis.axis_label = 'wnum'
    fig.yaxis.axis_label = 'radiance'
    
    def _update(dex):
        line1.data_source.data['y'] = y1[dex]
        line2.data_source.data['y'] = y2[dex]
        line3.data_source.data['y'] = y3[dex]
        fig.title.text = str(dex)
        push_notebook()
    
    hnd = show(fig, notebook_handle=True)
    wdgt.interact(_update, dex=(0, yn, 1))
    
    
    Out [27]:
    0.0
    
    Out [27]:
    Out [27]:
    interactive(children=(IntSlider(value=4, description='dex', max=9), Output()), _dom_classes=('widget-interact'…
    Out [27]:
    <function __main__._update(dex)>
    In [28]:
    np.nanmax(abs((plw-tlw).ravel()))
    Out [28]:
    0.0
    In [29]:
    np.nanmax(abs((pmw-tmw).ravel()))
    Out [29]:
    0.0
    In [30]:
    np.nanmax(abs((psw-tsw).ravel()))
    Out [30]:
    0.0