Пример #1
0
def make_compare(caObj, caObj2, name):
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    height_c = (1000 * caObj.calipso.all_arrays['layer_top_altitude'][:, 0] -
                caObj.calipso.all_arrays['elevation'])
    height_pps1 = caObj.avhrr.all_arrays['ctth_height']
    height_pps2 = caObj2.avhrr.all_arrays['ctth_height']
    use = np.logical_and(height_pps1 > -1, height_pps2 > -1)
    use = np.logical_and(
        use, caObj.calipso.all_arrays['layer_top_altitude'][:, 0] > -1)

    low = np.logical_and(low_clouds, use)
    medium = np.logical_and(medium_clouds, use)
    high = np.logical_and(high_clouds, use)
    bias1 = height_pps1 - height_c
    bias2 = height_pps2 - height_c
    limit = np.percentile(bias2[use], 5)
    print limit
    fig = plt.figure(figsize=(9, 9))
    ax = fig.add_subplot(111)
    plt.boxplot(
        [
            bias1[low], bias1[medium], bias1[high], bias2[low], bias2[medium],
            bias2[high]
        ],
        whis=[2, 98],
        sym='',
        labels=["low1", "medium1", "high1", "low2", "medium2", "high2"],
        showmeans=True)
    ax.set_ylim(-15000, 15000)
    ax.fill_between(np.arange(0, 12),
                    -1500,
                    1500,
                    facecolor='green',
                    alpha=0.2)
    ax.fill_between(np.arange(0, 12), 2000, 15000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0, 12),
                    -2000,
                    -15000,
                    facecolor='red',
                    alpha=0.2)
    for y_val in xrange(-5000, 6000, 1000):
        plt.plot(np.arange(0, 12), y_val + 0 * np.arange(0, 12), ':k')
    plt.title(name)
    plt.savefig(
        "/home/a001865/PICTURES_FROM_PYTHON/CTTH_LAPSE_RATE_INVESTIGATION/ctth_box_plot_%s.png"
        % (name))
    plt.show()
    """
Пример #2
0
def table_21_do_for_atbd(caObj):
    cloudtype_conditions = caObj.avhrr.all_arrays['cloudtype_conditions']
    cloudtype_status = caObj.avhrr.all_arrays['cloudtype_status']
    (no_qflag, night_flag, twilight_flag, day_flag,
     all_dnt_flag) = get_day_night_twilight_info_pps2014(cloudtype_conditions)
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    caliop_ok = np.logical_or(low_clouds,
                              np.logical_or(high_clouds, medium_clouds))
    pps_ctype = caObj.avhrr.all_arrays['cloudtype']
    use = np.logical_and(pps_ctype > 4, pps_ctype < 23)
    use = np.logical_and(
        use,
        np.logical_and(caliop_ok,
                       caObj.calipso.all_arrays['cloud_fraction'] > 0.9))
    pps_low = [pps_ctype_i in [5, 6, 10] for pps_ctype_i in pps_ctype]
    pps_medium = [pps_ctype_i in [7] for pps_ctype_i in pps_ctype]
    pps_high = [
        pps_ctype_i in [8, 9, 11, 12, 13, 14, 15, 16, 17, 18]
        for pps_ctype_i in pps_ctype
    ]
    print "POD low medium high FAR low medium high"
    for use_i, name in zip([all_dnt_flag, day_flag, night_flag, twilight_flag],
                           ["all", "day", "night", "twilight"]):

        use_this = np.logical_and(use, use_i)

        pps_low_i = np.logical_and(pps_low, use_this)
        low_clouds_i = np.logical_and(low_clouds, use_this)
        n_low_ok = 1.0 * np.sum(np.logical_and(pps_low_i, low_clouds_i))
        POD_low = 100 * n_low_ok / np.sum(low_clouds_i)
        FAR_low = 100 * (np.sum(pps_low_i) -
                         n_low_ok) * 1.0 / np.sum(pps_low_i)
        print n_low_ok, np.sum(pps_low_i), np.sum(low_clouds_i)
        pps_medium_i = np.logical_and(pps_medium, use_this)
        medium_clouds_i = np.logical_and(medium_clouds, use_this)
        n_medium_ok = 1.0 * np.sum(
            np.logical_and(pps_medium_i, medium_clouds_i))
        POD_medium = 100 * n_medium_ok / np.sum(medium_clouds_i)
        FAR_medium = 100 * (np.sum(pps_medium_i) -
                            n_medium_ok) / np.sum(pps_medium_i)
        pps_high_i = np.logical_and(pps_high, use_this)
        high_clouds_i = np.logical_and(high_clouds, use_this)
        n_high_ok = 1.0 * np.sum(np.logical_and(pps_high_i, high_clouds_i))
        POD_high = 100 * n_high_ok / np.sum(high_clouds_i)
        FAR_high = 100 * (np.sum(pps_high_i) - n_high_ok) / np.sum(pps_high_i)
        print "%3.1f %3.1f %3.1f %3.1f %3.1f %3.1f" % (
            POD_low, POD_medium, POD_high, FAR_low, FAR_medium, FAR_high)
Пример #3
0
def make_boxplot(caObj, name):
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    height_c = (1000 * caObj.calipso.all_arrays['layer_top_altitude'][:, 0] -
                caObj.calipso.all_arrays['elevation'])
    height_pps = caObj.avhrr.all_arrays['ctth_height']
    use = np.logical_and(
        height_pps > -1,
        caObj.calipso.all_arrays['layer_top_altitude'][:, 0] > -1)

    low = np.logical_and(low_clouds, use)
    medium = np.logical_and(medium_clouds, use)
    high = np.logical_and(high_clouds, use)
    bias = height_pps - height_c
    limit = np.percentile(bias[use], 5)
    print limit
    from matplotlib import rcParams
    rcParams.update({'figure.autolayout': True})
    fig = plt.figure(figsize=(6, 9))
    ax = fig.add_subplot(111)
    #plt.tight_layout()
    #plt.subplots_adjust(left=0.2)
    #plt.subplots_adjust(left=10, bottom=10, right=10, top=10, wspace=0, hspace=0)
    plt.boxplot([bias[low], bias[medium], bias[high]],
                whis=[2, 98],
                sym='',
                labels=["low", "medium", "high"],
                showmeans=True)
    ax.set_ylim(-14000, 8000)
    ax.fill_between(np.arange(0, 6), -500, 500, facecolor='green', alpha=0.6)
    ax.fill_between(np.arange(0, 6), -1000, 1000, facecolor='green', alpha=0.4)
    ax.fill_between(np.arange(0, 6), -1500, 1500, facecolor='green', alpha=0.2)
    ax.fill_between(np.arange(0, 6), 2000, 15000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0, 6), -2000, -15000, facecolor='red', alpha=0.2)
    for y_val in [-5, -4, -3, -2, 2, 3, 4, 5]:
        plt.plot(np.arange(0, 6), y_val * 1000 + 0 * np.arange(0, 6), ':k')
        plt.plot(np.arange(0, 6), -10 * 1000 + 0 * np.arange(0, 6), ':k')
    plt.plot(np.arange(0, 6), 0 + 0 * np.arange(0, 6), 'k')
    plt.title(name)
    plt.savefig(
        "/home/a001865/PICTURES_FROM_PYTHON/CTTH_LAPSE_RATE_INVESTIGATION/ctth_box_plot_%s.png"
        % (name))
Пример #4
0
def prototype_ctth_alg_lapse_rate(caObj, filename):
   from get_flag_info import (get_semi_opaque_info_pps2014,
                              get_calipso_high_clouds,
                              get_calipso_medium_clouds,
                              get_calipso_low_clouds)
   low_clouds = get_calipso_low_clouds(caObj)
   high_clouds = get_calipso_high_clouds(caObj)
   medium_clouds = get_calipso_medium_clouds(caObj)
   semi, opaq = get_semi_opaque_info_pps2014(caObj.avhrr.ctth_status)

   print "prototype new ctth height"
   height_c = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,0] - 
               caObj.calipso.all_arrays['elevation'])
   height_pps = caObj.avhrr.all_arrays['ctth_height']
   bias = height_pps - height_c
   tsur = caObj.avhrr.all_arrays['surftemp']
   tsur = caObj.avhrr.all_arrays['segment_nwp_temp'][:,0] 
   d45 = (caObj.avhrr.all_arrays['bt11micron'] - 
          caObj.avhrr.all_arrays['bt12micron'])
   temperature_pps = caObj.avhrr.all_arrays['bt12micron'].copy()#
   temp_diff = temperature_pps - tsur
   new_pps_h = calculate_lapse_rate_h(caObj)
   bias_l_rate = new_pps_h - height_c

   use = np.logical_and(caObj.avhrr.all_arrays['ctth_height']>-8,
                        caObj.calipso.all_arrays['layer_top_altitude'][:,0]>-999)
   #use = np.logical_and(use,caObj.calipso.all_arrays['elevation']<10)
   #use = np.logical_and(use,semi)
   #use = np.logical_and(use,low_clouds)
   #print "bias", np.mean(bias_nona[use]), "bias", np.mean(bias_l_rate_nona[use])
                        #caObj.calipso.all_arrays['number_layers_found'][:]>0)
   print "low, medium, high", filename                     
   for clouds in [low_clouds, medium_clouds, high_clouds, use]:
       use_this_type = np.logical_and(use,clouds)
       if not use_this_type.any():
          continue
       print "N %d", len(bias[use_this_type])
       print "bias old %d"%(np.mean(bias[use_this_type])), 
       print "bias %d"%(np.mean(bias_l_rate[use_this_type]))
       print "std old %d"%(np.std(bias[use_this_type])),
       print "std %d"%(np.std(bias_l_rate[use_this_type]))
       print "MAE old %d"%(np.mean(np.abs(bias[use_this_type]))),
       print "MAE %d"%(np.mean(np.abs(bias_l_rate[use_this_type])))
       print "RMS old %d"%(np.sqrt(np.mean((bias[use_this_type])**2))),
       print "RMS %d"%(np.sqrt(np.mean((bias_l_rate[use_this_type])**2)))
       print "N %d", len(bias[use_this_type])
       bias_p =bias/height_c
       bias_l_rate_p =bias_l_rate/height_c
       print "percent bias old %1.2f"%(np.mean(bias_p[use_this_type])), 
       print "percent bias %1.2f"%(np.mean(bias_l_rate_p[use_this_type]))
       print "percent std old %1.2f"%(np.std(bias_p[use_this_type])),
       print "percent std %1.2f"%(np.std(bias_l_rate_p[use_this_type]))
       print "percent MAE old %1.2f"%(np.mean(np.abs(bias_p[use_this_type]))),
       print "percent MAE %1.2f"%(np.mean(np.abs(bias_l_rate_p[use_this_type])))
       print "percent RMS old %1.2f"%(np.sqrt(np.mean((bias_p[use_this_type])**2))),
       print "percent RMS %1.2f"%(np.sqrt(np.mean((bias_l_rate_p[use_this_type])**2)))  

       if len(bias[use_this_type])>1 and 1==2:
           print "n", len(bias[use_this_type]), "%d/"%(np.mean(bias[use_this_type])), 
           print "%d"%(np.mean(bias_l_rate[use_this_type])), 
           print "%d/"%(np.mean(bias[np.logical_and(temp_diff>0, use_this_type)])), 
           print "%d"%(np.mean(bias_l_rate[np.logical_and(temp_diff>0, use_this_type)])), 
           print "%0.2f"%(np.mean(d45[use_this_type])), 
           print "%d %d %d %d"%(np.percentile(new_pps_h[use_this_type],10), 
                                np.percentile(new_pps_h[use_this_type],90),
                                np.percentile(height_pps[use_this_type],10), 
                                np.percentile(height_pps[use_this_type],90))

   from cloudsat_calipso_avhrr_plot import (drawCalClsatGEOPROFAvhrrPlot,
                                            drawCalPPSHeightPlot_PrototypePPSHeight  )      
   """
   drawCalClsatGEOPROFAvhrrPlot(None,
                                caObj.calipso,
                                None, 
                                use,
                                None, 
                                caObj.calipso.layer_base_altitude*1000,
                                caObj.calipso.layer_top_altitude*1000,
                                use,
                                new_pps_h + caObj.calipso.all_arrays['elevation'], 
                                "/home/a001865/CTTH_LAPSE_RATE_INVESTIGATION/",
                                "test_plot_file_orig",
                                'BASIC', 
                                emissfilt_calipso_ok=None, 
                                file_type='png',
                                instrument='modis')
   """
   """
