当前位置: 首页>>代码示例>>Python>>正文


Python Table.from_template方法代码示例

本文整理汇总了Python中km3pipe.dataclasses.Table.from_template方法的典型用法代码示例。如果您正苦于以下问题:Python Table.from_template方法的具体用法?Python Table.from_template怎么用?Python Table.from_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在km3pipe.dataclasses.Table的用法示例。


在下文中一共展示了Table.from_template方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_incomplete_template

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def test_incomplete_template(self):
     n = 10
     channel_ids = np.arange(n)
     dom_ids = np.arange(n)
     # times = np.arange(n)
     tots = np.arange(n)
     triggereds = np.ones(n)
     d_hits = {
         'channel_id': channel_ids,
         'dom_id': dom_ids,
     # 'time': times,
         'tot': tots,
         'triggered': triggereds,
         'group_id': 0,    # event_id
     }
     with pytest.raises(KeyError):
         tab = Table.from_template(d_hits, 'Hits')
         assert tab is not None
     ar_hits = {
         'channel_id': np.ones(n, dtype=int),
         'dom_id': np.ones(n, dtype=int),
     # 'time': np.ones(n, dtype=float),
         'tot': np.ones(n, dtype=float),
         'triggered': np.ones(n, dtype=bool),
         'group_id': np.ones(n, dtype=int),
     }
     with pytest.raises(KeyError):
         tab = Table.from_template(ar_hits, 'Hits')
         assert tab is not None
开发者ID:tamasgal,项目名称:km3pipe,代码行数:31,代码来源:test_dataclasses.py

示例2: test_template

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def test_template(self):
     n = 10
     channel_ids = np.arange(n)
     dom_ids = np.arange(n)
     times = np.arange(n)
     tots = np.arange(n)
     triggereds = np.ones(n)
     d_hits = {
         'channel_id': channel_ids,
         'dom_id': dom_ids,
         'time': times,
         'tot': tots,
         'triggered': triggereds,
         'group_id': 0,    # event_id
     }
     tab = Table.from_template(d_hits, 'Hits')
     assert tab.name == 'Hits'
     assert tab.split_h5 is True
     assert isinstance(tab, Table)
     ar_hits = {
         'channel_id': np.ones(n, dtype=int),
         'dom_id': np.ones(n, dtype=int),
         'time': np.ones(n, dtype=float),
         'tot': np.ones(n, dtype=float),
         'triggered': np.ones(n, dtype=bool),
         'group_id': np.ones(n, dtype=int),
     }
     tab = Table.from_template(ar_hits, 'Hits')
     assert tab.name == 'Hits'
     assert tab.split_h5 is True
     assert isinstance(tab, Table)
开发者ID:tamasgal,项目名称:km3pipe,代码行数:33,代码来源:test_dataclasses.py

示例3: process_event

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
    def process_event(self, data, blob):
        data_io = BytesIO(data)
        preamble = DAQPreamble(file_obj=data_io)    # noqa
        event = DAQEvent(file_obj=data_io)
        header = event.header

        hits = event.snapshot_hits
        n_hits = event.n_snapshot_hits
        if n_hits == 0:
            return
        dom_ids, channel_ids, times, tots = zip(*hits)
        triggereds = np.zeros(n_hits)
        triggered_map = {}
        for triggered_hit in event.triggered_hits:
            dom_id, pmt_id, time, tot, _ = triggered_hit
            triggered_map[(dom_id, pmt_id, time, tot)] = True
        for idx, hit in enumerate(hits):
            triggereds[idx] = hit in triggered_map

        hit_series = Table.from_template({
            'channel_id': channel_ids,
            'dom_id': dom_ids,
            'time': times,
            'tot': tots,
            'triggered': triggereds,
            'group_id': self.event_id,
        }, 'Hits')

        blob['Hits'] = hit_series

        event_info = Table.from_template(
            {
                'det_id': header.det_id,
        # 'frame_index': self.index,  # header.time_slice,
                'frame_index': header.time_slice,
                'livetime_sec': 0,
                'mc_id': 0,
                'mc_t': 0,
                'n_events_gen': 0,
                'n_files_gen': 0,
                'overlays': event.overlays,
                'trigger_counter': event.trigger_counter,
                'trigger_mask': event.trigger_mask,
                'utc_nanoseconds': header.ticks * 16,
                'utc_seconds': header.time_stamp,
                'weight_w1': 0,
                'weight_w2': 0,
                'weight_w3': 0,    # MC weights
                'run_id': header.run,    # run id
                'group_id': self.event_id,
            },
            'EventInfo'
        )
        blob['EventInfo'] = event_info

        self.event_id += 1
        self.index += 1
开发者ID:tamasgal,项目名称:km3pipe,代码行数:59,代码来源:daq.py

