Github user jarifibrahim commented on a diff in the pull request:

    https://github.com/apache/climate/pull/362#discussion_r67599123
  
    --- Diff: ocw/utils.py ---
    @@ -326,97 +339,107 @@ def calc_climatology_monthly(dataset):
             raise ValueError(error)
         else:
             values = reshape_monthly_to_annually(dataset).mean(axis=0)
    -        
    +
             # A year can commence from any month
             first_month = dataset.times[0].month
    -        times = np.array([datetime.datetime(1, first_month, 1) + 
relativedelta(months = x) 
    -                for x in range(12)])
    +        times = np.array([dt.datetime(1, first_month, 1) +
    +                          relativedelta(months=x)
    +                          for x in range(12)])
             return values, times
     
    +
     def calc_time_series(dataset):
         ''' Calculate time series mean values for a dataset
     
    -    :param dataset: Dataset object 
    +    :param dataset: Dataset object
         :type dataset: :class:`dataset.Dataset`
     
         :returns: time series for the dataset of shape (nT)
         '''
     
    -    t_series =[]
    +    t_series = []
         for t in xrange(dataset.values.shape[0]):
    -        t_series.append(dataset.values[t,:,:].mean())
    -    
    +        t_series.append(dataset.values[t, :, :].mean())
    +
         return t_series
     
    +
     def get_temporal_overlap(dataset_array):
         ''' Find the maximum temporal overlap across the observation and model 
datasets
     
         :param dataset_array: an array of OCW datasets
         '''
    -    start_time =[]
    -    end_time =[]
    +    start_time = []
    +    end_time = []
         for dataset in dataset_array:
             start_time.append(dataset.time_range()[0])
             end_time.append(dataset.time_range()[1])
     
         return np.max(start_time), np.min(end_time)
     
    +
     def calc_subregion_area_mean_and_std(dataset_array, subregions):
    -    ''' Calculate area mean and standard deviation values for a given 
subregions using datasets on common grid points
    +    ''' Calculate area mean and standard deviation values for a given
    +        subregions using datasets on common grid points
         :param dataset_array: An array of OCW Dataset Objects
    -    :type list:  
    +    :type list:
         :param subregions: list of subregions
         :type subregions: :class:`numpy.ma.array`
    -    :returns: area averaged time series for the dataset of shape (ntime, 
nsubregion)
    +    :returns: area averaged time series for the dataset of shape
    +              (ntime, nsubregion)
         '''
     
         ndata = len(dataset_array)
         dataset0 = dataset_array[0]
         if dataset0.lons.ndim == 1:
    -       lons, lats = np.meshgrid(dataset0.lons, dataset0.lats)
    +        lons, lats = np.meshgrid(dataset0.lons, dataset0.lats)
         else:
    -       lons = dataset0.lons
    -       lats = dataset0.lats
    +        lons = dataset0.lons
    +        lats = dataset0.lats
         subregion_array = np.zeros(lons.shape)
    -    mask_array = dataset_array[0].values[0,:].mask
    +    mask_array = dataset_array[0].values[0, :].mask
         # dataset0.values.shsape[0]: length of the time dimension
         # spatial average
    -    t_series =ma.zeros([ndata, dataset0.values.shape[0], len(subregions)])
    +    t_series = ma.zeros([ndata, dataset0.values.shape[0], len(subregions)])
         # spatial standard deviation
    -    spatial_std =ma.zeros([ndata, dataset0.values.shape[0], 
len(subregions)])
    +    spatial_std = ma.zeros([ndata, dataset0.values.shape[0], 
len(subregions)])
     
         for iregion, subregion in enumerate(subregions):
             lat_min, lat_max, lon_min, lon_max = subregion[1]
    -        y_index,x_index = np.where((lats >= lat_min) & (lats <= lat_max) & 
(lons >= lon_min) & (lons <= lon_max))
    -        subregion_array[y_index,x_index] = iregion+1
    +        y_index, x_index = np.where((lats >= lat_min) & (
    +            lats <= lat_max) & (lons >= lon_min) & (lons <= lon_max))
    +        subregion_array[y_index, x_index] = iregion + 1
             for idata in np.arange(ndata):
    -            t_series[idata, :, iregion] = 
ma.mean(dataset_array[idata].values[:,y_index, x_index], axis=1)
    -            spatial_std[idata, :, iregion] = 
ma.std(dataset_array[idata].values[:,y_index, x_index], axis=1)
    -    subregion_array = ma.array(subregion_array, mask=mask_array) 
    +            t_series[idata, :, iregion] = 
ma.mean(dataset_array[idata].values[
    +                                                  :, y_index, x_index], 
axis=1)
    +            spatial_std[idata, :, iregion] = ma.std(
    +                dataset_array[idata].values[:, y_index, x_index], axis=1)
    +    subregion_array = ma.array(subregion_array, mask=mask_array)
         return t_series, spatial_std, subregion_array
     
    +
     def calc_area_weighted_spatial_average(dataset, area_weight=False):
         '''Calculate area weighted average of the values in OCW dataset
     
    -    :param dataset: Dataset object 
    +    :param dataset: Dataset object
         :type dataset: :class:`dataset.Dataset`
     
         :returns: time series for the dataset of shape (nT)
         '''
     
    -    if dataset.lats.ndim ==1:
    +    if dataset.lats.ndim == 1:
             lons, lats = np.meshgrid(dataset.lons, dataset.lats)
         else:
    -        lons = dataset.lons
    --- End diff --
    
    `lons` variable was not used anywhere.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to