import numpy as np

import matplotlib.pyplot as plt
from scripts.spatial_maps.orientation_map import OrientationMap
from scripts.interneuron_placement import create_grid_of_excitatory_neurons, \
    plot_neural_sheet

N_E = 900

sheet_x = 450
sheet_y = 450

number_of_excitatory_neurons_per_row = int(np.sqrt(N_E))

for corr_len in range(0,451,15):
    for seed in range(10):
        map = OrientationMap(number_of_excitatory_neurons_per_row +1, number_of_excitatory_neurons_per_row +1,
                             corr_len, sheet_x, sheet_y,seed)
        try:
            map.load_orientation_map()

            tuning_map = lambda x, y: map.orientation_map(x, y)

            ex_positions, ex_tunings = create_grid_of_excitatory_neurons(sheet_x, sheet_y,
                                                                         number_of_excitatory_neurons_per_row, tuning_map)

            plot_neural_sheet(ex_positions, ex_tunings)
            plt.savefig('../noise_maps/seeded_orientation_maps/pics/map_{}x{}_pixels_{}_corr_pix.png'.format(map.x_dim,map.y_dim,map.corr_len))
            plt.close()
        except:
            print('No map with {}x{} pixels and {} pixel correllation length to plot'.format(map.x_dim,map.y_dim,map.corr_len))