Esempio n. 1
0
def plot_bomb_frequency_typed(stormObj):
    print("plot_bomb_frequency_typed()")
    fig = plt.figure(figsize=(12, 9))
    yrs = np.arange(1979, 2020, 1)
    totals_year = np.zeros((len(yrs)))
    for className in typeStr.keys():
        count_list_ind = np.zeros((len(yrs)))
        for y in yrs:
            indCount = 0
            for ed in range(len(stormObj)):
                if (stormObj[ed]['type'] == 'cyclonic'
                        and stormObj[ed]['classification'] == className):
                    if (stormObj[ed]['month'][0] in [1, 2, 3, 4, 10, 11, 12]
                            and stormObj[ed]['year'][0] == y):
                        #Calculate the pressure falls over the storm's lifetime
                        bergeron = storm.calculate_bergeron(stormObj[ed])
                        if (any(b >= 1 for b in bergeron)):
                            indCount += 1
            count_list_ind[y - 1979] = indCount
        #Draw the plot
        plt.bar(yrs,
                count_list_ind,
                bottom=totals_year,
                color=zoneColors[className])
        totals_year += count_list_ind
    plt.ylim(0, 60)
    plt.xlabel("Year")
    plt.ylabel("Number of Cyclones")
    plt.legend(typeStr.values(), loc=0, framealpha=1.0)
    plt.title("Number of Bomb Cyclones by Cyclone Type")
    plt.savefig('figures/bomb_frequency_typed',
                bbox_inches='tight',
                pad_inches=0.05,
                dpi=300)
    print("plot_bomb_frequency_typed(): Done")
Esempio n. 2
0
def plot_bomb_frequency(stormObj):
    print("plot_bomb_frequency()")
    fig = plt.figure(figsize=(12, 9))
    yrs = np.arange(1979, 2020, 1)
    counts = []
    for y in yrs:
        indCount = 0
        for ed in range(len(stormObj)):
            if (stormObj[ed]['type'] == 'cyclonic'):
                if (stormObj[ed]['month'][0] in [1, 2, 3, 4, 10, 11, 12]
                        and stormObj[ed]['year'][0] == y):
                    #Calculate the pressure falls over the storm's lifetime
                    bergeron = storm.calculate_bergeron(stormObj[ed])
                    if (any(b >= 1 for b in bergeron)):
                        indCount += 1
        counts.append(indCount)
    #Draw the plot
    plt.bar(yrs, counts)
    plt.xlabel("Year")
    plt.ylabel("Number of Cyclones")
    plt.title("Number of Bomb Cyclones")
    plt.savefig('figures/bomb_frequency',
                bbox_inches='tight',
                pad_inches=0.05,
                dpi=300)
    print("plot_bomb_frequency(): Done.")
Esempio n. 3
0
def plot_cyclone_lifespan(stormObj, bombOnly=False):
    print("plot_cyclone_lifespan(bombOnly = " + str(bombOnly) + ")")
    fig = plt.figure(figsize=(12, 9))

    months = [1, 2, 3, 4, 10, 11, 12]
    years = np.arange(1979, 2020, 1)
    dt = 3

    # Find the longest cyclone.
    longest = 0
    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'
                and stormObj[ed]['month'][0] in months
                and stormObj[ed]['year'][0] in years):
            count = len(stormObj[ed]['amp'])
            if (count > longest):
                longest = count

    lifespan_array = np.zeros((longest))

    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'
                and stormObj[ed]['month'][0] in months
                and stormObj[ed]['year'][0] in years):
            bergeron = storm.calculate_bergeron(stormObj[ed])
            if (bombOnly == True):
                if (any(b >= 1 for b in bergeron)):
                    lifespan = len(stormObj[ed]['amp'])
                    lifespan_array[lifespan - 1] += 1
            else:
                lifespan = len(stormObj[ed]['amp'])
                lifespan_array[lifespan - 1] += 1

    idx_of_last_non_zero = np.max(np.nonzero(lifespan_array))
    splitArray = lifespan_array[0:idx_of_last_non_zero + 1]
    times = np.arange(0, (len(splitArray) * 3), 3)

    plt.bar(times, splitArray)
    plt.xlabel("Cyclone Lifespan (Hours)")
    plt.ylabel("Count")
    if (bombOnly == True):
        plt.title("Lifespan of Cyclones (Bomb Cyclones Only)")
        plt.savefig('figures/lifespan_bombs',
                    bbox_inches='tight',
                    pad_inches=0.05,
                    dpi=300)
    else:
        plt.yscale('log')
        plt.title("Lifespan of Cyclones")
        plt.savefig('figures/lifespan',
                    bbox_inches='tight',
                    pad_inches=0.05,
                    dpi=300)
    print("plot_cyclone_lifespan(): Done")
Esempio n. 4
0
def plot_strength_bars_bombs(stormObj):
    print("plot_strength_bars_bombs()")
    fig = plt.figure(figsize=(12, 9))

    months = [1, 2, 3, 4, 10, 11, 12]
    years = np.arange(1979, 2020, 1)
    dt = 3

    # Find the longest cyclone.
    longest = 0
    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'
                and stormObj[ed]['month'][0] in months
                and stormObj[ed]['year'][0] in years):
            count = len(stormObj[ed]['amp'])
            if (count > longest):
                longest = count

    totals_column = np.zeros((longest))
    for className in typeStr.keys():
        fall_array = np.zeros((longest))
        for ed in range(len(stormObj)):
            if (stormObj[ed]['type'] == 'cyclonic'
                    and stormObj[ed]['month'][0] in months
                    and stormObj[ed]['year'][0] in years
                    and stormObj[ed]['classification'] == className):
                bergeron = storm.calculate_bergeron(stormObj[ed])
                if (any(b >= 1 for b in bergeron)):
                    dPressure = np.diff(stormObj[ed]['amp'])
                    largestFall = np.nanmin(dPressure)
                    index_of_largest_fall = np.argmin(dPressure)
                    time_of_fall = index_of_largest_fall * dt
                    fall_array[index_of_largest_fall] += 1
        times = np.arange(0, (len(fall_array) * 3), 3)
        plt.bar(times + 1,
                fall_array,
                bottom=totals_column,
                width=2,
                color=zoneColors[className])
        totals_column += fall_array
    idx_of_last_non_zero = np.max(np.nonzero(fall_array))
    plt.xlim(0, idx_of_last_non_zero * 3)
    plt.legend(typeStr.values(), loc=0, framealpha=1.0)
    plt.xlabel("Time after cyclogenesis (hours)")
    plt.ylabel("Count")
    plt.title("Time of Maximum 3-Hour Pressure Fall (Bomb Cyclones Only)")
    plt.savefig('figures/pressure_fall_bombs_occurance',
                bbox_inches='tight',
                pad_inches=0.05,
                dpi=300)
    print("plot_strength_bars_bombs(): Done")
Esempio n. 5
0
def plot_mean_pressure_bombs(stormObj):
    print("plot_mean_pressure_bombs()")
    fig = plt.figure(figsize=(12, 9))

    months = [1, 2, 3, 4, 10, 11, 12]
    years = np.arange(1979, 2020, 1)
    cyclGroups = [
        "Clipper", "Colorado", "GreatBasin", "GulfOfMexico", "EastCoast"
    ]

    for year in years:
        for type in cyclGroups:
            meanPressure = 0
            count = 0
            for ed in range(len(stormObj)):
                if (stormObj[ed]['type'] == 'cyclonic'
                        and stormObj[ed]['classification'] == type
                        and stormObj[ed]['month'][0] in months
                        and stormObj[ed]['year'][0] == year):
                    bergeron = storm.calculate_bergeron(stormObj[ed])
                    if (any(b >= 1 for b in bergeron)):
                        #lat = stormObj[ed]['lat'][0]
                        lowestP = np.nanmin(stormObj[ed]['amp'])
                        meanPressure += lowestP
                        count += 1
            if (count != 0):
                meanPressure = (meanPressure / count) / 100
                plt.plot(year, meanPressure, '-o', color=zoneColors[type])
    # Add "Fake" Lines for Legend
    for type in cyclGroups:
        plt.plot(0,
                 0,
                 linestyle='-',
                 alpha=1,
                 color=zoneColors[type],
                 label=typeStr[type])
    plt.xlim(1979, 2020)
    plt.ylim(900, 1000)
    plt.xlabel("Year")
    plt.ylabel("Pressure")
    plt.legend(framealpha=1.0)
    plt.title('Cyclone Mean Lowest Pressure (Bomb Cyclones Only)')
    plt.savefig('figures/mean_lowest_pressure_bomb',
                bbox_inches='tight',
                pad_inches=0.05,
                dpi=300)
    print("plot_mean_pressure_bombs(): Done")
