def test_detx_format_comments(self): det = Detector(filename=data_path("detx/detx_v1.detx")) assert len(det.comments) == 0 det = Detector(filename=data_path("detx/detx_v2.detx")) assert len(det.comments) == 0 det = Detector(filename=data_path("detx/detx_v3.detx")) assert len(det.comments) == 2 assert " a comment line" == det.comments[0] assert " another comment line starting with '#'" == det.comments[1]
def test_detx_v5(self): det = Detector(filename=data_path("detx/detx_v5.detx")) assert np.allclose([464.4, 564.7, 190.583], det.dom_positions[808956908], atol=1e-2) assert np.allclose([464.4, 564.7, 95.389], det.dom_positions[808981864], atol=1e-2) assert det.n_doms == 114 assert det.det_id == 49 assert det.n_pmts_per_dom == 31 assert det.n_dus == 6 assert np.allclose( det.doms[808981864], [ 1.0000000e01, 8.0000000e00, 3.1000000e01, 4.6440000e02, 5.6470000e02, 9.5389000e01, 9.9995400e-01, -7.8470000e-03, 3.9110000e-03, 4.0080000e-03, 0.0000000e00, 3.7861343e04, ], atol=1e-2, ) assert np.allclose( np.array([ [484.6, 564.65], [464.4, 564.7], [442.5, 567.45], [474.15, 583.45], [454.2, 583.0], [431.1, 583.5], ]), det.xy_positions, ) assert np.allclose( [ 3, 0.73205, 0.614161, 0.29479, 808981864, 10, 8, 13367, 464.546, 564.823, 95.448, 0, 207862.961, ], list(det.get_pmt(808981864, 3)), )
def test_detx_format_version_1(self): det = Detector(filename=data_path("detx/detx_v1.detx")) assert 2 == det.n_dus assert 6 == det.n_doms assert 3 == det.n_pmts_per_dom assert 1 == det.version self.assertListEqual([1.1, 1.2, 1.3], list(det.pmts.pos[0])) self.assertListEqual([3.4, 3.5, 3.6], list(det.pmts.pos[7])) self.assertListEqual([23.4, 23.5, 23.6], list(det.pmts.pos[16]))
def configure(self): self._should_apply = self.get("apply", default=True) self.filename = self.get("filename") self.det_id = self.get("det_id") self.run = self.get("run") self.t0set = self.get("t0set") self.calibset = self.get("calibset") self.detector = self.get("detector") self.key = self.get("key", default="Hits") self.outkey = self.get("outkey", default="CalibHits") self.key_mc = self.get("key_mc", default="McHits") self.outkey_mc = self.get("outkey_mc", default="CalibMcHits") self._pos_dom_channel = None self._dir_dom_channel = None self._t0_dom_channel = None self._pos_pmt_id = None self._dir_pmt_id = None self._t0_pmt_id = None self._lookup_tables = None # for Numba if self.det_id and self.run: self.cprint( "Grabbing the calibration for Det ID {} and run {}".format( self.det_id, self.run)) raw_detx = km3db.tools.detx_for_run(self.det_id, self.run) self.detector = Detector(string=raw_detx) self._create_dom_channel_lookup() self._create_pmt_id_lookup() return if self.filename or self.det_id: if self.filename is not None: self.detector = Detector(filename=self.filename) if self.det_id: self.detector = Detector(det_id=self.det_id, t0set=self.t0set, calibset=self.calibset) if self.detector is not None: self.log.debug("Creating lookup tables") self._create_dom_channel_lookup() self._create_pmt_id_lookup() else: self.log.critical("No detector information loaded.")
def test_jdetectordb_output_with_detx_v3(self): det = Detector( data_path( "detx/D_ORCA006_t.A02181836.p.A02181837.r.A02182001.detx")) assert det.utm_info is not None assert det.utm_info.ellipsoid == "WGS84" assert det.utm_info.grid == "32N" assert det.utm_info.easting == 256500.0 assert det.utm_info.northing == 4743000.0 assert det.utm_info.z == -2440.0
def test_detx_v4(self): det = Detector(filename=data_path("detx/detx_v4.detx")) assert np.allclose([119.6, -12.2, 192.77], det.dom_positions[808956908], atol=1e-2) assert np.allclose([119.6, -12.2, 97.44], det.dom_positions[808981864], atol=1e-2) assert det.n_doms == 90 assert det.det_id == 44 assert det.n_pmts_per_dom == 31 assert det.n_dus == 5 assert np.allclose( det.doms[808945480], [ 1, 5, 31, 86.500, 9.100, 66.821, 1.000000, 0.000000, 0.000000, 0.000000, 0.000, ], atol=1e-2, ) assert np.allclose( np.array([[86.5, 9.1], [86.6, 6.6], [109.6, 5.9], [97.8, -9.6], [119.6, -12.2]]), det.xy_positions, ) assert np.allclose( [ 3, 0.844, 0.449, 0.295, 808981864, 5, 8, 13367, 119.768, -12.11, 97.5, 0, 207863.242, ], list(det.get_pmt(808981864, 3)), )
def test_dom_table_with_another_detx(self): det = Detector() det._det_file = EXAMPLE_DETX_RADIAL det._parse() dt = det.dom_table assert 4 == len(dt) assert np.allclose([1, 2, 3, 4], dt.dom_id) assert np.allclose([1, 1, 1, 2], dt.du) assert np.allclose([1, 2, 3, 1], dt.floor) assert np.allclose([0, 0, 0, 0], dt.pos_x) assert np.allclose([0, 0, 0, 0], dt.pos_y) assert np.allclose([0, 0, 0, 0], dt.pos_z)
def test_rotate_dom_set_by_step_by_360_degrees(self): det = Detector() det._det_file = EXAMPLE_DETX_RADIAL det._parse() dom_id = 1 channel_id = 0 pmt_dir = det.pmts[det.pmts.dom_id == dom_id].dir[channel_id].copy() pmt_pos = det.pmts[det.pmts.dom_id == dom_id].pos[channel_id].copy() for i in range(36): det.rotate_dom_by_yaw(dom_id, 10) pmt_dir_rot = det.pmts[det.pmts.dom_id == dom_id].dir[channel_id] assert np.allclose(pmt_dir, pmt_dir_rot) pmt_pos_rot = det.pmts[det.pmts.dom_id == dom_id].pos[channel_id] assert np.allclose(pmt_pos, pmt_pos_rot)
def setUp(self): self.track = { "pos_x": 1.7524502152598151, "pos_y": 39.06202405657308, "pos_z": 130.44049806891948, "dir_x": 0.028617421257374293, "dir_y": -0.489704257367248, "dir_z": -0.8714188335794505, } self.det = Detector(data_path("detx/detx_v3.detx")) pd = km3pipe.extras.pandas() self.DU = pd.DataFrame(self.det.dom_table).mean()
def test_detx_format_version_3_with_whitespace(self): det = Detector(filename=data_path("detx/detx_v3_whitespace.detx")) assert 2 == det.n_dus assert 6 == det.n_doms assert 3 == det.n_pmts_per_dom assert 256500.0 == det.utm_info.easting assert 4743000.0 == det.utm_info.northing assert "WGS84" == det.utm_info.ellipsoid assert "32N" == det.utm_info.grid assert -2425.0 == det.utm_info.z assert 1500000000.1 == det.valid_from assert 9999999999.0 == det.valid_until assert 3 == det.version self.assertListEqual([1.1, 1.2, 1.3], list(det.pmts.pos[0])) self.assertListEqual([3.4, 3.5, 3.6], list(det.pmts.pos[7])) self.assertListEqual([23.4, 23.5, 23.6], list(det.pmts.pos[16]))
def test_rotate_du_by_yaw_step_by_step_360_degrees(self): det = Detector() det._det_file = EXAMPLE_DETX_RADIAL det._parse() du = 2 pmt_dir = det.pmts[det.pmts.du == du].dir.copy() pmt_pos = det.pmts[det.pmts.du == du].pos.copy() pmt_dir_other_dus = det.pmts[det.pmts.du != du].dir.copy() pmt_pos_other_dus = det.pmts[det.pmts.du != du].pos.copy() for i in range(36): det.rotate_du_by_yaw(du, 10) pmt_dir_rot = det.pmts[det.pmts.du == du].dir pmt_pos_rot = det.pmts[det.pmts.du == du].pos assert np.allclose(pmt_dir, pmt_dir_rot) assert np.allclose(pmt_pos, pmt_pos_rot) assert np.allclose(pmt_dir_other_dus, det.pmts[det.pmts.du != du].dir) assert np.allclose(pmt_pos_other_dus, det.pmts[det.pmts.du != du].pos)
def test_rotate_dom_by_yaw(self): det = Detector() det._det_file = EXAMPLE_DETX_RADIAL det._parse() # here, only one PMT is checked dom_id = 1 heading = 23 channel_id = 0 pmt_dir = det.pmts[det.pmts.dom_id == dom_id].dir[channel_id].copy() pmt_dir_rot = qrot_yaw(pmt_dir, heading) det.rotate_dom_by_yaw(dom_id, heading) assert np.allclose(pmt_dir_rot, det.pmts[det.pmts.dom_id == dom_id].dir[channel_id]) assert np.allclose( [0.92050485, 0.39073113, 0], det.pmts[det.pmts.dom_id == dom_id].pos[channel_id], )
def test_init_from_string(self): detx_string = "\n".join(( "1 3", "8 1 1 3", " 1 1.1 1.2 1.3 1.1 2.1 3.1 10.0", " 2 1.4 1.5 1.6 4.1 5.1 6.1 20.0", " 3 1.7 1.8 1.9 7.1 8.1 9.1 30.0", "4 1 2 3", " 4 2.1 2.2 2.3 1.2 2.2 3.2 40.0", " 5 2.4 2.5 2.6 4.2 5.2 6.2 50.0", " 6 2.7 2.8 2.9 7.2 8.2 9.2 60.0", "9 1 3 3", " 7 3.1 3.2 3.3 1.3 2.3 3.3 70.0", " 8 3.4 3.5 3.6 4.3 5.3 6.3 80.0", " 9 3.7 3.8 3.9 7.3 8.3 9.3 90.0\n", )) det = Detector(string=detx_string) assert 1 == det.n_dus assert 3 == det.n_doms
def test_ascii_with_mixed_dom_ids(self): detx_string = "\n".join(( "1 3", "8 1 1 3", " 1 1.1 1.2 1.3 1.1 2.1 3.1 10.0", " 2 1.4 1.5 1.6 4.1 5.1 6.1 20.0", " 3 1.7 1.8 1.9 7.1 8.1 9.1 30.0", "4 1 2 3", " 4 2.1 2.2 2.3 1.2 2.2 3.2 40.0", " 5 2.4 2.5 2.6 4.2 5.2 6.2 50.0", " 6 2.7 2.8 2.9 7.2 8.2 9.2 60.0", "9 1 3 3", " 7 3.1 3.2 3.3 1.3 2.3 3.3 70.0", " 8 3.4 3.5 3.6 4.3 5.3 6.3 80.0", " 9 3.7 3.8 3.9 7.3 8.3 9.3 90.0\n", )) detx_fobj = StringIO(detx_string) self.det = Detector() self.det._det_file = detx_fobj self.det._parse() assert detx_string == self.det.ascii
def test_center_of_mass(self): det = Detector() det._det_file = EXAMPLE_DETX det._parse() assert np.allclose([2.4, 2.5, 2.6], det.com)
import numpy as np from scipy.spatial import ConvexHull import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # noqa from km3net_testdata import data_path from km3pipe.hardware import Detector from km3pipe.math import Polygon import km3pipe.style km3pipe.style.use("km3pipe") detx = data_path( "detx/orca_115strings_av23min20mhorizontal_18OMs_alt9mvertical_v1.detx") detector = Detector(detx) xy = detector.xy_positions hull = ConvexHull(xy) ############################################################################## # Plot it: plt.plot(xy[:, 0], xy[:, 1], "o") for simplex in hull.simplices: plt.plot(xy[simplex, 0], xy[simplex, 1], "k-") ############################################################################## # We could also have directly used the vertices of the hull, which # for 2-D are guaranteed to be in counterclockwise order: plt.plot(xy[hull.vertices, 0], xy[hull.vertices, 1], "r--", lw=2)
def setUp(self): self.det = Detector() self.det._det_file = EXAMPLE_DETX
def test_center_of_mass_with_another_detx(self): det = Detector() det._det_file = EXAMPLE_DETX_RADIAL det._parse() assert np.allclose([-0.2, 0.0, 0.2], det.com)
def test_detector_repr(self): det = Detector(filename=data_path("detx/detx_v3.detx")) assert "Detector id: '23', n_doms: 6, dus: [1, 2]" == repr(det)
def test_comments_are_written(self): det = Detector(filename=data_path("detx/detx_v3.detx")) det.add_comment("foo") assert 3 == len(det.comments) assert det.comments[2] == "foo" assert "# foo" == det.ascii.splitlines()[2]
def test_detx_v3_is_the_same_ascii(self): det = Detector(filename=data_path("detx/detx_v3.detx")) with open(data_path("detx/detx_v3.detx"), "r") as fobj: assert fobj.read() == det.ascii
def test_init_with_detector(self): det = Detector(data_path("detx/detx_v1.detx")) Calibration(detector=det)
import pandas as pd import numpy as np from km3pipe import Pipeline, Module from km3pipe.hardware import Detector from km3pipe.io import CHPump from km3pipe.io.daq import DAQPreamble, DAQSummaryslice, DAQEvent from km3pipe.time import tai_timestamp import km3pipe.style km3pipe.style.use('km3pipe') PLOTS_PATH = '/home/km3net/monitoring/www/plots' N_DOMS = 18 N_DUS = 2 detector = Detector(det_id=14) xfmt = md.DateFormatter('%Y-%m-%d %H:%M') lock = threading.Lock() class DOMHits(Module): def configure(self): self.run = True self.max_events = 1000 self.hits = deque(maxlen=1000) self.triggered_hits = deque(maxlen=1000) self.thread = threading.Thread(target=self.plot).start() def process(self, blob): tag = str(blob['CHPrefix'].tag)