Creating an interactive model

From GeoMod

Jump to: navigation, search

the interactive model is having some issues. I have created a virtual river. Each section of the river has two main components,overland flow, and aquifer discharge. I added sliders to allow for change of any aspect of either part to make possible a real time view of the flow profile and alkalinity. Problems include:

  Sliders don't like to have labels
  Sliders don't like to show their values
  the graph function adds each while loop's points together, creating a mess
  It doesn't like my use of log functions, so i had to hard wire it.
    Why can't controls be simple?


here's the code so far:


from visual import *
from visual.graph import *
from visual.controls import *
from Numeric import *



runoff_cont = controls(title='Runoff Control Bar', x=-400, y=400, width=600, height=300, range=200)

s1 = slider(pos=(-60,-25,0),axis=(0,100,0),text="Organic Carbon Concentration", color=(0,1,0), min=0.0, max=15.0)
s2 = slider(pos=(-50,-25,0),axis=(0,100,0),text="Nitrogen Concentration", color=(1,0,0), min=0.0, max=2.0)
s3 = slider(pos=(-40,-25,0),axis=(0,100,0),text="Phosphate Concentration", color=(1,0,1), min=0.0, max=1.0)
s4 = slider(pos=(-30,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=7.0, max=14.0)
s45 = slider(pos=(-20,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=0.0, max=1.0)



s5 = slider(pos=(0,-25,0),axis=(0,100,0),text="Organic Carbon Concentration", color=(0,1,0), min=0.0, max=15.0)
s6 = slider(pos=(10,-25,0),axis=(0,100,0),text="Nitrogen Concentration", color=(1,0,0), min=0.0, max=2.0)
s7 = slider(pos=(20,-25,0),axis=(0,100,0),text="Phosphate Concentration", color=(1,0,1), min=0.0, max=1.0)
s8 = slider(pos=(30,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1.0, max=14.0)
s85 = slider(pos=(40,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=0.0, max=1.0)

s9 = slider(pos=(60,-25,0),axis=(0,100,0),text="Organic Carbon Concentration", color=(0,1,0), min=0.0, max=15.0)
s10 = slider(pos=(70,-25,0),axis=(0,100,0),text="Nitrogen Concentration", color=(1,0,0), min=0.0, max=2.0)
s11 = slider(pos=(80,-25,0),axis=(0,100,0),text="Phosphate Concentration", color=(1,0,1), min=0.0, max=1.0)
s12 = slider(pos=(90,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1.0, max=14.0)
s125 = slider(pos=(100,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=0.0, max=1.0)


s13 = slider(pos=(120,-25,0),axis=(0,100,0),text="Organic Carbon Concentration", color=(0,1,0), min=0.0, max=15.0)
s14 = slider(pos=(130,-25,0),axis=(0,100,0),text="Nitrogen Concentration", color=(1,0,0), min=0.0, max=2.0)
s15 = slider(pos=(140,-25,0),axis=(0,100,0),text="Phosphate Concentration", color=(1,0,1), min=0.0, max=1.0)
s16 = slider(pos=(150,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1, max=14.0)
s165 = slider(pos=(160,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=0, max=1.0)

aq_cont = controls(title='Aquifer Chemistry Bar',
     x=-400, y=-1600, width=300, height=300, range=100)

s17 = slider(pos=(-50,-25,0),axis=(0,100,0),text="Carbonate Concentration", color=(1,0,1), min=0.0, max=100.0)
s18 = slider(pos=(-40,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1.0, max=14.0)
s185 = slider(pos=(-30,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=-1.0, max=1.0)

s19 = slider(pos=(-10,-25,0),axis=(0,100,0),text="Carbonate Concentration", color=(1,0,1), min=0.0, max=100.0)
s20 = slider(pos=(0,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1, max=14.0)
s205 = slider(pos=(10,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=-1.0, max=1.0)

s21 = slider(pos=(30,-25,0),axis=(0,100,0),text="Carbonate Concentration", color=(1,0,1), min=0.0, max=100.0)
s22 = slider(pos=(40,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1, max=14.0)
s225 = slider(pos=(50,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=-1.0, max=1.0)

s23 = slider(pos=(70,-25,0),axis=(0,100,0),text="Carbonate Concentration", color=(1,0,1), min=0.0, max=100.0)
s24 = slider(pos=(80,-25,0),axis=(0,100,0),text="pH", color=(1,1,1), min=1, max=14.0)
s245 = slider(pos=(90,-25,0),axis=(0,100,0),text="Flow", color=(2,1,1), min=-1.0, max=1.0)

##info for graphing
pos1 = array([35.311139,-89.639073],Float)#hwy 70
pos2 = array([35.306869,-89.668077],Float)# Hwy 205
pos3 = array([35.281040,-89.766085],Float)# New Brunswick
pos4 = array([35.275161,-89.887326],Float)#204 Singleton Pkwy
pos5 = array([35.263172,-89.929469],Float)#Raliegh Millington
pos6 = array([35.259577,-89.993882],Float)#Hwy 51
pos7 = array([35.254232,-90.026146],Float)#N. Watkins

wellpos1 = array((35.244580,-89.956463))
wellpos2 = array((35.037847,-89.855829))
wellpos3 = array((35.020714,-90.121397))
        

#flow for pos location in months(Jan,Feb,mar...Dec)
flow1 = array([498,673,659,574,399,274,203,163,171,179,349,633],Float)																				
flow2 = 0
flow3 = array([1368,1591,1308,1108,699,358,262,198,228,141,444,831],Float)										
flow4 = 0
flow5 = array([2.03,1.19,2.99,2.97,3.32,0.99,0.92,0.38,0.55,0.24,1.43,2.83],Float)																			    
flow6 = array([0,0,0,0,0,0,353,213,164,0,0,0],Float)		
											
											

        
d1_2 = int(sqrt(pow((pos2[0]-pos1[0]),2)+pow((pos2[1]-pos1[1]),2))*91021.855)
d2_3 = int(sqrt(pow((pos3[0]-pos2[0]),2)+pow((pos3[1]-pos2[1]),2))*91021.855)
d3_4 = int(sqrt(pow((pos4[0]-pos3[0]),2)+pow((pos4[1]-pos3[1]),2))*91021.855)
d4_5 = int(sqrt(pow((pos5[0]-pos4[0]),2)+pow((pos5[1]-pos4[1]),2))*91021.855)
d5_6 = int(sqrt(pow((pos6[0]-pos5[0]),2)+pow((pos6[1]-pos5[1]),2))*91021.855)
d6_7 = int(sqrt(pow((pos7[0]-pos6[0]),2)+pow((pos7[1]-pos6[1]),2))*91021.855)
# deg * 91021.855 = meters        
p1 = (0)
p2 = d1_2
p3 = p2 + d2_3
p4 = p3 + d3_4
p5 = p4 + d4_5
p6 = p5 + d5_6
p7 = p6 + d6_7


scale = 100

p1 = p1/scale
p2 = p2/scale
p3 = p3/scale
p4 = p3/scale
p5 = p5/scale
p6 = p6/scale
p7 = p7/scale

     
        #print d1_2,d2_3,d3_4,d4_5,d5_6,d6_7
       
sec1 = arrayrange(0, d1_2, 1)
sec2 = arrayrange(d1_2, d2_3, 1)
sec3 = arrayrange(d2_3, d3_4, 1)
sec4 = arrayrange(d3_4, d4_5, 1)
sec5 = arrayrange(d4_5, d5_6, 1)
sec6 = arrayrange(d5_6, d6_7, 1)



plotvals = ones((1,(p7)),Float)
flow_vol = ones((1,(p7)),Float) * 150
#print plotvals
#print plotpos
#print flow_vol
        
flow_profile = gdisplay(xtitle='Distance(m)', ytitle='flow rate(ft3/s)', title='Flow Profile Plot' )
functa = gcurve(color=color.blue)
functb = gcurve(color=color.red)

while 1:

    #bl = button(pos=(0,0,0), height=30, width=40,text = '%0.3f' % s1.value)


    runoff_cont.interact() # Check for mouse events for runoff
    orgcarb1 = s1.value
    nit1 = s2.value
    phos1 = s3.value
    ph1 = s4.value + 1
    overflow1 = s45.value



    orgcarb2 = s5.value
    nit2 = s6.value
    phos2 = s7.value
    ph2 = s8.value + 1
    overflow2 = s85.value

    orgcarb3 = s9.value
    nit3 = s10.value
    phos3 = s11.value
    ph3 = s12.value + 1
    overflow3 = s125.value

    orgcarb4 = s13.value
    nit4 = s14.value
    phos4 = s15.value
    ph4 = s16.value + 1
    overflow4 = s165.value
    

    aq_cont.interact() # check for mouse events and actions for aquifer

    carb4 = s17.value
    ph4 = s18.value + 1
    aqflow1 = s185.value

    carb5 = s19.value
    ph5 = s20.value + 1
    aqflow2 = s205.value

    carb6 = s21.value
    ph6 = s22.value + 1
    aqflow3 = s225.value

    carb7 = s23.value
    ph7 = s24.value + 1
    aqflow4 = s245.value    
    
   
    for i in range((p1+1),p2):
        plotvals[0,i] = overflow1*(orgcarb1 - phos1 - nit1 -log(ph1)) + aqflow1*(carb4 - log(ph4)) + flow_vol[0,i]*plotvals[0,i]
        flow_vol[0,i] = flow_vol[0,i-1] + overflow1 + aqflow1

    for i in range(p2+1,p3):
        plotvals[0,i] = overflow2*(orgcarb2 - phos2 - nit2 -log(ph2)) + aqflow2*(carb5 - log(ph5)) + flow_vol[0,i]*plotvals[0,i]
        flow_vol[0,i] = flow_vol[0,i-1] + overflow2 + aqflow2

    for i in range(p3+1,p4):
        plotvals[0,i] = overflow3*(orgcarb3 - phos3 - nit3 -log(ph3)) + aqflow3*(carb6 - log(ph6)) + flow_vol[0,i]*plotvals[0,i]
        flow_vol[0,i] = flow_vol[0,i-1] + overflow3 + aqflow3

    for i in range(p4+1,p7):
        plotvals[0,i] = overflow4*(orgcarb4 - phos4 - nit4 -log(ph4)) + aqflow4*(carb7 - log(ph7)) + flow_vol[0,i]*plotvals[0,i]
        flow_vol[0,i] = flow_vol[0,i-1] + overflow4 + aqflow4


    for i in range(p1,p7):
        functa.plot(pos=(i,flow_vol[0,i]))
        #functb.plot(pos=(i,plotvals[0,i]))


    plotvals = ones((1,(p7)),Float)
    flow_vol = ones((1,(p7)),Float) * 150

          
<pre/>
Personal tools