Skip to content

Commit

Permalink
Merge branch 'main' into watcher_skip
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong authored Jul 26, 2023
2 parents 38dd7de + 9b3155f commit 242f8a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/toffy/rosetta.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,16 @@ def rescale_raw_imgs(img_out_dir, scale=200):
fov_dir = os.path.join(img_out_dir, fov)
# create subdirectory for the new images
sub_dir = os.path.join(fov_dir, "rescaled")
os.makedirs(sub_dir)
if not os.path.exists(sub_dir):
os.makedirs(sub_dir)
chans = io_utils.list_files(fov_dir)
# rescale each channel image
for chan in chans:
img = io.imread(os.path.join(fov_dir, chan))
img = (img / scale).astype("float32")
fname = os.path.join(sub_dir, chan)
image_utils.save_image(fname, img)
if not os.path.exists(fname):
img = io.imread(os.path.join(fov_dir, chan))
img = (img / scale).astype("float32")
image_utils.save_image(fname, img)


def generate_rosetta_test_imgs(
Expand Down
8 changes: 8 additions & 0 deletions tests/rosetta_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import os
import tempfile
import time
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -639,10 +640,17 @@ def test_rescale_raw_imgs():

# test successful rescale of data
rescaled_img_data = load_utils.load_imgs_from_tree(temp_dir, "rescaled")
create_time = Path(os.path.join(temp_dir, fovs[0], "rescaled")).stat().st_ctime
assert rescaled_img_data.all() == (img_data / 200).all()

assert rescaled_img_data.dtype == "float32"

# re-run function and check the files are not re-written
time.sleep(3)
rosetta.rescale_raw_imgs(temp_dir)
modify_time = Path(os.path.join(temp_dir, fovs[0], "rescaled")).stat().st_mtime
assert np.isclose(modify_time, create_time)


def create_rosetta_comp_structure(
raw_data_dir,
Expand Down

0 comments on commit 242f8a9

Please sign in to comment.