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

feat(io.utils): use user-specified nd2 files #11

Merged
merged 1 commit into from
May 22, 2024
Merged
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
45 changes: 32 additions & 13 deletions suite2p/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,41 @@ def get_nd2_list(ops):
if ops["look_one_level_down"], then all nd2"s in all folders + one level down
"""
froot = ops["data_path"]
fold_list = ops["data_path"]
fsall = []
nfs = 0
first_tiffs = []
for k, fld in enumerate(fold_list):
fs, ftiffs = list_files(fld, ops["look_one_level_down"], ["*.nd2"])
fsall.extend(fs)
first_tiffs.extend(list(ftiffs))
if len(fs) == 0:
print("Could not find any nd2 files")
raise Exception("no nd2s")
# use a user-specified list of nd2 files (specified in "tiff_list")
if "tiff_list" in ops:
fsall = []
for nd2_file in ops["tiff_list"]:
assert nd2_file.endswith(".nd2"), f"{nd2_file} is not an nd2 file"
fsall.append(os.path.join(froot[0], nd2_file))
ops["first_tiffs"] = np.zeros((len(fsall),), dtype="bool")
ops["first_tiffs"][0] = True
else:
ops["first_tiffs"] = np.array(first_tiffs).astype("bool")
print("** Found %d nd2 files - converting to binary **" % (len(fsall)))
if len(froot) == 1:
if "subfolders" in ops and len(ops["subfolders"]) > 0:
fold_list = []
for folder_down in ops["subfolders"]:
fold = os.path.join(froot[0], folder_down)
fold_list.append(fold)
else:
fold_list = ops["data_path"]
else:
fold_list = froot
fsall = []
nfs = 0
first_tiffs = []
for k, fld in enumerate(fold_list):
fs, ftiffs = list_files(fld, ops["look_one_level_down"], ["*.nd2"])
fsall.extend(fs)
first_tiffs.extend(list(ftiffs))
if len(fs) == 0:
print("Could not find any nd2 files")
raise Exception("no nd2s")
else:
ops["first_tiffs"] = np.array(first_tiffs).astype("bool")
print("** Found %d nd2 files - converting to binary **" % (len(fsall)))
return fsall, ops


def get_dcimg_list(ops):
""" make list of dcimg files to process
if ops["look_one_level_down"], then all dcimg"s in all folders + one level down
Expand Down
Loading