plt.figure(2) plt.plot(range(2),range(2)) """ class MatplotlibMarkerComboBoxWidget(ComboBoxWidget): """Marker constants used for drawing markers on a matplotlib plot.""" _KEY_VALUES = {'plus': '+', 'circle': 'o', 'diamond': 'd', 'star': '*', 'square': 's', 'cross': 'x', 'hexagon': 'h', 'triangle_down': 'v', 'triangle_right': '>', 'triangle_left': '<', 'triangle_up': '^', } MatplotlibMarkerComboBox = basic_modules.new_constant('Plot Marker', staticmethod(str), 's', staticmethod(lambda x: type(x) == str), MatplotlibMarkerComboBoxWidget) class MatplotlibLineStyleComboBoxWidget(ComboBoxWidget): """Marker constants used for drawing markers on a matplotlib plot.""" _KEY_VALUES = {'solid': '-', 'dashed': '--', 'dash-dot': '-.', 'dotted': ':'} MatplotlibLineStyleComboBox = basic_modules.new_constant('Plot Line Style', staticmethod(str), '-', staticmethod(lambda x: type(x) == str), MatplotlibLineStyleComboBoxWidget)
tf = self.get_input('TransferFunction') new_tf = copy.copy(tf) if self.has_input('Input'): port = self.get_input('Input') algo = port.vtkInstance.GetProducer() output = algo.GetOutput(port.vtkInstance.GetIndex()) (new_tf._min_range, new_tf._max_range) = output.GetScalarRange() elif self.has_input('Dataset'): algo = self.get_input('Dataset').vtkInstance output = algo (new_tf._min_range, new_tf._max_range) = output.GetScalarRange() else: (new_tf._min_range, new_tf._max_range) = self.get_input('Range') self.set_output('TransferFunction', new_tf) string_conversion = staticmethod(lambda x: pickle.dumps(x).encode('hex')) conversion = staticmethod(lambda x: pickle.loads(x.decode('hex'))) validation = staticmethod(lambda x: isinstance(x, TransferFunction)) TransferFunctionConstant = new_constant('TransferFunction', conversion, default_tf, validation, TransferFunctionWidget) TransferFunctionConstant.translate_to_string = string_conversion ############################################################################## def initialize(): init_constant(TransferFunctionConstant)
""" self._contents = str(self.toPlainText()) if self.parent(): QtCore.QCoreApplication.sendEvent(self.parent(), event) QtGui.QTextEdit.focusInEvent(self, event) def focusOutEvent(self, event): self.update_parent() QtGui.QTextEdit.focusOutEvent(self, event) if self.parent(): QtCore.QCoreApplication.sendEvent(self.parent(), event) GeoString = basic_modules.new_constant('GeoString', staticmethod(str), None, staticmethod(lambda x: type(x) == str), GeoStringConstantWidget) GMLString = basic_modules.new_constant('GMLString', staticmethod(str), None, staticmethod(lambda x: type(x) == str), GeoStringConstantWidget) WKTString = basic_modules.new_constant('WKTString', staticmethod(str), "", staticmethod(lambda x: type(x) == str), GeoStringConstantWidget) GeoJSONString = basic_modules.new_constant('GeoJSONString', staticmethod(str), None,
def initialize(*args, **keywords): from core.modules import basic_modules from packages.spreadsheet import basic_widgets from core.modules.vistrails_module import Module import DropDownListWidget from Array import NDArrayEO from Experiment import Timer from ListFilter import ListFilter from ListCell import ListCell from Random import Random from session import Session from ThreadSafe import Fork, ThreadTestModule, ThreadSafeFold, \ ThreadSafeMap reg = get_module_registry() utils_namespace = "tools|utils" utils_test_namespace = "tools|utils|tests" # ========================================================================= # Abstract Modules - these MUST appear FIRST # ========================================================================= reg.add_module(Session, namespace=utils_namespace, abstract=True) # ========================================================================= # ComboBox definitions # ========================================================================= # LinuxComboBox LinuxDemoComboBox = basic_modules.new_constant('LinuxDemoComboBox', staticmethod(eval), (1, 1), staticmethod(lambda x: type(x) == tuple), DropDownListWidget.LinuxDemoComboBoxWidget) reg.add_module(LinuxDemoComboBox, namespace=utils_test_namespace) # DateFormatComboBox DateFormatComboBox = basic_modules.new_constant('Date Format', staticmethod(str), 's', staticmethod(lambda x: type(x) == str), DropDownListWidget.DateFormatComboBoxWidget) reg.add_module(DateFormatComboBox, namespace=utils_namespace, abstract=True) # ========================================================================= # Standard Modules - Ports defined here # ========================================================================= # Experiment reg.add_module(Timer, name="WorkflowTimer", namespace=utils_namespace) # Fork reg.add_module(Fork, namespace=utils_namespace) reg.add_input_port( Fork, 'modules', basic_modules.Module) # Add ListCell reg.add_module(ListCell, namespace=utils_namespace) reg.add_input_port(ListCell, "List", basic_modules.List) #reg.add_input_port(ListCell, "File", basic_modules.File) reg.add_input_port(ListCell, "Heading", basic_modules.String) reg.add_input_port(ListCell, "Location", basic_widgets.CellLocation) reg.add_input_port(ListCell, "LineNumber?", basic_modules.Boolean) reg.add_input_port(ListCell, "Disabled?", basic_modules.Boolean) reg.add_output_port(ListCell, "HTML File", basic_modules.File) # ListFilter reg.add_module(ListFilter, namespace=utils_namespace) reg.add_input_port( ListFilter, 'list_in', basic_modules.List) reg.add_input_port( ListFilter, 'subset', basic_modules.String) reg.add_output_port( ListFilter, 'string', (basic_modules.String, 'String representation of sub-setted list')) reg.add_output_port( ListFilter, 'list_out', (basic_modules.List, 'sub-setted list')) # NDArray reg.add_module(NDArrayEO, name="EONumpyArray", namespace=utils_namespace, abstract=True) reg.add_output_port( NDArrayEO, "self", (NDArrayEO, 'self')) # ThreadTest reg.add_module(ThreadTestModule, namespace=utils_test_namespace) reg.add_input_port( ThreadTestModule, 'someModuleAboveMe', basic_modules.Module) # ========================================================================= # Control Flow Modules - # ========================================================================= registerControl(ThreadSafeFold) registerControl(ThreadSafeMap) reg.add_input_port(ThreadSafeFold, 'FunctionPort', (Module, "")) reg.add_input_port(ThreadSafeFold, 'InputList', (basic_modules.List, "")) reg.add_input_port(ThreadSafeFold, 'InputPort', (basic_modules.List, "")) reg.add_input_port(ThreadSafeFold, 'OutputPort', (basic_modules.String, "")) reg.add_output_port(ThreadSafeFold, 'Result', (basic_modules.Variant, "")) # ========================================================================= # Other Modules - without ports OR with locally defined ports # ========================================================================= reg.add_module(Random, namespace=utils_namespace)
res = [float(elt) for elt in v_list] return robjects.FloatVector(res) elif is_str and (desired_type is None or desired_type == str): res = [str(elt) for elt in v_list] return robjects.StrVector(res) if desired_type is not None: raise TypeException("Cannot coerce vector to type '%s'" % desired_type) return robjects.RVector(v_list) def vector_conv(v, desired_type=None): v_list = eval(v) return create_vector(v_list, desired_type) RVector = new_constant('RVector', staticmethod(vector_conv), robjects.RVector([]), staticmethod(lambda x: isinstance(x, robjects.RVector))) def bool_vector_conv(v): return vector_conv(v, bool) RBoolVector = new_constant('RBoolVector' , staticmethod(bool_vector_conv), robjects.BoolVector([]), staticmethod(lambda x: isinstance(x, robjects.RVector)), base_class=RVector) def int_vector_conv(v): return vector_conv(v, int) RIntVector = new_constant('RIntVector' , staticmethod(int_vector_conv), robjects.IntVector([]),
## ## 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." ## ############################################################################### from core.modules.basic_modules import new_constant ################################################################################# ## The ListOfElements Module def list_conv(l): if (l[0] != '[') and (l[-1] != ']'): raise ValueError('List from String in VisTrails should start with \ "[" and end with "]".') else: l = eval(l) return l ListOfElements = new_constant('ListOfElements' , staticmethod(list_conv), [],\ staticmethod(lambda x: type(x) == list))
tf = self.getInputFromPort('TransferFunction') new_tf = copy.copy(tf) if self.hasInputFromPort('Input'): port = self.getInputFromPort('Input') algo = port.vtkInstance.GetProducer() output = algo.GetOutput(port.vtkInstance.GetIndex()) (new_tf._min_range, new_tf._max_range) = output.GetScalarRange() elif self.hasInputFromPort('Dataset'): algo = self.getInputFromPort('Dataset').vtkInstance output = algo (new_tf._min_range, new_tf._max_range) = output.GetScalarRange() else: (new_tf._min_range, new_tf._max_range) = self.getInputFromPort('Range') self.setResult('TransferFunction', new_tf) string_conversion = staticmethod(lambda x: pickle.dumps(x).encode('hex')) conversion = staticmethod(lambda x: pickle.loads(x.decode('hex'))) validation = staticmethod(lambda x: isinstance(x, TransferFunction)) TransferFunctionConstant = new_constant('TransferFunction', conversion, default_tf, validation, TransferFunctionWidget) TransferFunctionConstant.translate_to_string = string_conversion ############################################################################## def initialize(): init_constant(TransferFunctionConstant)
from core.modules.module_registry import get_module_registry from core.utils import getHomeRelativePath, getFullPath def expand_port_specs(port_specs, pkg_identifier=None): if pkg_identifier is None: pkg_identifier = identifier reg = get_module_registry() out_specs = [] for port_spec in port_specs: out_specs.append((port_spec[0], reg.expand_port_spec_string(port_spec[1], pkg_identifier))) return out_specs URL = new_constant("URL", staticmethod(str), "", staticmethod(lambda x: type(x) == str), base_class=String) class VariableSource(Module): _input_ports = expand_port_specs([("file", "basic:File"), ("url", "URL")]) _output_ports = expand_port_specs([("variables", "basic:List"), ("dimensions", "basic:List"), ("attributes", "basic:List")]) class Variable(Module): # TODO default load to False here... _input_ports = expand_port_specs([("file", "basic:File"), ("url", "URL"), ("source", "VariableSource"), ("name", "basic:String"),
def expand_port_specs(port_specs, pkg_identifier=None): if pkg_identifier is None: pkg_identifier = identifier reg = get_module_registry() out_specs = [] for port_spec in port_specs: out_specs.append((port_spec[0], reg.expand_port_spec_string(port_spec[1], pkg_identifier))) return out_specs URL = new_constant("URL", staticmethod(str), "", staticmethod(lambda x: type(x) == str), base_class=String) class VariableSource(Module): _input_ports = expand_port_specs([("file", "basic:File"), ("url", "URL")]) _output_ports = expand_port_specs([("variables", "basic:List"), ("dimensions", "basic:List"), ("attributes", "basic:List")]) class Variable(Module): # TODO default load to False here... _input_ports = expand_port_specs([("file", "basic:File"), ("url", "URL"), ("source", "VariableSource"),
import d1_client import d1_common import d1_common.types.generated.dataoneTypes as dataoneTypes from d1_client.mnclient import MemberNodeClient from d1_client.cnclient import CoordinatingNodeClient from access_control import access_control from replication_policy import replication_policy from data_package import DataPackage import identifiers import utils D1DateTime = new_constant("D1DateTime", staticmethod(str), "", staticmethod(lambda x: type(x) == str), base_class=String) D1Identifier = new_constant("D1Identifier", staticmethod(str), "", staticmethod(lambda x: type(x) == str), base_class=String) D1Identifier._input_ports = [('value', String)] def get_cn_url(module, required=True): if module.hasInputFromPort("coordinatingNodeURL"): return module.getInputFromPort("coordinatingNodeURL") elif configuration.check("cn_url"): return configuration.cn_url elif required: raise ModuleError(module, "The Coordinating Node URL is required. " \ "Please set it globally in the package " \ "configuration or as a parameter.")
## 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) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ## ############################################################################### from core.modules.basic_modules import new_constant ################################################################################# ## The ListOfElements Module def list_conv(l): if (l[0] != '[') and (l[-1] != ']'): raise ValueError('List from String in VisTrails should start with \ "[" and end with "]".') else: l = eval(l) return l ListOfElements = new_constant('ListOfElements' , staticmethod(list_conv), [],\ staticmethod(lambda x: type(x) == list))
writeImage(ndarray.get_array(), prototype, outfile.name, outformat) self.setResult('output file path', outfile) from core.modules import basic_modules from vistrails.packages.eo4vistrails.tools.utils.DropDownListWidget import ComboBoxWidget class GDALFormatComboBoxWidget(ComboBoxWidget): """TODO: Write docstring.""" _KEY_VALUES = {'HFA': 'HFA', 'GEOTiff': 'GTiff'} # LinuxComboBox GDALFormatComboBox = basic_modules.new_constant('GDAL Format', staticmethod(str), 'HFA', staticmethod(lambda x: type(x) == str), GDALFormatComboBoxWidget) def writeImage(arrayData, prototype, path, format): """Write the given array data to the file 'path' with the given extent. If arrayData shape is of length 3, then we have multibands (nbad,rows,cols), otherwise one band """ driver = gdal.GetDriverByName(format) metadata = driver.GetMetadata() if gdal.DCAP_CREATE in metadata and metadata[gdal.DCAP_CREATE] == 'YES': pass
'(za.co.csir.eo4vistrails:Raster Layer Drawing Style:visualisation|maps)')] _output_ports = [('raster_layer', '(za.co.csir.eo4vistrails:RasterLayer:data)')] def compute(self): raster_layer = self.getInputFromPort('raster_layer') raster_style = self.forceGetInputFromPort('raster_style', None) layer_name = self.forceGetInputFromPort('label', None) raster_type = raster_layer.rasterType() # 0=GrayOrUndefined (single), 1=Palette (single), 2=Multiband, 3=Color print "LayerStyling:124", raster_type #TO DO - style layer # layer props if layer_name: raster_layer.setLayerName(layer_name) self.setResult('raster_layer', raster_layer) class QgsRasterLayerDrawingStyleComboBoxWidget(ComboBoxWidget): """Constants used for setting drawing style for a QGIS raster layer.""" _KEY_VALUES = {'1': 'SingleBandGray', '2': 'SingleBandPseudoColor', } QgsRasterLayerDrawingStyleComboBox = basic_modules.new_constant( 'Raster Layer Drawing Style', staticmethod(str), 'SingleBandGray', staticmethod(lambda x: type(x) == str), QgsRasterLayerDrawingStyleComboBoxWidget)
# local from threading import Thread, currentThread, RLock from DataRequest import DataRequest class EPSGComboBoxWidget(ComboBoxWidget): """TODO: Add docstring """ default = ('4326', 4326) def getKeyValues(self): return {'3867': 3786, '4326': 4326} EPSGCode = basic_modules.new_constant('EPSG Code', staticmethod(eval), 4326, staticmethod(lambda x: type(x) == int), EPSGComboBoxWidget) #global globalQgsLock #globalQgsLock = RLock() class QgsMapLayer(Module, NotCacheable): """Create a QGIS layer from a file .. warning:: This is not threadsafe and has race conditions on the QGIS drivers """ def __init__(self):