Science Score: 75.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
✓Institutional organization owner
Organization spacetelescope has institutional domain (www.stsci.edu) -
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.5%) to scientific vocabulary
Repository
Clip polygons against a pixel grid
Basic Info
Statistics
- Stars: 7
- Watchers: 7
- Forks: 6
- Open Issues: 1
- Releases: 3
Metadata Files
README.md
pypolyclip
A Python package to clip polygons against a pixel grid.
The polyclip functions were originally developed for the CUBISM project Smith et al. 2007 (PASP 119, 1133).
Installation
The package can be installed using pip from the command line:
pip install pypolyclip
Description
The polyclip code employs the Sutherland-Hodgman algorithm to clip simple polygons against a tessellated grid of square pixels. Therefore, this differs from similar packages, which often clip between two arbitrary polygons.
The test module test_pypolyclip.py can be run to produce the following example figures:

In each figure, the Cartesian coordinates for each pixel that overlaps with a given polygon are labeled with the area of that pixel that is covered (the area of a pixel is defined as 1). Therefore, the sum of the areas of the individual pixels for each polygon should be the total area of the polygon.
Pypolyclip uses a coordinate grid where integer pixel coordinates are located at the lower-left corner of each pixel, starting from zero. To clip polygons on a coordinate grid where integer pixel coordinates are located at the center of pixels, one will need to add 0.5 pixel to both the x and y vertices of the input polygons.
The first figure shows clipping of polygons with differing numbers of vertices, which internally requires the use of "for loops". However, if the number of vertices is the same for all polygons (such as the second figure), then NumPy is used internally to improve performance by several percent.
Example usage
This first example demonstrates polygons with the same number of vertices:
``` import numpy as np from pypolyclip import clip_multi
define the size of the pixel grid
naxis = (100, 100)
create 3 polygons to clip
the x-vertices of the polygon
px = np.array([[3.4, 3.4, 4.4, 4.4], [3.5, 3.5, 4.3, 4.3], [3.1, 3.1, 3.9, 3.9]])
the y-vertices of the polygon
py = np.array([[1.4, 1.9, 1.9, 1.4], [3.7, 4.4, 4.4, 3.7], [2.1, 2.9, 2.9, 2.1]])
call the clipper
xc, yc, area, slices = clip_multi(px, py, naxis)
xc, yc are the grid indices with overlapping pixels.
area is the overlapping area on a given pixel.
slices is a list of slice objects to link between the input polygons
and the clipped pixel grid.
the slices object can be used to get the area of each polygon
for i, s in enumerate(slices): print(f'total area for polygon {i}={np.sum(area[s])}') ```
This second example demonstrates clipping polygons that have a different
number of vertices. Note that px and py are lists of lists instead
of NumPy arrays as in the first example.
``` import numpy as np from pypolyclip import clip_multi
define the size of the pixel grid
naxis = (100, 100)
create 3 polygons to clip
the x-vertices of the polygon
px = [[3.4, 3.4, 4.4, 4.8, 4.4], [3.5, 3.5, 4.3, 4.3], [3.1, 3.8, 3.1]]
the y-vertices of the polygon
py = [[1.4, 1.9, 1.9, 1.65, 1.4], [3.7, 4.4, 4.4, 3.7], [2.1, 2.1, 3.4]]
call the clipper
xc, yc, area, slices = clip_multi(px, py, naxis)
xc, yc are the grid indices with overlapping pixels.
area is the overlapping area on a given pixel.
slices is a list of slice objects to link between the input polygons
and the clipped pixel grid.
the slices object can be used to get the area of each polygon
for i, s in enumerate(slices): print(f'total area for polygon {i}={np.sum(area[s])}') ```
Owner
- Name: Space Telescope Science Institute
- Login: spacetelescope
- Kind: organization
- Email: help@stsci.edu
- Location: Baltimore, MD
- Website: http://www.stsci.edu
- Repositories: 305
- Profile: https://github.com/spacetelescope
STScI is operated by AURA for NASA
Citation (CITATION.cff)
cff-version: 1.2.0
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- family-names: "Ryan"
given-names: "Russell"
orcid: "https://orcid.org/0000-0003-0894-1588"
- family-names: "Smith"
given-names: "John-David"
orcid: "https://orcid.org/0000-0003-1545-5078"
- family-names: "Bradley"
given-names: "Larry"
orcid: "https://orcid.org/0000-0002-7908-9284"
- family-names: "O'Steen"
given-names: "Richard"
orcid: "https://orcid.org/0000-0002-2432-8946"
- family-names: "Lim"
given-names: "Pey Lian"
orcid: "https://orcid.org/0000-0003-0079-4114"
- family-names: "Nguyen"
given-names: "Duy"
orcid: "https://orcid.org/0000-0002-1534-336X"
- family-names: "Sosey"
given-names: "Megan"
orcid: "https://orcid.org/0000-0002-4206-6492"
title: "pypolyclip"
version: 1.0.0
doi:
date-released:
url: https://github.com/spacetelescope/pypolyclip
GitHub Events
Total
- Issues event: 1
- Watch event: 2
- Delete event: 12
- Push event: 20
- Pull request review event: 9
- Pull request event: 30
- Create event: 13
Last Year
- Issues event: 1
- Watch event: 2
- Delete event: 12
- Push event: 20
- Pull request review event: 9
- Pull request event: 30
- Create event: 13
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 18
- Average time to close issues: 10 months
- Average time to close pull requests: about 11 hours
- Total issue authors: 1
- Total pull request authors: 3
- Average comments per issue: 0.0
- Average comments per pull request: 0.11
- Merged pull requests: 12
- Bot issues: 0
- Bot pull requests: 14
Past Year
- Issues: 0
- Pull requests: 17
- Average time to close issues: N/A
- Average time to close pull requests: about 12 hours
- Issue authors: 0
- Pull request authors: 3
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 11
- Bot issues: 0
- Bot pull requests: 14
Top Authors
Issue Authors
- Russell-Ryan (1)
- sosey (1)
Pull Request Authors
- dependabot[bot] (9)
- pre-commit-ci[bot] (5)
- larrybradley (5)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 466 last-month
- Total dependent packages: 1
- Total dependent repositories: 3
- Total versions: 4
- Total maintainers: 3
pypi.org: pypolyclip
A python driver to the polyclip functions
- Homepage: https://github.com/spacetelescope/pypolyclip
- Documentation: https://pypolyclip.readthedocs.io/
- License: Original polyclip C code (BSD 3-clause license) ----------------------------------------------- Copyright (c) 2001-2007, J.D. Smith Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Python wrapper code (BSD 3-clause license) ------------------------------------------ Copyright (C) 2010 Association of Universities for Research in Astronomy (AURA) Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of AURA and its representatives may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AURA "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
Latest release: 1.1.0
published almost 2 years ago
Rankings
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- codecov/codecov-action v3 composite