def main():
    basemap = polar_stereographic.basemap
    xs = polar_stereographic.xs
    ys = polar_stereographic.ys

    basin_patches = get_features_from_shape(basemap,linewidth = 0.5)

    cache_file = 'cache_high_dates.bin'
    if os.path.isfile(cache_file):
        data = pickle.load(open(cache_file))
        to_plot_current = data[0]
        to_plot_future = data[1]
    else:
        db = OccurrencesDB()

        current_days = db.get_mean_dates_of_maximum_annual_flow(current = True)
        print 'got current dates'

        future_days = db.get_mean_dates_of_maximum_annual_flow(current = False)
        print 'got future dates'

        print 'got data, plotting ...'

        to_plot_current = np.ma.masked_all(xs.shape)
        to_plot_future = np.ma.masked_all(xs.shape)
        for i, j, c_day, f_day in zip(db.i_indices, db.j_indices, current_days, future_days):
            to_plot_current[i, j] = c_day
            to_plot_future[i, j] = f_day
        data = [to_plot_current, to_plot_future]
        pickle.dump(data, open(cache_file, 'wb'))


    plt.figure()
    plt.subplot(1, 2, 1)
    basemap.pcolormesh(xs, ys, to_plot_current, vmin=1, vmax=300, cmap=mpl.cm.get_cmap('jet', 10))
    basemap.drawcoastlines(linewidth=0.3)
    # plot_basin_boundaries_from_shape(basemap, plotter = plt, linewidth = 0.5)
    plot_patches(plt, get_copies(basin_patches))
    zoom_to_qc()
    cb = plt.colorbar(ticks = MaxNLocator(nbins = 10))
    plt.title('current mean')

    plt.subplot(1, 2, 2)
    basemap.pcolormesh(xs, ys, to_plot_future, vmin=1, vmax=300, cmap=mpl.cm.get_cmap('jet', 10))
    basemap.drawcoastlines(linewidth=0.3)
    zoom_to_qc()
    plot_patches(plt, get_copies(basin_patches))
    # plot_basin_boundaries_from_shape(basemap, plotter = plt)
    plt.title('future mean')

    plt.colorbar(ticks = MaxNLocator(nbins = 10))

    plt.savefig('high_dates.png')
Example #2
0
def main():
    db = OccurrencesDB()

    #define animation period
    current_start_date = datetime(1996,3,1,0,0,0)
    current_end_date = datetime(1999,8,1,0,0,0)

    future_start_date = datetime(2067,3,1,0,0,0)
    future_end_date = datetime(2070,8,1,0,0,0)

    simulation_step = timedelta(days = 5)


    #domain properties
    xs = polar_stereographic.xs
    ys = polar_stereographic.ys
    basemap = polar_stereographic.basemap

    positions = db.get_all_positions()
    i_indices = db.i_indices
    j_indices = db.j_indices
    index_zip = zip(i_indices, j_indices, positions)

    basin_patches = get_features_from_shape(basemap,linewidth = 0.5)

    #plot plots
    i = 0
    current_time = current_start_date
    future_time = future_start_date

    while current_time < current_end_date:
        to_plot_current = np.ma.masked_all(xs.shape)
        to_plot_future = np.ma.masked_all(xs.shape)
        for x, y, position in index_zip:
            current_year_pos = YearPositionObject(current_time.year, position)
            future_year_pos = YearPositionObject(future_time.year, position)

            to_plot_current[x, y] = \
                db.get_measure_of_distance_to_high_event(current_year_pos, current_time, current = True)
            to_plot_future[x, y] = \
                db.get_measure_of_distance_to_high_event(future_year_pos, future_time, current = False)



        #actual plotting
        plt.figure()
        plt.subplot(1,2,1)
        basemap.pcolormesh(xs, ys, to_plot_current, vmin = 0, vmax = 1, cmap = 'Blues')
        basemap.drawcoastlines(linewidth = 0.3)
       # plot_basin_boundaries_from_shape(basemap, plotter = plt, linewidth = 0.5)
        plot_patches(plt, get_copies(basin_patches))
        zoom_to_qc()
        plt.title(current_time.strftime('current: %Y-%m-%d'))

        plt.subplot(1,2,2)
        basemap.pcolormesh(xs, ys, to_plot_future, vmin = 0, vmax = 1, cmap = 'Blues', linewidth = 0.5)
        basemap.drawcoastlines(linewidth = 0.3)
        zoom_to_qc()
        plot_patches(plt, get_copies(basin_patches))
       # plot_basin_boundaries_from_shape(basemap, plotter = plt)
        plt.title(future_time.strftime('future: %Y-%m-%d'))

        plt.savefig('frame_%010d.png' % i)

        i += 1
        current_time += simulation_step
        future_time += simulation_step

        if current_time.month > current_end_date.month:
            current_time = datetime(current_time.year + 1, current_start_date.month, current_start_date.day)
            future_time = datetime(future_time.year + 1, future_start_date.month, future_start_date.day)


    pass