region¶
The region
module provides a polygon filling algorithm
used by skymatch
to create data masks.
Polygon filling algorithm.
Authors: | Nadezhda Dencheva, Mihai Cara (contact: help@stsci.edu) |
---|
-
class
jwst.skymatch.region.
Region
(rid, coordinate_system)[source]¶ Base class for regions.
Parameters: - rid (int or string) – region ID
- coordinate_system (astropy.wcs.CoordinateSystem instance or a string) – in the context of WCS this would be an instance of wcs.CoordinateSysem
-
scan
(mask)[source]¶ Sets mask values to region id for all pixels within the region. Subclasses must define this method.
Parameters: mask (ndarray) – a byte array with the shape of the observation to be used as a mask Returns: mask – pixels which are not included in any region). Return type: array where the value of the elements is the region ID or 0 (for
-
class
jwst.skymatch.region.
Edge
(name=None, start=None, stop=None, next=None)[source]¶ Edge representation
An edge has a “start” and “stop” (x,y) vertices and an entry in the GET table of a polygon. The GET entry is a list of these values:
[ymax, x_at_ymin, delta_x/delta_y]
-
compute_AET_entry
(edge)[source]¶ Compute the entry for an edge in the current Active Edge Table
[ymax, x_intersect, 1/m] note: currently 1/m is not used
-
next
¶
-
start
¶
-
stop
¶
-
ymax
¶
-
ymin
¶
-
-
class
jwst.skymatch.region.
Polygon
(rid, vertices, coord_system='Cartesian')[source]¶ Represents a 2D polygon region with multiple vertices
Parameters: - rid (string) – polygon id
- vertices (list of (x,y) tuples or lists) – The list is ordered in such a way that when traversed in a counterclockwise direction, the enclosed area is the polygon. The last vertex must coincide with the first vertex, minimum 4 vertices are needed to define a triangle
- coord_system (string) – coordinate system
-
scan
(data)[source]¶ This is the main function which scans the polygon and creates the mask
Parameters: - data (array) – the mask array it has all zeros initially, elements within a region are set to the region’s ID
- Algorithm –
- Set the Global Edge Table (GET) (-) –
- Set y to be the smallest y coordinate that has an entry in GET (-) –
- Initialize the Active Edge Table (AET) to be empty (-) –
- For each scan line (-) –
- Add edges from GET to AET for which ymin==y
- Remove edges from AET fro which ymax==y
- Compute the intersection of the current scan line with all edges in the AET
- Sort on X of intersection point
- Set elements between pairs of X in the AET to the Edge’s ID