Exemplo n.º 1
0
    capture_strike_directory = os.path.join(experiment.subdirs['analysis'],
                                            'capture_strikes')

    # Import data

    stimulus_map_directory = os.path.join(experiment.subdirs['analysis'],
                                          'stimulus_maps')
    random_histogram = np.load(
        os.path.join(stimulus_map_directory, 'random_histogram.npy'))
    random_average = np.load(
        os.path.join(stimulus_map_directory, 'random_average.npy'))
    random_histogram = random_histogram[100:200, 100:150].T
    random_average = random_average[100:150, 100:200]
    random_histogram = smoothed_histogram(random_histogram,
                                          random_average,
                                          sigma=1.0)

    strike_sequence_directory = os.path.join(experiment.subdirs['analysis'],
                                             'capture_strikes',
                                             'strike_sequences')

    attack_histograms = np.load(
        os.path.join(strike_sequence_directory, 'attack_histogram.npy'))
    attack_averages = np.load(
        os.path.join(strike_sequence_directory, 'attack_average.npy'))

    sstrike_histograms = np.load(
        os.path.join(strike_sequence_directory, 'sstrike_histogram.npy'))
    sstrike_averages = np.load(
        os.path.join(strike_sequence_directory, 'sstrike_average.npy'))
Exemplo n.º 2
0
import numpy as np


stimulus_map_directory = os.path.join(experiment.subdirs['analysis'], 'stimulus_maps')

# RANDOM MAPS FOR BLU
random_histogram = np.load(os.path.join(stimulus_map_directory, 'random_histogram.npy'))
random_average = np.load(os.path.join(stimulus_map_directory, 'random_average.npy'))[..., 1:251]

ymin, ymax = 50, 200
xmin, xmax = 60, 190
sigma = 2.0

random_histogram = random_histogram[ymin:ymax, xmin:xmax].T
random_average = random_average[xmin:xmax, ymin:ymax]
random = smoothed_histogram(random_histogram, random_average, threshold=150, sigma=sigma)


for condition in ('control', 'unilateral'):

    averages = np.load(os.path.join(stimulus_map_directory, '{}_module_averages.npy'.format(condition)))[..., 1:251]
    histograms = np.load(os.path.join(stimulus_map_directory, '{}_module_histograms.npy'.format(condition)))

    for i in range(7):

        fig, axes = plt.subplots(1, 3)

        pre_histogram = histograms[i, 0, ymin:ymax, xmin:xmax].T
        post_histogram = histograms[i, 1, ymin:ymax, xmin:xmax].T

        pre_average = averages[i, 0, xmin:xmax, ymin:ymax]
    attack_average = attack_average[:, 100:150, 100:200]

    sstrike_histogram = np.load(
        os.path.join(strike_sequence_directory, 'sstrike_histogram.npy'))
    sstrike_average = np.load(
        os.path.join(strike_sequence_directory, 'sstrike_average.npy'))
    sstrike_histogram = sstrike_histogram[:, 100:200, 100:150]
    sstrike_average = sstrike_average[:, 100:150, 100:200]

    random_histogram = np.load(
        os.path.join(stimulus_map_directory, 'random_histogram.npy'))
    random_average = np.load(
        os.path.join(stimulus_map_directory, 'random_average.npy'))
    random_histogram = random_histogram[100:200, 100:150].T
    random_average = random_average[100:150, 100:200]
    random_histogram = smoothed_histogram(random_histogram, random_average)

    attack = []
    for cropped, average in zip(attack_histogram, attack_average):
        smoothed = smoothed_histogram(cropped.T,
                                      average,
                                      threshold=20,
                                      sigma=1.0)
        diff = (smoothed - random_histogram).T[::-1]
        attack.append(diff)
    attack = np.array(attack)

    sstrike = []
    for cropped, average in zip(sstrike_histogram, sstrike_average):
        smoothed = smoothed_histogram(cropped.T,
                                      average,
    control_average = np.load(os.path.join(hunting_sequence_directory, 'control_attack_average.npy'))

    random_histogram = np.load(os.path.join(stimulus_map_directory, 'random_histogram.npy'))
    random_average = np.load(os.path.join(stimulus_map_directory, 'random_average.npy'))

    # Take the frame of strike onset and crop images

    unilateral_histogram = unilateral_histogram[-50, 100:200, 100:150].T
    unilateral_average = unilateral_average[-50, 100:150, 100:200]
    control_histogram = control_histogram[-50, 100:200, 100:150].T
    control_average = control_average[-50, 100:150, 100:200]
    random_histogram = random_histogram[100:200, 100:150].T
    random_average = random_average[100:150, 100:200]

    # Mask out fish
    unilateral_histogram = smoothed_histogram(unilateral_histogram, unilateral_average)
    control_histogram = smoothed_histogram(control_histogram, control_average)
    random_histogram = smoothed_histogram(random_histogram, random_average)

    fig, axes = plt.subplots(1, 2, figsize=(1.4, 1.4), gridspec_kw=dict(bottom=0, top=1, left=0, right=1, wspace=0))

    control = (control_histogram - random_histogram).T[::-1]
    axes[0].imshow(control_average.T[::-1], cmap='binary_r', vmin=0, vmax=255, interpolation='bilinear')
    axes[0].contourf(control, cmap='magma', levels=np.linspace(0.0001, 0.005, 100))

    unilateral = (unilateral_histogram - random_histogram).T[::-1]
    axes[1].imshow(unilateral_average.T[::-1], cmap='binary_r', vmin=0, vmax=255, interpolation='bilinear')
    axes[1].contourf(unilateral, cmap='magma', levels=np.linspace(0.0001, 0.005, 100))

    for ax in axes:
        ax.axis('off')