-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_render.py
More file actions
60 lines (43 loc) · 1.92 KB
/
Copy pathbatch_render.py
File metadata and controls
60 lines (43 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Batch-render brainreg scenes to PNG from presets/viewer_presets.json.
Run::
python -m bg_viz_pipeline.scripts.batch_render [--only-subdir ...] [--only-subject ...]
"""
import argparse
import json
from pathlib import Path
from bg_viz_pipeline.lib import core
core.init_brainrender_settings()
ATLAS_NAME = core.DEFAULT_ATLAS_NAME
BASE_DIR = Path("/media/viktor/DataDrive/use_cases")
PRESETS_PATH = Path(__file__).resolve().parents[1] / "presets" / "viewer_presets.json"
def render_one(preset):
settings = core.settings_from_preset(preset, atlas_name=ATLAS_NAME)
core.configure_brainrender(settings)
brainreg_dir = BASE_DIR / settings["brainreg_subdir"]
subject_id = core.subject_from_folder(brainreg_dir)
scene = core.create_scene(settings, title=subject_id, offscreen=True)
core.add_atlas_content(scene, settings)
core.print_root_bounds(scene, subject_id)
core.add_brainreg_overlays(scene, brainreg_dir, settings)
camera = core.apply_view(scene, settings)
scene.title = " | ".join(core.batch_png_title_parts(subject_id, settings))
core.render_scene(scene, camera, interactive=False)
scene.screenshot(name=core.batch_png_filename(subject_id, settings), scale=2)
def main():
parser = argparse.ArgumentParser(description="Render brainreg PNGs from JSON presets.")
parser.add_argument("--only-subdir", help="Filter by BRAINREG_SUBDIR substring")
parser.add_argument("--only-subject", help="Filter by subject id substring")
args = parser.parse_args()
with PRESETS_PATH.open() as f:
presets = json.load(f)
for preset in presets:
subdir = preset["BRAINREG_SUBDIR"]
if args.only_subdir and args.only_subdir not in subdir:
continue
if args.only_subject and args.only_subject not in core.subject_from_folder(Path(subdir)):
continue
render_one(preset)
if __name__ == "__main__":
main()