示例4: extract_event

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
    def extract_event(self):
        blob = self._current_blob
        r = self.event_reader
        r.retrieve_next_event()    # do it at the beginning!

        n = r.number_of_snapshot_hits

        if n > self.buf_size:
            self._resize_buffers(int(n * 3 / 2))

        r.get_hits(
            self._channel_ids, self._dom_ids, self._times, self._tots,
            self._triggereds
        )

        hit_series = Table.from_template({
            'channel_id': self._channel_ids[:n],
            'dom_id': self._dom_ids[:n],
            'time': self._times[:n],
            'tot': self._tots[:n],
            'triggered': self._triggereds[:n],
            'group_id': self.event_index,
        }, 'Hits')

        event_info = Table.from_template({
            'det_id': r.det_id,
            'frame_index': r.frame_index,
            'livetime_sec': 0,
            'mc_id': 0,
            'mc_t': 0,
            'n_events_gen': 0,
            'n_files_gen': 0,
            'overlays': r.overlays,
            'trigger_counter': r.trigger_counter,
            'trigger_mask': r.trigger_mask,
            'utc_nanoseconds': r.utc_nanoseconds,
            'utc_seconds': r.utc_seconds,
            'weight_w1': np.nan,
            'weight_w2': np.nan,
            'weight_w3': np.nan,
            'run_id': 0,
            'group_id': self.event_index,
        }, 'EventInfo')

        self.event_index += 1
        blob['EventInfo'] = event_info
        blob['Hits'] = hit_series
        return blob
开发者ID:tamasgal,项目名称:km3pipe,代码行数:50,代码来源:jpp.py

示例5: summaryslice_generator

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def summaryslice_generator(self):
     slice_id = 0
     while self.r.has_next:
         summary_slice = {}
         self.r.retrieve_next_summaryslice()
         blob = Blob()
         summaryslice_info = Table.from_template({
             'frame_index': self.r.frame_index,
             'slice_id': slice_id,
             'timestamp': self.r.utc_seconds,
             'nanoseconds': self.r.utc_nanoseconds,
             'n_frames': self.r.n_frames,
         }, 'SummarysliceInfo')
         blob['SummarysliceInfo'] = summaryslice_info
         while self.r.has_next_frame:
             rates = np.zeros(31, dtype='f8')
             hrvs = np.zeros(31, dtype='i4')
             fifos = np.zeros(31, dtype='i4')
             self.r.get_rates(rates)
             self.r.get_hrvs(hrvs)
             self.r.get_fifos(fifos)
             summary_slice[self.r.dom_id] = {
                 'rates': rates,
                 'hrvs': hrvs.astype(bool),
                 'fifos': fifos.astype(bool),
                 'n_udp_packets': self.r.number_of_received_packets,
                 'max_sequence_number': self.r.max_sequence_number,
                 'has_udp_trailer': self.r.has_udp_trailer,
                 'high_rate_veto': self.r.high_rate_veto,
                 'fifo_status': self.r.fifo_status,
             }
             self.r.retrieve_next_frame()
         blob['Summaryslice'] = summary_slice
         slice_id += 1
         yield blob
开发者ID:tamasgal,项目名称:km3pipe,代码行数:37,代码来源:jpp.py

示例6: _extract_hits

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
    def _extract_hits(self):
        total_hits = self.r.number_of_hits

        if total_hits > self.buf_size:
            buf_size = int(total_hits * 3 / 2)
            self._resize_buffers(buf_size)

        self.r.get_hits(
            self._channel_ids, self._dom_ids, self._times, self._tots
        )

        group_id = 0 if total_hits > 0 else []

        hits = Table.from_template(
            {
                'channel_id': self._channel_ids[:total_hits],
                'dom_id': self._dom_ids[:total_hits],
                'time': self._times[:total_hits].astype('f8'),
                'tot': self._tots[:total_hits],
        # 'triggered': self._triggereds[:total_hits],  # dummy
                'group_id': group_id,    # slice_id will be set afterwards
            },
            'TimesliceHits'
        )
        return hits
开发者ID:tamasgal,项目名称:km3pipe,代码行数:27,代码来源:jpp.py

示例7: test_init_from_template_with_differently_ordered_dicts

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def test_init_from_template_with_differently_ordered_dicts(self):
     t1 = Table.from_template({
         'frame_index': 1,
         'slice_id': 2,
         'timestamp': 3,
         'nanoseconds': 4,
         'n_frames': 5,
     }, 'TimesliceInfo')
     t2 = Table.from_template({
         'n_frames': 5,
         'timestamp': 3,
         'nanoseconds': 4,
         'slice_id': 2,
         'frame_index': 1,
     }, 'TimesliceInfo')
     assert t1.dtype == t2.dtype
     assert t1.frame_index[0] == t2.frame_index[0]
     assert t1.slice_id[0] == t2.slice_id[0]
     assert t1.nanoseconds[0] == t2.nanoseconds[0]
     assert t1.n_frames[0] == t2.n_frames[0]
     assert t1.timestamp[0] == t2.timestamp[0]
