climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huiky...@apache.org
Subject [1/2] climate git commit: CLIMATE-814 - Fix PEP8 violations in dataset
Date Mon, 27 Jun 2016 00:38:45 GMT
Repository: climate
Updated Branches:
  refs/heads/master 8e35e4407 -> 264263a6c


CLIMATE-814 - Fix PEP8 violations in dataset


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/e42c3626
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/e42c3626
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/e42c3626

Branch: refs/heads/master
Commit: e42c3626f40b8b70c279d50d5cfcfdd4a751e4af
Parents: 705403a
Author: Ibrahim Jarif <jarifibrahim@gmail.com>
Authored: Sat Jun 18 16:10:43 2016 +0530
Committer: Ibrahim Jarif <jarifibrahim@gmail.com>
Committed: Sat Jun 18 16:10:43 2016 +0530

----------------------------------------------------------------------
 ocw/dataset.py | 83 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/e42c3626/ocw/dataset.py
----------------------------------------------------------------------
diff --git a/ocw/dataset.py b/ocw/dataset.py
index a597778..78e6c14 100644
--- a/ocw/dataset.py
+++ b/ocw/dataset.py
@@ -28,10 +28,9 @@ import datetime as dt
 
 import ocw.utils as utils
 
-from mpl_toolkits.basemap import shiftgrid
-
 logger = logging.getLogger(__name__)
 
+
 class Dataset:
     '''Container for a dataset's attributes and data.'''
 
@@ -45,12 +44,12 @@ class Dataset:
         :param lons: One dimensional numpy array of unique longitude values.
         :type lons: :class:`numpy.ndarray`
 
-        :param times: One dimensional numpy array of unique python datetime 
+        :param times: One dimensional numpy array of unique python datetime
             objects.
         :type times: :class:`numpy.ndarray`
 
-        :param values: Three dimensional numpy array of parameter values with 
-            shape [timesLength, latsLength, lonsLength]. 
+        :param values: Three dimensional numpy array of parameter values with
+            shape [timesLength, latsLength, lonsLength].
         :type values: :class:`numpy.ndarray`
 
         :param variable: Name of the value variable.
@@ -92,11 +91,10 @@ class Dataset:
         return (float(numpy.min(self.lats)), float(numpy.max(self.lats)),
                 float(numpy.min(self.lons)), float(numpy.max(self.lons)))
 
-
     def time_range(self):
         '''Calculate the temporal range
 
-        :returns: The start and end date of the Dataset's temporal range as 
+        :returns: The start and end date of the Dataset's temporal range as
             a tuple in the form (start_time, end_time).
         :rtype: :func:`tuple` of the form (:class:`datetime.datetime`,
             :class:`datetime.datetime`)
@@ -107,28 +105,26 @@ class Dataset:
 
         return (start_time, end_time)
 
-
     def spatial_resolution(self):
         '''Calculate the latitudinal and longitudinal spatial resolution.
 
-           If self.lats and self.lons are from curvilinear coordinates, 
+           If self.lats and self.lons are from curvilinear coordinates,
            the output resolutions are approximate values.
         :returns: The Dataset's latitudinal and longitudinal spatial resolution
             as a tuple of the form (lat_resolution, lon_resolution).
         :rtype: (:class:`float`, :class:`float`)
         '''
-        if self.lats.ndim == 1 and self.lons.ndim ==1:
+        if self.lats.ndim == 1 and self.lons.ndim == 1:
             sorted_lats = numpy.sort(list(set(self.lats)))
             sorted_lons = numpy.sort(list(set(self.lons)))
             lat_resolution = sorted_lats[1] - sorted_lats[0]
             lon_resolution = sorted_lons[1] - sorted_lons[0]
-        if self.lats.ndim == 2 and self.lons.ndim ==2:
-            lat_resolution = self.lats[1,1] - self.lats[0,0]
-            lon_resolution = self.lons[1,1] - self.lons[0,0]
+        if self.lats.ndim == 2 and self.lons.ndim == 2:
+            lat_resolution = self.lats[1, 1] - self.lats[0, 0]
+            lon_resolution = self.lons[1, 1] - self.lons[0, 0]
 
         return (lat_resolution, lon_resolution)
 
-
     def temporal_resolution(self):
         '''Calculate the temporal resolution.
 
