Why does the following function

==================================================================
def _rcmes_calc_average_on_new_time_unit(data, dates, unit):
 """ Rebin 3d array and list of dates using the provided unit parameter

    :param data: Input data that needs to be averaged
    :type data: 3D masked numpy array of shape (times, lats, lons)
    :param dates: List of dates that correspond to the given data values
    :type dates: Python datetime objects
    :param unit: Time unit to average the data into
    :type unit: String matching one of these values : full | annual |
monthly | daily

    :returns: meanstorem, newTimesList
    :rtype: 3D numpy masked array the same shape as the input array, list
of python datetime objects
    """

    # Check if the user-selected temporal grid is valid. If not, EXIT
    acceptable =
(unit=='full')|(unit=='annual')|(unit=='monthly')|(unit=='daily')
    if not acceptable:
        print 'Error: unknown unit type selected for time averaging: EXIT'
        return -1,-1,-1,-1

    nt, ny, nx = data.shape
    if unit == 'full':
        new_data = ma.mean(data, axis=0)
        new_date = [dates[dates.size/2]]
    if unit == 'annual':
        years = [d.year for d in dates]
        years_sorted = np.unique(years)
        new_data = ma.zeros([years_sorted.size, ny, nx])
        it = 0
        new_date = []
        for year in years_sorted:
            index = np.where(years == year)[0]
            new_data[it,:] = ma.mean(data[index,:], axis=0)
            new_date.append(datetime.datetime(year=year, month=7, day=2))
            it = it+1

=======================================
have new_date.append(datetime.datetime(year=year, month=7, day=2) ?
Shouldn't it be datetime(year=year, month=1, day=1) ?

Reply via email to