def check(path = 'data/hydrosheds/directions_for_streamflow9.nc'):
    cells = pe.get_connected_cells(directions_path = path)
Example #2
0
def compare_swe_2d():
    """
    Compare seasonal mean
    """
    start = datetime(1980,01,01,00)
    end = datetime(1996, 12, 31,00)
    months = [12,1,2]
    #calculate mean for ccc data accounting for the mask
    domain_mask = get_domain_mask()
    cccData = getTemporalMeanCCCDataForMask(domain_mask,
                                            startDate = start,
                                            endDate = end, months = months)
    lon_selected = polar_stereographic.lons[domain_mask == 1]
    lat_selected = polar_stereographic.lats[domain_mask == 1]

    geopointList = []
    for lon, lat in zip(lon_selected, lat_selected):
        geopointList.append(GeoPoint(longitude = lon, latitude = lat))

    print 'Selecting obs data'
    sweObs = SweHolder()
    obsData = sweObs.getTemporalMeanDataFromNetCDFforPoints(geopointList, startDate = start,
                                                            endDate = end, months = months)

    

    to_plot = np.ma.masked_all(polar_stereographic.lons.shape)
    condition = domain_mask == 1
    to_plot[condition] = (cccData - obsData) / obsData * 100
    xs = polar_stereographic.xs
    ys = polar_stereographic.ys
    basemap = polar_stereographic.basemap

    plot_utils.apply_plot_params()
    basemap.pcolormesh(xs, ys, to_plot, cmap = mpl.cm.get_cmap('jet', 9), vmin = -60, vmax = 120)
    basemap.drawcoastlines()
    plt.colorbar(ticks = LinearLocator(numticks = 10), format = '%.1f')
    plt.title('Snow Water Equivalent (%) \n $(S_{\\rm CRCM4} - S_{\\rm obs.})/S_{\\rm obs.}\\cdot100\%$\n')

    #zoom to domain
    selected_x = xs[~to_plot.mask]
    selected_y = ys[~to_plot.mask]
    marginx = abs(np.min(selected_x) * 5.0e-2)
    marginy = abs(np.min(selected_y) * 5.0e-2)

    plt.xlim(np.min(selected_x) - marginx, np.max(selected_x) + marginx)
    plt.ylim(np.min(selected_y) - marginy, np.max(selected_y) + marginy)

    bb.plot_basin_boundaries_from_shape(basemap, plotter = plt, linewidth = 2, edge_color = 'k')



    ##overlay flow directions
    cells  = cpe.get_connected_cells('data/hydrosheds/directions_for_streamflow9.nc')

    read_infocell.plot_directions(cells, basemap = basemap, domain_mask = get_domain_mask())


    selected_stations = [
            104001, 103715, 93806, 93801,
            92715, 81006, 61502, 80718,
            40830, 42607
    ]
    selected_ids = map(lambda x: "%06d" % x, selected_stations)
    print selected_ids

    cpe.plot_station_positions(id_list=selected_ids, use_warpimage=False,
                               save_to_file=False, the_basemap=basemap)

    plt.savefig('swe_djf_validation.pdf', bbox_inches = 'tight')


    pass