From edf9f01e8547fd6f148e812e8d25d6313bf1112e Mon Sep 17 00:00:00 2001 From: cdpaiva Date: Sun, 5 Oct 2025 16:54:35 -0400 Subject: [PATCH 1/3] chore: update env name --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index cd1ea69..6efb9e8 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,4 @@ -name: snazzy-test-env +name: snazzy-env channels: - conda-forge - defaults From a4e0b585c91f35de7ca23bd004fd30a68d80d0f7 Mon Sep 17 00:00:00 2001 From: cdpaiva Date: Sun, 5 Oct 2025 16:56:51 -0400 Subject: [PATCH 2/3] fix: convert tif pages to expected shape --- snazzy_processing/snazzy_processing/slice_img.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/snazzy_processing/snazzy_processing/slice_img.py b/snazzy_processing/snazzy_processing/slice_img.py index 0516384..753c41f 100644 --- a/snazzy_processing/snazzy_processing/slice_img.py +++ b/snazzy_processing/snazzy_processing/slice_img.py @@ -60,7 +60,11 @@ def save_first_frames_as_tiff(file: Path, dest_path: Path, n: int): print(f"File '{dest.name}' already exists.") return if file.suffix == ".tif" or file.suffix == ".tiff": - initial_frames = imread(file, key=slice(0, n)) + # tiffile will slice over pages, so we need to reshape + initial_frames = imread(file, key=slice(0, 2 * n)) + _, y, x = initial_frames.shape + initial_frames = np.reshape(initial_frames, (n, 2, y, x)) + imwrite(dest_path, initial_frames) else: with ND2File(file) as f: @@ -426,6 +430,7 @@ def get_first_image(img_path: Path): The channel 2 frames are averaged and equalized, for better visualization.""" img = imread(img_path) + print(img.shape) first_frame = np.average(img[:, 1, :, :], axis=0) return equalize_hist(first_frame) From 26c5d05828817876c406dba98df537c93c6e0bc3 Mon Sep 17 00:00:00 2001 From: cdpaiva Date: Sun, 5 Oct 2025 16:57:38 -0400 Subject: [PATCH 3/3] feat: simplify required data --- .../snazzy-processing-pipeline.ipynb | 56 +++++++------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/snazzy_processing/notebooks/snazzy-processing-pipeline.ipynb b/snazzy_processing/notebooks/snazzy-processing-pipeline.ipynb index 0afb9f0..9d43cd5 100644 --- a/snazzy_processing/notebooks/snazzy-processing-pipeline.ipynb +++ b/snazzy_processing/notebooks/snazzy-processing-pipeline.ipynb @@ -8,7 +8,12 @@ "\n", "Integrates all of the modules from the package, to go from raw data to csv output.\n", "More information about each module can be found in the other Jupyter Notebooks.\n", - "You should change the `experiment name` and the `img_path` at the fist cell." + "You should change the `experiment name` and the `img_path` at the fist cell.\n", + "\n", + "If the raw data is in nd2 format, it can be converted directly using the pipeline.\n", + "For other formats, the image must me converted to tif using another application, for example ImageJ.\n", + "\n", + "Adjust the image paths to where the nd2 file is, and where the tif file will be saved." ] }, { @@ -27,38 +32,14 @@ "\n", "from snazzy_processing import pipeline, slice_img\n", "\n", - "experiment_name = '20240611_25C'\n", + "experiment_name = '20240611'\n", "root_dir = Path.cwd().parent\n", "project_dir = root_dir.joinpath('data', experiment_name)\n", "res_dir = root_dir.joinpath('results', experiment_name)\n", "res_dir.mkdir(parents=True, exist_ok=True)\n", "\n", - "# Provide an absolute path for the raw tif image\n", - "# If you are starting with another image format, ignore this line and convert the\n", - "# image in the next cell\n", - "img_path = ''" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If the raw data is in nd2 format, it must first be converted to a tif file, and that tif file should be used in the other cells of this jupyter notebook.\n", - "\n", - "Adjust the image paths to where the nd2 file is, and where the tif file will be saved." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "base_path = Path.home()\n", - "# Path where the raw image is located:\n", - "nd2_path = base_path.joinpath(\"Documents\", \"raw_data\", f\"{experiment_name}.nd2\")\n", - "# Path where the new tiff file will be saved:\n", - "img_path = base_path.joinpath(\"Documents\", \"raw_data\", f\"{experiment_name}.tif\")" + "# Provide an absolute path for the raw tif or nd2 image\n", + "img_path = Path.home().joinpath(\"Documents\", \"raw_data\", f\"{experiment_name}.nd2\")" ] }, { @@ -74,13 +55,12 @@ "metadata": {}, "outputs": [], "source": [ - "first_frames = f\"first_frames.tif\"\n", + "first_frames = \"first_frames.tif\"\n", "first_frames_path = root_dir.joinpath(\"results\", experiment_name, first_frames)\n", "if first_frames_path.exists():\n", " print(f\"{first_frames_path.stem} already exists.\\nPlease choose another path.\")\n", "else:\n", - " file_path = nd2_path if nd2_path else img_path\n", - " slice_img.save_first_frames_as_tiff(file_path, first_frames_path, 10)" + " slice_img.save_first_frames_as_tiff(img_path, first_frames_path, 10)" ] }, { @@ -103,11 +83,11 @@ "img = slice_img.get_first_image(first_frames_path)\n", "\n", "coords = slice_img.calculate_slice_coordinates(\n", - " first_frames_path, n_cols=4, thres_adjust=-5\n", + " first_frames_path, n_cols=2, thres_adjust=-10\n", ")\n", "\n", "# If necessary, manually change the bboxes size by changing w and h:\n", - "boundaries = slice_img.increase_bbox(coords, w=150, h=40, shape=img.shape)\n", + "boundaries = slice_img.increase_bbox(coords, w=190, h=40, shape=img.shape)\n", "\n", "rect_coords = [slice_img.boundary_to_rect_coords(b) for b in boundaries.values()]\n", "recs = [Rectangle((y, x), w, h) for (x, y, w, h) in rect_coords]\n", @@ -159,7 +139,7 @@ "clean_up_data = False\n", "# List of the ids of the embryos that should be processed\n", "# The ids are the bbox numbers from the previous cell output\n", - "embryos = [1, 2, 3, 4, 5]\n", + "embryos = []\n", "# Interval (number of frames) used to calculate VNC length\n", "vnc_length_interval = 10\n", "# Window (number of frames) to calculate VNC ROI (which is then used to calculate activity)\n", @@ -170,9 +150,11 @@ "embs_dest.mkdir(parents=True, exist_ok=True)\n", "\n", "# nd2 to tif\n", - "if nd2_path:\n", + "if img_path.suffix == \".nd2\":\n", " print(\"Converting from nd2 to tif\")\n", - " slice_img.save_as_tiff(nd2_path, img_path)\n", + " output_path = img_path.parent.joinpath(f\"{img_path.stem}.tif\")\n", + " slice_img.save_as_tiff(img_path, output_path)\n", + " img_path = output_path\n", "\n", "# tif to individual movies\n", "print(\"Cropping individual movies\")\n", @@ -212,7 +194,7 @@ "# write params used\n", "output_path = root_dir.joinpath(\"results\", experiment_name, \"params.txt\")\n", "pipeline.log_params(\n", - " path=output_path,\n", + " output_path=output_path,\n", " experiment_name=experiment_name,\n", " embryos=embryos,\n", " window=window,\n",