@@ -156,42 +152,48 @@ class Dataset:
 
     def _validate_inputs(self, lats, lons, times, values):
         """Check that Dataset inputs are valid.
-        
+
         :raises: ValueError
         """
         err_msg = None
-        #Setup and Check parameter dimensionality is correct
+        # Setup and Check parameter dimensionality is correct
         lat_dim = len(lats.shape)
         lon_dim = len(lons.shape)
         time_dim = len(times.shape)
         value_dim = len(values.shape)
         lat_count = lats.shape[0]
         lon_count = lons.shape[0]
-        
+
         if lat_dim == 2 and lon_dim == 2:
             lon_count = lons.shape[1]
         time_count = times.shape[0]
-        
+
         if time_dim != 1:
-            err_msg = "Time Array should be 1 dimensional.  %s dimensions found." % time_dim
+            err_msg = ("Time Array should be 1 dimensional.  %s dimensions"
+                       " found." % time_dim)
         elif value_dim < 2:
-            err_msg = "Value Array should be at least 2 dimensional.  %s dimensions found."
% value_dim
+            err_msg = ("Value Array should be at least 2 dimensional."
+                       "  %s dimensions found." % value_dim)
         # Finally check that the Values array conforms to the proper shape
         if value_dim == 2:
-            if values.shape[0] != time_count and values.shape != (lat_count, lon_count):
+            if (values.shape[0] != time_count and
+                    values.shape != (lat_count, lon_count)):
                 err_msg = """Value Array must be of shape (lats, lons) or (times, locations).
-                Expected shape (%s, %s) but received (%s, %s)""" % (lat_count,
-                                                                lon_count,
-                                                                values.shape[0],
-                                                                values.shape[1])
-        if value_dim == 3 and values.shape != (time_count, lat_count, lon_count):
+                Expected shape (%s, %s) but received (%s, %s)""" % (
+                    lat_count,
+                    lon_count,
+                    values.shape[0],
+                    values.shape[1])
+        if (value_dim == 3 and
+                values.shape != (time_count, lat_count, lon_count)):
             err_msg = """Value Array must be of shape (times, lats, lons).
-            Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (time_count,
-                                                                lat_count,
-                                                                lon_count,
-                                                                values.shape[0],
-                                                                values.shape[1],
-                                                                values.shape[2])
+            Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (
+                time_count,
+                lat_count,
+                lon_count,
+                values.shape[0],
+                values.shape[1],
+                values.shape[2])
         if err_msg:
             logger.error(err_msg)
             raise ValueError(err_msg)
@@ -226,33 +228,36 @@ class Bounds(object):
     '''Container for holding spatial and temporal bounds information.
 
     Certain operations require valid bounding information to be present for
-    correct functioning. Bounds guarantees that a function receives well 
+    correct functioning. Bounds guarantees that a function receives well
     formed information without the need to do the validation manually.
 
     Spatial and temporal bounds must follow the following guidelines.
 
     * Latitude values must be in the range [-90, 90]
     * Longitude values must be in the range [-180, 180]
-    * Lat/Lon Min values must be less than the corresponding Lat/Lon Max values.
+    * Lat/Lon Min values must be less than the corresponding Lat/Lon Max
+      values.
     * Temporal bounds must a valid datetime object
     '''
 
-    def __init__(self, lat_min, lat_max, lon_min, lon_max, start=None, end=None):
+    def __init__(self, lat_min, lat_max, lon_min,
+                 lon_max, start=None, end=None):
         '''Default Bounds constructor
 
         :param lat_min: The minimum latitude bound.
         :type lat_min: :class:`float`
-        
+
         :param lat_max: The maximum latitude bound.
         :type lat_max: :class:`float`
 
         :param lon_min: The minimum longitude bound.
         :type lon_min: :class:`float`
-        
+
         :param lon_max: The maximum longitude bound.
         :type lon_max: :class:`float`
 
-        :param start: An optional datetime object for the starting datetime bound.
+        :param start: An optional datetime object for the starting
+                      datetime bound.
         :type start: :class:`datetime.datetime`
 
         :param end: An optional datetime object for the ending datetime bound.
@@ -274,7 +279,7 @@ class Bounds(object):
             self._end = end
         else:
             self._end = None
-       
+
     @property
     def lat_min(self):
         return self._lat_min


Mime
View raw message