from read_chirp_data import *
from func_chirp import *
from utility import *
import matplotlib.pyplot as plt
import numpy as np
from IPython import embed



data_dir = "../data"
data = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-invivo-1", "2018-11-13-ah-invivo-1", "2018-11-13-ai-invivo-1", "2018-11-13-aj-invivo-1", "2018-11-13-ak-invivo-1", "2018-11-13-al-invivo-1", "2018-11-14-aa-invivo-1", "2018-11-14-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-invivo-1", "2018-11-14-ak-invivo-1", "2018-11-14-al-invivo-1", "2018-11-14-am-invivo-1", "2018-11-14-an-invivo-1", "2018-11-20-aa-invivo-1", "2018-11-20-ab-invivo-1", "2018-11-20-ac-invivo-1", "2018-11-20-ad-invivo-1", "2018-11-20-ae-invivo-1", "2018-11-20-af-invivo-1", "2018-11-20-ag-invivo-1", "2018-11-20-ah-invivo-1", "2018-11-20-ai-invivo-1") 



for dataset in data:
	print(dataset)
	eod = read_chirp_eod(os.path.join(data_dir, dataset))
	times = read_chirp_times(os.path.join(data_dir, dataset))
	df_map = map_keys(eod)
	sort_df = sorted(df_map.keys())


	chirp_eod_plot(df_map, eod, times)


	chirp_mods =  []
	beat_mods = []
	for i in sort_df:
		freq = list(df_map[i])
		ls_mod, beat_mod = cut_chirps(freq, eod, times)
		chirp_mods.append(ls_mod)
		beat_mods.append(beat_mod)




	#Chirps einer Phase zuordnen - zusammen plotten

	chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset))
	df_map = map_keys(chirp_spikes)
	sort_df = sorted(df_map.keys())

	#plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods)




	#Vatriablen speichern, die man für die Übersicht aller Zellen braucht
	name = str(dataset.strip('invivo-1'))
	f = open('../results/Chirpcut/Cc_' + name + '.dat' , 'w') 
	f.write(str(sort_df)) 
	f.write(str(df_map)) 
	f.write(str(chirp_spikes)) 
	f.write(str(eod))
	f.write(str(times))
	#f.write(str(chirp_mods))
	#f.write(str(beat_mods)) 
	f.close() 
