Select to view content in your preferred language

Writing an equation in Python

17021
5
07-09-2013 08:58 AM
VirginiaMoore
Emerging Contributor
Hi,
I am new to python, and need some help writing an equation into python.  The algorithm calculates the energetic costs of human movement over different terrains.  I would like to create a script with this where I can allow users to input different values for the various variables. 

M= 1.5W + 2.0(W+L)(L/W)^2+n(W+L)(1.5V^2+0.35VS)

where
M= metabolic rate in watts (kilojoules/minute)
W=the weight of the person in kilograms
L=the load carried by the person in kilograms
n=value reflecting the terrain
V=the speed of waling in m/s
S=percentage gradient

This is probably a lot easier than I am making it, but I am also in a time crunch (need it in a week), and as of yet have had no luck figuring it out.  I would greatly appreciate any help that I can get .

Thank you,
Ginger
Tags (2)
0 Kudos
5 Replies
RhettZufelt
MVP Notable Contributor
This works, but you will have to check with your numbers to make sure it is working "correctly"

m = (1.5 * W + 2 * (W + L) * (L / W)**2 + n * (W + L) * (1.5 * V**2 + 0.35 * V * S))


R_
0 Kudos
VirginiaMoore
Emerging Contributor
Thanks for the response.  I was also wanting to allow for user input to change the values of the variables.  How would I go about doing that?  I know that I can create a toolbox that runs the script, but I am not sure how to write it in python.
0 Kudos
RhettZufelt
MVP Notable Contributor
To get user input in python, can use raw_input.

W = raw_input("Enter Weight in kg. -->")



If running within a tool, you would probably need the GetPrameters... and set the parameters in the script itself.  Would suggest the help files for info on that.


http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000004000000
0 Kudos
VirginiaMoore
Emerging Contributor
I forgot to mention that I am using this to create a cost surface.  Tried just making it into a vertical factor table, but when i run the path distance tool with my table I get an arcSOCP exe. error.  So...I was wondering if anyone had any suggestions on how to fix this.  I would really like to just program it python where it does the calculations and creates the cost surface all in one go, but I am afraid that is beyond my skill level at this point in time. 

Thanks,
Virginia
0 Kudos
RhettZufelt
MVP Notable Contributor
Believe that error is related to using background geoprocessing.

ArcMap, Geoprocessing menu, un-check Enable on Background Processing.

R_
0 Kudos