def make_boxplot_pressure(caObj, name, modis_lvl2=False):
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    pressure_c = caObj.calipso.all_arrays['layer_top_pressure'][:, 0]
    if modis_lvl2:
        pressure_pps = caObj.modis.all_arrays['pressure']
    else:
        pressure_pps = 0.01 * caObj.avhrr.all_arrays['ctth_pressure']
    if modis_lvl2:
        height_pps = caObj.modis.all_arrays['height']
    else:
        height_pps = caObj.avhrr.all_arrays['ctth_height']

    thin = np.logical_and(
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] <
        0.30,
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] >
        0)
    very_thin = np.logical_and(
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] <
        0.10,
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] >
        0)
    thin_top = np.logical_and(
        caObj.calipso.all_arrays['number_layers_found'] > 1, thin)
    thin_1_lay = np.logical_and(
        caObj.calipso.all_arrays['number_layers_found'] == 1, thin)
    use = np.logical_and(
        pressure_pps > 0,
        caObj.calipso.all_arrays['layer_top_altitude'][:, 0] >= 0)
    low = np.logical_and(low_clouds, use)
    medium = np.logical_and(medium_clouds, use)
    high = np.logical_and(high_clouds, use)
    c_all = np.logical_or(high, np.logical_or(low, medium))
    high_very_thin = np.logical_and(high, very_thin)
    high_thin = np.logical_and(high, np.logical_and(~very_thin, thin))
    high_thick = np.logical_and(high, ~thin)
    #print "thin, thick high", np.sum(high_thin), np.sum(high_thick)
    bias = pressure_pps - pressure_c
    abias = np.abs(bias)
    #abias[abias>2000]=2000
    print name.ljust(30, " "), "%3.1f" % (np.mean(
        abias[c_all])), "%3.1f" % (np.mean(abias[low])), "%3.1f" % (np.mean(
            abias[medium])), "%3.1f" % (np.mean(abias[high]))

    c_all = np.logical_or(np.logical_and(~very_thin, high),
                          np.logical_or(low, medium))
    number_of = np.sum(c_all)

    #print name.ljust(30, " "), "%3.1f"%(np.sum(abias[c_all]<250)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<500)*100.0/number_of),  "%3.1f"%(np.sum(abias[c_all]<1000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<2000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<3000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<4000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<5000)*100.0/number_of)
    from matplotlib import rcParams
    rcParams.update({'figure.autolayout': True})
    fig = plt.figure(figsize=(6, 9))
    ax = fig.add_subplot(111)
    plt.xticks(rotation=70)
    ax.fill_between(np.arange(0, 8), -50, 50, facecolor='green', alpha=0.6)
    ax.fill_between(np.arange(0, 8), -100, 100, facecolor='green', alpha=0.4)
    ax.fill_between(np.arange(0, 8), -150, 150, facecolor='green', alpha=0.2)
    ax.fill_between(np.arange(0, 8), 200, 2000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0, 8), -2000, -200, facecolor='red', alpha=0.2)
    for y_val in [-6, -4, -2, 2, 4, 6, 8, -8]:
        plt.plot(np.arange(0, 8),
                 y_val * 100 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
    plt.plot(np.arange(0, 8), 0 + 0 * np.arange(0, 8), ':k', alpha=0.4)
    bplot = ax.boxplot([
        bias[low], bias[medium], bias[high], bias[high_thick], bias[high_thin],
        bias[high_very_thin]
    ],
                       whis=[5, 95],
                       sym='',
                       labels=[
                           "low", "medium", "high-all", "high-thick\n od>0.4",
                           "high-thin \n 0.1<od<0.4", "high-vthin\n od<0.1"
                       ],
                       showmeans=True,
                       patch_artist=True)
    ax.set_ylim(-1000, 800)
    for box in bplot['boxes']:
        box.set_facecolor('0.9')
    plt.title(name)
    plt.savefig(
        "/home/a001865/PICTURES_FROM_PYTHON/CTTH_BOX/ctth_box_plot_pressure_%s_5_95_filt.png"
        % (name))
def make_boxplot(caObj, name, month="xx", modis_lvl2=False, use_m2_pix=True):
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    height_c = 1000 * caObj.calipso.all_arrays['layer_top_altitude'][:, 0]
    cloud_elevation = 1000 * caObj.calipso.all_arrays[
        'layer_top_altitude'][:, 0] - caObj.calipso.all_arrays['elevation']
    if modis_lvl2:
        height_imager = caObj.modis.all_arrays['height']
    else:
        height_imager = caObj.avhrr.all_arrays[
            'imager_ctth_m_above_seasurface']
        if height_imager is None:
            height_imager = caObj.avhrr.all_arrays[
                'ctth_height'] + caObj.calipso.all_arrays['elevation']

    use = np.logical_and(height_imager > -1, height_c >= 0)
    use = np.logical_and(height_imager < 45000, use)
    USE_ONLY_PIXELS_WHERE_PPS_AND_MODIS_C6_HAVE_VALUES = use_m2_pix
    if USE_ONLY_PIXELS_WHERE_PPS_AND_MODIS_C6_HAVE_VALUES:
        height_mlvl2 = caObj.modis.all_arrays['height']
        height_pps = caObj.avhrr.all_arrays['imager_ctth_m_above_seasurface']
        use = np.logical_and(use, height_mlvl2 > -1)
        use = np.logical_and(use, height_mlvl2 < 45000)
        use = np.logical_and(use, height_pps > -1)
        use = np.logical_and(use, height_pps < 45000)

    thin = np.logical_and(
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] <
        0.30,
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] >
        0)
    very_thin = np.logical_and(
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] <
        0.10,
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] >
        0)
    thin_top = np.logical_and(
        caObj.calipso.all_arrays['number_layers_found'] > 1, thin)
    thin_1_lay = np.logical_and(
        caObj.calipso.all_arrays['number_layers_found'] == 1, thin)

    low = np.logical_and(low_clouds, use)
    medium = np.logical_and(medium_clouds, use)
    high = np.logical_and(high_clouds, use)
    c_all = np.logical_or(high, np.logical_or(low, medium))
    high_very_thin = np.logical_and(high, very_thin)
    high_thin = np.logical_and(high, np.logical_and(~very_thin, thin))
    high_thick = np.logical_and(high, ~thin)
    #print "thin, thick high", np.sum(high_thin), np.sum(high_thick)
    bias = height_imager - height_c
    abias = np.abs(bias)
    #abias[abias>2000]=2000
    print name.ljust(30, " "), "%3.1f" % (np.mean(
        abias[c_all])), "%3.1f" % (np.mean(abias[low])), "%3.1f" % (np.mean(
            abias[medium])), "%3.1f" % (np.mean(abias[high]))

    c_all = np.logical_or(np.logical_and(~very_thin, high),
                          np.logical_or(low, medium))
    number_of = np.sum(c_all)
    MAE = np.mean(abias[c_all])
    #print name.ljust(30, " "), "%3.1f"%(np.sum(abias[c_all]<250)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<500)*100.0/number_of),  "%3.1f"%(np.sum(abias[c_all]<1000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<2000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<3000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<4000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<5000)*100.0/number_of)
    from matplotlib import rcParams
    rcParams.update({'figure.autolayout': True})
    fig = plt.figure(figsize=(6, 9))
    ax = fig.add_subplot(111)
    plt.xticks(rotation=70)
    ax.fill_between(np.arange(0, 8), -500, 500, facecolor='green', alpha=0.6)
    ax.fill_between(np.arange(0, 8), -1000, 1000, facecolor='green', alpha=0.4)
    ax.fill_between(np.arange(0, 8), -1500, 1500, facecolor='green', alpha=0.2)
    ax.fill_between(np.arange(0, 8), 2000, 15000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0, 8), -2000, -15000, facecolor='red', alpha=0.2)
    for y_val in [-5, -4, -3, -2, 2, 3, 4, 5]:
        plt.plot(np.arange(0, 8),
                 y_val * 1000 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
        plt.plot(np.arange(0, 8),
                 -10 * 1000 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
    plt.plot(np.arange(0, 8), 0 + 0 * np.arange(0, 8), ':k', alpha=0.4)
    bplot = ax.boxplot([
        bias[low], bias[medium], bias[high], bias[high_thick], bias[high_thin],
        bias[high_very_thin]
    ],
                       whis=[5, 95],
                       sym='',
                       labels=[
                           "low", "medium", "high-all", "high-thick\n od>0.4",
                           "high-thin \n 0.1<od<0.4", "high-vthin\n od<0.1"
                       ],
                       showmeans=True,
                       patch_artist=True)
    ax.set_ylim(-14000, 8000)
    for box in bplot['boxes']:
        box.set_facecolor('0.9')
    plt.title("%s MAE = %3.0f" % (name, MAE))
    plt.savefig(
        "/home/a001865/PICTURES_FROM_PYTHON/CTTH_BOX/ctth_box_plot_%s_5_95_filt.png"
        % (name))

    elevation_zero = np.logical_and(
        use, caObj.calipso.all_arrays['elevation'] > 5000)
    low_clouds = height_c < 2500
    medium_clouds = np.logical_and(height_c >= 2500, height_c <= 5000)
    high_clouds = height_c > 5000
    low = np.logical_and(low_clouds, use)
    medium = np.logical_and(medium_clouds, use)
    high = np.logical_and(high_clouds, use)
    fig = plt.figure(figsize=(6, 9))
    ax = fig.add_subplot(111)
    plt.xticks(rotation=50)
    ax.fill_between(np.arange(0, 8), -500, 500, facecolor='green', alpha=0.6)
    ax.fill_between(np.arange(0, 8), -1000, 1000, facecolor='green', alpha=0.4)
    ax.fill_between(np.arange(0, 8), -1500, 1500, facecolor='green', alpha=0.2)
    ax.fill_between(np.arange(0, 8), 2000, 15000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0, 8), -2000, -15000, facecolor='red', alpha=0.2)
    for y_val in [-5, -4, -3, -2, 2, 3, 4, 5]:
        plt.plot(np.arange(0, 8),
                 y_val * 1000 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
        plt.plot(np.arange(0, 8),
                 -10 * 1000 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
    plt.plot(np.arange(0, 8), 0 + 0 * np.arange(0, 8), ':k', alpha=0.4)
    bplot = ax.boxplot(
        [bias[low], bias[medium], bias[high], bias[elevation_zero]],
        whis=[5, 95],
        sym='',
        labels=["low <2.5km", "medium", "high>5km", "ground>5km"],
        showmeans=True,
        patch_artist=True)
    ax.set_ylim(-8000, 8000)
    for box in bplot['boxes']:
        box.set_facecolor('0.9')
    plt.title("Calipso %s \nHeight bias comparison MAE= %3.0f" % (name, MAE))
    plt.savefig(
        "/home/a001865/PICTURES_FROM_PYTHON/CTTH_BOX/ctth_box_plot_hkm_%s_5_95_filt.png"
        % (name))
def extract_data(cObj, sat='cloudsat'):
    pltObj = PlotAndDataObject()
    if sat.lower() in 'cloudsat':
        pltObj.height_c2 = cObj.cloudsat.all_arrays['clsat_max_height']
        clsat_max_height = -9 + 0 * np.zeros(cObj.cloudsat.latitude.shape)
        for i in range(125):
            height = cObj.cloudsat.Height[:, i]
            cmask_ok = cObj.cloudsat.CPR_Cloud_mask[:, i]
            top_height = height + 120
            #top_height[height<240*4] = -9999 #Do not use not sure why these are not used Nina 20170317
            is_cloudy = cmask_ok > 30
            top_height[~is_cloudy] = -9999
            clsat_max_height[clsat_max_height < top_height] = top_height[
                clsat_max_height < top_height]
        height_c = clsat_max_height

        pltObj.low_clouds = np.logical_and(
            height_c < cObj.avhrr.all_arrays['segment_nwp_h680'],
            height_c > -9)
        pltObj.medium_clouds = np.logical_and(
            height_c >= cObj.avhrr.all_arrays['segment_nwp_h680'],
            height_c <= cObj.avhrr.all_arrays['segment_nwp_h440'])
        pltObj.high_clouds = np.logical_and(
            height_c > cObj.avhrr.all_arrays['segment_nwp_h440'],
            height_c > -9)
        elevation = cObj.cloudsat.all_arrays['elevation']
        elevation[elevation < 0] = 0
    elif sat.lower() in 'calipso':
        height_c = 1000 * cObj.calipso.all_arrays['layer_top_altitude'][:, 0]
        pltObj.low_clouds = get_calipso_low_clouds(cObj)
        pltObj.high_clouds = get_calipso_high_clouds(cObj)
        pltObj.medium_clouds = get_calipso_medium_clouds(cObj)
        elevation = cObj.calipso.all_arrays['elevation']
        elevation[elevation < 0] = 0

        use_part = False
        part = "all"
        if use_part:
            part = "single_layer_sea_below_60_in5km_as_art"
            use_part = np.logical_and(
                use_part, cObj.calipso.all_arrays['number_layers_found'] == 1)
            use_part = np.logical_and(
                use_part,
                np.abs(cObj.calipso.all_arrays['latitude']) < 60)
            use = np.logical_and(use_part,
                                 np.equal(cObj.calipso.igbp_surface_type, 17))
            #use = np.logical_and(use_part,height_c<3000+cObj.calipso.all_arrays['elevation'])
            use_part = np.logical_and(
                use_part, cObj.calipso.
                all_arrays['feature_optical_depth_532_top_layer_5km'] > 0)
            use_part = np.logical_and(
                use_part, cObj.calipso.
                all_arrays['feature_optical_depth_532_top_layer_5km'] ==
                cObj.calipso.all_arrays['total_optical_depth_5km'])
            part = "single_layer_sea_below_60_in5km_all_od_top"
            low = np.logical_and(low_clouds, use_part)
            #low = np.logical_and(height_c<low_clouds,use_part)
            low = np.logical_and(
                use_part, height_c <
                (3000 + cObj.calipso.all_arrays['elevation']))
            medium = np.logical_and(medium_clouds, use_part)
            high = np.logical_and(height_c > 8000, use_part)

    pltObj.height_c = height_c
    pltObj.height_mlvl2 = cObj.modis.all_arrays['height']  #+elevation #??
    #height_pps = cObj.avhrr.all_arrays['imager_ctth_m_above_seasurface']
    pltObj.height_pps = cObj.avhrr.all_arrays['ctthnnant_height'] + elevation
    pltObj.height_old = cObj.avhrr.all_arrays['ctthold_height'] + elevation
    pltObj.pps_bias = pltObj.height_pps - height_c
    pltObj.old_bias = pltObj.height_old - height_c
    pltObj.mlvl2_bias = pltObj.height_mlvl2 - height_c
    use = height_c >= 0
    use = np.logical_and(use, pltObj.height_mlvl2 > -1)
    use = np.logical_and(use,
                         cObj.modis.all_arrays['pressure'] >= 70)  #no_effekt
    use = np.logical_and(use, cObj.avhrr.all_arrays['ctthnnant_height'] > -1)
    use = np.logical_and(use, cObj.avhrr.all_arrays['ctthold_height'] > -1)
    #use = np.logical_and(use,cObj.avhrr.all_arrays['ctthnnant_height']<55000)no_effekt
    use = np.logical_and(use,
                         cObj.avhrr.all_arrays['ctthold_pressure'] >= 70 * 100)
    use = np.logical_and(use, cObj.modis.all_arrays['cloud_emissivity'] <= 100)
    pltObj.use = use
    use_all = use.copy()
    for var in [
            'ctthnnant_height', 'ctthnna1nt_height', 'ctthnnvnt_height',
            'ctthnnm2nt_height', 'ctthnnmintnco2_height', 'ctthnnmint_height',
            'ctthold_height'
    ]:
        name = var.replace('_height', '').replace('ctth', 'bias_')
        pltObj.all_arrays[
            name] = cObj.avhrr.all_arrays[var] + elevation - height_c
        #ok_ctth = np.logical_and(cObj.avhrr.all_arrays[var]<550000, cObj.avhrr.all_arrays[var]>-1)
        ok_ctth = cObj.avhrr.all_arrays[var] > -1
        use_all = np.logical_and(use_all, ok_ctth)
        if 'nnmi' in var:
            ok_ctth = np.logical_and(ok_ctth,
                                     cObj.avhrr.all_arrays['modis_27'] > -1)
        if 'nna1' in var:
            ok_ctth = np.logical_and(ok_ctth,
                                     cObj.avhrr.all_arrays['bt37micron'] > -1)
        if 'nnv' in var or 'nnm' in var:
            ok_ctth = np.logical_and(ok_ctth,
                                     cObj.avhrr.all_arrays['bt86micron'] > -1)
        if 'nna1' not in var:
            ok_ctth = np.logical_and(ok_ctth,
                                     cObj.avhrr.all_arrays['bt12micron'] > -1)
        if 'nnm' in var:
            ok_ctth = np.logical_and(ok_ctth,
                                     cObj.avhrr.all_arrays['modis_28'] > -1)
        if 'ctthnnmint_height' == var:
            ok_ctth = np.logical_and(ok_ctth,
                                     cObj.avhrr.all_arrays['modis_33'] > -1)
        ok_ctth = np.logical_and(ok_ctth,
                                 cObj.avhrr.all_arrays['bt11micron'] > -1)
        use_all = np.logical_and(use_all, ok_ctth)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['modis_27'] > -1)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['modis_28'] > -1)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['modis_33'] > -1)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['text_t37'] > -9)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['warmest_t37'] > -9)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['coldest_t37'] > -9)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['bt11micron'] > -1)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['bt12micron'] > -1)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['bt37micron'] > -1)
        use_all = np.logical_and(use_all,
                                 cObj.avhrr.all_arrays['bt86micron'] > -1)
        use_all = np.logical_and(use_all, cObj.avhrr.all_arrays['ciwv'] > -9)
        pltObj.all_arrays[name.replace('bias_', 'ok_')] = ok_ctth

    pltObj.use_all = use_all
    pltObj.ok_cma_mlvl2 = cObj.modis.all_arrays['cloud_emissivity'] <= 100
    pltObj.ok_cma_pps = np.logical_or(cObj.avhrr.all_arrays['cloudmask'] == 1,
                                      cObj.avhrr.all_arrays['cloudmask'] == 2)
    pltObj.ok_cma_pps = np.logical_and(pltObj.ok_cma_pps, height_c >= 0)
    pltObj.ok_cma_mlvl2 = np.logical_and(pltObj.ok_cma_mlvl2, height_c >= 0)
    pltObj.ok_modis = np.logical_and(pltObj.height_mlvl2 > -1,
                                     pltObj.height_mlvl2 < 45000)
    pltObj.ok_cma = np.logical_and(pltObj.ok_modis, pltObj.ok_cma_pps)

    return pltObj
