Skip to content

Commit

Permalink
Merge pull request #33 from AminAlam/dev
Browse files Browse the repository at this point in the history
multiple small bugs fixed
  • Loading branch information
AminAlam authored Jan 15, 2024
2 parents 3bd7d77 + c81ef55 commit 1e4794c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,5 @@ docs/source/_static
docs/source/_templates
docs/*.bat
docs/Makefile

paradigm.sh
3 changes: 2 additions & 1 deletion elecphys/data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def load_all_npz_files(npz_folder: str, ignore_channels: [
else:
data, _ = load_npz(npz_file_path)
data_all[ch_indx, :] = data
ch_indx += 1
return data_all, fs


Expand Down Expand Up @@ -164,4 +165,4 @@ def write_separate_npz_files(
Warning(f'{output_npz_folder} already exists. Files will be overwritten.')
for ch_indx in range(data.shape[0]):
np.savez(os.path.join(output_npz_folder,
f'Ch{ch_indx}.npz'), data=data[ch_indx, :], fs=fs)
f'Ch{ch_indx+1}.npz'), data=data[ch_indx, :], fs=fs)
3 changes: 0 additions & 3 deletions elecphys/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def re_reference(data: np.ndarray, ignore_channels: [
channels_list = [i for i in range(data.shape[0])]

rr_channel = rr_channel - 1 if rr_channel is not None else None

data_rereferenced = data.copy()

if rr_channel is not None:
reference = data[rr_channel, :].reshape(1, -1)
data_rereferenced[channels_list, :] = data[channels_list,
Expand All @@ -202,5 +200,4 @@ def re_reference(data: np.ndarray, ignore_channels: [
reference = np.mean(data[channels_list, :], axis=0).reshape(1, -1)
data_rereferenced[channels_list, :] = data[channels_list,
:] - np.repeat(reference, len(channels_list), axis=0)

return data_rereferenced
1 change: 1 addition & 0 deletions elecphys/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def sort_file_names(file_names: list) -> list:
file_names: list
sorted list of file names
"""
file_names = keep_npz_files(file_names)
file_names_with_number = []
file_names_without_number = []
for file_name in file_names:
Expand Down
9 changes: 7 additions & 2 deletions elecphys/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def plot_stft_from_array(Zxx: np.ndarray, t: np.ndarray, f: np.ndarray, f_min: i
f = f[desired_freq_index_low:desired_freq_index_high]
t = t[desired_time_index_low:desired_time_index_high]

plt.figure(figsize=(30, 15))
pc = plt.pcolormesh(t, f, Zxx, cmap=plt.get_cmap('jet'), shading='auto')
plt.colorbar(pc)
plt.xlabel('Time (s)')
Expand Down Expand Up @@ -234,6 +235,7 @@ def plot_signals_from_npz(npz_folder_path: str, output_plot_file: str, t_min: fl
"""

npz_files = os.listdir(npz_folder_path)
# remove non-NPZ files
npz_files = utils.sort_file_names(npz_files)

if channels_list is None:
Expand Down Expand Up @@ -308,6 +310,8 @@ def plot_signals_from_npz(npz_folder_path: str, output_plot_file: str, t_min: fl
ax[row_no].tick_params(axis='both', which='both', length=0)
ax[row_no].set_yticks([])
ax[row_no].set_xlim(t_min, t_max)
if row_no != len(channels_list) - 1:
ax[row_no].set_xticks([])
else:
scale_bar_size = np.max(signal_chan) - np.min(signal_chan)
ax[row_no, 0].plot(t, signal_chan, color='k')
Expand All @@ -325,8 +329,9 @@ def plot_signals_from_npz(npz_folder_path: str, output_plot_file: str, t_min: fl
1 / fs, 0, f'{scale_bar_size:.2f} uV', ha='left')
ax[row_no, 1].axis('off')
ax[row_no, 0].set_xlim(t_min, t_max)
ax[row_no, 0].set_xticks([])
ax[row_no, 1].set_xticks([])
if row_no != len(channels_list) - 1:
ax[row_no, 0].set_xticks([])
ax[row_no, 1].set_xticks([])

if not scale_bar:
ax[-1].set_xlabel('Time (s)')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read_description():

setup(
name="ElecPhys",
version="0.0.6",
version="0.0.53",
author='Amin Alam',
description='Electrophysiology data processing',
long_description=read_description(),
Expand Down

0 comments on commit 1e4794c

Please sign in to comment.