Skip to content

Commit

Permalink
Merge pull request #337 from mraspaud/arpm-master
Browse files Browse the repository at this point in the history
Switch docstrings to Google style
  • Loading branch information
mraspaud committed Mar 12, 2021
2 parents d4a10d5 + 68dd4c5 commit 3869ce8
Show file tree
Hide file tree
Showing 30 changed files with 197 additions and 329 deletions.
19 changes: 8 additions & 11 deletions pyresample/_spatial_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@

class cKDTree_MP(object):

''' Multiprocessing cKDTree subclass, shared memory '''
"""Multiprocessing cKDTree subclass, shared memory."""

def __init__(self, data, leafsize=10, nprocs=2, chunk=None,
schedule='guided'):
'''
Same as cKDTree.__init__ except that an internal copy
of data to shared memory is made.
"""Same as cKDTree.__init__ except that an internal copy of data to
shared memory is made.
Extra keyword arguments:
chunk : Minimum chunk size for the load balancer.
schedule: Strategy for balancing work load
('static', 'dynamic' or 'guided').
'''
"""

self.n, self.m = data.shape
# Allocate shared memory for data
Expand All @@ -69,10 +69,8 @@ def __init__(self, data, leafsize=10, nprocs=2, chunk=None,
self._schedule = schedule

def query(self, x, k=1, eps=0, p=2, distance_upper_bound=np.inf):
'''
Same as cKDTree.query except parallelized with multiple
processes and shared memory.
'''
"""Same as cKDTree.query except parallelized with multiple processes
and shared memory."""

# allocate shared memory for x and result
nx = x.shape[0]
Expand Down Expand Up @@ -197,8 +195,7 @@ def transform_lonlats(self, lons, lats):


def _run_jobs(target, args, nprocs):
"""Run process pool
"""
"""Run process pool."""

# return status in shared memory
# access to these values are serialized automatically
Expand Down
19 changes: 6 additions & 13 deletions pyresample/area_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load_area(area_file_name, *regions):
area_file_name : str, pathlib.Path, stream, or list thereof
List of paths or streams. Any str or pathlib.Path will be
interpreted as a path to a file. Any stream will be interpreted
as containing a yaml definition. To read directly from a string,
as containing a yaml definition file. To read directly from a string,
use :func:`load_area_from_string`.
regions : str argument list
Regions to parse. If no regions are specified all
Expand Down Expand Up @@ -113,7 +113,7 @@ def load_area_from_string(area_strs, *regions):


def parse_area_file(area_file_name, *regions):
"""Parse area information from area file
"""Parse area information from area file.
Parameters
-----------
Expand Down Expand Up @@ -311,7 +311,7 @@ def _parse_legacy_area_file(area_file_name, *regions):


def _create_area(area_id, area_content):
"""Parse area configuration"""
"""Parse area configuration."""
from configobj import ConfigObj
config_obj = area_content.replace('{', '').replace('};', '')
config_obj = ConfigObj([line.replace(':', '=', 1)
Expand Down Expand Up @@ -345,7 +345,7 @@ def _create_area(area_id, area_content):


def get_area_def(area_id, area_name, proj_id, proj4_args, width, height, area_extent, rotation=0):
"""Construct AreaDefinition object from arguments
"""Construct AreaDefinition object from arguments.
Parameters
-----------
Expand Down Expand Up @@ -552,7 +552,6 @@ def _get_proj_data(projection: Any) -> CRS:
is installed then the string ``+init=EPSG:XXXX`` is passed to
``proj4_str_to_dict`` which provides limited information to area
config operations.
"""
if isinstance(projection, dict) and 'EPSG' in projection:
projection = "EPSG:{}".format(projection['EPSG'])
Expand All @@ -577,7 +576,6 @@ def _sign(num):
Returns:
1 if number is greater than 0, -1 otherwise
"""
return -1 if num < 0 else 1

Expand All @@ -586,7 +584,6 @@ def _round_poles(center, units, p):
"""Round center to the nearest pole if it is extremely close to said pole.
Used to work around floating point precision issues .
"""
# For a laea projection, this allows for an error of 11 meters around the pole.
error = .0001
Expand Down Expand Up @@ -640,7 +637,6 @@ def _convert_units(
"""Converts units from lon/lat to projection coordinates (meters).
If `inverse` it True then the inverse calculation is done.
"""
if var is None:
return None
Expand Down Expand Up @@ -688,9 +684,8 @@ def _round_shape(shape, radius=None, resolution=None):
"""Make sure shape is an integer.
Rounds down if shape is less than .01 above nearest whole number to
handle floating point precision issues. Otherwise the number is round
up.
handle floating point precision issues. Otherwise the number is
round up.
"""
# Used for area definition to prevent indexing None.
if shape is None:
Expand Down Expand Up @@ -724,7 +719,6 @@ def _validate_variable(var, new_var, var_name, input_list):
If a variable that was given by the user contradicts other data provided, an exception is raised.
Example: upper_left_extent is (-10, 10), but area_extent is (-20, -20, 20, 20).
"""
if var is not None and not np.allclose(np.array(var, dtype=float), np.array(new_var, dtype=float), equal_nan=True):
raise ValueError('CONFLICTING DATA: {0} given does not match {0} found from {1}'.format(
Expand All @@ -748,7 +742,6 @@ def _extrapolate_information(area_extent, shape, center, radius, resolution, upp
4. resolution and shape
5. radius and center
6. upper_left_extent and radius
"""
# Input unaffected by data below: When area extent is calculated, it's either with
# shape (giving you an area definition) or with center/radius/upper_left_extent (which this produces).
Expand Down
1 change: 0 additions & 1 deletion pyresample/bilinear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
The algorithm is taken from
https://www.ahinson.com/algorithms_general/Sections/InterpolationRegression/InterpolationIrregularBilinear.pdf
"""
# file deepcode ignore W0611: sub-package imports

Expand Down
28 changes: 11 additions & 17 deletions pyresample/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""The Boundary classes.
"""
"""The Boundary classes."""


import logging
Expand All @@ -36,8 +35,7 @@

class Boundary(object):

"""Boundary objects.
"""
"""Boundary objects."""

def __init__(self, lons=None, lats=None, frequency=1):
self._contour_poly = None
Expand All @@ -51,23 +49,20 @@ def contour(self):

@property
def contour_poly(self):
"""Get the Spherical polygon corresponding to the Boundary
"""
"""Get the Spherical polygon corresponding to the Boundary."""
if self._contour_poly is None:
self._contour_poly = SphPolygon(
np.deg2rad(np.vstack(self.contour()).T))
return self._contour_poly

def draw(self, mapper, options, **more_options):
"""Draw the current boundary on the *mapper*
"""
"""Draw the current boundary on the *mapper*"""
self.contour_poly.draw(mapper, options, **more_options)


class AreaBoundary(Boundary):

"""Area boundary objects.
"""
"""Area boundary objects."""

def __init__(self, *sides):
Boundary.__init__(self)
Expand All @@ -76,8 +71,7 @@ def __init__(self, *sides):
self.sides_lats = list(self.sides_lats)

def decimate(self, ratio):
"""Remove some points in the boundaries, but never the corners.
"""
"""Remove some points in the boundaries, but never the corners."""
for i in range(len(self.sides_lons)):
length = len(self.sides_lons[i])
start = int((length % ratio) / 2)
Expand All @@ -91,17 +85,15 @@ def decimate(self, ratio):
self.sides_lats[i] = self.sides_lats[i][points]

def contour(self):
"""Get the (lons, lats) tuple of the boundary object.
"""
"""Get the (lons, lats) tuple of the boundary object."""
lons = np.concatenate([lns[:-1] for lns in self.sides_lons])
lats = np.concatenate([lts[:-1] for lts in self.sides_lats])

return lons, lats


class AreaDefBoundary(AreaBoundary):
"""Boundaries for area definitions (pyresample).
"""
"""Boundaries for area definitions (pyresample)."""

def __init__(self, area, frequency=1):
lons, lats = area.get_bbox_lonlats()
Expand All @@ -114,7 +106,9 @@ def __init__(self, area, frequency=1):

class SimpleBoundary(object):
"""Container for geometry boundary.
Labelling starts in upper left corner and proceeds clockwise"""
Labelling starts in upper left corner and proceeds clockwise
"""

def __init__(self, side1, side2, side3, side4):
self.side1 = side1
Expand Down
26 changes: 13 additions & 13 deletions pyresample/data_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.

"""Reduce data sets based on geographical information"""
"""Reduce data sets based on geographical information."""

from __future__ import absolute_import

Expand All @@ -27,8 +27,8 @@

def swath_from_cartesian_grid(cart_grid, lons, lats, data,
radius_of_influence):
"""Makes coarse data reduction of swath data by comparison with
cartesian grid
"""Makes coarse data reduction of swath data by comparison with cartesian
grid.
Parameters
----------
Expand Down Expand Up @@ -62,7 +62,7 @@ def swath_from_cartesian_grid(cart_grid, lons, lats, data,
def get_valid_index_from_cartesian_grid(cart_grid, lons, lats,
radius_of_influence):
"""Calculates relevant data indices using coarse data reduction of swath
data by comparison with cartesian grid
data by comparison with cartesian grid.
Parameters
----------
Expand Down Expand Up @@ -109,8 +109,8 @@ def _get_lats(z):

def swath_from_lonlat_grid(grid_lons, grid_lats, lons, lats, data,
radius_of_influence):
"""Makes coarse data reduction of swath data by comparison with
lon lat grid
"""Makes coarse data reduction of swath data by comparison with lon lat
grid.
Parameters
----------
Expand Down Expand Up @@ -145,8 +145,8 @@ def swath_from_lonlat_grid(grid_lons, grid_lats, lons, lats, data,

def swath_from_lonlat_boundaries(boundary_lons, boundary_lats, lons, lats, data,
radius_of_influence):
"""Makes coarse data reduction of swath data by comparison with
lon lat boundary
"""Makes coarse data reduction of swath data by comparison with lon lat
boundary.
Parameters
----------
Expand Down Expand Up @@ -181,7 +181,7 @@ def swath_from_lonlat_boundaries(boundary_lons, boundary_lats, lons, lats, data,

def get_valid_index_from_lonlat_grid(grid_lons, grid_lats, lons, lats, radius_of_influence):
"""Calculates relevant data indices using coarse data reduction of swath
data by comparison with lon lat grid
data by comparison with lon lat grid.
Parameters
----------
Expand Down Expand Up @@ -221,8 +221,8 @@ def get_valid_index_from_lonlat_grid(grid_lons, grid_lats, lons, lats, radius_of


def get_valid_index_from_lonlat_boundaries(boundary_lons, boundary_lats, lons, lats, radius_of_influence):
"""Find relevant indices from grid boundaries using the
winding number theorem"""
"""Find relevant indices from grid boundaries using the winding number
theorem."""

valid_index = _get_valid_index(boundary_lons.side1, boundary_lons.side2,
boundary_lons.side3, boundary_lons.side4,
Expand All @@ -236,8 +236,8 @@ def get_valid_index_from_lonlat_boundaries(boundary_lons, boundary_lats, lons, l
def _get_valid_index(lons_side1, lons_side2, lons_side3, lons_side4,
lats_side1, lats_side2, lats_side3, lats_side4,
lons, lats, radius_of_influence):
"""Find relevant indices from grid boundaries using the
winding number theorem"""
"""Find relevant indices from grid boundaries using the winding number
theorem."""

# Coarse reduction of data based on extrema analysis of the boundary
# lon lat values of the target grid
Expand Down
1 change: 0 additions & 1 deletion pyresample/ewa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
For more information on these steps see the documentation for the
corresponding modules.
"""

from .ewa import ll2cr, fornav # noqa
Expand Down
5 changes: 2 additions & 3 deletions pyresample/ewa/_fornav.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Resampling swath data to uniform grid using an Elliptical Weighted
Averaging (EWA) algorithm.
"""
"""Resampling swath data to uniform grid using an Elliptical Weighted Averaging
(EWA) algorithm."""
__docformat__ = "restructuredtext en"

import cython
Expand Down
14 changes: 6 additions & 8 deletions pyresample/ewa/_ll2cr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Map longitude/latitude points to column/rows of a grid.
"""
"""Map longitude/latitude points to column/rows of a grid."""
__docformat__ = "restructuredtext en"

from pyproj import Proj
Expand All @@ -39,10 +38,10 @@ cdef extern from "numpy/npy_math.h":


def projection_circumference(p):
"""Return the projection circumference if the projection is cylindrical. None is returned otherwise.
"""Return the projection circumference if the projection is cylindrical, None otherwise.
Projections that are not cylindrical and centered on the globes axis can not easily have data cross the antimeridian
of the projection.
Projections that are not cylindrical and centered on the globes axis
can not easily have data cross the antimeridian of the projection.
"""
lon0, lat0 = p(0, 0, inverse=True)
lon1 = lon0 + 180.0
Expand All @@ -63,7 +62,7 @@ def ll2cr_dynamic(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtyp
double cell_width, double cell_height,
width=None, height=None,
origin_x=None, origin_y=None):
"""Project longitude and latitude points to column rows in the specified grid in place
"""Project longitude and latitude points to column rows in the specified grid in place.
This function is meant to operate on dynamic grids and is theoretically
slower than the `ll2cr_static` function. Dynamic grids are those that
Expand Down Expand Up @@ -205,7 +204,7 @@ def ll2cr_static(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtype
double cell_width, double cell_height,
unsigned int width, unsigned int height,
double origin_x, double origin_y):
"""Project longitude and latitude points to column rows in the specified grid in place
"""Project longitude and latitude points to column rows in the specified grid in place.
:param lon_arr: Numpy array of longitude floats
:param lat_arr: Numpy array of latitude floats
Expand All @@ -225,7 +224,6 @@ def ll2cr_static(numpy.ndarray[cr_dtype, ndim=2] lon_arr, numpy.ndarray[cr_dtype
Note longitude and latitude arrays are limited to 64-bit floats because
of limitations in pyproj.
"""
# pure python stuff for now
p = Proj(proj4_definition)
Expand Down
Loading

0 comments on commit 3869ce8

Please sign in to comment.