Skip to content
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

Load templates as memmap rather than in memory #167

Merged
merged 8 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions src/MEArec/simulate_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def calc_extracellular(
if verbose >= 1:
print(f"Done generating EAPs for {cell_name}")

saved_eaps = np.array(saved_eaps)
saved_eaps = np.array(saved_eaps, dtype=np.float32)
saved_positions = np.array(saved_positions)
saved_rotations = np.array(saved_rotations)

Expand Down Expand Up @@ -1268,14 +1268,14 @@ def check_solidangle(matrix, pre, post, polarlim):
cell.set_rotation(x=x_rot, y=y_rot, z=z_rot)
rot = [x_rot, y_rot, z_rot]

lfp = electrodes.get_transformation_matrix() @ cell.imem
lfp = np.array(electrodes.get_transformation_matrix() @ cell.imem, dtype=np.float32)

# Reverse rotation to bring cell back into initial rotation state
if rotation is not None:
rev_rot = [-r for r in rot]
cell.set_rotation(rev_rot[0], rev_rot[1], rev_rot[2], rotation_order="zyx")

return 1000 * lfp, pos, rot, found_position
return 1e3 * lfp, pos, rot, found_position


def str2bool(v):
Expand Down
13 changes: 10 additions & 3 deletions src/MEArec/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def load_tmp_eap(templates_folder, celltypes=None, samples_per_cat=None, verbose
print("loading cell type: ", f)
if celltypes is not None:
if celltype in celltypes:
eaps = np.load(str(eaplist[idx]))
eaps = np.load(str(eaplist[idx]), mmap_mode="r")
locs = np.load(str(loclist[idx]))
rots = np.load(str(rotlist[idx]))

Expand All @@ -230,7 +230,7 @@ def load_tmp_eap(templates_folder, celltypes=None, samples_per_cat=None, verbose
else:
ignored_categories.add(celltype)
else:
eaps = np.load(str(eaplist[idx]))
eaps = np.load(str(eaplist[idx]), mmap_mode="r")
locs = np.load(str(loclist[idx]))
rots = np.load(str(rotlist[idx]))

Expand All @@ -245,10 +245,17 @@ def load_tmp_eap(templates_folder, celltypes=None, samples_per_cat=None, verbose
cat_list.extend([celltype] * samples_to_read)
loaded_categories.add(celltype)

if len(eap_list) > 0:
all_eaps = np.lib.format.open_memmap(templates_folder / "all_eaps.npy", mode="w+", dtype=eaps[0].dtype, shape=(len(eap_list), *eap_list[0].shape))
for i in range(len(eap_list)):
all_eaps[i, ...] = eap_list[i]
else:
all_eaps = np.array([])

if verbose:
print("Done loading spike data ...")

return np.array(eap_list), np.array(loc_list), np.array(rot_list), np.array(cat_list, dtype=str)
return all_eaps, np.array(loc_list), np.array(rot_list), np.array(cat_list, dtype=str)


def load_templates(templates, return_h5_objects=True, verbose=False, check_suffix=True):
Expand Down
Loading