Iterating over a list

27 views
Skip to first unread message

Michelle Emily DePrenger-Levin

unread,
Jul 5, 2017, 5:04:44 PM7/5/17
to VisTrails SAHM
Hello,

I'm trying to use one csv with hundreds of species split by an ID number. I'd like to iterate over each ID number matching in the Query of the FieldDataQuery. I can create a list (eg. ['"[ID]" == "1"','"[ID]" == "2"','"[ID]" == "36"','"[ID]" == "37"','"[ID]" == "38"','"[ID]" == "39"','"[ID]" == "40"']) but I would sure love to be able to just say 1 through 384. I'm guessing there is a widget to do this or to populate a spreadsheet and feed it in instead of typing each number by hand but I can't figure it out. Maybe the "For" widget? 

Then I apply each species to a high and low emmisions future. I can give them the output names for the two different future climates but cannot figure out how to follow the ID number through in naming folders. I believe I need an iterative input that will insert into the Query [ID] == "iteration number" and tag onto the first climate and the applied ones. 

Any advice as to which widgets to use? 


Thanks!
Michelle

Gericke Cook

unread,
Jul 5, 2017, 5:33:52 PM7/5/17
to Michelle Emily DePrenger-Levin, VisTrails SAHM
Hi Michelle, 

I am another user and not the support team, but I think I can help answer your question.

You may use the "Explore" button at the top of the VisTrails interface to explore splitting your species by ID number. After you have created your workflow in the "Pipeline" view, open the dialog for the FieldDataQuery module and enter the column name containing the species ID in the "Query_column" parameter box. Then click on the "Explore" tab and drag the paramter "Query_column" left over to the canvas. You can enter a list [1,2,3,4, etc] or you may create a user-defined function to automatically generate the series. What should happen is for each value in the list of the parameter exploration, that value will be applied to the FieldDataQuery module, effectively subsetting your input data by species ID before applying the rest of the workflow. I think it auto-generates output folder names for the models by the value being evaluated in the list, but it has been a while since I've used this.

I think you could do a row x column exploration by simultaneously exploring different emission scenario input data as another parameter exploration. So then your output is species x scenario. I think I've pointed you in the right direction, but there might be fiddly setup bits with the Parameter Explorer that you'll need help to get it running correctly.

Gericke

--
You received this message because you are subscribed to the Google Groups "VisTrails SAHM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vistrails-sahm+unsubscribe@googlegroups.com.
To post to this group, send email to vistrails-sahm@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michelle Emily DePrenger-Levin

unread,
Jul 5, 2017, 5:56:45 PM7/5/17
to VisTrails SAHM, miche...@gmail.com
Yes! Thank you. That was what I was looking for. 

Thank you so much!

Michelle
To unsubscribe from this group and stop receiving emails from it, send an email to vistrails-sah...@googlegroups.com.
To post to this group, send email to vistrai...@googlegroups.com.

Michelle Emily DePrenger-Levin

unread,
Jul 7, 2017, 11:05:17 AM7/7/17
to VisTrails SAHM, miche...@gmail.com
Hello group.

Thanks again, Gericke. I wrote a script in the explore section to generate my list for the FieldDataQuery:

['[', '','.join(map("'[ID]' == '{0}'".format, range(1,384)))', ']']

Is there a way to name range(1,384) as a variable in OutputName or in a way that could append the first and the two ApplyModel OutputNames? I'd like to iterate over the 384 IDs and have a way to name each new output folder with the corresponding ID number. My first attempt tried to run through 384 output folders each running through 384 outputs. Oops. I don't know how to either iterate over one widget that feeds into the four other widgets or tell VisTrails to do the first and then second ... of all lists. 

Any thoughts? 

Thanks in advance,

MIchelle

Michelle Emily DePrenger-Levin

unread,
Jul 11, 2017, 3:03:02 PM7/11/17
to VisTrails SAHM, miche...@gmail.com
I've got a list of numbers that I want to apply to:
 (1) FieldDataQuery (to pull different species by ID one at a time) and to
 (2) FieldDataQuery as the run_name_info (so I can tell which folder holds which species by ID),
 (3) PARC for one future climate model (to make a folder matching the model and the ID) and
 (4) PARC for another future climate model (to identify the model and the ID)

In PythonSource I've got:
rangestring = range(1,381)
S2 = (','.join(map("'[ID]' == '{0}'".format, rangestring))).split(",")
outputrecent =  ("".join(",".join(map("Recent_{0}".format,rangestring)))).split(",")
output26 =  ("".join(",".join(map("BCrcp26_{0}".format,rangestring)))).split(",")
output85 =  ("".join(",".join(map("BCrcp85_{0}".format,rangestring)))).split(",")
zip_outputs = zip(outputrecent,output26,output85)

In case anyone out there can help - I think I want to use PythonSource to make a tuple ("zip_outputs" but should add in S2 as well) and then some other widget to tell it to use the first element of each tuple for IDs, the second for the first run_name_info... and so on. 

I need to not result in nested looping when I want to work through the one list of the four lists once. 

I'm looking at the Control Flow choices and feel like I'm close with Map or Filter but can't quite work out which will let me type [x[0] for x in zip_outputs]... to pick the correct element of each tuple as it works through. 

Thanks, 
Michelle
Reply all
Reply to author
Forward
0 new messages