Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions xds_python/xds.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def clean_up_trials(self):
For some trials the timings for trial_start, trial_end or trial_gocue are nans.
This function will get rid of these trials.

Trials with invalid timings will also be removed.

Returns
-------
None.
Expand All @@ -189,6 +191,13 @@ def clean_up_trials(self):
end_nan_idx = np.argwhere(np.isnan(trial_end_time))[:,0]
union_nan_idx = np.asarray(sorted(list(set(gocue_nan_idx).union(set(start_nan_idx)).union(set(end_nan_idx))),
reverse = True))
start_early_idx = np.argwhere(trial_start_time < self.time_frame[0])[:,0]
end_late_idx = np.argwhere(trial_end_time > self.time_frame[-1])[:,0]
union_invalid_idx = np.asarray(sorted(list(set(start_early_idx).union(set(end_late_idx))),
reverse = True))

union_nan_idx = np.asarray(sorted(list(set(union_nan_idx).union(set(union_invalid_idx))),
reverse = True))
if len(union_nan_idx)>0:
self.trial_gocue_time = np.delete(self.trial_gocue_time, union_nan_idx, axis = 0)
self.trial_start_time = np.delete(self.trial_start_time, union_nan_idx)
Expand Down Expand Up @@ -239,15 +248,16 @@ def compute_movement_onset_time(self, channel = 0, thr = 0.4):
"""
if (hasattr(self, 'curs_p')|hasattr(self, 'kin_p')):
idx = [np.where((self.time_frame > t[0]) & (self.time_frame < t[1]) )[0]
for t in zip(self.trial_start_time, self.trial_end_time)]
# for t in zip(self.trial_start_time, self.trial_end_time)]
for t in zip(self.trial_gocue_time, self.trial_end_time)]
trial_time_frame = [self.time_frame[n] for n in idx]
trial_curs_p = [self.curs_p[n] for n in idx]
idx_onset = find_movement_onset(trial_curs_p, channel, thr)
time_onset = [trial_time_frame[i][idx_onset[i]] for i in range(len(trial_time_frame))]
print('Get the movement onset time!')
self.trial_movement_onset_time = np.array(time_onset).reshape((-1,))
else:
print('There is no force data in this file')
print('There is no movement data in this file')

def get_trials_idx(self, my_type, start_event, time_before_start, end_event = 'end_time', time_after_end = 0, raw_flag = 0, gadget_number = -1):
"""
Expand Down Expand Up @@ -543,7 +553,10 @@ def bin_spikes(self, bin_size, mode = 'center'):
out, _ = np.histogram(bb, bins)
spike_counts.append(out)
bins = bins.reshape((len(bins),1))
return bins[1:], np.asarray(spike_counts).T
bins = bins[1:] - bin_size / 2
bins = bins[1:-1]; spike_counts = np.asarray(spike_counts).T[1:-1, ...]
return bins, spike_counts
# return bins[1:], np.asarray(spike_counts).T

def resample_EMG(self, new_bin_size):
"""
Expand Down
11 changes: 9 additions & 2 deletions xds_python/xds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def parse_meta(raw_meta):
meta['array'] = ''.join([chr(int(each)) for each in np.asarray(raw_meta['array'])])
meta['dateTime'] = ''.join([chr(int(each)) for each in np.asarray(raw_meta['dateTime'])])
meta['processedTime'] = ''.join([chr(int(each)) for each in np.asarray(raw_meta['processedTime'])])
meta['rawFileName'] = ''.join([chr(int(each)) for each in np.asarray(raw_meta['rawFileName'])])
try:
meta['rawFileName'] = ''.join([chr(int(each)) for each in np.asarray(raw_meta['rawFileName'])])
except Exception:
meta['rawFileName'] = ''
meta['task'] = ''.join([chr(int(each)) for each in np.asarray(raw_meta['task'])])
meta['duration'] = np.asarray(raw_meta['duration'])[0][0]
meta['lab'] = np.asarray(raw_meta['lab'])[0][0]
Expand Down Expand Up @@ -127,7 +130,11 @@ def parse_scipy(path, file_name):
parsed = {}
if path[-1] != '/':
path = path + '/'
read_data = sio.loadmat(path + file_name)
try:
read_data = sio.loadmat(path + file_name)
except:
import mat73
read_data = mat73.loadmat(path + file_name)
xds = read_data['xds']

# -------- meta information -------- #
Expand Down