示例#1
0
def get_live_timeseries():
    ts = TimeSeries()
    ts.set_live()
    ts.dt = 1 / sampling_rate
    ts.npts = ts_size
    # ts.put('net', 'IU')
    ts.put('npts', ts_size)
    ts.put('sampling_rate', sampling_rate)
    ts.tref = TimeReferenceType.UTC
    ts.t0 = datetime.utcnow().timestamp()
    ts['delta'] = 0.1
    ts['calib'] = 0.1
    ts['site_id'] = bson.objectid.ObjectId()
    ts['channel_id'] = bson.objectid.ObjectId()
    ts['source_id'] = bson.objectid.ObjectId()
    ts.set_as_origin('test', '0', '0', AtomicType.TIMESERIES)
    ts.data = DoubleVector(np.random.rand(ts_size))
    return ts
示例#2
0
文件: helper.py 项目: wangyinz/mspass
def get_live_timeseries():
    ts = TimeSeries()
    ts.set_live()
    ts.dt = 1 / sampling_rate
    ts.npts = ts_size
    # ts.put('net', 'IU')
    ts.put("npts", ts_size)
    ts.put("sampling_rate", sampling_rate)
    ts.tref = TimeReferenceType.UTC
    ts.t0 = datetime.utcnow().timestamp()
    ts["delta"] = 0.1
    ts["calib"] = 0.1
    ts["site_id"] = bson.objectid.ObjectId()
    ts["channel_id"] = bson.objectid.ObjectId()
    ts["source_id"] = bson.objectid.ObjectId()
    ts.set_as_origin("test", "0", "0", AtomicType.TIMESERIES)
    ts.data = DoubleVector(np.random.rand(ts_size))
    return ts
示例#3
0
def read_data(d):
    di = d.get_string("dir")
    dfile = d.get_string("dfile")
    foff = d.get("foff")
    fname = os.path.join(di, dfile)
    with open(fname, mode="rb") as fh:
        fh.seek(foff)
        float_array = array("d")
        float_array.frombytes(fh.read(d.get("nofbytes")))
        d.data = DoubleVector(float_array)


if __name__ == "__main__":
    s = TimeSeries()
    s.data = DoubleVector(np.random.rand(255))
    s["dir"] = "./"
    s["dfile"] = "test_op"
    save_data(s)

    s2 = TimeSeries()
    for k in s:
        s2[k] = s[k]
    s2.data = DoubleVector([])
    print(len(s2.data))
    read_data(s2)
    print(len(s2.data))
    assert all(a == b for a, b in zip(s.data, s2.data))
    # client = MongoClient('localhost', 27017)
    # db = client.mspass
    # channels = db.channels