From 705e02fd06ef4b234c550ee32214eedc9936f7d4 Mon Sep 17 00:00:00 2001 From: Matteo Visconti di Oleggio Castello Date: Tue, 3 Oct 2023 13:17:10 -0700 Subject: [PATCH 1/2] ENH allow setting curvature values when starting webgl viewer --- cortex/webgl/view.py | 52 +++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/cortex/webgl/view.py b/cortex/webgl/view.py index f633cb19..55ec77cc 100644 --- a/cortex/webgl/view.py +++ b/cortex/webgl/view.py @@ -1,27 +1,29 @@ -import os -import glob +import binascii import copy -import json -import time -# Now assumes python 3 -from queue import Queue -from configparser import NoOptionError -import shutil -import random import functools -import binascii +import glob +import json import mimetypes +import os +import random +import shutil import threading +import time import warnings import webbrowser +from configparser import NoOptionError + +# Now assumes python 3 +from queue import Queue + import numpy as np from tornado import web -from .FallbackLoader import FallbackLoader -from .. import utils, options, volume, dataset +from .. import dataset, options, utils, volume from ..database import db from . import serve from .data import Package +from .FallbackLoader import FallbackLoader try: cmapdir = options.config.get('webgl', 'colormaps') @@ -235,7 +237,11 @@ def show(data, types=("inflated", ), recache=False, cmap='RdBu_r', layout=None, autoclose=None, open_browser=None, port=None, pickerfun=None, template="mixer.html", overlays_available=None, overlays_visible=('rois', 'sulci'), labels_visible=('rois', ), - overlay_file=None, title='Brain', **kwargs): + overlay_file=None, + curvature_brightness=None, + curvature_smoothness=None, + curvature_contrast=None, + title='Brain', **kwargs): """ Creates a webGL MRI viewer that is dynamically served by a tornado server running inside the current python process. @@ -287,6 +293,15 @@ def show(data, types=("inflated", ), recache=False, cmap='RdBu_r', layout=None, overlay_file : str or None, optional Custom overlays.svg file to use instead of the default one for this subject (if not None). Default None. + curvature_brightness : float or None, optional + Brightness of curvature overlay. Default None, which uses the value + specified in the config file. + curvature_smoothness : float or None, optional + Smoothness of curvature overlay. Default None, which uses the value + specified in the config file. + curvature_contrast : float or None, optional + Contrast of curvature overlay. Default None, which uses the value + specified in the config file. title : str, optional The title that is displayed on the viewer website when it is loaded in a browser. @@ -345,9 +360,12 @@ def show(data, types=("inflated", ), recache=False, cmap='RdBu_r', layout=None, my_viewopts = dict(options.config.items('webgl_viewopts')) my_viewopts['overlays_visible'] = overlays_visible my_viewopts['labels_visible'] = labels_visible - my_viewopts['brightness'] = options.config.get('curvature', 'brightness') - my_viewopts['smoothness'] = options.config.get('curvature', 'webgl_smooth') - my_viewopts['contrast'] = options.config.get('curvature', 'contrast') + if curvature_brightness is None: + my_viewopts['brightness'] = options.config.get('curvature', 'brightness') + if curvature_smoothness is None: + my_viewopts['smoothness'] = options.config.get('curvature', 'webgl_smooth') + if curvature_contrast is None: + my_viewopts['contrast'] = options.config.get('curvature', 'contrast') for sec in options.config.sections(): if 'paths' in sec or 'labels' in sec: @@ -824,7 +842,7 @@ def get_local_client(self): return client else: try: - from IPython.display import display, HTML + from IPython.display import HTML, display display(HTML('Open viewer: {0}'.format(url))) except: pass From 0d66ffe9645707feaa64a117ec0339a3ea65b207 Mon Sep 17 00:00:00 2001 From: Matteo Visconti di Oleggio Castello Date: Tue, 3 Oct 2023 13:23:48 -0700 Subject: [PATCH 2/2] Actually set the passed values --- cortex/webgl/view.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cortex/webgl/view.py b/cortex/webgl/view.py index 55ec77cc..fd37d1bd 100644 --- a/cortex/webgl/view.py +++ b/cortex/webgl/view.py @@ -360,12 +360,12 @@ def show(data, types=("inflated", ), recache=False, cmap='RdBu_r', layout=None, my_viewopts = dict(options.config.items('webgl_viewopts')) my_viewopts['overlays_visible'] = overlays_visible my_viewopts['labels_visible'] = labels_visible - if curvature_brightness is None: - my_viewopts['brightness'] = options.config.get('curvature', 'brightness') - if curvature_smoothness is None: - my_viewopts['smoothness'] = options.config.get('curvature', 'webgl_smooth') - if curvature_contrast is None: - my_viewopts['contrast'] = options.config.get('curvature', 'contrast') + my_viewopts['brightness'] = options.config.get('curvature', 'brightness') \ + if curvature_brightness is None else curvature_brightness + my_viewopts['smoothness'] = options.config.get('curvature', 'webgl_smooth') \ + if curvature_smoothness is None else curvature_smoothness + my_viewopts['contrast'] = options.config.get('curvature', 'contrast') \ + if curvature_contrast is None else curvature_contrast for sec in options.config.sections(): if 'paths' in sec or 'labels' in sec: