Skip to content

Commit

Permalink
Merge commit '7cade60719eb972594b2ea0644a9667cb8c1ad2f' into code-cle…
Browse files Browse the repository at this point in the history
…anup
  • Loading branch information
lauraporta committed Dec 12, 2023
2 parents 59f7b45 + 7cade60 commit 1192ef1
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions examples/derotation_slurm_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import os
import sys
from pathlib import Path

import yaml

from derotation.analysis.full_rotation_pipeline import FullPipeline
from derotation.analysis.incremental_rotation_pipeline import (
IncrementalPipeline,
)

job_id = int(sys.argv[1:][0])
dataset_path = sys.argv[1:][1]
datasets = [path for path in os.listdir(dataset_path) if path.startswith("23")]
dataset = datasets[job_id]

bin_files = [
file
for file in os.listdir(f"{dataset_path}/{dataset}/aux_stim/")
if file.endswith(".bin")
]
full_rotation_bin = [file for file in bin_files if "_rotation" in file][0]
incremental_bin = [file for file in bin_files if "increment" in file][0]

image_files = [
file
for file in os.listdir(f"{dataset_path}/{dataset}/imaging/")
if file.endswith(".tif")
]
full_rotation_image = [file for file in image_files if "rotation_0" in file][0]
incremental_image = [file for file in image_files if "increment_0" in file][0]

# make debug_plots and logs and derotated folder in dataset
Path(f"{dataset_path}/{dataset}/debug_plots_incremental/").mkdir(
parents=True, exist_ok=True
)
Path(f"{dataset_path}/{dataset}/debug_plots_full/").mkdir(
parents=True, exist_ok=True
)
Path(f"{dataset_path}/{dataset}/logs/").mkdir(parents=True, exist_ok=True)
Path(f"{dataset_path}/{dataset}/derotated/").mkdir(parents=True, exist_ok=True)

for config_name in ["incremental_rotation", "full_rotation"]:
with open(f"derotation/config/{config_name}.yml") as f:
config = yaml.load(f, Loader=yaml.FullLoader)

config["paths_read"][
"path_to_randperm"
] = f"{dataset_path}/stimlus_randperm.mat"
bin_name = (
incremental_bin
if config_name == "incremental_rotation"
else full_rotation_bin
)
config["paths_read"][
"path_to_aux"
] = f"{dataset_path}/{dataset}/aux_stim/{bin_name}"
image_name = (
incremental_image
if config_name == "incremental_rotation"
else full_rotation_image
)
config["paths_read"][
"path_to_tif"
] = f"{dataset_path}/{dataset}/imaging/{image_name}"
config["paths_write"][
"debug_plots_folder"
] = f"{dataset_path}/{dataset}/debug_plots_{config_name.split('_')[0]}"
config["paths_write"]["logs_folder"] = f"{dataset_path}/{dataset}/logs/"
config["paths_write"][
"derotated_tiff_folder"
] = f"{dataset_path}/{dataset}/derotated/"
config["paths_write"][
"saving_name"
] = f"derotated_image_stack_{config_name.split('_')[0]}"

with open(f"derotation/config/{config_name}_{job_id}.yml", "w") as f:
yaml.dump(config, f)


derotate = IncrementalPipeline(f"incremental_rotation_{job_id}")
derotate()

derotate_full = FullPipeline(f"full_rotation_{job_id}")
derotate_full()

0 comments on commit 1192ef1

Please sign in to comment.