Ejemplo n.º 1
0
def render_aerosol_subtype(filename, x_range, y_range, fig, pfig):
    """
    Renders the Vertical Feature Mask on the current plot. Note that L2 data is organized
    differently than L1. See comments below and the CALIPSO data product catalogue for more
    information before editing

    :param filename: L2 HDF file
    :param x_range: Tuple of first and last profile index to load from ToolsWindow
    :param y_range: Tuple of first and last altitude index to load from ToolsWindow
    :param fig: Matplotlib backend object
    :param pfig: Matplotlib backend object
    """

    # 15 profiles are in 1 record of VFM data. At the highest altitudes 5 profiles are averaged
    # together. In the mid altitudes 3 are averaged and at roughly 8 km or less, there are
    # separate profiles.
    prof_per_row = 15

    # constant variables
    alt_len = 545
    first_alt = y_range[0]
    last_alt = y_range[1]
    first_lat = int(x_range[0]/prof_per_row)
    last_lat = int(x_range[1]/prof_per_row)
    colormap = 'dat/calipso-aerosol_subtype.cmap'

    # naming products within the HDF file
    with HDF(filename) as product:
        time = product['Profile_UTC_Time'][first_lat:last_lat, 0]
        minimum = min(product['Profile_UTC_Time'][::])[0]
        maximum = max(product['Profile_UTC_Time'][::])[0]

        # Determine how far the file can be viewed
        if time[-1] >= maximum and len(time) < 950:
            raise IndexError
        if time[0] < minimum:
            raise IndexError

        height = product['metadata']['Lidar_Data_Altitudes'][33:-5:]
        dataset = product['Feature_Classification_Flags'][first_lat:last_lat]
        latitude = product['Latitude'][first_lat:last_lat, 0]
        latitude = latitude[::prof_per_row]
        time = np.array([ccplot.utils.calipso_time2dt(t) for t in time])

        # Mask all unknown values
        dataset = np.ma.masked_equal(dataset, -999)

        # Give the number of rows in the dataset
        num_rows = dataset.shape[0]

        # Create an empty array the size of of L1 array so they match on the plot
        unpacked_aerosol_subtype = np.zeros((alt_len, prof_per_row * num_rows), np.uint8)

        # Assign the values from 0-7 to subtype
        aerosol_subtype = extract_aerosol_subtype(dataset)

        # Place 15-wide, alt_len-tall blocks of data into the
        for i in range(num_rows):
            unpacked_aerosol_subtype[:, prof_per_row * i:prof_per_row * (i + 1)] = \
                vfm_row2block(aerosol_subtype[i, :])
        aerosol_subtype = unpacked_aerosol_subtype

        max_alt = 20
        unif_alt = uniform_alt_2(max_alt, height)
        regrid_aerosol_subtype = regrid_lidar(height, aerosol_subtype, unif_alt)

        # Format color map
        cmap = ccplot.utils.cmap(colormap)
        cm = mpl.colors.ListedColormap(cmap['colors'] / 255.0)
        cm.set_under(cmap['under'] / 255.0)
        cm.set_over(cmap['over'] / 255.0)
        cm.set_bad(cmap['bad'] / 255.0)
        norm = mpl.colors.BoundaryNorm(cmap['bounds'], cm.N)

        im = fig.imshow(
            regrid_aerosol_subtype,
            extent=(latitude[0], latitude[-1], first_alt, last_alt),
            cmap=cm,
            aspect='auto',
            norm=norm,
            interpolation='nearest',
        )

        fig.set_ylabel('Altitude (km)')
        fig.set_xlabel('Latitude')
        fig.set_title('Aerosol Subtype')

        cbar_label = 'Aerosol Subtype Flags'
        cbar = pfig.colorbar(im)
        cbar.set_label(cbar_label)
        cbar.ax.set_yticklabels(['N/a','Clean Marine','Dust','Polluted\nContinental','Clean\nContinental',
                             'Polluted\nDust','Smoke','Other'])

        ax = fig.twiny()
        ax.set_xlabel('Time')
        ax.set_xlim(time[0], time[-1])
        ax.get_xaxis().set_major_formatter(mpl.dates.DateFormatter('%H:%M:%S'))

        fig.set_zorder(0)
        ax.set_zorder(1)

        title = fig.set_title('Aerosol Subtype')
        title_xy = title.get_position()
        title.set_position([title_xy[0], title_xy[1] * 1.07])

        return ax
Ejemplo n.º 2
0
def render_depolarized(filename, x_range, y_range, fig, pfig):
    x1 = x_range[0]
    x2 = x_range[1]
    h1 = y_range[0]
    h2 = y_range[1]
    colormap = 'dat/calipso-depolar.cmap'
    averaging_width = 5

    print('xrange: ' + str(x_range) + ', yrange: ' + str(y_range))

    with HDF(filename) as product:
        time = product['Profile_UTC_Time'][x1:x2, 0]
        alt = product['metadata']['Lidar_Data_Altitudes']
        minimum = min(product['Profile_UTC_Time'][::])[0]
        maximum = max(product['Profile_UTC_Time'][::])[0]
        latitude = product['Latitude'][x1:x2, 0]

        # length of time determines how far the file can be viewed
        if time[-1] >= maximum and len(time) < 950:
            raise IndexError
        if time[0] < minimum:
            raise IndexError

        time = np.array([ccplot.utils.calipso_time2dt(t) for t in time])
        latitude = latitude[::averaging_width]

        tot_532 = product['Total_Attenuated_Backscatter_532'][x1:x2].T
        perp_532 = product['Perpendicular_Attenuated_Backscatter_532'][x1:x2].T
        avg_tot_532 = avg_horz_data(tot_532, averaging_width)
        avg_perp_532 = avg_horz_data(perp_532, averaging_width)

        avg_parallel_AB = avg_tot_532 - avg_perp_532
        depolar_ratio = avg_perp_532/avg_parallel_AB

        # Put altitudes above 8.2 km on same spacing as lower ones
        MAX_ALT = 20
        unif_alt = uniform_alt_2(MAX_ALT, alt)
        regrid_depolar_ratio = regrid_lidar(alt, depolar_ratio, unif_alt)

        cmap = ccplot.utils.cmap(colormap)
        cm = mpl.colors.ListedColormap(cmap['colors']/255.0)
        cm.set_under(cmap['under']/255.0)
        cm.set_over(cmap['over']/255.0)
        cm.set_bad(cmap['bad']/255.0)
        norm = mpl.colors.BoundaryNorm(cmap['bounds'], cm.N)

        im = fig.imshow(
            regrid_depolar_ratio,
            extent=(latitude[0], latitude[-1], h1, h2),
            cmap=cm,
            norm=norm,
            aspect='auto',
            interpolation='nearest',
        )

        fig.set_ylabel('Altitude (km)')
        fig.set_xlabel('Latitude')
        fig.set_title("532 nm Depolarization Ratio")
       
        cbar_label = 'Depolarization Ratio'
        cbar = pfig.colorbar(im)
        cbar.set_label(cbar_label)

        ax = fig.twiny()
        ax.set_xlabel('Time')
        ax.set_xlim(time[0], time[-1])
        ax.get_xaxis().set_major_formatter(mpl.dates.DateFormatter('%H:%M:%S'))
 
        fig.set_zorder(0)
        ax.set_zorder(1)

        title = fig.set_title('532 nm Depolarized Ratio')
        title_xy = title.get_position()
        title.set_position([title_xy[0], title_xy[1]*1.07])

        return ax
Ejemplo n.º 3
0
# Enable for debugging
# cgitb.enable()

#Set HDF File Name here
filename = str(sys.argv[1])
m = re.search('CAL_LID_L1-ValStage1-V3-30.(.+?)T([0-9\-]+)', filename)
if m:
    date = m.group(1)
    time = m.group(2)
name = 'Total_Attenuated_Backscatter_532'
label = 'Total Attenuated Backscatter 532nm (km$^{-1}$ sr$^{-1}$)'
colormap = '/usr/local/share/ccplot/cmap/calipso-backscatter.cmap'
output_dir = os.path.join(os.path.dirname(__file__), "images")

if __name__ == '__main__':
    with HDF(filename) as product:
        x1 = -1
        h1 = 0  # km
        h2 = 30  # km
        nz = 600

        x2 = 0

        i = -1

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        granule_dir = os.path.join(output_dir, date, time)
        if not os.path.exists(granule_dir):
            os.makedirs(granule_dir)
Ejemplo n.º 4
0
def render_backscattered(filename, x_range, y_range, fig, pfig):
    x1 = x_range[0]
    x2 = x_range[1]
    h1 = y_range[0]
    h2 = y_range[1]
    # averaging_width = 15
    # Adjust the averaging with so its uniform per range
    averaging_width = int((x2 - x1) / 1000)
    if averaging_width < 5:
        averaging_width = 5
    if averaging_width > 15:
        averaging_width = 15

    colormap = 'dat/calipso-backscatter.cmap'

    print('xrange: ' + str(x_range) + ', yrange: ' + str(y_range))

    with HDF(filename) as product:
        time = product['Profile_UTC_Time'][x1:x2, 0]
        minimum = min(product['Profile_UTC_Time'][::])[0]
        maximum = max(product['Profile_UTC_Time'][::])[0]

        # length of time determines how far the file can be viewed
        if time[-1] >= maximum and len(time) < 950:
            raise IndexError
        if time[0] < minimum:
            raise IndexError

        alt = product['metadata']['Lidar_Data_Altitudes']
        dataset = product['Total_Attenuated_Backscatter_532'][x1:x2].T
        latitude = product['Latitude'][x1:x2, 0]
        latitude = latitude[::averaging_width]

        print(np.shape(time))

        time = np.array([ccplot.utils.calipso_time2dt(t) for t in time])
        dataset = np.ma.masked_equal(dataset, -9999)

        # The following method has been translated from MatLab code written by R. Kuehn 7/10/07
        # Translated by Collin Pampalone 7/19/17
        avg_dataset = avg_horz_data(dataset, averaging_width)
        # Put altitudes above 8.2 km on same spacing as lower ones
        MAX_ALT = 20
        unif_alt = uniform_alt_2(MAX_ALT, alt)
        regrid_dataset = regrid_lidar(alt, avg_dataset, unif_alt)
        data = regrid_dataset
        # End method

        cmap = ccplot.utils.cmap(colormap)
        cm = mpl.colors.ListedColormap(cmap['colors'] / 255.0)
        cm.set_under(cmap['under'] / 255.0)
        cm.set_over(cmap['over'] / 255.0)
        cm.set_bad(cmap['bad'] / 255.0)
        norm = mpl.colors.BoundaryNorm(cmap['bounds'], cm.N)

        im = fig.imshow(
            #data.T,
            data,
            extent=(latitude[0], latitude[-1], h1, h2),
            cmap=cm,
            aspect='auto',
            norm=norm,
            interpolation='nearest',
        )

        fig.set_ylabel('Altitude (km)')
        fig.set_xlabel('Latitude')
        fig.set_title("Averaged 532 nm Total Attenuated Backscatter")

        cbar_label = 'Total Attenuated Backscatter 532nm (km$^{-1}$ sr$^{-1}$)'
        cbar = pfig.colorbar(im)
        cbar.set_label(cbar_label)

        ax = fig.twiny()
        ax.set_xlabel('Time')
        ax.set_xlim(time[0], time[-1])
        ax.get_xaxis().set_major_formatter(mpl.dates.DateFormatter('%H:%M:%S'))

        fig.set_zorder(0)
        ax.set_zorder(1)

        title = fig.set_title('Averaged 532 nm Total Attenuated Backscatter')
        title_xy = title.get_position()
        title.set_position([title_xy[0], title_xy[1] * 1.07])

        return ax