def makepacket(data, samprate=666, net='net', sta='sta', chan='chan', loc='loc', type='GENC', time=0): """returns stuffed packet in form (pkttype, packet, srcname, time) Packet has one channel. """ from mi.core.kudu import _pkt pkt = _pkt._newPkt() try: _pkt._Pkt_pkttype_set(pkt, type) _pkt._Pkt_time_set(pkt, time) pktchan = _pkt._newPktChannel() _pkt._PktChannel_time_set(pktchan, time) _pkt._PktChannel_data_set(pktchan, data) _pkt._PktChannel_samprate_set(pktchan, samprate) _pkt._PktChannel_net_set(pktchan, net) _pkt._PktChannel_sta_set(pktchan, sta) _pkt._PktChannel_chan_set(pktchan, chan) _pkt._PktChannel_loc_set(pktchan, loc) _pkt._Pkt_channels_set(pkt, [ pktchan, ]) return _pkt._stuffPkt(pkt) finally: _pkt._freePkt(pkt)
def setUp(self): from mi.core.kudu import _pkt log.debug("*********************************************************************") log.debug("Starting Dataset Test %s", self._testMethodName) log.debug("*********************************************************************") log.debug("ID: %s", self.id()) log.debug("DataSetTestCase setUp") # Test to ensure we have initialized our test config if not self.test_config.initialized: return TestNotInitialized(msg="Tests non initialized. Missing DataSetTestCase.initialize(...)?") log.debug("Driver Config: %s", self._driver_config()) self.state_callback_result = [] self.data_callback_result = [] self.event_callback_result = [] self.exception_callback_result = [] self.memento = {} self.PKT_ID = PKT_ID = 123 self.PKT_TYPE = PKT_TYPE = 'GENC' self.PKT_DATA = PKT_DATA = 1,2,3,4 self.PKT_TIME = PKT_TIME = 999 self.PKT_SAMPRATE = PKT_SAMPRATE = 666 self.PKT_NET = PKT_NET = 'net' self.PKT_STA = PKT_STA = 'sta' self.PKT_CHAN = PKT_CHAN = 'chan' self.PKT_LOC = PKT_LOC = 'loc' pkt = _pkt._newPkt() _pkt._Pkt_pkttype_set(pkt, PKT_TYPE) pktchan = _pkt._newPktChannel() _pkt._PktChannel_data_set(pktchan, PKT_DATA) _pkt._PktChannel_samprate_set(pktchan, PKT_SAMPRATE) _pkt._PktChannel_time_set(pktchan, PKT_TIME) _pkt._PktChannel_net_set(pktchan, PKT_NET) _pkt._PktChannel_sta_set(pktchan, PKT_STA) _pkt._PktChannel_chan_set(pktchan, PKT_CHAN) _pkt._PktChannel_loc_set(pktchan, PKT_LOC) _pkt._Pkt_channels_set(pkt, [pktchan,]) self.pkttype, self.packet, self.srcname, self.time = _pkt._stuffPkt(pkt) _pkt._freePkt(pkt) self.driver = self._get_driver_object() # NOTE why not do this in tearDown? self.addCleanup(self._stop_driver) self._metadata = None self._get_metadata()
def setUp(self): ParserUnitTestCase.setUp(self) self.error_callback_values = [] self.state_callback_values = [] self.publish_callback_values = [] self.parser_config = { ParserConfigKey.ORBNAME: ParserConfigKey.ORBNAME, ParserConfigKey.SELECT: ParserConfigKey.SELECT, ParserConfigKey.REJECT: ParserConfigKey.REJECT, } self.parser_state = None self.PKT_ID = PKT_ID = 123 self.PKT_TYPE = PKT_TYPE = 'GENC' self.PKT_DATA = PKT_DATA = 1, 2, 3, 4 self.PKT_TIME = PKT_TIME = 999 self.PKT_SAMPRATE = PKT_SAMPRATE = 666 self.PKT_NET = PKT_NET = 'net' self.PKT_STA = PKT_STA = 'sta' self.PKT_CHAN = PKT_CHAN = 'chan' self.PKT_LOC = PKT_LOC = 'loc' from mi.core.kudu import _pkt pkt = _pkt._newPkt() _pkt._Pkt_pkttype_set(pkt, PKT_TYPE) pktchan = _pkt._newPktChannel() _pkt._PktChannel_data_set(pktchan, PKT_DATA) _pkt._PktChannel_samprate_set(pktchan, PKT_SAMPRATE) _pkt._PktChannel_time_set(pktchan, PKT_TIME) _pkt._PktChannel_net_set(pktchan, PKT_NET) _pkt._PktChannel_sta_set(pktchan, PKT_STA) _pkt._PktChannel_chan_set(pktchan, PKT_CHAN) _pkt._PktChannel_loc_set(pktchan, PKT_LOC) _pkt._Pkt_channels_set(pkt, [ pktchan, ]) pkttype, packet, srcname, time = _pkt._stuffPkt(pkt) _pkt._freePkt(pkt) with patch( 'mi.dataset.parser.antelope_orb.OrbReapThr') as MockOrbReapThr: self.parser = AntelopeOrbParser(self.parser_config, self.parser_state, self.state_callback, self.pub_callback, self.error_callback) self.parser._orbreapthr.get = MagicMock(return_value=(PKT_ID, srcname, time, packet))
def make_antelope_particle(get_r, *args, **kwargs): """Inspects packet channel, returns instance of appropriate antelope data particle class.""" pktid, srcname, orbtimestamp, raw_packet = get_r pkt = None pkttype, pkt = _pkt._unstuffPkt(srcname, orbtimestamp, raw_packet) if pkttype < 0: raise SampleException("Failed to unstuff ORB packet") try: srcnameparts = _pkt._Pkt_srcnameparts_get(pkt) net, sta, chan, loc, dtype, subcode = srcnameparts ParticleClass = PARTICLE_CLASSES[chan.lower()] raw_data = pktid, srcname, orbtimestamp, raw_packet, pkttype, pkt except Exception: _pkt._freePkt(pkt) raise return ParticleClass(raw_data, *args, **kwargs)
def setUp(self): ParserUnitTestCase.setUp(self) self.error_callback_values = [] self.state_callback_values = [] self.publish_callback_values = [] self.parser_config = { ParserConfigKey.ORBNAME: ParserConfigKey.ORBNAME, ParserConfigKey.SELECT: ParserConfigKey.SELECT, ParserConfigKey.REJECT: ParserConfigKey.REJECT, } self.parser_state = None self.PKT_ID = PKT_ID = 123 self.PKT_TYPE = PKT_TYPE = 'GENC' self.PKT_DATA = PKT_DATA = 1,2,3,4 self.PKT_TIME = PKT_TIME = 999 self.PKT_SAMPRATE = PKT_SAMPRATE = 666 self.PKT_NET = PKT_NET = 'net' self.PKT_STA = PKT_STA = 'sta' self.PKT_CHAN = PKT_CHAN = 'chan' self.PKT_LOC = PKT_LOC = 'loc' from mi.core.kudu import _pkt pkt = _pkt._newPkt() _pkt._Pkt_pkttype_set(pkt, PKT_TYPE) pktchan = _pkt._newPktChannel() _pkt._PktChannel_data_set(pktchan, PKT_DATA) _pkt._PktChannel_samprate_set(pktchan, PKT_SAMPRATE) _pkt._PktChannel_time_set(pktchan, PKT_TIME) _pkt._PktChannel_net_set(pktchan, PKT_NET) _pkt._PktChannel_sta_set(pktchan, PKT_STA) _pkt._PktChannel_chan_set(pktchan, PKT_CHAN) _pkt._PktChannel_loc_set(pktchan, PKT_LOC) _pkt._Pkt_channels_set(pkt, [pktchan,]) pkttype, packet, srcname, time = _pkt._stuffPkt(pkt) _pkt._freePkt(pkt) with patch('mi.dataset.parser.antelope_orb.OrbReapThr') as MockOrbReapThr: self.parser = AntelopeOrbParser(self.parser_config, self.parser_state, self.state_callback, self.pub_callback, self.error_callback) self.parser._orbreapthr.get = MagicMock(return_value=(PKT_ID, srcname, time, packet))
def makepacket(data, samprate=666, net='net', sta='sta', chan='chan', loc='loc', type='GENC', time=0): """returns stuffed packet in form (pkttype, packet, srcname, time) Packet has one channel. """ from mi.core.kudu import _pkt pkt = _pkt._newPkt() try: _pkt._Pkt_pkttype_set(pkt, type) _pkt._Pkt_time_set(pkt, time) pktchan = _pkt._newPktChannel() _pkt._PktChannel_time_set(pktchan, time) _pkt._PktChannel_data_set(pktchan, data) _pkt._PktChannel_samprate_set(pktchan, samprate) _pkt._PktChannel_net_set(pktchan, net) _pkt._PktChannel_sta_set(pktchan, sta) _pkt._PktChannel_chan_set(pktchan, chan) _pkt._PktChannel_loc_set(pktchan, loc) _pkt._Pkt_channels_set(pkt, [pktchan,]) return _pkt._stuffPkt(pkt) finally: _pkt._freePkt(pkt)
def _build_parsed_values(self): """ Take something in the data format and turn it into an array of dictionaries defining the data in the particle with the appropriate tag. @throws SampleException If there is a problem with sample creation """ log.trace("_build_parsed_values") pktid, srcname, orbtimestamp, raw_packet = self.raw_data result = [] pk = AntelopeOrbPacketParticleKey vid = DataParticleKey.VALUE_ID v = DataParticleKey.VALUE pkt = None try: pkttype, pkt = _pkt._unstuffPkt(srcname, orbtimestamp, raw_packet) if pkttype < 0: raise SampleException("Failed to unstuff ORB packet") # Calculate sample timestamp self.set_internal_timestamp(unix_time=_pkt._Pkt_time_get(pkt)) result.append({vid: pk.ID, v: pktid}) result.append({vid: pk.DB, v: _pkt._Pkt_db_get(pkt)}) result.append({vid: pk.DFILE, v: _pkt._Pkt_dfile_get(pkt)}) result.append({vid: pk.SRCNAME, v: _pkt._Pkt_srcnameparts_get(pkt)}) result.append({vid: pk.VERSION, v: _pkt._Pkt_version_get(pkt)}) result.append({vid: pk.STRING, v: _pkt._Pkt_string_get(pkt)}) result.append({vid: pk.TIME, v: _pkt._Pkt_time_get(pkt)}) result.append({vid: pk.TYPE, v: _pkt._Pkt_pkttype_get(pkt)}) pf = None pfptr = _pkt._Pkt_pfptr_get(pkt) if pfptr != None: try: pf = _stock._pfget(pfptr, None) finally: _stock._pffree(pfptr) result.append({vid: pk.PF, v: pf}) # channels channels = [] ck = AntelopeOrbPacketParticleChannelKey for pktchan in _pkt._Pkt_channels_get(pkt): channel = {} channels.append(channel) channel[ck.CALIB] = _pkt._PktChannel_calib_get(pktchan) channel[ck.CALPER] = _pkt._PktChannel_calper_get(pktchan) channel[ck.CHAN] = _pkt._PktChannel_chan_get(pktchan) channel[ck.CUSER1] = _pkt._PktChannel_cuser1_get(pktchan) channel[ck.CUSER2] = _pkt._PktChannel_cuser2_get(pktchan) channel[ck.DATA] = np.array(_pkt._PktChannel_data_get(pktchan)) channel[ck.DUSER1] = _pkt._PktChannel_duser1_get(pktchan) channel[ck.DUSER2] = _pkt._PktChannel_duser2_get(pktchan) channel[ck.IUSER1] = _pkt._PktChannel_iuser1_get(pktchan) channel[ck.IUSER2] = _pkt._PktChannel_iuser2_get(pktchan) channel[ck.IUSER3] = _pkt._PktChannel_iuser3_get(pktchan) channel[ck.LOC] = _pkt._PktChannel_loc_get(pktchan) channel[ck.NET] = _pkt._PktChannel_net_get(pktchan) channel[ck.SAMPRATE] = _pkt._PktChannel_samprate_get(pktchan) channel[ck.SEGTYPE] = _pkt._PktChannel_segtype_get(pktchan) channel[ck.STA] = _pkt._PktChannel_sta_get(pktchan) channel[ck.TIME] = _pkt._PktChannel_time_get(pktchan) result.append({vid: pk.CHANNELS, v: channels}) finally: if pkt is not None: _pkt._freePkt(pkt) return result
def __del__(self): log.trace("del pkt: %s", self._pkt) if self._pkt is not None: _pkt._freePkt(self._pkt)
def setUp(self): from mi.core.kudu import _pkt log.debug( "*********************************************************************" ) log.debug("Starting Dataset Test %s", self._testMethodName) log.debug( "*********************************************************************" ) log.debug("ID: %s", self.id()) log.debug("DataSetTestCase setUp") # Test to ensure we have initialized our test config if not self.test_config.initialized: return TestNotInitialized( msg= "Tests non initialized. Missing DataSetTestCase.initialize(...)?" ) log.debug("Driver Config: %s", self._driver_config()) self.state_callback_result = [] self.data_callback_result = [] self.event_callback_result = [] self.exception_callback_result = [] self.memento = {} self.PKT_ID = PKT_ID = 123 self.PKT_TYPE = PKT_TYPE = 'GENC' self.PKT_DATA = PKT_DATA = 1, 2, 3, 4 self.PKT_TIME = PKT_TIME = 999 self.PKT_SAMPRATE = PKT_SAMPRATE = 666 self.PKT_NET = PKT_NET = 'net' self.PKT_STA = PKT_STA = 'sta' self.PKT_CHAN = PKT_CHAN = 'chan' self.PKT_LOC = PKT_LOC = 'loc' pkt = _pkt._newPkt() _pkt._Pkt_pkttype_set(pkt, PKT_TYPE) pktchan = _pkt._newPktChannel() _pkt._PktChannel_data_set(pktchan, PKT_DATA) _pkt._PktChannel_samprate_set(pktchan, PKT_SAMPRATE) _pkt._PktChannel_time_set(pktchan, PKT_TIME) _pkt._PktChannel_net_set(pktchan, PKT_NET) _pkt._PktChannel_sta_set(pktchan, PKT_STA) _pkt._PktChannel_chan_set(pktchan, PKT_CHAN) _pkt._PktChannel_loc_set(pktchan, PKT_LOC) _pkt._Pkt_channels_set(pkt, [ pktchan, ]) self.pkttype, self.packet, self.srcname, self.time = _pkt._stuffPkt( pkt) _pkt._freePkt(pkt) self.driver = self._get_driver_object() # NOTE why not do this in tearDown? self.addCleanup(self._stop_driver) self._metadata = None self._get_metadata()