Select to view content in your preferred language

Setting script output parameter in Python

381
1
03-07-2011 05:00 AM
MarcFasel
Deactivated User
Hi everyone,

I'm working on a simple model (see picture attached) that, basically, takes a location and an hour as inputs and deliver a IDW predicted value (e.g. 2375.54) as output based on the cell values of rasters stored in a geodatabase.

There are four rasters stored, one for each period of the day (morning, afternoon, evening and night).

I added a Python script aimed to change the name of the raster to use by the model tools according to the hour given in parameter. For example if hour = 7 the tools should use the "Morning" raster to make the prediction. If hour = 15 = 3pm, it should use the afternoon raster and so on.

The model works fine if I set all the input and output parameters manually, but I can't figure out how to change dynamically the name of the raster the model has to work with.

What would be the best way to switch dynamically between rasters in this kind of model?

Thanks for any help or suggestion..

Marc
Tags (2)
0 Kudos
1 Reply
MarcFasel
Deactivated User
[Resolved]

If it can help someone:


h = int(arcpy.GetParameterAsText(0))

if h >= 6 and h < 12:
    arcpy.SetParameterAsText(1, "Raster_Morning")
elif h >= 12 and h < 18:
    arcpy.SetParameterAsText(1, "Raster_Afternoon")
elif h >= 18 and h < 23:
    arcpy.SetParameterAsText(1, "Raster_Evening")
else:
    arcpy.SetParameterAsText(1, "Raster_Night")



And don't forget to check if you have to put the output parameter type as "derived" in the parameter proprieties.

I'm interested in any better (faster?) solution, though...

Happy arcgising

Marc
0 Kudos