-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to run derotation in the cluster
- Loading branch information
1 parent
8d1f7db
commit 7cade60
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |