diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a0299a..53e2e6c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,3 +19,15 @@ hooks: - id: blacken-docs args: [--skip-errors] + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.7.7 + hooks: + - id: flake8 + additional_dependencies: [flake8-comprehensions>=3.1.0] + args: [--max-line-length, '88', --ignore, "E225,W503,C408"] + - id: flake8 + name: flake8-pyx + files: \.(pyx|pxd)$ + types: + - file + args: [--append-config=flake8/cython.cfg] diff --git a/LICENSE b/LICENSE index 761fadd..03b95bd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,16 +1,19 @@ -Contact: Jeffrey Whitaker -Contact: Jeffrey Whitaker 0: @@ -79,7 +94,14 @@ @cython.boundscheck(False) @cython.wraparound(False) - def _inv(self, object lons1, object lats1, object lons2, object lats2, bint radians=False): + def _inv( + self, + object lons1, + object lats1, + object lons2, + object lats2, + bint radians=False, + ): """ inverse transformation - return forward and back azimuths, plus distance between an initial and terminus lat/lon pair. @@ -130,13 +152,28 @@ @cython.boundscheck(False) @cython.wraparound(False) - def _npts(self, double lon1, double lat1, double lon2, double lat2, int npts, bint radians=False): + def _npts( + self, + double lon1, + double lat1, + double lon2, + double lat2, + int npts, + bint radians=False, + ): """ given initial and terminus lat/lon, find npts intermediate points. """ cdef Py_ssize_t iii - cdef double del_s,ps12,pazi1,pazi2,s12,plon2,plat2 + cdef double del_s + cdef double ps12 + cdef double pazi1 + cdef double pazi2 + cdef double s12 + cdef double plon2 + cdef double plat2 cdef geod_geodesicline line + if radians: lon1 = _RAD2DG * lon1 lat1 = _RAD2DG * lat1 @@ -278,7 +315,6 @@ ) return (polygon_area, polygon_perimeter) - def __repr__(self): return "{classname}({init!r})".format( classname=self.__class__.__name__, diff --git a/pyproj/_list.pyx b/pyproj/_list.pyx index 392af76..699308d 100644 --- a/pyproj/_list.pyx +++ b/pyproj/_list.pyx @@ -6,6 +6,7 @@ from pyproj.compat import cstrencode, pystrdecode from pyproj.enums import PJType from pyproj._datadir cimport pyproj_context_initialize + def get_proj_operations_map(): """ @@ -163,6 +164,7 @@ PJType.OTHER_COORDINATE_OPERATION: PJ_TYPE_OTHER_COORDINATE_OPERATION, } + def get_codes(auth_name, pj_type, allow_deprecated=False): """ .. versionadded:: 2.4.0 diff --git a/pyproj/_proj.pyx b/pyproj/_proj.pyx index 36f068f..b4d16f3 100644 --- a/pyproj/_proj.pyx +++ b/pyproj/_proj.pyx @@ -18,7 +18,8 @@ ) -Factors = namedtuple("Factors", +Factors = namedtuple( + "Factors", [ "meridional_scale", "parallel_scale", @@ -32,14 +33,14 @@ "dx_dphi", "dy_dlam", "dy_dphi", - ] + ], ) Factors.__doc__ = """ .. versionadded:: 2.6.0 These are the scaling and angular distortion factors. -See `PJ_FACTORS documentation `__ +See `PJ_FACTORS documentation `__ # noqa Parameters ---------- @@ -107,9 +108,9 @@ def _fwd(self, object lons, object lats, bint errcheck=False): """ forward transformation - lons,lats to x,y (done in place). - if errcheck=True, an exception is raised if the forward transformation is invalid. - if errcheck=False and the forward transformation is invalid, no exception is - raised and 'inf' is returned. + if errcheck=True, an exception is raised if the forward + transformation is invalid. if errcheck=False and the forward + transformation is invalid, no exception is raised and 'inf' is returned. """ cdef PyBuffWriteManager lonbuff = PyBuffWriteManager(lons) cdef PyBuffWriteManager latbuff = PyBuffWriteManager(lats) @@ -127,7 +128,10 @@ proj_errno_reset(self.projobj) for iii in range(latbuff.len): # if inputs are nan's, return big number. - if lonbuff.data[iii] != lonbuff.data[iii] or latbuff.data[iii] != latbuff.data[iii]: + if ( + lonbuff.data[iii] != lonbuff.data[iii] + or latbuff.data[iii] != latbuff.data[iii] + ): lonbuff.data[iii] = HUGE_VAL latbuff.data[iii] = HUGE_VAL if errcheck: @@ -169,14 +173,14 @@ latbuff.data[iii] = projxyout.xy.y ProjError.clear() - @cython.boundscheck(False) @cython.wraparound(False) def _inv(self, object xx, object yy, bint errcheck=False): """ inverse transformation - x,y to lons,lats (done in place). - if errcheck=True, an exception is raised if the inverse transformation is invalid. - if errcheck=False and the inverse transformation is invalid, no exception is + if errcheck=True, an exception is raised if the inverse + transformation is invalid. if errcheck=False and the + inverse transformation is invalid, no exception is raised and 'inf' is returned. """ if not self.has_inverse: @@ -199,7 +203,10 @@ proj_errno_reset(self.projobj) for iii in range(xbuff.len): # if inputs are nan's, return big number. - if xbuff.data[iii] != xbuff.data[iii] or ybuff.data[iii] != ybuff.data[iii]: + if ( + xbuff.data[iii] != xbuff.data[iii] + or ybuff.data[iii] != ybuff.data[iii] + ): xbuff.data[iii] = HUGE_VAL ybuff.data[iii] = HUGE_VAL if errcheck: @@ -269,14 +276,21 @@ dx_dphi = copy.copy(longitude) dy_dlam = copy.copy(longitude) dy_dphi = copy.copy(longitude) - cdef PyBuffWriteManager meridional_scale_buff = PyBuffWriteManager(meridional_scale) - cdef PyBuffWriteManager parallel_scale_buff = PyBuffWriteManager(parallel_scale) + cdef PyBuffWriteManager meridional_scale_buff = PyBuffWriteManager( + meridional_scale) + cdef PyBuffWriteManager parallel_scale_buff = PyBuffWriteManager( + parallel_scale) cdef PyBuffWriteManager areal_scale_buff = PyBuffWriteManager(areal_scale) - cdef PyBuffWriteManager angular_distortion_buff = PyBuffWriteManager(angular_distortion) - cdef PyBuffWriteManager meridian_parallel_angle_buff = PyBuffWriteManager(meridian_parallel_angle) - cdef PyBuffWriteManager meridian_convergence_buff = PyBuffWriteManager(meridian_convergence) - cdef PyBuffWriteManager tissot_semimajor_buff = PyBuffWriteManager(tissot_semimajor) - cdef PyBuffWriteManager tissot_semiminor_buff = PyBuffWriteManager(tissot_semiminor) + cdef PyBuffWriteManager angular_distortion_buff = PyBuffWriteManager( + angular_distortion) + cdef PyBuffWriteManager meridian_parallel_angle_buff = PyBuffWriteManager( + meridian_parallel_angle) + cdef PyBuffWriteManager meridian_convergence_buff = PyBuffWriteManager( + meridian_convergence) + cdef PyBuffWriteManager tissot_semimajor_buff = PyBuffWriteManager( + tissot_semimajor) + cdef PyBuffWriteManager tissot_semiminor_buff = PyBuffWriteManager( + tissot_semiminor) cdef PyBuffWriteManager dx_dlam_buff = PyBuffWriteManager(dx_dlam) cdef PyBuffWriteManager dx_dphi_buff = PyBuffWriteManager(dx_dphi) cdef PyBuffWriteManager dy_dlam_buff = PyBuffWriteManager(dy_dlam) @@ -330,9 +344,15 @@ meridional_scale_buff.data[iii] = pj_factors.meridional_scale parallel_scale_buff.data[iii] = pj_factors.parallel_scale areal_scale_buff.data[iii] = pj_factors.areal_scale - angular_distortion_buff.data[iii] = pj_factors.angular_distortion * _RAD2DG - meridian_parallel_angle_buff.data[iii] = pj_factors.meridian_parallel_angle * _RAD2DG - meridian_convergence_buff.data[iii] = pj_factors.meridian_convergence * _RAD2DG + angular_distortion_buff.data[iii] = ( + pj_factors.angular_distortion * _RAD2DG + ) + meridian_parallel_angle_buff.data[iii] = ( + pj_factors.meridian_parallel_angle * _RAD2DG + ) + meridian_convergence_buff.data[iii] = ( + pj_factors.meridian_convergence * _RAD2DG + ) tissot_semimajor_buff.data[iii] = pj_factors.tissot_semimajor tissot_semiminor_buff.data[iii] = pj_factors.tissot_semiminor dx_dlam_buff.data[iii] = pj_factors.dx_dlam diff --git a/pyproj/_transformer.pyx b/pyproj/_transformer.pyx index 65bd8c9..a849159 100644 --- a/pyproj/_transformer.pyx +++ b/pyproj/_transformer.pyx @@ -33,7 +33,8 @@ } -AreaOfInterest = namedtuple("AreaOfInterest", +AreaOfInterest = namedtuple( + "AreaOfInterest", ["west_lon_degree", "south_lat_degree", "east_lon_degree", "north_lat_degree"] ) AreaOfInterest.__doc__ = """ @@ -99,7 +100,8 @@ if area_of_interest is not None: if not isinstance(area_of_interest, AreaOfInterest): raise ProjError( - "Area of interest must be of the type pyproj.transformer.AreaOfInterest." + "Area of interest must be of the type " + "pyproj.transformer.AreaOfInterest." ) west_lon_degree = area_of_interest.west_lon_degree south_lat_degree = area_of_interest.south_lat_degree @@ -213,7 +215,7 @@ def _initialize_from_projobj(self): self.proj_info = proj_pj_info(self.projobj) if self.proj_info.id == NULL: - raise ProjError("Input is not a transformation.") + raise ProjError("Input is not a transformation.") cdef PJ_TYPE transformer_type = proj_get_type(self.projobj) self.type_name = _TRANSFORMER_TYPE_MAP[transformer_type] self._set_base_info() @@ -277,13 +279,17 @@ Create a transformer from CRS objects """ cdef PJ_AREA *pj_area_of_interest = NULL - cdef double west_lon_degree, south_lat_degree, east_lon_degree, north_lat_degree + cdef double west_lon_degree + cdef double south_lat_degree + cdef double east_lon_degree + cdef double north_lat_degree cdef _Transformer transformer = _Transformer() try: if area_of_interest is not None: if not isinstance(area_of_interest, AreaOfInterest): raise ProjError( - "Area of interest must be of the type pyproj.transformer.AreaOfInterest." + "Area of interest must be of the type " + "pyproj.transformer.AreaOfInterest." ) pj_area_of_interest = proj_area_create() west_lon_degree = area_of_interest.west_lon_degree @@ -411,7 +417,10 @@ bint radians, bint errcheck, ): - if self.projections_exact_same or (self.projections_equivalent and self.skip_equivalent): + if ( + self.projections_exact_same + or (self.projections_equivalent and self.skip_equivalent) + ): return if radians and self.is_pipeline: warnings.warn( @@ -507,7 +516,10 @@ bint radians, bint errcheck, ): - if self.projections_exact_same or (self.projections_equivalent and self.skip_equivalent): + if ( + self.projections_exact_same + or (self.projections_equivalent and self.skip_equivalent) + ): return tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)] cdef PJ_DIRECTION pj_direction = tmp_pj_direction @@ -576,7 +588,6 @@ elif errcheck and ProjError.internal_proj_error is not None: raise ProjError("itransform error") - # radians to degrees if not radians and self._output_radians[pj_direction]: with nogil: diff --git a/pyproj/compat.py b/pyproj/compat.py index b5af58c..c68fe2d 100644 --- a/pyproj/compat.py +++ b/pyproj/compat.py @@ -1,4 +1,6 @@ -# -*- coding: utf-8 -*- +""" +This module is for compatibility between string types +""" def cstrencode(pystr): diff --git a/pyproj/crs/__init__.py b/pyproj/crs/__init__.py index 3574210..73666d3 100644 --- a/pyproj/crs/__init__.py +++ b/pyproj/crs/__init__.py @@ -1,10 +1,7 @@ -# -*- coding: utf-8 -*- """ This module interfaces with PROJ to produce a pythonic interface to the coordinate reference system (CRS) information through the CRS class. - -Original Author: Alan D. Snow [github.com/snowman2] (2019) """ from pyproj._crs import ( # noqa: F401 diff --git a/pyproj/crs/coordinate_operation.py b/pyproj/crs/coordinate_operation.py index 6504f22..5a347db 100644 --- a/pyproj/crs/coordinate_operation.py +++ b/pyproj/crs/coordinate_operation.py @@ -1,3 +1,9 @@ +""" +This module is for building operations to be used when +building a CRS. + +https://proj.org/operations/ +""" import warnings from distutils.version import LooseVersion from typing import Any diff --git a/pyproj/crs/coordinate_system.py b/pyproj/crs/coordinate_system.py index 1ba13f9..2fb49b8 100644 --- a/pyproj/crs/coordinate_system.py +++ b/pyproj/crs/coordinate_system.py @@ -1,3 +1,7 @@ +""" +This module is for building coordinate systems to be used when +building a CRS. +""" from typing import Union from pyproj._crs import CoordinateSystem diff --git a/pyproj/crs/crs.py b/pyproj/crs/crs.py index 0ba2c86..f50870f 100644 --- a/pyproj/crs/crs.py +++ b/pyproj/crs/crs.py @@ -1,10 +1,6 @@ -# -*- coding: utf-8 -*- """ This module interfaces with PROJ to produce a pythonic interface to the coordinate reference system (CRS) information. - -Original Author: Alan D. Snow [github.com/snowman2] (2019) - """ import json import re diff --git a/pyproj/crs/datum.py b/pyproj/crs/datum.py index 26ec2b2..e94eadb 100644 --- a/pyproj/crs/datum.py +++ b/pyproj/crs/datum.py @@ -1,3 +1,7 @@ +""" +This module is for building datums to be used when +building a CRS. +""" from typing import Any, Dict, Optional, Union from pyproj._crs import Datum, Ellipsoid, PrimeMeridian diff --git a/pyproj/datadir.py b/pyproj/datadir.py index 12135fb..f2a88ea 100644 --- a/pyproj/datadir.py +++ b/pyproj/datadir.py @@ -1,5 +1,5 @@ """ -Set the datadir path to the local data directory +Module for managing the PROJ data directory. """ import os import sys diff --git a/pyproj/exceptions.py b/pyproj/exceptions.py index f946b7f..d9cde01 100644 --- a/pyproj/exceptions.py +++ b/pyproj/exceptions.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Exceptions for pyproj """ diff --git a/pyproj/geod.py b/pyproj/geod.py index 7792c6b..5076dcf 100644 --- a/pyproj/geod.py +++ b/pyproj/geod.py @@ -1,9 +1,4 @@ """ -Cython wrapper to provide python interfaces to -PROJ (https://proj.org) functions. - -Performs geodetic computations. - The Geod class can perform forward and inverse geodetic, or Great Circle, computations. The forward computation involves determining latitude, longitude and back azimuth of a terminus @@ -11,23 +6,7 @@ azimuth and distance. The inverse computation involves determining the forward and back azimuths and distance given the latitudes and longitudes of an initial and terminus point. - -Contact: Jeffrey Whitaker