Skip to content
Snippets Groups Projects
Commit be55e454 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

LUT/ColourMap lookup is now case-insensitive. LUTs can be set by their

key on the command line.
parent 82ec1009
No related branches found
No related tags found
No related merge requests found
......@@ -154,6 +154,28 @@ _cmaps = None
_luts = None
def _caseInsensitiveLookup(d, k, default=None):
"""Performs a case-insensitive lookup on the dictionary ``d``,
with the key ``k``.
"""
v = d.get(k, None)
if v is not None:
return v
keys = d.keys()
lKeys = map(str.lower, keys)
try:
idx = lKeys.index(k.lower())
except:
if default is not None: return default
else: raise KeyError(k)
return d[keys[idx]]
class _Map(object):
"""A little class for storing details on each installed/available
colour map/lookup table. This class is only used internally.
......@@ -275,8 +297,9 @@ class LookupTable(props.HasProperties):
saved = props.Boolean(default=False)
def __init__(self, name, lutFile=None):
def __init__(self, key, name, lutFile=None):
self.key = key
self.name = name
if lutFile is not None:
......@@ -593,11 +616,12 @@ def registerLookupTable(lut,
log.debug('Loading and registering custom '
'lookup table: {}'.format(lutFile))
lut = LookupTable(name, lutFile)
lut = LookupTable(key, name, lutFile)
else:
if key is None: key = lut.name
if name is None: name = key
lut.key = key
lut.name = name
# Even though the lut may have been loaded from
......@@ -622,14 +646,14 @@ def registerLookupTable(lut,
lutChoice = opts.getProp('lut')
lutChoice.addChoice(lut,
label=lut.name,
alternate=[key, name],
alternate=[key],
instance=opts)
# and for any future label overlays
fsldisplay.LabelOpts.lut.addChoice(
lut,
label=lut.name,
alternate=[key, name])
alternate=[key])
return lut
......@@ -641,7 +665,7 @@ def getLookupTables():
def getLookupTable(lutName):
"""Returns the :class:`LutTable` instance of the specified name."""
return _luts[lutName].mapObj
return _caseInsensitiveLookup(_luts, lutName).mapObj
def getColourMaps():
......@@ -651,7 +675,7 @@ def getColourMaps():
def getColourMap(cmapName):
"""Returns the colour map instance of the specified name."""
return _cmaps[cmapName].mapObj
return _caseInsensitiveLookup(_cmaps, cmapName).mapObj
def isColourMapRegistered(cmapName):
......
......@@ -13,11 +13,12 @@ import fsl.fslview.colourmaps as fslcm
luts = fslcm.getLookupTables()
names = [l.name for l in luts]
names = [l.name for l in luts]
alts = [[l.key] for l in luts]
class LabelOpts(volumeopts.ImageOpts):
lut = props.Choice(luts, names)
lut = props.Choice(luts, labels=names, alternates=alts)
outline = props.Boolean(default=False)
outlineWidth = props.Real(minval=0, maxval=1, default=0.25, clamped=True)
showNames = props.Boolean(default=False)
......
......@@ -346,7 +346,16 @@ EXTRA = td.TypeDict({
'default' : fsldisplay.ALL_OVERLAY_TYPES[0]},
'LabelOpts.lut' : {
'choices' : [l.name for l in colourmaps.getLookupTables()]
# The LabelOpts.lut choice property has
# LookupTable instances as values, which
# obviously cannot be passed in on the
# command line. But the lut property will
# also accept the lut key as an alternate
# value, so we accept these on the command
# line instead. See the colourmaps and
# labelopts modules for more detail.
'choices' : [],
'useAlts' : True
}
})
......@@ -362,10 +371,6 @@ EXTRA = td.TypeDict({
def _imageTrans(i):
if i == 'none': return None
else: return i.dataSource
def _lutTrans(i):
if isinstance(i, basestring): return colourmaps.getLookupTable(i)
else: return i.name
TRANSFORMS = td.TypeDict({
......@@ -375,8 +380,6 @@ TRANSFORMS = td.TypeDict({
'OrthoOpts.showZCanvas' : lambda b: not b,
'OrthoOpts.showLabels' : lambda b: not b,
'LabelOpts.lut' : _lutTrans,
# These properties are handled specially
# when reading in command line arguments -
# the transform function specified here
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment