MODEL BUILDER: How to use decimal numbers as increment in "for"-loops

1619
4
03-08-2013 04:29 AM
ThomasFischer
New Contributor
Hi,

I have made a workflow in Model Builder (with topo-to-raster interpolation) and i want to iterate this with a "for"-loop beween the values 0 to 1 within 0.1 steps (=11 loops overall). But it is not possible for me to set the incremet (By Value) to 0.1 or any other decimal number. Do anybody have a wokaround solution for this problem?

Many thanks and greetings, Thomas
0 Kudos
4 Replies
DarrenWiens2
MVP Honored Contributor
As far as I can tell, the For iterator uses the built-in range() function to make the array of numbers to feed into the loop. It seems range() converts the step value (0.1) to an integer (0). You can multiply your numbers by 10 while making the iterator (0 - 10, step by 1), and then divide the value by 10 to use it inside the loop.

Sadly, if you were using Python it would be as simple as:
import numpy
for num in numpy.arange(0,1.1,0.1):
    print num
0 Kudos
ThomasFischer
New Contributor
Darren thanks for Your reply,

multiplying could be a possible solution. As I havent't wrote in my first post: "Unfortunately", I want to iterate over the roughness-penalty parameter in the topo-to-raster interpolation tool which only can be set -reasonable- to decimal numbers between 0 to 0.5 (recommended).

And another problem:
Instead of the "roughness-penalty " I also tried to iterate over the "maximum iteration number" field in the topo-to-raster parameter settings, but it seems to be not possible to connect this with a "for"-loop.

What I want to do is to find best parameter settings with topo-to-raster for my source data, compared to a reference data set. Allover, there are five parameters I want to prove. Actually 168 possible parameter combinations are set by implementing "multiple-value" variables, considering 3 parameters (disket. error fdactor, vertical standard error, profile curvature). It would be useful and time-gaining to iterate this with a fourth parameter: roughness penalty or maximum iteration number. But it seems not possible...

Greetings, Thomas
0 Kudos
curtvprice
MVP Esteemed Contributor
I have made a workflow in Model Builder (with topo-to-raster interpolation) and i want to iterate this with a "for"-loop beween the values 0 to 1 within 0.1 steps (=11 loops overall). But it is not possible for me to set the incremet (By Value) to 0.1 or any other decimal number. Do anybody have a workaround solution for this problem?


A way to get what you want in ModelBuilder is to calculate a float value from your index using the Calculate Value tool.

[ATTACH=CONFIG]22467[/ATTACH]

Another approach could be to try Iterate Multi-value instead of For.

I also tried to iterate over the "maximum iteration number" field in the topo-to-raster parameter settings, but it seems to be not possible to connect this with a "for"-loop.

Calculate Value has a parameter called Data Type that can cast the output into the data type your tool requires. Often you can just enter %element name% in your tool dialog within ModelBuilder as well.



A similar approach would work with your other parameter.

The way to nest loops in model buider to put one model inside another:

Integrating a model within a model
0 Kudos
ThomasFischer
New Contributor
A way to get what you want in ModelBuilder is to calculate a float value from your index using the Calculate Value tool.

[ATTACH=CONFIG]22467[/ATTACH]

Another approach could be to try Iterate Multi-value instead of For.


Calculate Value has a parameter called Data Type that can cast the output into the data type your tool requires. Often you can just enter %element name% in your tool dialog within ModelBuilder as well.



A similar approach would work with your other parameter.

The way to nest loops in model buider to put one model inside another:

Integrating a model within a model



Hi Curtis,

thanks, it's working well! Greetings, Thomas
0 Kudos