示例#1
0
def compare_daily_normals_integral_over_mask(mask = None, start = None, end = None, label = '',
                                             subplot_count = None, subplot_total = 10
                                             ):
    """

    """
    lons = polar_stereographic.lons
    lats = polar_stereographic.lats

    lons_selected = lons[ mask == 1 ]
    lats_selected = lats[ mask == 1 ]

    global swe_fig

    if subplot_count == 1:
        swe_fig = plt.figure()
        plot_utils.apply_plot_params(font_size=25, width_pt=900, aspect_ratio=2.5)
        swe_fig.subplots_adjust(hspace = 0.6, wspace = 0.2, top = 0.9)



    points = [GeoPoint(longitude = lon, latitude = lat) for lon, lat in zip(lons_selected, lats_selected)]

    sweObs = SweHolder()
    obsData = sweObs.getSpatialIntegralFromNetcdfForPoints(points, startDate = start, endDate = end)
    print 'finished reading observations'
    modelData = getSpatialIntegralCCCDataForMask(mask = mask, path_to_ccc = 'data/ccc_data/aex/aex_p1sno',
                                                 startDate = start, endDate = end)
    print 'finished reading model data'
    print 'finished reading input mean timeseries'

    stamp_year = 2000
    obsStamp = map(lambda x: toStampYear(x, stamp_year = stamp_year), obsData[0])
    modelStamp = map(lambda x: toStampYear(x, stamp_year = stamp_year), modelData[0])
    print 'calculated stamp dates'

    ##calculate mean for a day of year
    obsDict = {}
    for stampDate, value in zip(obsStamp, obsData[1]):
        if not obsDict.has_key(stampDate):
            obsDict[stampDate] = []
        obsDict[stampDate].append(value)

    for key, theList in obsDict.iteritems():
        obsDict[key] = np.mean(theList)

    obsDates = sorted(obsDict)
    obsMeanValues = [obsDict[d] for d in obsDates]



    #do the same thing as for obs for the model data
    modelDict = {}
    for stampDate, value in zip(modelStamp, modelData[1]):
        if not modelDict.has_key(stampDate):
            modelDict[stampDate] = []
        modelDict[stampDate].append(value)


    for key, theList in modelDict.iteritems():
        modelDict[key] = np.mean(theList)

    modelDates = sorted(modelDict)
    modelMeanValues = [modelDict[d] for d in modelDates]

    print 'Calculated mean for day of year and over selected points'


    plt.title('Upstream of {0}'.format(label))
    line1 = plt.plot(modelDates, modelMeanValues, color = 'blue', lw = 3)
    line2 = plt.plot(obsDates, obsMeanValues, color = 'red', lw = 3)

    #plt.ylabel('mm')

    ax = plt.gca()
    ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b'))
    ax.xaxis.set_major_locator(
        mpl.dates.MonthLocator(bymonth = range(2,13,2))
    )


    if subplot_count == subplot_total:
         lines = (line1, line2)
         labels = ("CRCM4", "CRU")
         swe_fig.legend(lines, labels, 'upper center')
         swe_fig.text(0.05, 0.5, 'SWE (mm)',
                       rotation=90,
                       ha = 'center', va = 'center'
                        )
         swe_fig.savefig("swe.pdf")