Exemple #1
0
#  plot <ntrace> max
#  Variable area option is usually too slow and loose data

import a1das
import matplotlib.pyplot as plt

# parameters
# for the DAS
port = 16667
address = '192.168.1.10'
# for a file, set according to the parameter chosen when running a1das.vserver.ZMQVirtualDasServer()
# usually, port = 6667 and address = 127.0.0.1

va = False
nblock = 4
clip = 50
ntrace = 50

# open stream
f = a1das.open(a1das.tcp_address(address, port), format='socket')

# read 2 block and make 1st plot
a = f.read(block=nblock)
fig, lines = a.plot(max=ntrace, clip=clip, variable_area=va)

Running_Time = 0
Time_Max = 3600 * 5
while Running_Time < Time_Max:
    a = f.read(block=nblock)
    a.plot(fig=fig, max=ntrace, redraw=lines, clip=clip, variable_area=va)
Exemple #2
0
#import a1das_util
import a1das
import matplotlib.pyplot as plt

#fichier reduit
filei = 'SR_2021-01-14_11-55-54_UTC.h5'
fileo = 'SRRNT_2021-01-14_11-55-54_UTC.h5'
a1das.reduction.reduction_notranspose(filei, fileo)
fileo = 'SRRT_2021-01-14_11-55-54_UTC.h5'
a1das.reduction.reduction_transpose(filei, fileo)

f1 = a1das.open('SRRNT_2021-01-14_11-55-54_UTC.h5', 'reducted')
f2 = a1das.open('SRRT_2021-01-14_11-55-54_UTC.h5', 'reducted')

a1 = f1.read()
a2 = f2.read()

a1.plot()
a1.rplot()
a2.plot()
a2.rplot()

plt.show()
Exemple #3
0
def ZMQVirtualDasServer(file, host='127.0.0.1', port=6667, block=None):
    """
    ## Description
    Read Febus strain[rate] HDF5 file and send to a ZMQ socket stream

    ## Input
        file = hdf5 (.h5) file to read
        host = IP adress for the virtual server
        port = IP port for the virtual server

    ## Usage example
        >>> from a1das import vserver
        >>> vserver.ZMQVirtualDasServer('my_SR_file',host='127.0.0.1',port=6667)
    """
    import a1das
    import zmq
    import pickle
    from io import BytesIO
    from timeit import default_timer as timer

    # open ZMQ connection
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    socket.bind("tcp://%s:%d" % (host, port))
    print('launching DAS virtual server on address: <',
          "tcp://%s:%d" % (host, port), '>')

    #
    # open file
    #
    f = a1das.open(file)
    # set origin time
    #f.set_otime_from_filename()
    #read block info
    nblock = f.file_header.block_info['nb_block']
    #read freq_res
    freq_res = f.file_header.freq_res
    delta_t = 1. / freq_res
    #time = f.data_header['otime']
    block_times = f.file_header.block_info['block_times']
    time = block_times[0]

    # wait for an acq
    _wait_for_acq(socket, time)

    # Set and Send header(s)
    message2 = _set_and_send_header_to_ZMQ(f.data_header, f.file_header, time,
                                           socket)

    data = a1das._core_febus_file._read_febus_file_block(f, 0)
    time0 = timer()
    socket.send(data)

    if block is None:
        block = [0, nblock]

    for i in range(block[0], block[-1]):
        #
        # wait for acq
        #
        _wait_for_acq(socket, time)

        #
        # resend headers and data
        #
        time1 = timer()
        #temporisation
        #while (time1 - time0 < delta_t):
        #    time1 = timer()
        time0 = time1
        #time += delta_t
        time = block_times[i]
        message2 = _set_and_send_header_to_ZMQ(f.data_header,
                                               f.file_header,
                                               time,
                                               socket,
                                               message2=message2)

        data = a1das._core_febus_file._read_febus_file_block(f, block=i)
        socket.send(data)

    socket.close()
    f.close()
Exemple #4
0
#import a1das_util
import a1das
import matplotlib.pyplot as plt
import numpy as np

filename = 'SR_2021-01-14_11-55-54_UTC.h5'

# open febus file
f = a1das.open(filename, format='febus')

#test reading febus file
a1 = f.read()

#test index function
dlist3 = a1.index(drange=[[dist] for dist in np.arange(50, 60., 1.)])

#test setting origin time
a1.set_otime_from_filename()
print(a1)

#test conversion in obspy
S = a1.obspy_stream(drange=[60, 60])
print('\n\nnext steps may take a while...large plots coming soon')
S.plot()

#test a1das plot
plt.figure()
a1.plot(trange=[5., 7.])
a1.rplot()
print('\n\nkill figures to keep going')
plt.show()
Exemple #5
0
def ZMQReductedVirtualServer(filein,
                             prefix,
                             trange=None,
                             drange=None,
                             tdecim=1,
                             ddecim=1,
                             verbose=0,
                             host='127.0.0.1',
                             port=6667,
                             block_time=2.):
    """
    ##Description
    Read a reducted file and send data on a ZMQ socket server
    ##Input
    filein = (string) file name
    prefix = (string) prefix to be used to extract origin time from filename
    trange = [tmin, tmax] time range
    drange = [dmin, dmax] distance range
    tdecim = (int) time decimation
    ddecim = (int) space decimation
    verbose = (int) verbosity level
    host = (string) IP address of host
    port = (int) port
    block_time = length of time block sent
    """
    import a1das
    import zmq
    import pickle
    from io import BytesIO
    from timeit import default_timer as timer

    f = a1das.open(filein, format='reducted')

    #get header usefull values
    dt = f['dt']
    nspace = f['nspace']
    ntime = f['ntime']

    #set distance reading limits
    if drange is not None:
        dlist = f.index(drange=drange)
        space_range = range(dlist[0], dlist[1], ddecim)
    else:
        space_range = range(0, nspace, ddecim)

    # set time reading limits
    if trange is not None:
        tlist = f.index(trange=trange)
        time_range = range(tlist[0], tlist[1], tdecim)
    else:
        time_range = (0, ntime, tdecim)

    dt = dt * tdecim

    #set Febus-file-like parameters
    block_time_size = int(block_time / dt)
    shift_time_size = int(block_time_size / 2)
    delta_t = shift_time_size * dt
    f.file_header.block_info = {'block_time_size': block_time_size}

    # set origin time
    #f.set_otime_from_filename(prefix=prefix)
    time = f['otime']

    # open ZMQ connection
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    socket.bind("tcp://%s:%d" % (host, port))
    print('launching DAS virtual server on address: <',
          "tcp://%s:%d" % (host, port), '>')

    # wait for an acq
    _wait_for_acq(socket, time)

    # Set and Send header(s)
    message2 = _set_and_send_header_to_ZMQ(f.data_header, f.file_header, time,
                                           socket)

    #
    # Loop reading data
    #
    if f.is_transposed():

        #get HDF5 file descriptor
        fd = f.file_header.fd

        buffer = np.empty((len(space_range), block_time_size),
                          dtype=np.float32)
        # Loop on block time
        for i in range(0, ntime, shift_time_size):
            start = i
            end = i + block_time_size
            for j, jx in enumerate(space_range):
                buffer[j, :] = fd['/Traces/' + str(jx)][start:end]

            message3 = buffer.transpose().copy()
            socket.send(message3)

            time += delta_t
            _wait_for_acq(socket, time)
            message2 = _set_and_send_header_to_ZMQ(f.data_header,
                                                   f.file_header,
                                                   time,
                                                   socket,
                                                   message2=message2)
    else:
        print('not yet implemented')

    f.close()
    socket.close()