Repository: cta-observatory/ctapipe
Pull request #1956 (2022-06-27 10:52:13)

Hash rounded versions of floats for CameraGeometry
TODO: check other parts of the descriptions.

codecov[bot]: # [Codecov](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory) Report
> Merging [#1956](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory) (1c20b43) into [master](https://codecov.io/gh/cta-observatory/ctapipe/commit/5f5fd157a0818cfff6045aa4048ce79f6018d0f2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory) (5f5fd15) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master    #1956      +/-   ##
==========================================
+ Coverage   92.18%   92.19%   +0.01%     
==========================================
  Files         193      193              
  Lines       15192    15213      +21     
==========================================
+ Hits        14004    14026      +22     
+ Misses       1188     1187       -1     
```


| [Impacted Files](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory) | Coverage Δ | |
|---|---|---|
| [ctapipe/instrument/camera/geometry.py](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory#diff-Y3RhcGlwZS9pbnN0cnVtZW50L2NhbWVyYS9nZW9tZXRyeS5weQ==) | `90.70% <100.00%> (ø)` | |
| [ctapipe/core/qualityquery.py](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory#diff-Y3RhcGlwZS9jb3JlL3F1YWxpdHlxdWVyeS5weQ==) | `96.36% <0.00%> (-1.47%)` | :arrow_down: |
| [ctapipe/core/tests/test\_qualityquery.py](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory#diff-Y3RhcGlwZS9jb3JlL3Rlc3RzL3Rlc3RfcXVhbGl0eXF1ZXJ5LnB5) | `100.00% <0.00%> (+4.34%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory). Last update [5f5fd15...1c20b43](https://codecov.io/gh/cta-observatory/ctapipe/pull/1956?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory).


Patch:
diff --git a/ctapipe/core/qualityquery.py b/ctapipe/core/qualityquery.py
index 3fd23b31..fe3c3458 100644
--- a/ctapipe/core/qualityquery.py
+++ b/ctapipe/core/qualityquery.py
@@ -102,7 +102,7 @@ class QualityQuery(Component):
 
     def __str__(self):
         """Print a formatted string representation of the entire table."""
-        return self.to_table().pprint_all(show_unit=True, show_dtype=True)
+        return str(self.to_table())
 
     def __call__(self, **kwargs) -> np.ndarray:
         """
diff --git a/ctapipe/instrument/camera/geometry.py b/ctapipe/instrument/camera/geometry.py
index 2dc6c169..09a5eb8d 100644
--- a/ctapipe/instrument/camera/geometry.py
+++ b/ctapipe/instrument/camera/geometry.py
@@ -262,7 +262,7 @@ class CameraGeometry:
         scale = np.sqrt(uv_trans_x[0] ** 2 + uv_trans_y[0] ** 2) / cam.pix_x.unit
         trans_x = getattr(trans, trans_x_name)
         trans_y = getattr(trans, trans_y_name)
-        pix_area = (cam.pix_area * scale ** 2).to(trans_x.unit ** 2)
+        pix_area = (cam.pix_area * scale**2).to(trans_x.unit**2)
 
         return CameraGeometry(
             camera_name=cam.camera_name,
@@ -282,10 +282,10 @@ class CameraGeometry:
         return hash(
             (
                 self.camera_name,
-                self.pix_x[0].value,
-                self.pix_y[0].value,
+                round(self.pix_x[0].value, 3),
+                round(self.pix_y[0].value, 3),
                 self.pix_type,
-                self.pix_rotation.deg,
+                round(self.pix_rotation.deg, 3),
             )
         )
 
@@ -321,7 +321,7 @@ class CameraGeometry:
         if pix_type == PixelShape.HEXAGON:
             area = 2 * np.sqrt(3) * (dist / 2) ** 2
         elif pix_type == PixelShape.SQUARE:
-            area = dist ** 2
+            area = dist**2
         else:
             raise KeyError("unsupported pixel type")
 
@@ -582,7 +582,7 @@ class CameraGeometry:
         return CameraGeometry.from_table(table)
 
     def to_table(self):
-        """ convert this to an `astropy.table.Table` """
+        """convert this to an `astropy.table.Table`"""
         # currently the neighbor list is not supported, since
         # var-length arrays are not supported by astropy.table.Table
         t = Table(
@@ -771,18 +771,18 @@ class CameraGeometry:
             [
                 x,
                 y,
-                x ** 2,
+                x**2,
                 x * y,
-                y ** 2,
-                x ** 3,
-                x ** 2 * y,
-                x * y ** 2,
-                y ** 3,
-                x ** 4,
-                x ** 3 * y,
-                x ** 2 * y ** 2,
-                x * y ** 3,
-                y ** 4,
+                y**2,
+                x**3,
+                x**2 * y,
+                x * y**2,
+                y**3,
+                x**4,
+                x**3 * y,
+                x**2 * y**2,
+                x * y**3,
+                y**4,
             ]
         )
 
@@ -819,7 +819,7 @@ class CameraGeometry:
         self.cam_rotation = Angle(0, unit=u.deg)
 
     def info(self, printer=print):
-        """ print detailed info about this camera """
+        """print detailed info about this camera"""
         printer(f'CameraGeometry: "{self}"')
         printer("   - num-pixels: {}".format(len(self.pix_id)))
         printer(f"   - pixel-type: {self.pix_type}")
diff --git a/ctapipe/reco/shower_processor.py b/ctapipe/reco/shower_processor.py
index 40c1efa7..8ed30b6c 100644
--- a/ctapipe/reco/shower_processor.py
+++ b/ctapipe/reco/shower_processor.py
@@ -82,8 +82,8 @@ class ShowerProcessor(Component):
             shower_geom=event.dl2.stereo.geometry[k], subarray=self.subarray
         )
 
-        for tel_index, impact_distance in enumerate(impact_distances):
-            tel_id = self.subarray.tel_ids[tel_index]
+        for tel_id in event.trigger.tels_with_trigger:
+            tel_index = self.subarray.tel_indices[tel_id]
             event.dl2.tel[tel_id].impact[k] = TelescopeImpactParameterContainer(
-                distance=impact_distance
+                distance=impact_distances[tel_index]
             )


Test patch:
diff --git a/ctapipe/core/tests/test_qualityquery.py b/ctapipe/core/tests/test_qualityquery.py
index b70f7dc3..85c631c0 100644
--- a/ctapipe/core/tests/test_qualityquery.py
+++ b/ctapipe/core/tests/test_qualityquery.py
@@ -123,3 +123,12 @@ def test_table_mask():
     stats = query.to_table()
     np.testing.assert_equal(stats["counts"], [5, 3, 2])
     np.testing.assert_equal(stats["cumulative_counts"], [5, 3, 1])
+
+
+def test_printing():
+    """Just check the query can be stringified correctly"""
+    query = QualityQuery(
+        quality_criteria=[("check", "x>3")],
+    )
+
+    assert isinstance(str(query), str)
diff --git a/ctapipe/io/tests/test_table_loader.py b/ctapipe/io/tests/test_table_loader.py
index a22a3814..f6759cfc 100644
--- a/ctapipe/io/tests/test_table_loader.py
+++ b/ctapipe/io/tests/test_table_loader.py
@@ -151,7 +151,7 @@ def test_read_telescope_events_type(test_file_dl2):
         assert "HillasReconstructor_alt" in table.colnames
         assert "true_energy" in table.colnames
         assert "true_image" in table.colnames
-        assert {25, 125, 127}.issubset(set(table["tel_id"].data))
+        assert set(table["tel_id"].data).issubset([25, 125, 130])
         assert "equivalent_focal_length" in table.colnames
         assert "HillasReconstructor_impact_distance" in table.colnames