Commit 37c62a17 authored by David E. DeMarle's avatar David E. DeMarle

STYLE changes

ran flake8 on the code to find incompatibilities with Python's pep8
style guide.
TODO: add a commit hook that runs flake8 so we stay clean
parent 662ba5a3
Pipeline #40815 passed with stage
// Add predefined macros for your project here. For example:
// #define THE_ANSWER 42
build/CMakeFiles/3.6.2/CompilerIdC/CMakeCCompilerId.c
build/CMakeFiles/3.6.2/CompilerIdCXX/CMakeCXXCompilerId.cpp
build/CMakeFiles/feature_tests.c
build/CMakeFiles/feature_tests.cxx
\ No newline at end of file
#==============================================================================
# ==============================================================================
# Copyright (c) 2015, Kitware Inc., Los Alamos National Laboratory
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#==============================================================================
# ==============================================================================
"""
Manages the set of one or more fields that go into a layer.
"""
import copy
import numpy as np
class LayerSpec(object):
def __init__(self):
......@@ -47,13 +49,11 @@ class LayerSpec(object):
def addToBaseQuery(self, query):
""" add queries that together define the layer """
#print "ADDBASEQUERY", query
self.dict.update(query)
def addQuery(self, img_type, fieldname, fieldchoice):
""" add a query for a particular field of the layer """
#print "ADDQUERY", img_type, fieldname, fieldchoice
self._fields[img_type] = {fieldname:fieldchoice}
self._fields[img_type] = {fieldname: fieldchoice}
def loadImages(self, store):
"""
......@@ -62,60 +62,39 @@ class LayerSpec(object):
"""
nfields = len(self._fields)
if nfields == 0:
#print "FIND A ", self.dict
img = store.get(self.dict).data
self._addColor(img)
#print "FALLBACK RGB"
else:
for f in self._fields.keys():
query = copy.deepcopy(self.dict)
query.update(self._fields[f])
#print "->>> component, Q:", f, ", ", query
#print "FIND B ", query
foundPaths = store.get(query)
#print "FOUND", foundPaths
if foundPaths == None:
#print "->>> no image found for: ", query
if foundPaths is None:
return
#else:
#print "->>> found something for: ", query
img = foundPaths.data
#print "I", img
if f == 'RGB':
#print "ADD RGB"
self._addColor(img)
elif f == 'Z':
#print "ADD DEPTH"
self._setDepth(img)
elif f == 'VALUE':
#print "ADD VALUES ", img
self._addValues(img);
self._addValues(img)
elif f == 'LUMINANCE':
self._setLuminance(img)
def _setDepth(self, image):
self.depth = image
#print "SETDEPTH"
#print image
#print self.depth
def getDepth(self):
return self.depth
def _addColor(self, image):
self.colors.append(image)
#print "ADDCOLOR"
#print image
#print self.colors
def _addValues(self, image):
self.values.append(image)
#print "ADDVALUE"
#print image
#print self.values
def hasColorArray(self):
return (len(self.colors) > 0)
......@@ -123,18 +102,19 @@ class LayerSpec(object):
def hasValueArray(self):
return (len(self.values) > 0)
# TODO, do we still need indices for the rgb arrays? or would it always be one?
def getColorArray(self, index = 0):
# TODO, do we still need indices for the rgb arrays? or would it always
# be one?
def getColorArray(self, index=0):
c = None
if index < len(self.colors):
c = self.colors[index]
return c
def getValueArray(self, index = 0):
def getValueArray(self, index=0):
v = None
if index < len(self.values):
#print "->>> getValueArray: available ", len(self.values)
# print "->>> getValueArray: available ", len(self.values)
v = self.values[index]
return v
......
#==============================================================================
# ==============================================================================
# Copyright (c) 2015, Kitware Inc., Los Alamos National Laboratory
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#==============================================================================
# ==============================================================================
"""
Interface to OpenEXR library.
TODO: fold this into raster_wrangler.
......@@ -36,6 +38,7 @@ import OpenEXR as oe
import Imath as im
import numpy as np
class OexrCompression:
NONE = 0
RLE = 1
......@@ -44,13 +47,16 @@ class OexrCompression:
PIZ = 4
PXR24 = 5
def save_rgb(image, filePath, comp = OexrCompression.ZIP):
'''Saves the rgb (image) in OpenEXR format. Expects a 3-chan uint32 image.'''
def save_rgb(image, filePath, comp=OexrCompression.ZIP):
'''
Saves the rgb (image) in OpenEXR format. Expects a 3-chan uint32 image.
'''
if len(image.shape) != 3:
raise Exception("Incorrect dimensions!")
h, w, c = image.shape # expects Numpy convention (row, col) -> (height, width)
h, w, c = image.shape
if c != 3:
raise Exception("Incorrect number of channels!")
......@@ -61,9 +67,9 @@ def save_rgb(image, filePath, comp = OexrCompression.ZIP):
try:
header = oe.Header(w, h)
header["channels"] = {"R" : im.Channel(im.PixelType(oe.UINT)),
"G" : im.Channel(im.PixelType(oe.UINT)),
"B" : im.Channel(im.PixelType(oe.UINT))}
header["channels"] = {"R": im.Channel(im.PixelType(oe.UINT)),
"G": im.Channel(im.PixelType(oe.UINT)),
"B": im.Channel(im.PixelType(oe.UINT))}
header['compression'] = im.Compression(comp)
......@@ -71,15 +77,18 @@ def save_rgb(image, filePath, comp = OexrCompression.ZIP):
r_data = image[:, :, 0].tostring()
g_data = image[:, :, 1].tostring()
b_data = image[:, :, 2].tostring()
of.writePixels({"R" : r_data, "G" : g_data, "B" : b_data})
of.writePixels({"R": r_data, "G": g_data, "B": b_data})
of.close()
except:
raise
def save_depth(image, filePath, comp = OexrCompression.ZIP):
'''Saves the zBuffer (image) in OpenEXR format. Expects a 1-chann float32 image.'''
def save_depth(image, filePath, comp=OexrCompression.ZIP):
'''
Saves the zBuffer (image) in OpenEXR format. Expects a 1-chann float32
image.
'''
if len(image.shape) != 2:
raise Exception("Incorrect dimensions!")
......@@ -88,15 +97,15 @@ def save_depth(image, filePath, comp = OexrCompression.ZIP):
raise Exception("Incorrect type!, expected float32")
try:
h, w = image.shape # expects Numpy convention (row, col) -> (height, width)
h, w = image.shape
header = oe.Header(w, h)
header["channels"] = {"Z" : im.Channel(im.PixelType(oe.FLOAT))}
header["channels"] = {"Z": im.Channel(im.PixelType(oe.FLOAT))}
header['compression'] = im.Compression(comp)
of = oe.OutputFile(filePath, header)
image_data = image.tostring()
of.writePixels({"Z" : image_data})
of.writePixels({"Z": image_data})
of.close()
except:
......@@ -127,10 +136,13 @@ def load_rgb(filePath):
B = ifi.channel("B", im.PixelType(ifiType))
ifi.close()
image = np.zeros((h, w, 3), dtype = np.uint32) # order = "C"
image[:, :, 0] = np.core.multiarray.fromstring(R, dtype = np.uint32).reshape(h, w)
image[:, :, 1] = np.core.multiarray.fromstring(G, dtype = np.uint32).reshape(h, w)
image[:, :, 2] = np.core.multiarray.fromstring(B, dtype = np.uint32).reshape(h, w)
image = np.zeros((h, w, 3), dtype=np.uint32) # order = "C"
image[:, :, 0] = np.core.multiarray.fromstring(
R, dtype=np.uint32).reshape(h, w)
image[:, :, 1] = np.core.multiarray.fromstring(
G, dtype=np.uint32).reshape(h, w)
image[:, :, 2] = np.core.multiarray.fromstring(
B, dtype=np.uint32).reshape(h, w)
except:
raise
......@@ -160,8 +172,9 @@ def load_depth(filePath):
Z = ifi.channel("Z", im.PixelType(ifiType))
ifi.close()
image = np.zeros((h, w), dtype = np.float32) # order = "C"
image[:, :] = np.core.multiarray.fromstring(Z, dtype = np.float32).reshape(h, w)
image = np.zeros((h, w), dtype=np.float32) # order = "C"
image[:, :] = np.core.multiarray.fromstring(
Z, dtype=np.float32).reshape(h, w)
except:
raise
......
#==============================================================================
# ==============================================================================
# Copyright (c) 2015, Kitware Inc., Los Alamos National Laboratory
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#==============================================================================
# ==============================================================================
"""
API for creating images that correspond to a set of queries.
Used by viewer primarily.
"""
import abc
import cinema_store
from LayerSpec import *
import LayerSpec
class QueryTranslator(object):
__metaclass__ = abc.ABCMeta
''' Translates UI queries into a set of LayerSpecs. Abstract class, Derive
'''
Translates UI queries into a set of LayerSpecs. Abstract class, Derive
from this class to implement different query specifications. The UI queries
are expected to fully define the image file paths.'''
are expected to fully define the image file paths.
'''
def __init__(self):
self.__store = None
def __loadLayers(self, layers):
''' Loads the required images in the LayerSpec instances.'''
#print "->>> Loading layers, received: ", layers
#send queries to the store to obtain images
# send queries to the store to obtain images
lcnt = 0
for l in range(0,len(layers)):
#print "->>> Loading Image: ", layers[l].dict, " \n", layers[l]._fields
for l in range(0, len(layers)):
layers[l].loadImages(self.__store)
#print "loaded layer", lcnt,
#layers[l].printme()
lcnt +=1
lcnt += 1
@abc.abstractmethod
def __createBaseLayerFromQuery(self, query):
''' Creates a base LayerSpec containing the values that are shared (global) by the
set of user-selected layers (e.g. current time, camera, etc.). This
base LayerSpec will be used as an initial template for all of the LayerSpecs.
Abstract, implement in a derived class.'''
'''
Creates a base LayerSpec containing the values that are shared
(global) by the set of user-selected layers (e.g. current time,
camera, etc.). This base LayerSpec will be used as an initial template
for all of the LayerSpecs. Abstract, implement in a derived class.
'''
return
@abc.abstractmethod
......@@ -72,8 +73,9 @@ class QueryTranslator(object):
@abc.abstractmethod
def translateQuery(self, query):
''' Receives a set of parameters from the UI. The parameters (or UI queries) come in
the following form:
'''
Receives a set of parameters from the UI. The parameters (or UI
queries) come in the following form:
total_query = { "parameter_1" : set([values_of_1]),
"parameter_2" : set([values_of_2]), ... }
......@@ -84,11 +86,13 @@ class QueryTranslator(object):
"theta" : set([0]),
"Slice2" : set([-0.34, -0.1, 0.1]) }
The queries are passed to the LayerSpec instances which then use cinema_store to
parse these queries into image file paths. This method is expected to return a set
of LayerSpecs consisting of all the layers to render (each LayerSpec instance holds
all of its required images). Abstract, implement in a derived class.'''
return [LayerSpec()]
The queries are passed to the LayerSpec instances which then use
cinema_store to parse these queries into image file paths. This method
is expected to return a set of LayerSpecs consisting of all the layers
to render (each LayerSpec instance holds all of its required images).
Abstract, implement in a derived class.
'''
return [LayerSpec.LayerSpec()]
def setStore(self, store):
self.__store = store
......@@ -105,11 +109,11 @@ class QueryTranslator_SpecA(QueryTranslator):
def _QueryTranslator__createBaseLayerFromQuery(self, query):
baseLayer = LayerSpec()
baseLayer = LayerSpec.LayerSpec()
for name in query.keys():
values = query[name]
v = list(iter(values))[0] #no options in query, so only 1 result not many
baseLayer.addToBaseQuery({name:v})
v = list(iter(values))[0] # no options in query, so only 1 result
baseLayer.addToBaseQuery({name: v})
return baseLayer
......
This diff is collapsed.
This diff is collapsed.
#==============================================================================
# ==============================================================================
# Copyright (c) 2015, Kitware Inc., Los Alamos National Laboratory
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#==============================================================================
# ==============================================================================
import cinema_store
import itertools
import json
class Explorer(object):
"""
......@@ -39,12 +40,12 @@ class Explorer(object):
it cares about.
"""
def __init__(self,
def __init__(
self,
cinema_store,
parameters, #these are the things that this explorer is responsible for and their ranges
tracks #the things we pass off values to in order to do the work
):
parameters, # the things that this explorer is responsible for
tracks # the things we pass off values to in order to do the work
):
self.__cinema_store = cinema_store
self.parameters = parameters
self.tracks = tracks
......@@ -55,7 +56,8 @@ class Explorer(object):
def list_parameters(self):
"""
parameters is an ordered list of parameters that the Explorer varies over
parameters is an ordered list of parameters that the Explorer varies
over
"""
return self.parameters
......@@ -63,25 +65,27 @@ class Explorer(object):
""" Give tracks a chance to get ready for a run """
if self.tracks:
for e in self.tracks:
res = e.prepare(self)
e.prepare(self)
def execute(self, desc):
# Create the document/data product for this sample.
doc = cinema_store.Document(desc)
for e in self.tracks:
#print ("EXECUTING track ", e, doc.descriptor)
# print ("EXECUTING track ", e, doc.descriptor)
e.execute(doc)
self.insert(doc)
def explore(self, fixedargs=None):
"""
Explore the problem space to populate the store being careful not to hit combinations
where dependencies are not satisfied.
Fixed arguments are the parameters that we want to hold constant in the exploration.
Explore the problem space to populate the store being careful not to
hit combinations where dependencies are not satisfied.
Fixed arguments are the parameters that we want to hold constant in
the exploration.
"""
self.prepare()
for descriptor in self.cinema_store.iterate(self.list_parameters(), fixedargs):
for descriptor in self.cinema_store.iterate(
self.list_parameters(), fixedargs):
self.execute(descriptor)
self.finish()
......@@ -90,11 +94,12 @@ class Explorer(object):
""" Give tracks a chance to clean up after a run """
if self.tracks:
for e in self.tracks:
res = e.finish()
e.finish()
def insert(self, doc):
self.cinema_store.insert(doc)
class Track(object):
"""
abstract interface for things that can produce data
......@@ -119,24 +124,27 @@ class Track(object):
""" subclasses operate on parameters here"""
pass
class LayerControl(object):
"""
Prototype for something that Layer track can control
"""
def __init__(self, name, showFunc, hideFunc):
self.name = name
self.callShow = showFunc #todo, determine if function now and convert instead of try/except below
self.callShow = showFunc
self.callHide = hideFunc
class Layer(Track):
"""
A track that connects a layer to the set of objects in the scene that it controls.
A track that connects a layer to the set of objects in the scene that it
controls.
"""
def __init__(self, layer, objectlist):
super(Layer, self).__init__()
self.parameter = layer
# objlist is an array of class instances, they must have a name and
#show and hide method, use LayerControl to make them.
# show and hide method, use LayerControl to make them.
self.objectlist = objectlist
def execute(self, doc):
......@@ -146,9 +154,9 @@ class Layer(Track):
for obj in self.objectlist:
if obj.name == o:
try:
obj.callShow() #method
obj.callShow() # method
except TypeError:
obj.callShow(obj) #function
obj.callShow(obj) # function
else:
try:
obj.callHide()
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#==============================================================================
# ==============================================================================
# Copyright (c) 2015, Kitware Inc., Los Alamos National Laboratory
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#==============================================================================
# ==============================================================================
"""
Default color lookup tables.
TODO: move to Viewer.
"""
import json
import numpy as np
import math
def add_spectral(luts):