示例#1
0
def bartlett_beampattern(i, fc, sd, shading=None, theta=None, show=False):
    """Computes the beampattern for a Bartlett or delay-and-sum beamformer.

    :param i: row index of target steering distances
    :param fc: carrier frequency for the array data (Hz)
    :param sd: steering delays (s)
    :param shading: window function to use for array shading (None means no shading)
    :param theta: angles (in radians) for display if beampattern is plotted
    :param show: True to plot the beampattern, False to return it
    :returns: beampattern power response at all directions corresponding to rows in sd

    >>> from arlpy import bf
    >>> import numpy as np
    >>> sd = bf.steering(np.linspace(0, 5, 11), 1500, np.linspace(-np.pi/2, np.pi/2, 181))
    >>> bp = bf.bartlett_beampattern(90, 1500, sd, show=True)
    """
    a = _np.exp(-2j * _np.pi * fc * sd) / _np.sqrt(sd.shape[1])
    if shading is not None:
        s = _sig.get_window(shading, a.shape[1])
        a *= s / _np.sqrt(_np.mean(s**2))
    bp = _np.abs(_np.dot(a.conj(), a[i]))**2
    if show:
        if theta is None:
            _plt.plot(_utils.pow2db(bp),
                      ylabel='Array response (dB)',
                      title='Beam #' + str(i))
        else:
            a = theta * 180 / _np.pi
            _plt.plot(a,
                      _utils.pow2db(bp),
                      xlabel='Angle (deg)',
                      ylabel='Array response (dB)',
                      title='Beam #%d @ %0.1f deg' % (i, a[i]))
    else:
        return bp
示例#2
0
文件: uwapm.py 项目: org-arl/arlpy
def plot_rays(rays, env=None, invert_colors=False, **kwargs):
    """Plots ray paths.

    :param rays: ray paths
    :param env: environment definition
    :param invert_colors: False to use black for high intensity rays, True to use white

    If environment definition is provided, it is overlayed over this plot using default
    parameters for `arlpy.uwapm.plot_env()`.

    Other keyword arguments applicable for `arlpy.plot.plot()` are also supported.

    >>> import arlpy.uwapm as pm
    >>> env = pm.create_env2d()
    >>> rays = pm.compute_eigenrays(env)
    >>> pm.plot_rays(rays, width=1000)
    """
    rays = rays.sort_values('bottom_bounces', ascending=False)
    max_amp = _np.max(_np.abs(
        rays.bottom_bounces)) if len(rays.bottom_bounces) > 0 else 0
    if max_amp <= 0:
        max_amp = 1
    divisor = 1
    xlabel = 'Range (m)'
    r = []
    for _, row in rays.iterrows():
        r += list(row.ray[:, 0])
    if max(r) - min(r) > 10000:
        divisor = 1000
        xlabel = 'Range (km)'
    oh = _plt.hold()
    for _, row in rays.iterrows():
        c = int(255 * _np.abs(row.bottom_bounces) / max_amp)
        if invert_colors:
            c = 255 - c
        c = _bokeh.colors.RGB(c, c, c)
        _plt.plot(row.ray[:, 0] / divisor,
                  -row.ray[:, 1],
                  color=c,
                  xlabel=xlabel,
                  ylabel='Depth (m)',
                  **kwargs)
    if env is not None:
        plot_env(env)
    _plt.hold(oh)
示例#3
0
文件: uwapm.py 项目: org-arl/arlpy
def plot_arrivals(arrivals, dB=False, color='blue', **kwargs):
    """Plots the arrival times and amplitudes.

    :param arrivals: arrivals times (s) and coefficients
    :param dB: True to plot in dB, False for linear scale
    :param color: line color (see `Bokeh colors <https://bokeh.pydata.org/en/latest/docs/reference/colors.html>`_)

    Other keyword arguments applicable for `arlpy.plot.plot()` are also supported.

    >>> import arlpy.uwapm as pm
    >>> env = pm.create_env2d()
    >>> arrivals = pm.compute_arrivals(env)
    >>> pm.plot_arrivals(arrivals)
    """
    t0 = min(arrivals.time_of_arrival)
    t1 = max(arrivals.time_of_arrival)
    oh = _plt.hold()
    if dB:
        min_y = 20 * _np.log10(_np.max(_np.abs(
            arrivals.arrival_amplitude))) - 60
        ylabel = 'Amplitude (dB)'
    else:
        ylabel = 'Amplitude'
        _plt.plot([t0, t1], [0, 0],
                  xlabel='Arrival time (s)',
                  ylabel=ylabel,
                  color=color,
                  **kwargs)
        min_y = 0
    for _, row in arrivals.iterrows():
        t = row.time_of_arrival.real
        y = _np.abs(row.arrival_amplitude)
        if dB:
            y = max(20 * _np.log10(_fi.epsilon + y), min_y)
        _plt.plot([t, t], [min_y, y],
                  xlabel='Arrival time (s)',
                  ylabel=ylabel,
                  ylim=[min_y, min_y + 70],
                  color=color,
                  **kwargs)
    _plt.hold(oh)
示例#4
0
文件: uwapm.py 项目: org-arl/arlpy
def plot_ssp(env, **kwargs):
    """Plots the sound speed profile.

    :param env: environment description

    Other keyword arguments applicable for `arlpy.plot.plot()` are also supported.

    If the sound speed profile is range-dependent, this function only plots the first profile.

    >>> import arlpy.uwapm as pm
    >>> env = pm.create_env2d(soundspeed=[[ 0, 1540], [10, 1530], [20, 1532], [25, 1533], [30, 1535]])
    >>> pm.plot_ssp(env)
    """
    env = check_env2d(env)
    svp = env['soundspeed']
    if isinstance(svp, _pd.DataFrame):
        svp = _np.hstack((_np.array([svp.index]).T, _np.asarray(svp)))
    if _np.size(svp) == 1:
        if _np.size(env['depth']) > 1:
            max_y = _np.max(env['depth'][:, 1])
        else:
            max_y = env['depth']
        _plt.plot([svp, svp], [0, -max_y],
                  xlabel='Soundspeed (m/s)',
                  ylabel='Depth (m)',
                  **kwargs)
    elif env['soundspeed_interp'] == spline:
        s = svp
        ynew = _np.linspace(_np.min(svp[:, 0]), _np.max(svp[:, 0]), 100)
        tck = _interp.splrep(svp[:, 0], svp[:, 1], s=0)
        xnew = _interp.splev(ynew, tck, der=0)
        _plt.plot(xnew,
                  -ynew,
                  xlabel='Soundspeed (m/s)',
                  ylabel='Depth (m)',
                  hold=True,
                  **kwargs)
        _plt.plot(svp[:, 1], -svp[:, 0], marker='.', style=None, **kwargs)
    else:
        _plt.plot(svp[:, 1],
                  -svp[:, 0],
                  xlabel='Soundspeed (m/s)',
                  ylabel='Depth (m)',
                  **kwargs)
示例#5
0
def plot_ssp(env, **kwargs):
    """Plots the sound speed profile.

    :param env: environment description

    Other keyword arguments applicable for `arlpy.plot.plot()` are also supported.

    >>> import arlpy.uwapm as pm
    >>> env = pm.create_env2d(soundspeed=[[ 0, 1540], [10, 1530], [20, 1532], [25, 1533], [30, 1535]])
    >>> pm.plot_ssp(env)
    """
    check_env2d(env)
    if _np.size(env['soundspeed']) == 1:
        if _np.size(env['depth']) > 1:
            max_y = _np.max(env['depth'][:, 1])
        else:
            max_y = env['depth']
        _plt.plot([env['soundspeed'], env['soundspeed']], [0, -max_y],
                  xlabel='Soundspeed (m/s)',
                  ylabel='Depth (m)',
                  **kwargs)
    elif env['soundspeed_interp'] == spline:
        s = env['soundspeed']
        ynew = _np.linspace(_np.min(s[:, 0]), _np.max(s[:, 0]), 100)
        tck = _interp.splrep(s[:, 0], s[:, 1], s=0)
        xnew = _interp.splev(ynew, tck, der=0)
        _plt.plot(xnew,
                  -ynew,
                  xlabel='Soundspeed (m/s)',
                  ylabel='Depth (m)',
                  hold=True,
                  **kwargs)
        _plt.plot(s[:, 1], -s[:, 0], marker='.', style=None, **kwargs)
    else:
        s = env['soundspeed']
        _plt.plot(s[:, 1],
                  -s[:, 0],
                  xlabel='Soundspeed (m/s)',
                  ylabel='Depth (m)',
                  **kwargs)
