New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subset dev #14
base: master
Are you sure you want to change the base?
Subset dev #14
Changes from 6 commits
f29eb3b
d87fd23
ae6a2c4
6cceb7e
1028dcf
20983fd
8c65a27
2e52567
2c51078
1726bd8
87d299a
34f6a49
07741dc
e36021c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,11 @@ def from_file( | |
else: | ||
raise ValueError(f"Cannot load from filetype {filetype}.") | ||
|
||
<<<<<<< HEAD | ||
recording.lists = {"All": (list(range(len(recording["raw_"]))), None)} | ||
======= | ||
recording.subsets = {"All": (list(range(len(recording["raw_"]))), None)} | ||
>>>>>>> subsets | ||
|
||
return recording | ||
|
||
|
@@ -93,6 +97,7 @@ def __init__(self, filename="", sampling_rate=4e4): | |
# attributes for storing and managing the data | ||
self["raw_"] = [] | ||
self.current_datakey = "raw_" | ||
<<<<<<< HEAD | ||
self.current_ep_ind = 0 | ||
|
||
# variables for user created lists of episodes | ||
|
@@ -123,6 +128,43 @@ def episodes_in_lists(self, names): | |
debug_logger.debug(f"Selected episodes: {indices}") | ||
return np.array(self.series)[indices] | ||
|
||
======= | ||
self.current_subsets = ["All"] | ||
self.current_ep_ind = 0 | ||
|
||
# variables for user-created subsets of episodes | ||
# `subsets` stores the indices of the episodes in the subset in the first | ||
# element and the associated keyboard key as the second: | ||
# subsets[name] = ([indices], key) | ||
self.subsets = dict() | ||
|
||
def select_episodes(self, datakey=None, subsets=None): | ||
if datakey is None: | ||
datakey = self.current_datakey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another unimportant tip/comment: you can do this shorter like |
||
if subsets is None: | ||
subsets = self.current_subsets | ||
indices = list() | ||
for subsetname in subsets: | ||
indices.extend(self.subsets[subsetname][0]) | ||
indices = np.array(list(set(indices))) | ||
return np.array(self[datakey])[indices] | ||
|
||
def episodes_in_subsets(self, subset_names): | ||
if isinstance(subset_names, str): #AP corrected here 291121 | ||
subset_names = [subset_names] | ||
indices = list() | ||
for subsetname in subset_names: | ||
indices.extend(self.subsets[subsetname][0]) | ||
# remove duplicate indices | ||
indices = np.array(list(set(indices))) | ||
print (indices) | ||
aplested marked this conversation as resolved.
Show resolved
Hide resolved
|
||
debug_logger.debug(f"Selected episodes: {indices}") | ||
if indices != []: | ||
return np.array(self.series)[indices] | ||
else: | ||
return None | ||
|
||
>>>>>>> subsets | ||
@property | ||
def series(self): | ||
return self[self.current_datakey] | ||
|
@@ -289,7 +331,11 @@ def series_hist( | |
"""Create a histogram of all episodes in the presently selected series | ||
""" | ||
debug_logger.debug(f"series_hist") | ||
<<<<<<< HEAD | ||
# put all piezo traces and all current traces in lists | ||
======= | ||
# put all piezo traces and all current traces in subsets | ||
>>>>>>> subsets | ||
piezos = [episode.piezo for episode in self.series] | ||
traces = [episode.trace for episode in self.series] | ||
trace_list = [] | ||
|
@@ -397,7 +443,11 @@ def _load_from_pickle(recording): | |
def export_idealization( | ||
self, | ||
filepath, | ||
<<<<<<< HEAD | ||
lists_to_save, | ||
======= | ||
subsets_to_save, | ||
>>>>>>> subsets | ||
time_unit, | ||
trace_unit, | ||
amplitudes, | ||
|
@@ -410,7 +460,11 @@ def export_idealization( | |
if not filepath.endswith(".csv"): | ||
filepath += ".csv" | ||
|
||
<<<<<<< HEAD | ||
episodes = self.select_episodes(lists=lists_to_save) | ||
======= | ||
episodes = self.select_episodes(subsets=subsets_to_save) | ||
>>>>>>> subsets | ||
|
||
export_array = np.zeros( | ||
shape=(len(episodes) + 1, episodes[0].idealization.size) | ||
|
@@ -437,19 +491,31 @@ def export_matlab( | |
self, | ||
filepath, | ||
datakey, | ||
<<<<<<< HEAD | ||
lists_to_save, | ||
======= | ||
subsets_to_save, | ||
>>>>>>> subsets | ||
save_piezo, | ||
save_command, | ||
time_unit="s", | ||
trace_unit="A", | ||
piezo_unit="V", | ||
command_unit="V", | ||
): | ||
<<<<<<< HEAD | ||
"""Export all the episodes in the givens list(s) from the given series | ||
(only one) to a matlab file.""" | ||
debug_logger.debug( | ||
f"export_matlab:\n" | ||
f"saving the lists: {lists_to_save}\n" | ||
======= | ||
"""Export all the episodes in the givens subset(s) from the given series | ||
(only one) to a matlab file.""" | ||
debug_logger.debug( | ||
f"export_matlab:\n" | ||
f"saving the subsets: {subsets_to_save}\n" | ||
>>>>>>> subsets | ||
f"of series {datakey}\n" | ||
f"save piezo: {save_piezo}; " | ||
"save command: {save_command}\n" | ||
|
@@ -464,7 +530,11 @@ def export_matlab( | |
export_dict = dict() | ||
export_dict["time"] = self["raw_"][0].time * TIME_UNIT_FACTORS[time_unit] | ||
fill_length = len(str(len(self[datakey]))) | ||
<<<<<<< HEAD | ||
episodes = self.select_episodes(datakey, lists_to_save) | ||
======= | ||
episodes = self.select_episodes(datakey, subsets_to_save) | ||
>>>>>>> subsets | ||
# # get the episodes we want to save | ||
# indices = list() | ||
# for listname in lists_to_save: | ||
|
@@ -484,19 +554,31 @@ def export_matlab( | |
) | ||
io.savemat(filepath, export_dict) | ||
|
||
<<<<<<< HEAD | ||
def export_axo(self, filepath, datakey, lists_to_save, save_piezo, save_command): | ||
======= | ||
def export_axo(self, filepath, datakey, subsets_to_save, save_piezo, save_command): | ||
>>>>>>> subsets | ||
"""Export data to an axograph file. | ||
|
||
Argument: | ||
filepath - location where the file is to be stored | ||
datakey - series that should be exported | ||
<<<<<<< HEAD | ||
lists_to_save - the user-created lists of episodes that should be | ||
======= | ||
subsets_to_save - the user-created subsets of episodes that should be | ||
>>>>>>> subsets | ||
includes | ||
save_piezo - if true piezo data will be exported | ||
save_command - if true command voltage data will be exported""" | ||
debug_logger.debug( | ||
f"export_axo:\n" | ||
<<<<<<< HEAD | ||
f"saving the lists: {lists_to_save}\n" | ||
======= | ||
f"saving the subsets: {subsets_to_save}\n" | ||
>>>>>>> subsets | ||
f"of series {datakey}\n" | ||
f"save piezo: {save_piezo}; save command: {save_command}\n" | ||
f"saving to destination: {filepath}" | ||
|
@@ -515,7 +597,11 @@ def export_axo(self, filepath, datakey, lists_to_save, save_piezo, save_command) | |
data_list = [self.episode().time] | ||
|
||
# get the episodes we want to save | ||
<<<<<<< HEAD | ||
episodes = self.select_episodes(datakey, lists_to_save) | ||
======= | ||
episodes = self.select_episodes(datakey, subsets_to_save) | ||
>>>>>>> subsets | ||
|
||
for episode in episodes: | ||
data_list.append(np.array(episode.trace)) | ||
|
@@ -530,7 +616,11 @@ def export_axo(self, filepath, datakey, lists_to_save, save_piezo, save_command) | |
file.write(filepath) | ||
|
||
def create_first_activation_table( | ||
<<<<<<< HEAD | ||
self, datakey=None, time_unit="ms", lists_to_save=None, trace_unit="pA" | ||
======= | ||
self, datakey=None, time_unit="ms", subsets_to_save=None, trace_unit="pA" | ||
>>>>>>> subsets | ||
): | ||
if datakey is None: | ||
datakey = self.current_datakey | ||
|
@@ -544,7 +634,11 @@ def create_first_activation_table( | |
episode.first_activation_amplitude | ||
* CURRENT_UNIT_FACTORS[trace_unit], | ||
) | ||
<<<<<<< HEAD | ||
for episode in self.select_episodes(datakey, lists_to_save) | ||
======= | ||
for episode in self.select_episodes(datakey, subsets_to_save) | ||
>>>>>>> subsets | ||
] | ||
) | ||
return export_array.astype(object) | ||
|
@@ -554,12 +648,20 @@ def export_first_activation( | |
filepath, | ||
datakey=None, | ||
time_unit="ms", | ||
<<<<<<< HEAD | ||
lists_to_save=None, | ||
======= | ||
subsets_to_save=None, | ||
>>>>>>> subsets | ||
trace_unit="pA", | ||
): | ||
"""Export csv file of first activation times.""" | ||
export_array = self.create_first_activation_table( | ||
<<<<<<< HEAD | ||
datakey, time_unit, lists_to_save, trace_unit | ||
======= | ||
datakey, time_unit, subsets_to_save, trace_unit | ||
>>>>>>> subsets | ||
) | ||
header = [ | ||
"Episode Number", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
from scipy import io | ||
import os | ||
import json | ||
<<<<<<< HEAD | ||
======= | ||
import pickle | ||
from ..utils.tools import parse_filename | ||
>>>>>>> subsets | ||
|
||
|
||
def save_metadata(data, filename): | ||
|
@@ -96,8 +101,13 @@ def save_data(data, filename="", filetype="mat", save_piezo=True, save_command=T | |
save_piezo=save_piezo, | ||
save_command=save_command, | ||
) | ||
<<<<<<< HEAD | ||
# elif filetype == "pkl": | ||
# return_status = save_pickle(data=data, filepath=filepath) | ||
======= | ||
elif filetype == "pkl": | ||
return_status = save_pickle(data=data, filepath=filepath) | ||
>>>>>>> subsets | ||
else: | ||
print('Can only save as ".mat"!') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or as ".pkl" now :). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, actually no. The save_pickle function this is referring to is still commented out. Nevermind! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed it again |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as
if self.idealization(episode.n_episode):
so you don't have to useis not None
at the end. Python treatsNone
as well as empty list ([]
) and empty string (''
) asFalse
in this context.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Maybe I put an explanatory comment.