开发者ID:tamasgal,项目名称:km3pipe,代码行数:23,代码来源:test_dataclasses.py

示例8: test_adhoc_noname_template

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def test_adhoc_noname_template(self):
     a_template = {
         'dtype': np.dtype([('a', '<u4'), ('b', 'f4')]),
         'h5loc': '/yat',
         'split_h5': True,
         'h5singleton': True,
     }
     arr = np.array([(1, 3), (2, 4)], dtype=a_template['dtype'])
     tab = Table.from_template(arr, a_template)
     self.assertListEqual([1, 2], list(tab.a))
     self.assertListEqual([3.0, 4.0], list(tab.b))
     assert DEFAULT_NAME == tab.name
     assert tab.h5singleton
开发者ID:tamasgal,项目名称:km3pipe,代码行数:15,代码来源:test_dataclasses.py

示例9: test_apply_to_timeslice_hits

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def test_apply_to_timeslice_hits(self):
     tshits = Table.from_template({
         'channel_id': [0, 1, 2],
         'dom_id': [2, 3, 3],
         'time': [10.1, 11.2, 12.3],
         'tot': np.ones(3, dtype=float),
         'group_id': 0,
     }, 'TimesliceHits')
     calib = Calibration(filename=DETX_FILENAME)
     c_tshits = calib.apply(tshits)
     assert len(c_tshits) == len(tshits)
     assert np.allclose([40, 80, 90], c_tshits.t0)
     # TimesliceHits is using int4 for times, so it's truncated when we pass in float64
     assert np.allclose([50.1, 91.2, 102.3], c_tshits.time, atol=0.1)
开发者ID:tamasgal,项目名称:km3pipe,代码行数:16,代码来源:test_calib.py

示例10: get_blob

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
 def get_blob(self, index):
     """Index is slice ID"""
     blob = self._current_blob
     self.r.retrieve_timeslice(index)
     timeslice_info = Table.from_template({
         'frame_index': self.r.frame_index,
         'slice_id': index,
         'timestamp': self.r.utc_seconds,
         'nanoseconds': self.r.utc_nanoseconds,
         'n_frames': self.r.n_frames,
     }, 'TimesliceInfo')
     hits = self._extract_hits()
     hits.group_id = index
     blob['TimesliceInfo'] = timeslice_info
     blob[self._hits_blob_key] = hits
     return blob
开发者ID:tamasgal,项目名称:km3pipe,代码行数:18,代码来源:jpp.py

示例11: process

# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_template [as 别名]
    def process(self, blob):
        data = self._get_raw_data(blob)
        if data is None:
            return blob
        try:
            tsl_size, datatype = unpack('<ii', data.read(8))
            det_id, run, sqnr = unpack('<iii', data.read(12))
            timestamp, ns_ticks, n_frames = unpack('<iii', data.read(12))

            ts_info = Table.from_template({
                'frame_index': sqnr,
                'slice_id': 0,
                'timestamp': timestamp,
                'nanoseconds': ns_ticks * 16,
                'n_frames': n_frames
            }, 'TimesliceInfo')
            ts_frameinfos = {}

            _dom_ids = []
            _channel_ids = []
            _times = []
            _tots = []
            for _ in range(n_frames):
                frame_size, datatype = unpack('<ii', data.read(8))
                det_id, run, sqnr = unpack('<iii', data.read(12))
                timestamp, ns_ticks, dom_id = unpack('<iii', data.read(12))
                dom_status = unpack('<iiiii', data.read(5 * 4))
                n_hits = unpack('<i', data.read(4))[0]
                ts_frameinfos[dom_id] = Table.from_template({
                    'det_id': det_id,
                    'run_id': run,
                    'sqnr': sqnr,
                    'timestamp': timestamp,
                    'nanoseconds': ns_ticks * 16,
                    'dom_id': dom_id,
                    'dom_status': dom_status,
                    'n_hits': n_hits,
                }, 'TimesliceFrameInfo')
                for j in range(n_hits):
                    hit = unpack('!BlB', data.read(6))
                    _dom_ids.append(dom_id)
                    _channel_ids.append(hit[0])
                    _times.append(hit[1])
                    _tots.append(hit[2])

            tshits = Table.from_template(
                {
                    'channel_id': np.array(_channel_ids),
                    'dom_id': np.array(_dom_ids),
                    'time': np.array(_times),
                    'tot': np.array(_tots),
                    'triggered': np.zeros(len(_tots)),    # triggered
                    'group_id': 0    # event_id
                },
                'Hits'
            )
            blob['TimesliceInfo'] = ts_info
            blob['TimesliceFrameInfos'] = ts_frameinfos
            blob['TSHits'] = tshits
        except struct.error:
            log.error("Could not parse Timeslice")
            log.error(blob.keys())
        else:
            return blob
开发者ID:tamasgal,项目名称:km3pipe,代码行数:66,代码来源:daq.py


注:本文中的km3pipe.dataclasses.Table.from_template方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。