Skip to content

Commit dfc53b7

Browse files
committed
Avoid the magic number 6
with a module-level constant. Store that in the header FWIW.
1 parent b76c7b3 commit dfc53b7

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

python/lsst/cell_coadds/_fits.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
the form M.m, where M is the major version, m is the minor version.
120120
"""
121121

122+
MAX_POLYGON_VERTICES = 6
123+
"""Maximum number of vertices the overlap polygon region between a per-detector
124+
warp and the patch bounding box can have."""
125+
# 3 vertices from the detector, 3 vertices from the patch bounding box.
126+
122127
logger = logging.getLogger(__name__)
123128

124129

@@ -328,7 +333,10 @@ def readAsMultipleCellCoadd(self) -> MultipleCellCoadd:
328333
day_obs=visit_dict[visit].day_obs,
329334
physical_filter=visit_dict[visit].physical_filter,
330335
)
331-
num_vertices = row["num_vertices"] if written_version >= version.parse("0.7") else 6
336+
if written_version >= version.parse("0.7"):
337+
num_vertices = row["num_vertices"]
338+
else:
339+
num_vertices = None # li[:None] returns the entire list.
332340
visit_polygons[obs_id] = afwGeom.Polygon(
333341
[Point2D(vertex) for vertex in row["polygon_vertices"][:num_vertices]]
334342
)
@@ -673,22 +681,25 @@ def writeMultipleCellCoaddAsFits(
673681
number_of_vertices = []
674682
polygon_vertices_array = []
675683
for obs_id, poly in multiple_cell_coadd.common.visit_polygons.items():
676-
if num_vertices := len(poly.getVertices()) > 6:
684+
if num_vertices := len(poly.getVertices()) > MAX_POLYGON_VERTICES:
677685
logger.warning(
678-
"Visit %d, detector %d has a polygon with %d vertices; "
679-
"only the first 6 will be stored in the FITS file.",
686+
"Visit %d, detector %d has a polygon with %d vertices. "
687+
"This geometry should be impossible for two intersecting "
688+
"convex quadrilaterals. Only the first %d will be stored in "
689+
"the FITS file.",
680690
obs_id.visit,
681691
obs_id.detector,
682692
num_vertices,
693+
MAX_POLYGON_VERTICES,
683694
)
684695
number_of_vertices.append(num_vertices)
685696
vertices = poly.getVertices() + poly.getVertices()
686-
vertices = vertices[:6]
697+
vertices = vertices[:MAX_POLYGON_VERTICES]
687698
polygon_vertices_array.append(np.array(vertices))
688699
polygon_column = fits.Column(
689700
name="polygon_vertices",
690-
format="12E",
691-
dim="(2,6)",
701+
format=f"{2 * MAX_POLYGON_VERTICES}E",
702+
dim=f"(2,{MAX_POLYGON_VERTICES})",
692703
array=polygon_vertices_array,
693704
)
694705
number_of_vertices_column = fits.Column(
@@ -700,6 +711,7 @@ def writeMultipleCellCoaddAsFits(
700711
[visit_column, detector_column, number_of_vertices_column, polygon_column],
701712
name="VISIT_SUMMARY",
702713
)
714+
visit_summary_hdu.header["POLYVERT"] = MAX_POLYGON_VERTICES
703715

704716
visit_recarray = np.rec.fromrecords(
705717
recList=sorted(set(visit_records), key=lambda x: x[0]), # Sort by visit.

0 commit comments

Comments
 (0)