def process(job):

    job_id, (file, f, k, simulation, array) = job

    # remove enclosing lists
    f = f[0]
    k = k[0]

    # deserialize json objects
    simulation = abstract.loads(simulation)
    array = abstract.loads(array)

    simulation['frequency'] = f
    kwargs, meta = ReceiveCrosstalk.connector(simulation, array)

    simulation = ReceiveCrosstalk(**kwargs)
    simulation.solve()

    nodes = simulation.nodes
    membrane_ids = meta['membrane_id']
    element_ids = meta['element_id']
    channel_ids = meta['channel_id']
    displacement = simulation.result['displacement']

    with write_lock:
        with closing(sql.connect(file)) as con:

            if not sim.table_exists(con, 'nodes'):
                create_nodes_table(con, nodes, membrane_ids, element_ids,
                                   channel_ids)
            if not sim.table_exists(con, 'displacements'):
                create_displacements_table(con)

            update_displacements_table(con, f, k, nodes, displacement)
            sim.update_progress(con, job_id)
Example #2
0
def process(args):

    file, field_pos, rotation_rule, sim, arrays = args

    sim = abstract.loads(sim)
    arrays = abstract.loads(arrays)

    # set focus delays while arrays are flat
    tx_focus = sim['transmit_focus']
    rx_focus = sim['receive_focus']
    c = sim['sound_speed']
    quant = sim['delay_quantization']

    for array in arrays:
        abstract.focus_array(array,
                             tx_focus,
                             sound_speed=c,
                             quantization=quant,
                             kind='tx')
        abstract.focus_array(array,
                             rx_focus,
                             sound_speed=c,
                             quantization=quant,
                             kind='rx')

    # rotate arrays based on rotation rule
    for array_id, dir, angle in rotation_rule:

        if dir.lower() == 'x':
            vec = [1, 0, 0]
        elif dir.lower() == 'y':
            vec = [0, 1, 0]
        elif dir.lower() == 'z':
            vec = [0, 0, 1]

        for array in arrays:
            if array['id'] == array_id:
                abstract.rotate_array(array, vec, np.deg2rad(angle))

    # create and run simulation
    kwargs, meta = MultiArrayTransmitReceiveBeamplot.connector(sim, *arrays)
    simulation = MultiArrayTransmitReceiveBeamplot(**kwargs)
    simulation.solve(field_pos)

    # extract results and save
    rf_data = simulation.result['rf_data']
    times = simulation.result['times']

    with write_lock:
        with closing(sql.connect(file)) as con:

            if sim['save_image_data_only']:
                pass
            else:
                for rf, t in zip(rf_data, times):
                    update_pressures_table(con, field_pos, t, rf)
            update_progress(con, field_pos)
Example #3
0
def init_process(_write_lock, _simulation, _arrays):

    global write_lock, solver

    write_lock = _write_lock
    simulation = abstract.loads(_simulation)
    arrays = abstract.loads(_arrays)

    kwargs, meta = TransmitBeamplot.connector(simulation, *arrays)
    solver = TransmitBeamplot(**kwargs)
Example #4
0
def init_process(_write_lock, sim, array):

    global write_lock, simulation
    write_lock = _write_lock

    sim = abstract.loads(sim)
    array = abstract.loads(array)

    kwargs, meta = TransmitBeamplot.connector(sim, array)
    simulation = TransmitBeamplot(**kwargs)
Example #5
0
def init_process(_write_lock, _simulation, _arrays):

    global write_lock, simulation_base, arrays_base

    write_lock = _write_lock
    simulation_base = abstract.loads(_simulation)
    arrays_base = abstract.loads(_arrays)

    # important! avoid solver overriding current delays
    if 'transmit_focus' in simulation_base:
        simulation_base.pop('transmit_focus')
    if 'receive_focus' in simulation_base:
        simulation_base.pop('receive_focus')
Example #6
0
def init_process(_write_lock, _simulation, _arrays):

    global write_lock, simulation, arrays_base

    write_lock = _write_lock
    simulation = abstract.loads(_simulation)
    arrays_base = abstract.loads(_arrays)

    # set focus delays while arrays are flat
    focus = simulation['focus']
    if focus is not None:
        c = simulation['sound_speed']
        delay_quant = simulation['delay_quantization']
        for array in arrays_base:
            abstract.focus_array(array, focus, c, delay_quant, kind='both')

    # important! avoid solver overriding current delays
    if 'transmit_focus' in simulation:
        simulation.pop('transmit_focus')
    if 'receive_focus' in simulation:
        simulation.pop('receive_focus')