Source code for irfpy.npdcommon.npdpacket

""" Define the NPD packet / data structure.

"""
import datetime as _datetime
import logging as _logging

import numpy as _np

_logger = _logging.getLogger(__name__)

[docs]class NpdRawPacket: """ Represent 1s data of NPD (single sensor) with events. """ def __init__(self, t, dt, cnts, intens, calib, regs): """ Initialize :param t: Time. (``datetime``) :param dt: Delta T. Float in sec :param cnts: Counter values. (6,) shape :param intens: Intens values. (512,) shape :param calib: Calib(?). (4,) shape :param regs: Regs(?). (3,) shape All the events are parsed, and stored. User should filter the valid events (or will be prepared). Data is stored as attributes: """ self.t = t "Time" self.dt = _datetime.timedelta(seconds=dt) "Delta time" self.cnts = cnts "Counter values. (6,) array" self.intens = intens "Instens data. Not parsed values. (512,) array" self.calib = calib "Calib data." self.regs = regs "Regs data" self.event_tof = _np.bitwise_and(intens, int('0xfff',0)) # 0xfff = 12bit masking binary. bitwise_and copies the first 12bits, retains the shape of array "Event TOF data. (512,) array" self.event_ph = _np.bitwise_and(_np.right_shift(intens,12), int('0xff',0)) # 0xff = 8bits masking binary. shift the bits for 12bits to the right and copies the first 8bits "Event PH data. (512,) array" self.event_dir = _np.bitwise_and(_np.right_shift(intens,20), int('0x3',0)) # 0x3 = 2bits "Event DIR data. (512,) array" self.event_coins = _np.bitwise_and(_np.right_shift(intens,22), int('0x7',0)) # 0x7 = 3bits "Event COIN data. (512,) array" def __str__(self): return "<NpdRawPacket: {t:%FT%T} cnts={c[0]:} {c[1]:} {c[2]:} {c[3]:} {c[4]:} {c[5]:}>".format(t=self.t, c=self.cnts) def __repr__(self): return str(self)