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 Channels with . in their name #38

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ scikit-image = "0.*"
xarray = "*"
xmltodict = "^0.13.0"
charset-normalizer = "^2.1.1"
pytest = "^7.4.2"

[tool.poetry.group.test]
optional = true
Expand Down
13 changes: 9 additions & 4 deletions src/alpineer/load_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def load_imgs_from_tree(
raise ValueError(f"No fovs found in directory, {data_dir}")

# If the fov provided is a single string (`fov_1` instead of [`fov_1`])
if type(fovs) is str:
if not isinstance(fovs, list):
fovs = [fovs]
if img_sub_folder is None:
# no img_sub_folder, change to empty string to read directly from base folder
Expand All @@ -139,7 +139,9 @@ def load_imgs_from_tree(
# otherwise, fill channel names with correct file extension
elif not all([img.endswith(tuple(EXTENSION_TYPES["IMAGE"])) for img in channels]):
# need this to reorder channels back because list_files may mess up the ordering
channels_no_delim = [os.path.splitext(img)[0] for img in channels]
# channels_no_delim = [os.path.splitext(img)[0] for img in channels]
srivarra marked this conversation as resolved.
Show resolved Hide resolved

channels_no_delim = io_utils.remove_file_extensions(channels)

all_channels = io_utils.list_files(
dir_name=os.path.join(data_dir, fovs[0], img_sub_folder),
Expand All @@ -148,10 +150,13 @@ def load_imgs_from_tree(
)

# get the corresponding indices found in channels_no_delim
channels_indices = [channels_no_delim.index(chan.split(".")[0]) for chan in all_channels]
channels_indices = [
channels_no_delim.index(io_utils.remove_file_extensions([chan])[0])
for chan in all_channels
]

# verify if channels from user input are present in `all_channels`
all_channels_no_delim = [channel.split(".")[0] for channel in all_channels]
all_channels_no_delim = io_utils.remove_file_extensions(all_channels)

misc_utils.verify_same_elements(
all_channels_in_folder=all_channels_no_delim, all_channels_detected=channels_no_delim
Expand Down
3 changes: 3 additions & 0 deletions tests/load_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def test_load_imgs_from_tree():

fovs, chans, imgs = test_utils.gen_fov_chan_names(num_fovs=3, num_chans=3, return_imgs=True)

chans = [f"{chan}.0" for chan in chans]
imgs = [img.replace(".tiff", ".0.tiff") for img in imgs]

filelocs, data_xr = test_utils.create_paired_xarray_fovs(
temp_dir,
fovs,
Expand Down
Loading