Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Jul 1, 2024
1 parent c19e091 commit 089bb11
Show file tree
Hide file tree
Showing 12 changed files with 1,204 additions and 71 deletions.
41 changes: 26 additions & 15 deletions derotation/analysis/full_rotation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sklearn.mixture import GaussianMixture
from tifffile import imsave

from derotation.derotate_by_line import rotate_an_image_array_line_by_line
from derotation.derotate_by_line_plot import rotate_an_image_array_line_by_line
from derotation.load_data.custom_data_loaders import (
get_analog_signals,
read_randomized_stim_table,
Expand Down Expand Up @@ -55,7 +55,7 @@ def __call__(self):
- adding a circular mask to the rotated image stack
- saving the masked image stack
"""
self.contrast_enhancement()
# self.contrast_enhancement()
self.process_analog_signals()
rotated_images = self.rotate_frames_line_by_line()
masked = self.add_circle_mask(rotated_images, self.mask_diameter)
Expand Down Expand Up @@ -236,18 +236,29 @@ def process_analog_signals(self):
)
self.rotation_on = self.create_signed_rotation_array()

self.drop_ticks_outside_of_rotation()
if self.adjust_increment:
self.drop_ticks_outside_of_rotation()
self.check_number_of_rotations()

self.check_number_of_rotations()
if not self.is_number_of_ticks_correct() and self.adjust_increment:
(
self.corrected_increments,
self.ticks_per_rotation,
) = self.adjust_rotation_increment()
if not self.is_number_of_ticks_correct():
(
self.corrected_increments,
self.ticks_per_rotation,
) = self.adjust_rotation_increment()
else:
self.corrected_increments = [
self.rotation_increment
] * self.number_of_rotations
self.ticks_per_rotation = (
self.rot_deg
* self.rotation_increment
* self.number_of_rotations
)

self.interpolated_angles = self.get_interpolated_angles()

self.remove_artifacts_from_interpolated_angles()
if self.adjust_increment:
self.remove_artifacts_from_interpolated_angles()

(
self.line_start,
Expand Down Expand Up @@ -419,7 +430,7 @@ def drop_ticks_outside_of_rotation(self) -> np.ndarray:

inter_roatation_interval = [
idx
for i in range(self.number_of_rotations + 1)
for i in range(len(edited_ends))
for idx in range(
edited_ends[i],
rolled_starts[i],
Expand Down Expand Up @@ -457,8 +468,8 @@ def check_number_of_rotations(self):
raise ValueError(
"Start and end of rotations have different lengths"
)
if self.rot_blocks_idx["start"].shape[0] != self.number_of_rotations:
raise ValueError("Number of rotations is not as expected")
# if self.rot_blocks_idx["start"].shape[0] != self.number_of_rotations:
# raise ValueError("Number of rotations is not as expected")

logging.info("Number of rotations is as expected")

Expand Down Expand Up @@ -550,7 +561,7 @@ def get_interpolated_angles(self) -> np.ndarray:

ticks_with_increment = [
item
for i in range(self.number_of_rotations)
for i in range(len(self.corrected_increments))
for item in [self.corrected_increments[i]]
* self.ticks_per_rotation[i]
]
Expand Down Expand Up @@ -599,7 +610,7 @@ def remove_artifacts_from_interpolated_angles(self):
rotation_end = np.where(np.diff(thresholded) < 0)[0]

assert len(rotation_start) == len(rotation_end)
assert len(rotation_start) == self.number_of_rotations
# assert len(rotation_start) == self.number_of_rotations

for i, (start, end) in enumerate(
zip(rotation_start[1:], rotation_end[:-1])
Expand Down
2 changes: 1 addition & 1 deletion derotation/analysis/incremental_rotation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __call__(self):
After processing the analog signals, the image stack is rotated by
frame and then registered using phase cross correlation.
"""
self.contrast_enhancement()
# self.contrast_enhancement()
super().process_analog_signals()
rotated_images = self.roatate_by_frame()
masked_unregistered = self.add_circle_mask(rotated_images)
Expand Down
47 changes: 27 additions & 20 deletions derotation/config/full_rotation.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
paths_read:
path_to_randperm: "your_path_to/stimlus_randperm.mat"
path_to_aux: "your_path_to/rotation.bin"
path_to_tif: "your_path_to/rotation.tif"
path_to_randperm: /Users/lauraporta/local_data/rotation/stimlus_randperm.mat
path_to_aux: /Users/lauraporta/local_data/rotation/230731_25_micron_grid/aux_stim/230731_grid_1_001.bin
path_to_tif: /Users/lauraporta/local_data/rotation/230731_25_micron_grid/imaging/rotation_zf2_all_speeds_00002_enhanced.tif
paths_write:
debug_plots_folder: "your_path_to/debug_plots/"
logs_folder: "your_path_to/logs/"
derotated_tiff_folder: "your_path_to/data_folder/"
saving_name: "derotated_image_stack"
debug_plots_folder: /Users/lauraporta/local_data/rotation/230731_25_micron_grid/full/debug_plots/
logs_folder: /Users/lauraporta/local_data/rotation/230731_25_micron_grid/full/logs/
derotated_tiff_folder: /Users/lauraporta/local_data/rotation/230731_25_micron_grid/full/derotated/
saving_name: derotated_image_stack_CE
# paths_read:
# path_to_randperm: /Users/lauraporta/local_data/rotation/stimlus_randperm.mat
# path_to_aux: /Users/lauraporta/local_data/rotation/230802_CAA_1120182/aux_stim/230802_CAA_1120182_rotation_1_001.bin
# path_to_tif: /Users/lauraporta/local_data/rotation/230802_CAA_1120182/imaging/rotation_00001.tif
# paths_write:
# debug_plots_folder: /Users/lauraporta/local_data/rotation/230802_CAA_1120182/full/debug_plots/
# logs_folder: /Users/lauraporta/local_data/rotation/230802_CAA_1120182/full/logs/
# derotated_tiff_folder: /Users/lauraporta/local_data/rotation/230802_CAA_1120182/full/derotated/
# saving_name: derotated_image_stack_NO_ce


channel_names: [
"camera",
"scanimage_frameclock",
"scanimage_lineclock",
"photodiode2",
"PI_rotON",
"PI_rotticks",
]
channel_names:
- camera
- scanimage_frameclock
- scanimage_lineclock
- photodiode2
- PI_rotON
- PI_rotticks

rotation_increment: 0.2
adjust_increment: True
adjust_increment: false
rot_deg: 360

debugging_plots: True
debugging_plots: false

contrast_enhancement: 0.35

Expand All @@ -35,5 +42,5 @@ analog_signals_processing:
angle_interpolation_artifact_threshold: 0.15

interpolation:
line_use_start: True
frame_use_start: True
line_use_start: true
frame_use_start: true
16 changes: 8 additions & 8 deletions derotation/config/incremental_rotation.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
paths_read:
path_to_randperm: "your_path_to/stimlus_randperm.mat"
path_to_aux: "your_path_to/rotation.bin"
path_to_tif: "your_path_to/rotation.tif"
path_to_randperm: "/Users/lauraporta/local_data/rotation/stimlus_randperm.mat"
path_to_aux: "/Users/lauraporta/local_data/rotation/230802_CAA_1120182/aux_stim/230802_CAA_1120182_rotationincrement_1_001.bin"
path_to_tif: "/Users/lauraporta/local_data/rotation/230802_CAA_1120182/imaging/rotation_increment_00001.tif"
paths_write:
debug_plots_folder: "your_path_to/debug_plots/"
logs_folder: "your_path_to/logs/"
derotated_tiff_folder: "your_path_to/data_folder/"
saving_name: "derotated_image_stack"
debug_plots_folder: "/Users/lauraporta/local_data/rotation/230802_CAA_1120182/incremental/debug_plots/"
logs_folder: "/Users/lauraporta/local_data/rotation/230802_CAA_1120182/incremental/logs/"
derotated_tiff_folder: "/Users/lauraporta/local_data/rotation/230802_CAA_1120182/incremental/derotated/"
saving_name: "derotated_incremental_image_stack_NO_ce"


channel_names: [
Expand All @@ -22,7 +22,7 @@ rotation_increment: 0.2
adjust_increment: True
rot_deg: 360

debugging_plots: True
debugging_plots: False

contrast_enhancement: 0.35

Expand Down
Loading

0 comments on commit 089bb11

Please sign in to comment.