예제 #1
0
def test_stream():
    inventory = get_inventory()
    channels = ["HN1", "HN2", "HNZ"]
    data = np.random.rand(1000)
    traces = []
    network = inventory.networks[0]
    station = network.stations[0]
    chlist = station.channels
    channelcodes = [ch.code for ch in chlist]
    for channel in channels:
        chidx = channelcodes.index(channel)
        channeldata = chlist[chidx]
        header = {
            "sampling_rate": channeldata.sample_rate,
            "npts": len(data),
            "network": network.code,
            "location": channeldata.location_code,
            "station": station.code,
            "channel": channel,
            "starttime": UTCDateTime(2010, 1, 1, 0, 0, 0),
        }
        trace = Trace(data=data, header=header)
        traces.append(trace)
    invstream = StationStream(traces=traces, inventory=inventory)
    inventory2 = invstream.getInventory()
    inv2_channel1 = inventory2.networks[0].stations[0].channels[0]
    inv_channel1 = inventory2.networks[0].stations[0].channels[0]
    assert inv_channel1.code == inv2_channel1.code

    # test the streamparam functionality
    statsdict = {"name": "Fred", "age": 34}
    invstream.setStreamParam("stats", statsdict)
    assert invstream.getStreamParamKeys() == ["stats"]
    cmpdict = invstream.getStreamParam("stats")
    assert statsdict == cmpdict
예제 #2
0
def test_stream():
    inventory = get_inventory()
    channels = ['HN1', 'HN2', 'HNZ']
    data = np.random.rand(1000)
    traces = []
    network = inventory.networks[0]
    station = network.stations[0]
    chlist = station.channels
    channelcodes = [ch.code for ch in chlist]
    for channel in channels:
        chidx = channelcodes.index(channel)
        channeldata = chlist[chidx]
        header = {
            'sampling_rate': channeldata.sample_rate,
            'npts': len(data),
            'network': network.code,
            'location': channeldata.location_code,
            'station': station.code,
            'channel': channel,
            'starttime': UTCDateTime(2010, 1, 1, 0, 0, 0)
        }
        trace = Trace(data=data, header=header)
        traces.append(trace)
    invstream = StationStream(traces=traces, inventory=inventory)
    inventory2 = invstream.getInventory()
    inv2_channel1 = inventory2.networks[0].stations[0].channels[0]
    inv_channel1 = inventory2.networks[0].stations[0].channels[0]
    assert inv_channel1.code == inv2_channel1.code

    # test the streamparam functionality
    statsdict = {'name': 'Fred', 'age': 34}
    invstream.setStreamParam('stats', statsdict)
    assert invstream.getStreamParamKeys() == ['stats']
    cmpdict = invstream.getStreamParam('stats')
    assert statsdict == cmpdict