From 89d0611cfc4fa3bff7449d949ccfd4690f778fce Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:37:20 -0700 Subject: [PATCH 1/5] repeat names for re-export --- float_raster/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/float_raster/__init__.py b/float_raster/__init__.py index 5324115..b3bf735 100644 --- a/float_raster/__init__.py +++ b/float_raster/__init__.py @@ -5,7 +5,14 @@ Module for rasterizing polygons, with float-precision anti-aliasing on See the documentation for float_raster.raster(...) for details. """ -from .float_raster import * +from .float_raster import ( + raster as raster, + find_intersections as find_intersections, + create_vertices as create_vertices, + clip_vertices_to_window as clip_vertices_to_window, + get_raster_parts as get_raster_parts, + ) + __author__ = 'Jan Petykiewicz' __version__ = '0.7' From a12ef190fa905b643fa0d904284786e7329ab695 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:37:29 -0700 Subject: [PATCH 2/5] float_ -> floating --- float_raster/float_raster.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/float_raster/float_raster.py b/float_raster/float_raster.py index 5f1917b..ab4c258 100644 --- a/float_raster/float_raster.py +++ b/float_raster/float_raster.py @@ -50,9 +50,9 @@ def raster( def find_intersections( - vertices: NDArray[numpy.float_], - grid_x: NDArray[numpy.float_], - grid_y: NDArray[numpy.float_], + vertices: NDArray[numpy.floating], + grid_x: NDArray[numpy.floating], + grid_y: NDArray[numpy.floating], ) -> tuple[NDArray[numpy.float64], NDArray[numpy.float64], NDArray[numpy.float64]]: """ Find intersections between a polygon and grid lines @@ -127,9 +127,9 @@ def find_intersections( def create_vertices( - vertices: NDArray[numpy.float_], - grid_x: NDArray[numpy.float_], - grid_y: NDArray[numpy.float_], + vertices: NDArray[numpy.floating], + grid_x: NDArray[numpy.floating], + grid_y: NDArray[numpy.floating], new_vertex_data: tuple[NDArray[numpy.float64], NDArray[numpy.float64], NDArray[numpy.float64]] | None = None ) -> sparse.coo_matrix: """ From 9749cecef81e8ec41455a5170ae4f632ee0d280a Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:38:25 -0700 Subject: [PATCH 3/5] add some more keywords --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e9b447d..e406000 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,9 @@ homepage = "https://mpxd.net/code/jan/float_raster" repository = "https://mpxd.net/code/jan/float_raster" keywords = [ "coverage", + "raster", + "anti-alias", + "polygon", ] classifiers = [ "Programming Language :: Python :: 3", From 1799faeddd872ddaf0ce4f61d278e5dce2797642 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:42:31 -0700 Subject: [PATCH 4/5] add custom exception type --- float_raster/float_raster.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/float_raster/float_raster.py b/float_raster/float_raster.py index ab4c258..26cc4a1 100644 --- a/float_raster/float_raster.py +++ b/float_raster/float_raster.py @@ -4,6 +4,11 @@ from numpy import logical_and, diff, floor, ceil, ones, zeros, hstack, full_like from scipy import sparse +class FloatRasterError(Exception): + """ Custom exception for float_raster """ + pass + + def raster( vertices: ArrayLike, grid_x: ArrayLike, @@ -58,7 +63,7 @@ def find_intersections( Find intersections between a polygon and grid lines """ if vertices.shape[0] != 2: - raise Exception('vertices must be 2xN') + raise FloatRasterError('vertices must be 2xN') min_bounds = floor(vertices.min(axis=1)) max_bounds = ceil(vertices.max(axis=1)) @@ -136,9 +141,9 @@ def create_vertices( Create additional vertices where a polygon crosses gridlines """ if vertices.shape[0] != 2: - raise Exception('vertices must be 2xN') + raise FloatRasterError('vertices must be 2xN') if grid_x.size < 1 or grid_y.size < 1: - raise Exception('Grid must contain at least one line in each direction?') + raise FloatRasterError('Grid must contain at least one line in each direction?') num_poly_vertices = vertices.shape[1] @@ -235,7 +240,7 @@ def get_raster_parts( grid_y = numpy.array(grid_y) if grid_x.size < 2 or grid_y.size < 2: - raise Exception('Grid must contain at least one full pixel') + raise FloatRasterError('Grid must contain at least one full pixel') num_xy_px = numpy.array([grid_x.size, grid_y.size]) - 1 From 379abb5e82e28b70094372f322055606cf20d6e6 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:42:49 -0700 Subject: [PATCH 5/5] add configs for ruff any mypy --- pyproject.toml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e406000..e64259d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,3 +39,44 @@ dependencies = [ [tool.hatch.version] path = "float_raster/__init__.py" + + +[tool.ruff] +exclude = [ + ".git", + "dist", + ] +line-length = 145 +indent-width = 4 +lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" +lint.select = [ + "NPY", "E", "F", "W", "B", "ANN", "UP", "SLOT", "SIM", "LOG", + "C4", "ISC", "PIE", "PT", "RET", "TCH", "PTH", "INT", + "ARG", "PL", "R", "TRY", + "G010", "G101", "G201", "G202", + "Q002", "Q003", "Q004", + ] +lint.ignore = [ + #"ANN001", # No annotation + "ANN002", # *args + "ANN003", # **kwargs + "ANN401", # Any + "ANN101", # self: Self + "SIM108", # single-line if / else assignment + "RET504", # x=y+z; return x + "PIE790", # unnecessary pass + "ISC003", # non-implicit string concatenation + "C408", # dict(x=y) instead of {'x': y} + "PLR09", # Too many xxx + "PLR2004", # magic number + "PLC0414", # import x as x + "TRY003", # Long exception message + ] + + +[[tool.mypy.overrides]] +module = [ + "scipy", + "scipy.sparse", + ] +ignore_missing_imports = true