From c6facd6f0cfc5421c2b8a4c0e67c782342fd52f7 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Mon, 23 Jan 2023 14:51:36 +0100 Subject: [PATCH 1/8] adding mask for bodylength --- code/plot_chirp_bodylegth.py | 141 +++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 code/plot_chirp_bodylegth.py diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py new file mode 100644 index 0000000..e088da8 --- /dev/null +++ b/code/plot_chirp_bodylegth.py @@ -0,0 +1,141 @@ +import numpy as np + +import os + +import numpy as np +import matplotlib.pyplot as plt +from thunderfish.powerspectrum import decibel + +from IPython import embed +from pandas import read_csv +from modules.logger import makeLogger +from modules.plotstyle import PlotStyle + +ps = PlotStyle() + +logger = makeLogger(__name__) + + +class Behavior: + """Load behavior data from csv file as class attributes + Attributes + ---------- + behavior: 0: chasing onset, 1: chasing offset, 2: physical contact + behavior_type: + behavioral_category: + comment_start: + comment_stop: + dataframe: pandas dataframe with all the data + duration_s: + media_file: + observation_date: + observation_id: + start_s: start time of the event in seconds + stop_s: stop time of the event in seconds + total_length: + """ + + def __init__(self, folder_path: str) -> None: + + + LED_on_time_BORIS = np.load(os.path.join(folder_path, 'LED_on_time.npy'), allow_pickle=True) + + csv_filename = [f for f in os.listdir(folder_path) if f.endswith('.csv')][0] + logger.info(f'CSV file: {csv_filename}') + self.dataframe = read_csv(os.path.join(folder_path, csv_filename)) + + self.chirps = np.load(os.path.join(folder_path, 'chirps.npy'), allow_pickle=True) + self.chirps_ids = np.load(os.path.join(folder_path, 'chirps_ids.npy'), allow_pickle=True) + + self.ident = np.load(os.path.join(folder_path, 'ident_v.npy'), allow_pickle=True) + self.idx = np.load(os.path.join(folder_path, 'idx_v.npy'), allow_pickle=True) + self.freq = np.load(os.path.join(folder_path, 'fund_v.npy'), allow_pickle=True) + self.time = np.load(os.path.join(folder_path, "times.npy"), allow_pickle=True) + self.spec = np.load(os.path.join(folder_path, "spec.npy"), allow_pickle=True) + + for k, key in enumerate(self.dataframe.keys()): + key = key.lower() + if ' ' in key: + key = key.replace(' ', '_') + if '(' in key: + key = key.replace('(', '') + key = key.replace(')', '') + setattr(self, key, np.array(self.dataframe[self.dataframe.keys()[k]])) + + last_LED_t_BORIS = LED_on_time_BORIS[-1] + real_time_range = self.time[-1] - self.time[0] + factor = 1.034141 + shift = last_LED_t_BORIS - real_time_range * factor + self.start_s = (self.start_s - shift) / factor + self.stop_s = (self.stop_s - shift) / factor + + +def correct_chasing_events( + category: np.ndarray, + timestamps: np.ndarray + ) -> tuple[np.ndarray, np.ndarray]: + + onset_ids = np.arange( + len(category))[category == 0] + offset_ids = np.arange( + len(category))[category == 1] + + # Check whether on- or offset is longer and calculate length difference + if len(onset_ids) > len(offset_ids): + len_diff = len(onset_ids) - len(offset_ids) + longer_array = onset_ids + shorter_array = offset_ids + logger.info(f'Onsets are greater than offsets by {len_diff}') + elif len(onset_ids) < len(offset_ids): + len_diff = len(offset_ids) - len(onset_ids) + longer_array = offset_ids + shorter_array = onset_ids + logger.info(f'Offsets are greater than offsets by {len_diff}') + elif len(onset_ids) == len(offset_ids): + logger.info('Chasing events are equal') + return category, timestamps + + + # Correct the wrong chasing events; delete double events + wrong_ids = [] + for i in range(len(longer_array)-(len_diff+1)): + if (shorter_array[i] > longer_array[i]) & (shorter_array[i] < longer_array[i+1]): + pass + else: + wrong_ids.append(longer_array[i]) + longer_array = np.delete(longer_array, i) + + category = np.delete( + category, wrong_ids) + timestamps = np.delete( + timestamps, wrong_ids) + return category, timestamps + + + +def main(datapath: str): + # behabvior is pandas dataframe with all the data + bh = Behavior(datapath) + # chirps are not sorted in time (presumably due to prior groupings) + # get and sort chirps and corresponding fish_ids of the chirps + chirps = bh.chirps[np.argsort(bh.chirps)] + chirps_fish_ids = bh.chirps_ids[np.argsort(bh.chirps)] + category = bh.behavior + timestamps = bh.start_s + # Correct for doubles in chasing on- and offsets to get the right on-/offset pairs + # Get rid of tracking faults (two onsets or two offsets after another) + category, timestamps = correct_chasing_events(category, timestamps) + + + + + pass + + + + +if __name__ == '__main__': + + # Path to the data + datapath = '../data/mount_data/2020-05-13-10_00/' + main(datapath) \ No newline at end of file From c967a4e5a96f0ab9167a5bc321243827cb1efe0a Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 08:14:31 +0100 Subject: [PATCH 2/8] save plot --- code/plot_chirp_bodylegth.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index e088da8..d6c148f 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -124,13 +124,20 @@ def main(datapath: str): timestamps = bh.start_s # Correct for doubles in chasing on- and offsets to get the right on-/offset pairs # Get rid of tracking faults (two onsets or two offsets after another) + category, timestamps = correct_chasing_events(category, timestamps) - + + path_to_csv = ('/').join(datapath.split('/')[:-2]) + '/order_meta.csv' + folder_name = datapath.split('/')[-2] + meta_id = read_csv(path_to_csv) + meta_id['recording'] = meta_id['recording'].str[1:-1] + winner_id = meta_id[meta_id['recording'] == folder_name]['winner'].values[0] - pass + embed() + exit() @@ -138,4 +145,5 @@ if __name__ == '__main__': # Path to the data datapath = '../data/mount_data/2020-05-13-10_00/' + main(datapath) \ No newline at end of file From 2a32a29d4edc22c1fac00aa45d1b85f1b842762f Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 11:43:14 +0100 Subject: [PATCH 3/8] plot winner loser chirp counts --- code/plot_chirp_bodylegth.py | 110 ++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index d6c148f..8512b1e 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -36,8 +36,6 @@ class Behavior: """ def __init__(self, folder_path: str) -> None: - - LED_on_time_BORIS = np.load(os.path.join(folder_path, 'LED_on_time.npy'), allow_pickle=True) csv_filename = [f for f in os.listdir(folder_path) if f.endswith('.csv')][0] @@ -45,7 +43,7 @@ class Behavior: self.dataframe = read_csv(os.path.join(folder_path, csv_filename)) self.chirps = np.load(os.path.join(folder_path, 'chirps.npy'), allow_pickle=True) - self.chirps_ids = np.load(os.path.join(folder_path, 'chirps_ids.npy'), allow_pickle=True) + self.chirps_ids = np.load(os.path.join(folder_path, 'chirp_ids.npy'), allow_pickle=True) self.ident = np.load(os.path.join(folder_path, 'ident_v.npy'), allow_pickle=True) self.idx = np.load(os.path.join(folder_path, 'idx_v.npy'), allow_pickle=True) @@ -61,7 +59,7 @@ class Behavior: key = key.replace('(', '') key = key.replace(')', '') setattr(self, key, np.array(self.dataframe[self.dataframe.keys()[k]])) - + last_LED_t_BORIS = LED_on_time_BORIS[-1] real_time_range = self.time[-1] - self.time[0] factor = 1.034141 @@ -70,6 +68,8 @@ class Behavior: self.stop_s = (self.stop_s - shift) / factor + + def correct_chasing_events( category: np.ndarray, timestamps: np.ndarray @@ -80,59 +80,87 @@ def correct_chasing_events( offset_ids = np.arange( len(category))[category == 1] + woring_bh = np.arange(len(category))[category!=2][:-1][np.diff(category[category!=2])==0] + if onset_ids[0] > offset_ids[0]: + offset_ids = np.delete(offset_ids, 0) + help_index = offset_ids[0] + woring_bh = np.append(woring_bh, help_index) + + category = np.delete(category, woring_bh) + timestamps = np.delete(timestamps, woring_bh) + # Check whether on- or offset is longer and calculate length difference if len(onset_ids) > len(offset_ids): len_diff = len(onset_ids) - len(offset_ids) - longer_array = onset_ids - shorter_array = offset_ids logger.info(f'Onsets are greater than offsets by {len_diff}') elif len(onset_ids) < len(offset_ids): len_diff = len(offset_ids) - len(onset_ids) - longer_array = offset_ids - shorter_array = onset_ids - logger.info(f'Offsets are greater than offsets by {len_diff}') + logger.info(f'Offsets are greater than onsets by {len_diff}') elif len(onset_ids) == len(offset_ids): logger.info('Chasing events are equal') - return category, timestamps - # Correct the wrong chasing events; delete double events - wrong_ids = [] - for i in range(len(longer_array)-(len_diff+1)): - if (shorter_array[i] > longer_array[i]) & (shorter_array[i] < longer_array[i+1]): - pass - else: - wrong_ids.append(longer_array[i]) - longer_array = np.delete(longer_array, i) - - category = np.delete( - category, wrong_ids) - timestamps = np.delete( - timestamps, wrong_ids) return category, timestamps def main(datapath: str): - # behabvior is pandas dataframe with all the data - bh = Behavior(datapath) - # chirps are not sorted in time (presumably due to prior groupings) - # get and sort chirps and corresponding fish_ids of the chirps - chirps = bh.chirps[np.argsort(bh.chirps)] - chirps_fish_ids = bh.chirps_ids[np.argsort(bh.chirps)] - category = bh.behavior - timestamps = bh.start_s - # Correct for doubles in chasing on- and offsets to get the right on-/offset pairs - # Get rid of tracking faults (two onsets or two offsets after another) - - category, timestamps = correct_chasing_events(category, timestamps) - - - path_to_csv = ('/').join(datapath.split('/')[:-2]) + '/order_meta.csv' - folder_name = datapath.split('/')[-2] + + foldernames = [datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)] + path_to_csv = ('/').join(foldernames[0].split('/')[:-2]) + '/order_meta.csv' meta_id = read_csv(path_to_csv) meta_id['recording'] = meta_id['recording'].str[1:-1] - winner_id = meta_id[meta_id['recording'] == folder_name]['winner'].values[0] + + chirps_winner = [] + chirps_loser = [] + + for foldername in foldernames: + # behabvior is pandas dataframe with all the data + if foldername == '../data/mount_data/2020-05-12-10_00/': + continue + bh = Behavior(foldername) + # chirps are not sorted in time (presumably due to prior groupings) + # get and sort chirps and corresponding fish_ids of the chirps + category = bh.behavior + timestamps = bh.start_s + # Correct for doubles in chasing on- and offsets to get the right on-/offset pairs + # Get rid of tracking faults (two onsets or two offsets after another) + category, timestamps = correct_chasing_events(category, timestamps) + + folder_name = foldername.split('/')[-2] + winner_row = meta_id[meta_id['recording'] == folder_name] + winner = winner_row['winner'].values[0].astype(int) + winner_fish1 = winner_row['fish1'].values[0].astype(int) + winner_fish2 = winner_row['fish2'].values[0].astype(int) + if winner == winner_fish1: + winner_fish_id = winner_row['rec_id1'].values[0] + loser_fish_id = winner_row['rec_id2'].values[0] + elif winner == winner_fish2: + winner_fish_id = winner_row['rec_id2'].values[0] + loser_fish_id = winner_row['rec_id1'].values[0] + else: + continue + + print(foldername) + all_fish_ids = np.unique(bh.chirps_ids) + chirp_loser = len(bh.chirps[bh.chirps_ids == loser_fish_id]) + chirp_winner = len(bh.chirps[bh.chirps_ids == winner_fish_id]) + chirps_winner.append(chirp_winner) + chirps_loser.append(chirp_loser) + + + fish1_id = all_fish_ids[0] + fish2_id = all_fish_ids[1] + print(winner_fish_id) + print(all_fish_ids) + + + fig, ax = plt.subplots() + ax.boxplot([chirps_winner, chirps_loser]) + + ax.set_xticklabels(['winner', 'loser']) + ax.set_ylabel('Chirpscount per trial') + plt.show() @@ -144,6 +172,6 @@ def main(datapath: str): if __name__ == '__main__': # Path to the data - datapath = '../data/mount_data/2020-05-13-10_00/' + datapath = '../data/mount_data/' main(datapath) \ No newline at end of file From ce560bf9397dc3b54060246eb93ff782e4eb702c Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 12:06:29 +0100 Subject: [PATCH 4/8] export functions in modules, plot chirp --- code/modules/behaviour_handling.py | 99 +++++++++++ code/plot_chirp_bodylegth.py | 91 +--------- code/plot_event_timeline.py | 260 ++++++++++------------------- 3 files changed, 185 insertions(+), 265 deletions(-) create mode 100644 code/modules/behaviour_handling.py diff --git a/code/modules/behaviour_handling.py b/code/modules/behaviour_handling.py new file mode 100644 index 0000000..90a18ab --- /dev/null +++ b/code/modules/behaviour_handling.py @@ -0,0 +1,99 @@ +import numpy as np + +import os + +import numpy as np +from IPython import embed + + +from pandas import read_csv +from modules.logger import makeLogger + + +logger = makeLogger(__name__) + + +class Behavior: + """Load behavior data from csv file as class attributes + Attributes + ---------- + behavior: 0: chasing onset, 1: chasing offset, 2: physical contact + behavior_type: + behavioral_category: + comment_start: + comment_stop: + dataframe: pandas dataframe with all the data + duration_s: + media_file: + observation_date: + observation_id: + start_s: start time of the event in seconds + stop_s: stop time of the event in seconds + total_length: + """ + + def __init__(self, folder_path: str) -> None: + + LED_on_time_BORIS = np.load(os.path.join(folder_path, 'LED_on_time.npy'), allow_pickle=True) + + csv_filename = [f for f in os.listdir(folder_path) if f.endswith('.csv')][0] + logger.info(f'CSV file: {csv_filename}') + self.dataframe = read_csv(os.path.join(folder_path, csv_filename)) + + self.chirps = np.load(os.path.join(folder_path, 'chirps.npy'), allow_pickle=True) + self.chirps_ids = np.load(os.path.join(folder_path, 'chirp_ids.npy'), allow_pickle=True) + + self.ident = np.load(os.path.join(folder_path, 'ident_v.npy'), allow_pickle=True) + self.idx = np.load(os.path.join(folder_path, 'idx_v.npy'), allow_pickle=True) + self.freq = np.load(os.path.join(folder_path, 'fund_v.npy'), allow_pickle=True) + self.time = np.load(os.path.join(folder_path, "times.npy"), allow_pickle=True) + self.spec = np.load(os.path.join(folder_path, "spec.npy"), allow_pickle=True) + + for k, key in enumerate(self.dataframe.keys()): + key = key.lower() + if ' ' in key: + key = key.replace(' ', '_') + if '(' in key: + key = key.replace('(', '') + key = key.replace(')', '') + setattr(self, key, np.array(self.dataframe[self.dataframe.keys()[k]])) + + last_LED_t_BORIS = LED_on_time_BORIS[-1] + real_time_range = self.time[-1] - self.time[0] + factor = 1.034141 + shift = last_LED_t_BORIS - real_time_range * factor + self.start_s = (self.start_s - shift) / factor + self.stop_s = (self.stop_s - shift) / factor + + +def correct_chasing_events( + category: np.ndarray, + timestamps: np.ndarray + ) -> tuple[np.ndarray, np.ndarray]: + + onset_ids = np.arange( + len(category))[category == 0] + offset_ids = np.arange( + len(category))[category == 1] + + woring_bh = np.arange(len(category))[category!=2][:-1][np.diff(category[category!=2])==0] + if onset_ids[0] > offset_ids[0]: + offset_ids = np.delete(offset_ids, 0) + help_index = offset_ids[0] + woring_bh = np.append(woring_bh, help_index) + + category = np.delete(category, woring_bh) + timestamps = np.delete(timestamps, woring_bh) + + # Check whether on- or offset is longer and calculate length difference + if len(onset_ids) > len(offset_ids): + len_diff = len(onset_ids) - len(offset_ids) + logger.info(f'Onsets are greater than offsets by {len_diff}') + elif len(onset_ids) < len(offset_ids): + len_diff = len(offset_ids) - len(onset_ids) + logger.info(f'Offsets are greater than onsets by {len_diff}') + elif len(onset_ids) == len(offset_ids): + logger.info('Chasing events are equal') + + + return category, timestamps \ No newline at end of file diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index 8512b1e..a5966f6 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -10,100 +10,13 @@ from IPython import embed from pandas import read_csv from modules.logger import makeLogger from modules.plotstyle import PlotStyle +from modules.behaviour_handling import Behavior, correct_chasing_events ps = PlotStyle() logger = makeLogger(__name__) -class Behavior: - """Load behavior data from csv file as class attributes - Attributes - ---------- - behavior: 0: chasing onset, 1: chasing offset, 2: physical contact - behavior_type: - behavioral_category: - comment_start: - comment_stop: - dataframe: pandas dataframe with all the data - duration_s: - media_file: - observation_date: - observation_id: - start_s: start time of the event in seconds - stop_s: stop time of the event in seconds - total_length: - """ - - def __init__(self, folder_path: str) -> None: - LED_on_time_BORIS = np.load(os.path.join(folder_path, 'LED_on_time.npy'), allow_pickle=True) - - csv_filename = [f for f in os.listdir(folder_path) if f.endswith('.csv')][0] - logger.info(f'CSV file: {csv_filename}') - self.dataframe = read_csv(os.path.join(folder_path, csv_filename)) - - self.chirps = np.load(os.path.join(folder_path, 'chirps.npy'), allow_pickle=True) - self.chirps_ids = np.load(os.path.join(folder_path, 'chirp_ids.npy'), allow_pickle=True) - - self.ident = np.load(os.path.join(folder_path, 'ident_v.npy'), allow_pickle=True) - self.idx = np.load(os.path.join(folder_path, 'idx_v.npy'), allow_pickle=True) - self.freq = np.load(os.path.join(folder_path, 'fund_v.npy'), allow_pickle=True) - self.time = np.load(os.path.join(folder_path, "times.npy"), allow_pickle=True) - self.spec = np.load(os.path.join(folder_path, "spec.npy"), allow_pickle=True) - - for k, key in enumerate(self.dataframe.keys()): - key = key.lower() - if ' ' in key: - key = key.replace(' ', '_') - if '(' in key: - key = key.replace('(', '') - key = key.replace(')', '') - setattr(self, key, np.array(self.dataframe[self.dataframe.keys()[k]])) - - last_LED_t_BORIS = LED_on_time_BORIS[-1] - real_time_range = self.time[-1] - self.time[0] - factor = 1.034141 - shift = last_LED_t_BORIS - real_time_range * factor - self.start_s = (self.start_s - shift) / factor - self.stop_s = (self.stop_s - shift) / factor - - - - -def correct_chasing_events( - category: np.ndarray, - timestamps: np.ndarray - ) -> tuple[np.ndarray, np.ndarray]: - - onset_ids = np.arange( - len(category))[category == 0] - offset_ids = np.arange( - len(category))[category == 1] - - woring_bh = np.arange(len(category))[category!=2][:-1][np.diff(category[category!=2])==0] - if onset_ids[0] > offset_ids[0]: - offset_ids = np.delete(offset_ids, 0) - help_index = offset_ids[0] - woring_bh = np.append(woring_bh, help_index) - - category = np.delete(category, woring_bh) - timestamps = np.delete(timestamps, woring_bh) - - # Check whether on- or offset is longer and calculate length difference - if len(onset_ids) > len(offset_ids): - len_diff = len(onset_ids) - len(offset_ids) - logger.info(f'Onsets are greater than offsets by {len_diff}') - elif len(onset_ids) < len(offset_ids): - len_diff = len(offset_ids) - len(onset_ids) - logger.info(f'Offsets are greater than onsets by {len_diff}') - elif len(onset_ids) == len(offset_ids): - logger.info('Chasing events are equal') - - - return category, timestamps - - - def main(datapath: str): foldernames = [datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)] @@ -157,7 +70,7 @@ def main(datapath: str): fig, ax = plt.subplots() ax.boxplot([chirps_winner, chirps_loser]) - + ax.set_xticklabels(['winner', 'loser']) ax.set_ylabel('Chirpscount per trial') plt.show() diff --git a/code/plot_event_timeline.py b/code/plot_event_timeline.py index 6c984be..bb370b7 100644 --- a/code/plot_event_timeline.py +++ b/code/plot_event_timeline.py @@ -10,188 +10,96 @@ from IPython import embed from pandas import read_csv from modules.logger import makeLogger from modules.plotstyle import PlotStyle +from modules.behaviour_handling import Behavior, correct_chasing_events ps = PlotStyle() logger = makeLogger(__name__) -class Behavior: - """Load behavior data from csv file as class attributes - Attributes - ---------- - behavior: 0: chasing onset, 1: chasing offset, 2: physical contact - behavior_type: - behavioral_category: - comment_start: - comment_stop: - dataframe: pandas dataframe with all the data - duration_s: - media_file: - observation_date: - observation_id: - start_s: start time of the event in seconds - stop_s: stop time of the event in seconds - total_length: - """ - - def __init__(self, folder_path: str) -> None: - - - LED_on_time_BORIS = np.load(os.path.join(folder_path, 'LED_on_time.npy'), allow_pickle=True) - - csv_filename = [f for f in os.listdir(folder_path) if f.endswith('.csv')][0] - logger.info(f'CSV file: {csv_filename}') - self.dataframe = read_csv(os.path.join(folder_path, csv_filename)) - - self.chirps = np.load(os.path.join(folder_path, 'chirps.npy'), allow_pickle=True) - self.chirps_ids = np.load(os.path.join(folder_path, 'chirps_ids.npy'), allow_pickle=True) - - self.ident = np.load(os.path.join(folder_path, 'ident_v.npy'), allow_pickle=True) - self.idx = np.load(os.path.join(folder_path, 'idx_v.npy'), allow_pickle=True) - self.freq = np.load(os.path.join(folder_path, 'fund_v.npy'), allow_pickle=True) - self.time = np.load(os.path.join(folder_path, "times.npy"), allow_pickle=True) - self.spec = np.load(os.path.join(folder_path, "spec.npy"), allow_pickle=True) - - for k, key in enumerate(self.dataframe.keys()): - key = key.lower() - if ' ' in key: - key = key.replace(' ', '_') - if '(' in key: - key = key.replace('(', '') - key = key.replace(')', '') - setattr(self, key, np.array(self.dataframe[self.dataframe.keys()[k]])) - - last_LED_t_BORIS = LED_on_time_BORIS[-1] - real_time_range = self.time[-1] - self.time[0] - factor = 1.034141 - shift = last_LED_t_BORIS - real_time_range * factor - self.start_s = (self.start_s - shift) / factor - self.stop_s = (self.stop_s - shift) / factor - -def correct_chasing_events( - category: np.ndarray, - timestamps: np.ndarray - ) -> tuple[np.ndarray, np.ndarray]: - - onset_ids = np.arange( - len(category))[category == 0] - offset_ids = np.arange( - len(category))[category == 1] - - # Check whether on- or offset is longer and calculate length difference - if len(onset_ids) > len(offset_ids): - len_diff = len(onset_ids) - len(offset_ids) - longer_array = onset_ids - shorter_array = offset_ids - logger.info(f'Onsets are greater than offsets by {len_diff}') - elif len(onset_ids) < len(offset_ids): - len_diff = len(offset_ids) - len(onset_ids) - longer_array = offset_ids - shorter_array = onset_ids - logger.info(f'Offsets are greater than offsets by {len_diff}') - elif len(onset_ids) == len(offset_ids): - logger.info('Chasing events are equal') - return category, timestamps - - - # Correct the wrong chasing events; delete double events - wrong_ids = [] - for i in range(len(longer_array)-(len_diff+1)): - if (shorter_array[i] > longer_array[i]) & (shorter_array[i] < longer_array[i+1]): - pass - else: - wrong_ids.append(longer_array[i]) - longer_array = np.delete(longer_array, i) - - category = np.delete( - category, wrong_ids) - timestamps = np.delete( - timestamps, wrong_ids) - return category, timestamps - - - def main(datapath: str): - # behabvior is pandas dataframe with all the data - bh = Behavior(datapath) - # chirps are not sorted in time (presumably due to prior groupings) - # get and sort chirps and corresponding fish_ids of the chirps - chirps = bh.chirps[np.argsort(bh.chirps)] - chirps_fish_ids = bh.chirps_ids[np.argsort(bh.chirps)] - category = bh.behavior - timestamps = bh.start_s - # Correct for doubles in chasing on- and offsets to get the right on-/offset pairs - # Get rid of tracking faults (two onsets or two offsets after another) - category, timestamps = correct_chasing_events(category, timestamps) - - # split categories - chasing_onset = (timestamps[category == 0]/ 60) /60 - chasing_offset = (timestamps[category == 1]/ 60) /60 - physical_contact = (timestamps[category == 2] / 60) /60 - - all_fish_ids = np.unique(chirps_fish_ids) - fish1_id = all_fish_ids[0] - fish2_id = all_fish_ids[1] - # Associate chirps to inidividual fish - fish1 = (chirps[chirps_fish_ids == fish1_id] / 60) /60 - fish2 = (chirps[chirps_fish_ids == fish2_id] / 60) /60 - fish1_color = ps.red - fish2_color = ps.orange - - fig, ax = plt.subplots(4, 1, figsize=(10, 5), height_ratios=[0.5, 0.5, 0.5, 6], sharex=True) - # marker size - s = 200 - ax[0].scatter(physical_contact, np.ones(len(physical_contact)), color='firebrick', marker='|', s=s) - ax[1].scatter(chasing_onset, np.ones(len(chasing_onset)), color='green', marker='|', s=s ) - ax[2].scatter(fish1, np.ones(len(fish1))-0.25, color=fish1_color, marker='|', s=s) - ax[2].scatter(fish2, np.zeros(len(fish2))+0.25, color=fish2_color, marker='|', s=s) - - - freq_temp = bh.freq[bh.ident==fish1_id] - time_temp = bh.time[bh.idx[bh.ident==fish1_id]] - ax[3].plot((time_temp/ 60) /60, freq_temp, color=fish1_color) - - freq_temp = bh.freq[bh.ident==fish2_id] - time_temp = bh.time[bh.idx[bh.ident==fish2_id]] - ax[3].plot((time_temp/ 60) /60, freq_temp, color=fish2_color) - - #ax[3].imshow(decibel(bh.spec), extent=[bh.time[0]/60/60, bh.time[-1]/60/60, 0, 2000], aspect='auto', origin='lower') - - # Hide grid lines - ax[0].grid(False) - ax[0].set_frame_on(False) - ax[0].set_xticks([]) - ax[0].set_yticks([]) - ps.hide_ax(ax[0]) - - - ax[1].grid(False) - ax[1].set_frame_on(False) - ax[1].set_xticks([]) - ax[1].set_yticks([]) - ps.hide_ax(ax[1]) - - ax[2].grid(False) - ax[2].set_frame_on(False) - ax[2].set_yticks([]) - ax[2].set_xticks([]) - ps.hide_ax(ax[2]) - - - - ax[3].axvspan(0, 3, 0, 5, facecolor='grey', alpha=0.5) - ax[3].set_xticks(np.arange(0, 6.1, 0.5)) - - labelpad = 40 - ax[0].set_ylabel('Physical contact', rotation=0, labelpad=labelpad) - ax[1].set_ylabel('Chasing events', rotation=0, labelpad=labelpad) - ax[2].set_ylabel('Chirps', rotation=0, labelpad=labelpad) - ax[3].set_ylabel('EODf') - - ax[3].set_xlabel('Time [h]') - - plt.show() + + foldernames = [datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)] + for foldername in foldernames: + if foldername == '../data/mount_data/2020-05-12-10_00/': + continue + # behabvior is pandas dataframe with all the data + bh = Behavior(foldername) + + category = bh.behavior + timestamps = bh.start_s + # Correct for doubles in chasing on- and offsets to get the right on-/offset pairs + # Get rid of tracking faults (two onsets or two offsets after another) + category, timestamps = correct_chasing_events(category, timestamps) + + # split categories + chasing_onset = (timestamps[category == 0]/ 60) /60 + chasing_offset = (timestamps[category == 1]/ 60) /60 + physical_contact = (timestamps[category == 2] / 60) /60 + + all_fish_ids = np.unique(bh.chirps_ids) + fish1_id = all_fish_ids[0] + fish2_id = all_fish_ids[1] + # Associate chirps to inidividual fish + fish1 = (bh.chirps[bh.chirps_ids == fish1_id] / 60) /60 + fish2 = (bh.chirps[bh.chirps_ids == fish2_id] / 60) /60 + fish1_color = ps.red + fish2_color = ps.orange + + fig, ax = plt.subplots(4, 1, figsize=(10, 5), height_ratios=[0.5, 0.5, 0.5, 6], sharex=True) + # marker size + s = 200 + ax[0].scatter(physical_contact, np.ones(len(physical_contact)), color='firebrick', marker='|', s=s) + ax[1].scatter(chasing_onset, np.ones(len(chasing_onset)), color='green', marker='|', s=s ) + ax[2].scatter(fish1, np.ones(len(fish1))-0.25, color=fish1_color, marker='|', s=s) + ax[2].scatter(fish2, np.zeros(len(fish2))+0.25, color=fish2_color, marker='|', s=s) + + + freq_temp = bh.freq[bh.ident==fish1_id] + time_temp = bh.time[bh.idx[bh.ident==fish1_id]] + ax[3].plot((time_temp/ 60) /60, freq_temp, color=fish1_color) + + freq_temp = bh.freq[bh.ident==fish2_id] + time_temp = bh.time[bh.idx[bh.ident==fish2_id]] + ax[3].plot((time_temp/ 60) /60, freq_temp, color=fish2_color) + + #ax[3].imshow(decibel(bh.spec), extent=[bh.time[0]/60/60, bh.time[-1]/60/60, 0, 2000], aspect='auto', origin='lower') + + # Hide grid lines + ax[0].grid(False) + ax[0].set_frame_on(False) + ax[0].set_xticks([]) + ax[0].set_yticks([]) + ps.hide_ax(ax[0]) + + + ax[1].grid(False) + ax[1].set_frame_on(False) + ax[1].set_xticks([]) + ax[1].set_yticks([]) + ps.hide_ax(ax[1]) + + ax[2].grid(False) + ax[2].set_frame_on(False) + ax[2].set_yticks([]) + ax[2].set_xticks([]) + ps.hide_ax(ax[2]) + + + + ax[3].axvspan(0, 3, 0, 5, facecolor='grey', alpha=0.5) + ax[3].set_xticks(np.arange(0, 6.1, 0.5)) + + labelpad = 40 + ax[0].set_ylabel('Physical contact', rotation=0, labelpad=labelpad) + ax[1].set_ylabel('Chasing events', rotation=0, labelpad=labelpad) + ax[2].set_ylabel('Chirps', rotation=0, labelpad=labelpad) + ax[3].set_ylabel('EODf') + + ax[3].set_xlabel('Time [h]') + ax[0].set_title(foldername.split('/')[-2]) + + plt.show() embed() # plot chirps @@ -199,5 +107,5 @@ def main(datapath: str): if __name__ == '__main__': # Path to the data - datapath = '../data/mount_data/2020-05-13-10_00/' + datapath = '../data/mount_data/' main(datapath) From fd2207c8c57131eb7ce459a31c4c3dc0cc7c6388 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 13:23:12 +0100 Subject: [PATCH 5/8] finishing plot chirp_body length --- code/plot_chirp_bodylegth.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index a5966f6..32da016 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -69,18 +69,15 @@ def main(datapath: str): fig, ax = plt.subplots() - ax.boxplot([chirps_winner, chirps_loser]) - + ax.boxplot([chirps_winner, chirps_loser], showfliers=False) + ax.scatter(np.ones(len(chirps_winner)), chirps_winner, color='r') + ax.scatter(np.ones(len(chirps_loser))*2, chirps_loser, color='r') ax.set_xticklabels(['winner', 'loser']) - ax.set_ylabel('Chirpscount per trial') - plt.show() - - - - embed() - exit() - + for w, l in zip(chirps_winner, chirps_loser): + ax.plot([1,2], [w,l], color='r', alpha=0.5, linewidth=0.5) + ax.set_ylabel('Chirpscounts [n]') + plt.show() if __name__ == '__main__': From ea98a20a6868461da6bddebc96a52291ac49d90c Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 13:56:41 +0100 Subject: [PATCH 6/8] adding plotstyle boxplots --- code/modules/plotstyle.py | 11 ++++------- code/plot_chirp_bodylegth.py | 36 +++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/code/modules/plotstyle.py b/code/modules/plotstyle.py index 2325f62..2c05369 100644 --- a/code/modules/plotstyle.py +++ b/code/modules/plotstyle.py @@ -108,9 +108,6 @@ def PlotStyle() -> None: @classmethod def set_boxplot_color(cls, bp, color): plt.setp(bp["boxes"], color=color) - plt.setp(bp["whiskers"], color=color) - plt.setp(bp["caps"], color=color) - plt.setp(bp["medians"], color=color) @classmethod def label_subplots(cls, labels, axes, fig): @@ -250,11 +247,11 @@ def PlotStyle() -> None: # dark mode modifications plt.rcParams["boxplot.flierprops.color"] = white - plt.rcParams["boxplot.flierprops.markeredgecolor"] = gray + plt.rcParams["boxplot.flierprops.markeredgecolor"] = white plt.rcParams["boxplot.boxprops.color"] = gray - plt.rcParams["boxplot.whiskerprops.color"] = gray - plt.rcParams["boxplot.capprops.color"] = gray - plt.rcParams["boxplot.medianprops.color"] = gray + plt.rcParams["boxplot.whiskerprops.color"] = white + plt.rcParams["boxplot.capprops.color"] = white + plt.rcParams["boxplot.medianprops.color"] = white plt.rcParams["text.color"] = white plt.rcParams["axes.facecolor"] = black # axes background color plt.rcParams["axes.edgecolor"] = gray # axes edge color diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index 32da016..0cf1783 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -1,9 +1,9 @@ import numpy as np -import os +import os import numpy as np -import matplotlib.pyplot as plt +import matplotlib.pyplot as plt from thunderfish.powerspectrum import decibel from IPython import embed @@ -19,11 +19,13 @@ logger = makeLogger(__name__) def main(datapath: str): - foldernames = [datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)] - path_to_csv = ('/').join(foldernames[0].split('/')[:-2]) + '/order_meta.csv' + foldernames = [ + datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)] + path_to_csv = ( + '/').join(foldernames[0].split('/')[:-2]) + '/order_meta.csv' meta_id = read_csv(path_to_csv) meta_id['recording'] = meta_id['recording'].str[1:-1] - + chirps_winner = [] chirps_loser = [] @@ -61,27 +63,35 @@ def main(datapath: str): chirps_winner.append(chirp_winner) chirps_loser.append(chirp_loser) - fish1_id = all_fish_ids[0] fish2_id = all_fish_ids[1] print(winner_fish_id) print(all_fish_ids) - fig, ax = plt.subplots() - ax.boxplot([chirps_winner, chirps_loser], showfliers=False) - ax.scatter(np.ones(len(chirps_winner)), chirps_winner, color='r') - ax.scatter(np.ones(len(chirps_loser))*2, chirps_loser, color='r') + bplot1 = ax.boxplot(chirps_winner, positions=[ + 1], showfliers=False, patch_artist=True) + bplot2 = ax.boxplot(chirps_loser, positions=[ + 2], showfliers=False, patch_artist=True) + ax.scatter(np.ones(len(chirps_winner))*1.15, chirps_winner, color='r') + ax.scatter(np.ones(len(chirps_loser))*1.85, chirps_loser, color='r') ax.set_xticklabels(['winner', 'loser']) + for w, l in zip(chirps_winner, chirps_loser): - ax.plot([1,2], [w,l], color='r', alpha=0.5, linewidth=0.5) + ax.plot([1.15, 1.85], [w, l], color='r', alpha=0.5, linewidth=0.5) + + colors1 = ps.red + ps.set_boxplot_color(bplot1, colors1) + colors1 = ps.orange + ps.set_boxplot_color(bplot2, colors1) ax.set_ylabel('Chirpscounts [n]') plt.show() + if __name__ == '__main__': # Path to the data datapath = '../data/mount_data/' - - main(datapath) \ No newline at end of file + + main(datapath) From 726301c593a643b322ce8fffbd12135af8add876 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 14:04:44 +0100 Subject: [PATCH 7/8] adding plot to poster --- code/modules/filehandling.py | 1 + code/plot_chirp_bodylegth.py | 2 +- poster/figs/chirps_winner_loser.pdf | Bin 0 -> 11986 bytes 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 poster/figs/chirps_winner_loser.pdf diff --git a/code/modules/filehandling.py b/code/modules/filehandling.py index 334aefa..c3c71f2 100644 --- a/code/modules/filehandling.py +++ b/code/modules/filehandling.py @@ -3,6 +3,7 @@ import os import yaml import numpy as np from thunderfish.dataloader import DataLoader +import matplotlib.pyplot as plt class ConfLoader: diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index 0cf1783..fd34ebf 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -86,7 +86,7 @@ def main(datapath: str): ps.set_boxplot_color(bplot2, colors1) ax.set_ylabel('Chirpscounts [n]') - plt.show() + plt.savefig('../poster/figs/chirps_winner_loser.pdf') if __name__ == '__main__': diff --git a/poster/figs/chirps_winner_loser.pdf b/poster/figs/chirps_winner_loser.pdf new file mode 100644 index 0000000000000000000000000000000000000000..91718185eb8351d411370b1ffc558ed701c3888b GIT binary patch literal 11986 zcmd^lc{r3^_;4u8WXYP|qKC3Cv(Fe?_AC)YqEL*n6oZ+eq6MWWI}w#4iYQ5zgk(vU zqU<6qij_TX2LP(o^zElXQ@62@e@^Ocdmd@@}2800v$dI-+f=Y9R2dd4RVB|w%LRi)S zq}^thT~rDaBF;VC9wO=`;urKO&IU9?q_wGPSv!2ghup! z?o1B|J-4Hgrx&0XLK=AiCKymDKCV<4Z3dH0b@oQ=JyT)dMC&K4=zpVB>b3GB2|LJp zGctjo6Ra99J}iB&(cj7U%w5`>fwA<=T&14&BEjwG7292pYJNOuT#tM(^KE~?^sAQ< zLDR(=Px2pJ)u8VvdwMu}!z&u{`t>>y(}1mO9esDaA9K@X4t<%fJ)OMg>h_9T%S)$r zuf%_eymaD&iOcx$EvM47{riu-`?Bh0OxO9K9+{eA*R{rP_8ot+x1{n^r&Qqc$f%J0 z+oDVS4xNrsjxbx_=r6VYu0qmR2X;}uB+3?!E%@M@r|aTqpN#X59qaG6vN`wB>3qNX z*Y@S@XRF+Z{d>OizmpGM>GH`WF@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u#7@3Rwsv!JY~J{o)k} zpMJv+kNbTtUhQ`}2$+ZR=XCOE*f+HK*#|JhZEH`aJbMt{%#)IXC8BAw7ll8iSlOBeE LkdZOmY=rnfO0ajV literal 0 HcmV?d00001 From a371755b1c1abc5d7da1efd08c4e687811bc8978 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 24 Jan 2023 14:07:38 +0100 Subject: [PATCH 8/8] adding variable for scatter plot --- code/plot_chirp_bodylegth.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/code/plot_chirp_bodylegth.py b/code/plot_chirp_bodylegth.py index fd34ebf..f722fee 100644 --- a/code/plot_chirp_bodylegth.py +++ b/code/plot_chirp_bodylegth.py @@ -69,16 +69,18 @@ def main(datapath: str): print(all_fish_ids) fig, ax = plt.subplots() + scatterwinner = 1.15 + scatterloser = 1.85 bplot1 = ax.boxplot(chirps_winner, positions=[ 1], showfliers=False, patch_artist=True) bplot2 = ax.boxplot(chirps_loser, positions=[ 2], showfliers=False, patch_artist=True) - ax.scatter(np.ones(len(chirps_winner))*1.15, chirps_winner, color='r') - ax.scatter(np.ones(len(chirps_loser))*1.85, chirps_loser, color='r') + ax.scatter(np.ones(len(chirps_winner))*scatterwinner, chirps_winner, color='r') + ax.scatter(np.ones(len(chirps_loser))*scatterloser, chirps_loser, color='r') ax.set_xticklabels(['winner', 'loser']) for w, l in zip(chirps_winner, chirps_loser): - ax.plot([1.15, 1.85], [w, l], color='r', alpha=0.5, linewidth=0.5) + ax.plot([scatterwinner, scatterloser], [w, l], color='r', alpha=0.5, linewidth=0.5) colors1 = ps.red ps.set_boxplot_color(bplot1, colors1) @@ -87,6 +89,7 @@ def main(datapath: str): ax.set_ylabel('Chirpscounts [n]') plt.savefig('../poster/figs/chirps_winner_loser.pdf') + plt.show() if __name__ == '__main__':