You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@climate.apache.org by Ibrahim Jarif <ja...@gmail.com> on 2016/02/26 17:28:06 UTC
Issues with Test Cases
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) ?
Re: Issues with Test Cases
Posted by Ibrahim Jarif <ja...@gmail.com>.
If that's the case, why is it being compared with ten_year_annual_times
generated like
==============================================================================
ten_year_annual_times = np.array([datetime.datetime(year, 1, 1) for year in
range(2000, 2010)])
==============================================================================
in testing?
This test will always return false.
Re: Issues with Test Cases
Posted by Michael Anderson <mi...@gmail.com>.
Others can correct me, but I believe it's normalizing to the mid point of
the interval. July 2nd is the halfway point in the year just as the next
section new_date.append(datetime.datetime(year=year, month=month, day=15))
the 15th is more or less the middle of the month when the unit is monthly.
On Fri, Feb 26, 2016 at 11:28 AM, Ibrahim Jarif <ja...@gmail.com>
wrote:
> 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) ?
>