Пример #8
0
def make_boxplot(caObj, name):
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    height_c = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,0] - 
                caObj.calipso.all_arrays['elevation'])
    height_c1 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,0] - 
                 caObj.calipso.all_arrays['elevation'])
    height_c2 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,1] - 
                 caObj.calipso.all_arrays['elevation'])
    height_c3 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,2] - 
                 caObj.calipso.all_arrays['elevation'])
    height_c4 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,3] - 
                 caObj.calipso.all_arrays['elevation'])
    height_pps = caObj.avhrr.all_arrays['ctth_height']
    bias_1 =  height_pps - height_c1
    bias_2 =  height_pps - height_c2
    bias_3 =  height_pps - height_c3
    bias_4 =  height_pps - height_c4
    thin = np.logical_and(caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']<0.30, 
                          caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']>0) 
    very_thin = np.logical_and(caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']<0.10, 
                          caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']>0) 
    thin_top = np.logical_and(caObj.calipso.all_arrays['number_layers_found']>1, thin)
    thin_1_lay = np.logical_and(caObj.calipso.all_arrays['number_layers_found']==1, thin)
    #height_c[thin_top] =  height_c2[thin_top]
    #height_c[np.abs(bias_1)<np.abs(bias_2)] =  height_c1[np.abs(bias_1)<np.abs(bias_2)]
    #height_c[np.abs(bias_2)<np.abs(bias_1)] =  height_c2[np.abs(bias_2)<np.abs(bias_1)]
    #bias = height_pps - height_c
    #height_c[np.abs(bias_3)<np.abs(bias)] =  height_c3[np.abs(bias_3)<np.abs(bias)]
    #height_c[~thin_top] =  height_c1[~thin_top]
    #height_c[thin_top] =  height_c2[thin_top]

    
    
    use = np.logical_and(height_pps >-1,
                         caObj.calipso.all_arrays['layer_top_altitude'][:,0]>=0)
    use = np.logical_and(height_pps <45000,use)

    low = np.logical_and(low_clouds,use)
    medium = np.logical_and(medium_clouds,use)
    high = np.logical_and(high_clouds,use)
    c_all = np.logical_or(high,np.logical_or(low,medium))
    high_very_thin = np.logical_and(high, very_thin)
    high_thin = np.logical_and(high, np.logical_and(~very_thin,thin))
    high_thick = np.logical_and(high, ~thin)
    #print "thin, thick high", np.sum(high_thin), np.sum(high_thick) 
    bias = height_pps - height_c
    limit = np.percentile(bias[use],5)
    #print limit 
    abias = np.abs(bias)
    MAE = np.mean(abias[c_all])
    #abias[abias>2000]=2000
    print name.ljust(30, " "), "%3.1f"%(np.mean(abias[c_all])), "%3.1f"%(np.mean(abias[low])),"%3.1f"%(np.mean(abias[medium])),"%3.1f"%(np.mean(abias[high])), "%3.1f"%(limit)

    c_all = np.logical_or(np.logical_and(~very_thin,high),np.logical_or(low,medium))
    number_of = np.sum(c_all)
     
    #print name.ljust(30, " "), "%3.1f"%(np.sum(abias[c_all]<250)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<500)*100.0/number_of),  "%3.1f"%(np.sum(abias[c_all]<1000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<2000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<3000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<4000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<5000)*100.0/number_of)
    from matplotlib import rcParams
    rcParams.update({'figure.autolayout': True})
    fig = plt.figure(figsize = (6,9))        
    ax = fig.add_subplot(111)
    plt.xticks(rotation=70)
    #plt.tight_layout()
    #plt.subplots_adjust(left=0.2)
    #plt.subplots_adjust(left=10, bottom=10, right=10, top=10, wspace=0, hspace=0)

    ax.fill_between(np.arange(0,8),-500,500, facecolor='green', alpha=0.6)
    ax.fill_between(np.arange(0,8),-1000,1000, facecolor='green', alpha=0.4)
    ax.fill_between(np.arange(0,8),-1500,1500, facecolor='green', alpha=0.2)
    ax.fill_between(np.arange(0,8),2000,15000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0,8),-2000,-15000, facecolor='red', alpha=0.2)
    for y_val in [-5,-4,-3,-2,2,3,4,5]:
        plt.plot(np.arange(0,8), y_val*1000 + 0*np.arange(0,8),':k')
        plt.plot(np.arange(0,8), -10*1000 + 0*np.arange(0,8),':k')
    plt.plot(np.arange(0,8), 0 + 0*np.arange(0,8),'k')
    plt.boxplot([bias[low],bias[medium],bias[high],bias[high_thick],bias[high_thin],bias[high_very_thin]],whis=[5, 95],sym='',
                labels=["low","medium","high-all","high-thick\n od>0.4","high-thin \n 0.1<od<0.4","high-vthin\n od<0.1"],showmeans=True)
    ax.set_ylim(-14000,8000)
    plt.title("%s MAE = %3.0f"%(name,MAE))
    plt.savefig("/home/a001865/PICTURES_FROM_PYTHON/CTTH_LAPSE_RATE_INVESTIGATION/ctth_box_plot_%s_5_95_filt.png"%(name))
def make_violinplot(caObj, name, modis_lvl2=False):
    low_clouds = get_calipso_low_clouds(caObj)
    high_clouds = get_calipso_high_clouds(caObj)
    medium_clouds = get_calipso_medium_clouds(caObj)
    height_c = (1000 * caObj.calipso.all_arrays['layer_top_altitude'][:, 0] -
                caObj.calipso.all_arrays['elevation'])
    if modis_lvl2:
        height_pps = caObj.modis.all_arrays['height']
    else:
        height_pps = caObj.avhrr.all_arrays['ctth_height']
        print "min/max height", np.min(height_pps), np.max(height_pps)
    thin = np.logical_and(
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] <
        0.30,
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] >
        0)
    very_thin = np.logical_and(
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] <
        0.10,
        caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km'] >
        0)
    thin_top = np.logical_and(
        caObj.calipso.all_arrays['number_layers_found'] > 1, thin)
    thin_1_lay = np.logical_and(
        caObj.calipso.all_arrays['number_layers_found'] == 1, thin)
    use = np.logical_and(
        height_pps > -1,
        caObj.calipso.all_arrays['layer_top_altitude'][:, 0] >= 0)
    use = np.logical_and(height_pps < 45000, use)
    low = np.logical_and(low_clouds, use)
    medium = np.logical_and(medium_clouds, use)
    high = np.logical_and(high_clouds, use)
    c_all = np.logical_or(high, np.logical_or(low, medium))
    high_very_thin = np.logical_and(high, very_thin)
    high_thin = np.logical_and(high, np.logical_and(~very_thin, thin))
    high_thick = np.logical_and(high, ~thin)
    #print "thin, thick high", np.sum(high_thin), np.sum(high_thick)
    bias = height_pps - height_c
    abias = np.abs(bias)
    #abias[abias>2000]=2000
    print name.ljust(30, " "), "%3.1f" % (np.mean(
        abias[c_all])), "%3.1f" % (np.mean(abias[low])), "%3.1f" % (np.mean(
            abias[medium])), "%3.1f" % (np.mean(abias[high]))

    c_all = np.logical_or(np.logical_and(~very_thin, high),
                          np.logical_or(low, medium))
    number_of = np.sum(c_all)

    #print name.ljust(30, " "), "%3.1f"%(np.sum(abias[c_all]<250)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<500)*100.0/number_of),  "%3.1f"%(np.sum(abias[c_all]<1000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<2000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<3000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<4000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<5000)*100.0/number_of)
    from matplotlib import rcParams
    rcParams.update({'figure.autolayout': True})
    fig = plt.figure(figsize=(6, 9))
    ax = fig.add_subplot(111)
    plt.xticks(rotation=70)
    ax.fill_between(np.arange(0, 8), -1500, 1500, facecolor='green', alpha=0.2)
    ax.fill_between(np.arange(0, 8), 2000, 20000, facecolor='red', alpha=0.2)
    ax.fill_between(np.arange(0, 8), -2000, -20000, facecolor='red', alpha=0.2)
    for y_val in [-5, -4, -3, -2, 2, 3, 4, 5]:
        plt.plot(np.arange(0, 8),
                 y_val * 1000 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
        plt.plot(np.arange(0, 8),
                 -10 * 1000 + 0 * np.arange(0, 8),
                 ':k',
                 alpha=0.4)
    plt.plot(np.arange(0, 8), 0 + 0 * np.arange(0, 8), ':k', alpha=0.4)
    bplot = ax.violinplot([
        bias[low], bias[medium], bias[high], bias[high_thick], bias[high_thin],
        bias[high_very_thin]
    ],
                          widths=0.9,
                          showextrema=False,
                          showmedians=True)
    ax.set_ylim(-20000, 20000)
    plt.title(name)
    plt.savefig(
        "/home/a001865/PICTURES_FROM_PYTHON/CTTH_BOX/ctth_violin_%s_5_95_filt.png"
        % (name))