[vistrails-users] Custom Types for Ports

Talbert, Colin talbertc at usgs.gov
Fri Aug 8 09:59:33 EDT 2014


Hello Michael,

Both lists and dictionaries are supported port types.   I've used
dictionaries to pass a packet of keyword arguments between modules with a
single connection.

Something along the lines of:

class YourModule(Module):
    _input_ports = [('str_input', '(basic:String, basic:String)'),
                    ('flt_input', '(basic:String, basic:Float)')]
    _output_ports = [('output_dict', '(basic:String, basic:Dictionary)')]

    def compute(self):
        output = {}
        output['our_string'] = self.forceGetInputFromPort('str_input')
        output['our_float'] = self.forceGetInputFromPort('flt_input')

        self.setResult("output_dict", output)



Colin

Colin Talbert
GIS Analyst and Developer
US Geological Survey

talbertc at usgs.gov

USGS Fort Collins Science Center
2150 Centre Ave. Bldg. C
Fort Collins, CO 80526
(970) 226-9425

USGS North Central Climate Science Center
(970) 492-4283

Work schedule:
Monday       - 7:00 - 3:00  (NC CSC)
Tuesday       -  7:00 - 3:00  (NC CSC)
Wednesday  -  7:00 - 3:00 (FORT)
Thursday      -  7:00 - 5:00 (NC CSC)
Friday          -  7:00 - 5:00 (FORT)


On Fri, Aug 8, 2014 at 7:45 AM, Rémi Rampin <remi.rampin at nyu.edu> wrote:

> 2014-08-07 16:20 EDT, Michael Noseworthy:
>
>  I am in the process of writing my own modules and was wondering if its
>> possible to package multiple ports into one (for example have one port that
>> contains both a String and Float value). So when an input port/output port
>> are connected  like this, both pieces of data get passed through a single
>> port instead of two separate ones.
>>
>
> Hi Michael,
>
> While this is doable with some amount of trickery, it is not currently
> supported. Ports can have "tuple" types like you describe, e.g. "(String,
> Float)", but these are not automatically constructed by passing separate
> connections on a port. When packing or unpacking is required, you are
> supposed to use the Tuple and Untuple modules, like so:
>
>
>
> In this example, YourModule is defined as follow:
>
> class YourModule(Module): _input_ports = [('input', '(basic:String,
> basic:Float)')] _output_ports = [('output', '(basic:String, basic:Float)'
> )]
>
> Also, is it possible to define my own types for ports so I am not limited
>> to the basic String, Float, Integer, etc.?
>
>
> You can use any Module class as type for a port.
>
>
> Thank you for using VisTrails,
> --
> Rémi Rampin
> VisTrails developer
> Polytechnic School of Engineering, New York University
>
> _______________________________________________
> vistrails-users mailing list
> vistrails-users at vistrails.org
> http://lists.vistrails.org/mailman/listinfo/vistrails-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vistrails.org/pipermail/vistrails-users/attachments/20140808/3dfb15df/attachment-0001.html>


More information about the vistrails-users mailing list