Esempio n. 6
0
def plot_bomb_tracks(stormObj):
    print("plot_bomb_tracks()")
    projObj = get_projection_object()
    # Create our figure and axis object
    fig = plt.figure(figsize=(12, 9))
    ax = plt.axes(projection=projObj)
    #ax = plt.axes(projection=ccrs.PlateCarree())
    ax.set_extent(plotExtent, crs=ccrs.PlateCarree())

    # Draw our plot, coastlines first, then the contours.
    states = cartopy.feature.NaturalEarthFeature(
        category='cultural',
        name='admin_1_states_provinces_lakes',
        scale='110m',
        facecolor='none')
    ax.add_feature(states, edgecolor='k')
    ax.coastlines()
    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'):
            if (stormObj[ed]['month'][0] in [1, 2, 3, 4, 10, 11, 12]):
                #Calculate the pressure falls over the storm's lifetime
                bergeron = storm.calculate_bergeron(stormObj[ed])
                if (any(b >= 1 for b in bergeron)):
                    lon, lat = stormObj[ed]['lon'], stormObj[ed]['lat']
                    lon[lon < 0] = 360 + lon[lon < 0]

                    plt.plot(lon,
                             lat,
                             'r-',
                             linewidth=0.5,
                             alpha=0.35,
                             transform=ccrs.PlateCarree())
    # Show the plot.
    plt.title('Storm Tracks')
    plt.savefig('figures/storm_bomb_tracks',
                bbox_inches='tight',
                pad_inches=0.05,
                dpi=300)
    print("plot_bomb_tracks(): Done")
Esempio n. 7
0
def plot_mean_track(stormObj, bombOnly=False):
    print("plot_mean_track(bombOnly = " + str(bombOnly) + ")")
    projObj = get_projection_object()
    # Create our figure and axis object
    fig = plt.figure(figsize=(12, 9))
    ax = plt.axes(projection=projObj)
    #ax = plt.axes(projection=ccrs.PlateCarree())
    ax.set_extent(plotExtent, crs=ccrs.PlateCarree())

    # Draw our plot, coastlines first, then the contours.
    states = cartopy.feature.NaturalEarthFeature(
        category='cultural',
        name='admin_1_states_provinces_lakes',
        scale='110m',
        facecolor='none')
    ax.add_feature(states, edgecolor='k')
    ax.coastlines()

    # Process Variables
    monthList = [1, 2, 3, 4, 10, 11, 12]
    yearList = np.arange(1979, 2020, 1)
    cycloneList = [
        'Clipper', 'Northwest', 'Colorado', 'GreatBasin', 'GulfOfMexico',
        'EastCoast'
    ]

    for classification in cycloneList:
        # Find the longest cyclone.
        longest = 0
        for ed in range(len(stormObj)):
            if (stormObj[ed]['type'] == 'cyclonic'
                    and stormObj[ed]['month'][0] in monthList
                    and stormObj[ed]['year'][0] in yearList
                    and stormObj[ed]['classification'] == classification):
                count = len(stormObj[ed]['amp'])
                if (count > longest):
                    longest = count
        # Test classification
        meanLat = np.zeros((longest))
        meanLon = np.zeros((longest))
        count = np.zeros((longest))
        for ed in range(len(stormObj)):
            if (stormObj[ed]['type'] == 'cyclonic'):
                # Test months
                if (storms[ed]['month'][0] in monthList):
                    # Test years
                    if (storms[ed]['year'][0] in yearList):
                        if (storms[ed]['classification'] == classification):
                            bergeron = storm.calculate_bergeron(stormObj[ed])
                            if (bombOnly == True):
                                if (any(b >= 1 for b in bergeron)):
                                    for i in range(len(stormObj[ed]['lat'])):
                                        meanLat[i] += stormObj[ed]['lat'][i]
                                        meanLon[i] += stormObj[ed]['lon'][i]
                                        count[i] += 1
                            else:
                                for i in range(len(stormObj[ed]['lat'])):
                                    meanLat[i] += stormObj[ed]['lat'][i]
                                    meanLon[i] += stormObj[ed]['lon'][i]
                                    count[i] += 1
        meanLat[:] = meanLat[:] / count[:]
        meanLon[:] = meanLon[:] / count[:]

        print(classification + ": stdLat: %.3f" % np.std(meanLat))

        #print(meanLat)
        #print(meanLon)
        #print(count)
        # Draw the lines.
        plt.plot(meanLon,
                 meanLat,
                 linestyle='-',
                 color=zoneColors[classification],
                 alpha=1,
                 markeredgewidth=0,
                 transform=ccrs.PlateCarree())

    legendVals = list(typeStr.values())
    legendVals.remove("Other Lows")

    plt.legend(legendVals, loc=0, framealpha=1.0)
    if (bombOnly == True):
        plt.title("Mean Bomb Cyclone Track (" + str(yearList[0]) + " - " +
                  str(yearList[-1]) + ")")
        plt.savefig('figures/mean_track_bomb',
                    bbox_inches='tight',
                    pad_inches=0.05,
                    dpi=300)
    else:
        plt.title("Mean Cyclone Track (" + str(yearList[0]) + " - " +
                  str(yearList[-1]) + ")")
        plt.savefig('figures/mean_track',
                    bbox_inches='tight',
                    pad_inches=0.05,
                    dpi=300)
    print("plot_mean_track(): Done.")
Esempio n. 8
0
def plot_lifespan_panel(stormObj):
    print("plot_lifespan_panel()")

    fig, axs = plt.subplots(1, 2)
    ax1 = axs[0]
    ax2 = axs[1]

    months = [1, 2, 3, 4, 10, 11, 12]
    years = np.arange(1979, 2020, 1)
    dt = 3

    longest = 0
    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'
                and stormObj[ed]['month'][0] in months
                and stormObj[ed]['year'][0] in years):
            count = len(stormObj[ed]['amp'])
            if (count > longest):
                longest = count

    # Panel A
    lifespan_array1 = np.zeros((longest))
    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'
                and stormObj[ed]['month'][0] in months
                and stormObj[ed]['year'][0] in years):
            lifespan = len(stormObj[ed]['amp'])
            lifespan_array1[lifespan - 1] += 1

    idx_of_last_non_zero = np.max(np.nonzero(lifespan_array1))
    splitArray1 = lifespan_array1[0:idx_of_last_non_zero + 1]
    times1 = np.arange(0, (len(splitArray1) * 3), 3)

    #plt.bar(times, splitArray)
    ax1.scatter(times1, splitArray1, s=2)
    ax1.set(xlabel='Cyclone Lifespan (Hours)', ylabel='Count')

    #ax1.

    # Panel B
    lifespan_array2 = np.zeros((longest))
    for ed in range(len(stormObj)):
        if (stormObj[ed]['type'] == 'cyclonic'
                and stormObj[ed]['month'][0] in months
                and stormObj[ed]['year'][0] in years):
            bergeron = storm.calculate_bergeron(stormObj[ed])
            if (any(b >= 1 for b in bergeron)):
                lifespan = len(stormObj[ed]['amp'])
                lifespan_array2[lifespan - 1] += 1

    idx_of_last_non_zero = np.max(np.nonzero(lifespan_array2))
    splitArray2 = lifespan_array2[0:idx_of_last_non_zero + 1]
    times2 = np.arange(0, (len(splitArray2) * 3), 3)

    ax2.bar(times2, splitArray2)
    #ax1.scatter(times2, splitArray2)
    ax2.set(xlabel='Cyclone Lifespan (Hours)', ylabel='Count')

    plt.suptitle('Lifespan of Cyclones')
    plt.savefig('figures/lifespan_panel',
                bbox_inches='tight',
                pad_inches=0.05,
                dpi=300)
    print("plot_lifespan_panel(): Done")