Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
    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