示例#6
0
文件: uwapm.py 项目: org-arl/arlpy
def plot_env(env,
             surface_color='dodgerblue',
             bottom_color='peru',
             tx_color='orangered',
             rx_color='midnightblue',
             rx_plot=None,
             **kwargs):
    """Plots a visual representation of the environment.

    :param env: environment description
    :param surface_color: color of the surface (see `Bokeh colors <https://bokeh.pydata.org/en/latest/docs/reference/colors.html>`_)
    :param bottom_color: color of the bottom (see `Bokeh colors <https://bokeh.pydata.org/en/latest/docs/reference/colors.html>`_)
    :param tx_color: color of transmitters (see `Bokeh colors <https://bokeh.pydata.org/en/latest/docs/reference/colors.html>`_)
    :param rx_color: color of receviers (see `Bokeh colors <https://bokeh.pydata.org/en/latest/docs/reference/colors.html>`_)
    :param rx_plot: True to plot all receivers, False to not plot any receivers, None to automatically decide

    Other keyword arguments applicable for `arlpy.plot.plot()` are also supported.

    The surface, bottom, transmitters (marker: '*') and receivers (marker: 'o')
    are plotted in the environment. If `rx_plot` is set to None and there are
    more than 2000 receivers, they are not plotted.

    >>> import arlpy.uwapm as pm
    >>> env = pm.create_env2d(depth=[[0, 40], [100, 30], [500, 35], [700, 20], [1000,45]])
    >>> pm.plot_env(env)
    """
    env = check_env2d(env)
    min_x = 0
    max_x = _np.max(env['rx_range'])
    if max_x - min_x > 10000:
        divisor = 1000
        min_x /= divisor
        max_x /= divisor
        xlabel = 'Range (km)'
    else:
        divisor = 1
        xlabel = 'Range (m)'
    if env['surface'] is None:
        min_y = 0
    else:
        min_y = _np.min(env['surface'][:, 1])
    if _np.size(env['depth']) > 1:
        max_y = _np.max(env['depth'][:, 1])
    else:
        max_y = env['depth']
    mgn_x = 0.01 * (max_x - min_x)
    mgn_y = 0.1 * (max_y - min_y)
    oh = _plt.hold()
    if env['surface'] is None:
        _plt.plot([min_x, max_x], [0, 0],
                  xlabel=xlabel,
                  ylabel='Depth (m)',
                  xlim=(min_x - mgn_x, max_x + mgn_x),
                  ylim=(-max_y - mgn_y, -min_y + mgn_y),
                  color=surface_color,
                  **kwargs)
    else:
        # linear and curvilinear options use the same altimetry, just with different normals
        s = env['surface']
        _plt.plot(s[:, 0] / divisor,
                  -s[:, 1],
                  xlabel=xlabel,
                  ylabel='Depth (m)',
                  xlim=(min_x - mgn_x, max_x + mgn_x),
                  ylim=(-max_y - mgn_y, -min_y + mgn_y),
                  color=surface_color,
                  **kwargs)
    if _np.size(env['depth']) == 1:
        _plt.plot([min_x, max_x], [-env['depth'], -env['depth']],
                  color=bottom_color)
    else:
        # linear and curvilinear options use the same bathymetry, just with different normals
        s = env['depth']
        _plt.plot(s[:, 0] / divisor, -s[:, 1], color=bottom_color)
    txd = env['tx_depth']
    _plt.plot([0] * _np.size(txd),
              -txd,
              marker='*',
              style=None,
              color=tx_color)
    if rx_plot is None:
        rx_plot = _np.size(env['rx_depth']) * _np.size(env['rx_range']) < 2000
    if rx_plot:
        rxr = env['rx_range']
        if _np.size(rxr) == 1:
            rxr = [rxr]
        for r in _np.array(rxr):
            rxd = env['rx_depth']
            _plt.plot([r / divisor] * _np.size(rxd),
                      -rxd,
                      marker='o',
                      style=None,
                      color=rx_color)
    _plt.hold(oh)
示例#7
0
# import sys
# import time
# import datetime
# import numpy as np
# import arlpy as ap
# import matplotlib.pyplot as plt
# from matplotlib.pyplot import style
# from matplotlib.pyplot import figure
# from unetpy import *

import arlpy.plot as plt
import numpy as np

signal_file = '/home/ilan/projects/subnero_ng/evdmode/out/rx_out/rx_rec_1'
# signal_file = '/home/ilan/projects/subnero_ng/signals/subnero.sig'
# signal = np.loadtxt(signal_file)
signal = np.loadtxt(
    signal_file,
    dtype=complex,
    converters={0: lambda s: complex(s.decode().replace('+-', '-'))})

plt.plot(signal[:10000].real, fs=19200)

# figure(num=None, figsize=(15, 6), dpi=80, facecolor='w', edgecolor='k')
# plt.suptitle(signal_file, fontsize=20)
# plt.xlabel('Sample number', fontsize=18)
# plt.ylabel('Amplitude', fontsize=16)
# plt.plot(signal)
# plt.show()