Created
March 19, 2018 13:21
-
-
Save veggiesaurus/a147ee8df48ef1e42199b2b18a8d2422 to your computer and use it in GitHub Desktop.
Python code for loading files from notebook
This file contains hidden or 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
import IPython | |
def getViewerURL(file, subdir, cmap, range, imageWidth): | |
serverUrl = "https://viewer.idia.ac.za?" | |
if (len(subdir)): | |
serverUrl += "subdir={}&".format(subdir) | |
if (len(file)): | |
serverUrl += "file={}&".format(file) | |
if (len(cmap)): | |
serverUrl += "cmap={}&".format(cmap) | |
if (range>0): | |
serverUrl += "range={}&".format(range) | |
if (imageWidth!= 640): | |
serverUrl += "width={}&".format(imageWidth) | |
return serverUrl | |
def showViewer(file="", subdir="", cmap="", range=0, imageWidth=640, frameHeight=800): | |
serverUrl = getViewerURL(file, subdir, cmap, range, imageWidth) | |
iframe = "<iframe src={} width=100% height={}></iframe>".format(serverUrl, frameHeight) | |
outputFrame = IPython.display.HTML(iframe) | |
return outputFrame | |
def showViewerUrl(file="", subdir="", cmap="", range=0, imageWidth=640): | |
serverUrl = getViewerURL(file, subdir, cmap, range, imageWidth) | |
outputFrame = IPython.display.HTML("<a target='_blank' href={}>Viewer</a>".format(serverUrl)) | |
return outputFrame | |
def openViewerNewTab(file="", subdir="", cmap="", range=0, imageWidth=640): | |
serverUrl = getViewerURL(file, subdir, cmap, range, imageWidth) | |
s = '<script type="text/Javascript">' | |
s += 'window.open("{}");'.format(serverUrl) | |
s += '</script>' | |
return IPython.display.HTML(s) | |
# parameters: | |
# file: the file to load | |
# subdir: limit the file list to a specific subdirectory that the viewer server is watching | |
# cmap: the colour map to use | |
# range: the percentile range to use | |
# imageWidth: the width of the image display in the viewer | |
# (notebook cell only) frameHeight: the height of the output cell in notebook | |
# example use: | |
# | |
# Generates a clickable link to the viewer based on input parameter. | |
# showViewerUrl(file="LMCq.hdf5", subdir="angus", cmap="viridis", range=99.9) | |
# | |
# Opens the viewer in a new tab (popup blocking will have to be disabled for the notebook domain | |
# openViewerNewTab(subdir="angus", cmap="viridis", range=99.9) | |
# | |
# Opens the viewer in the notebook itself as an output | |
# showViewer(file="LMCq.hdf5", subdir="angus", cmap="viridis", range=99.9) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment