import numpy as np
import DiscretizedMaps as dm
import DiscretizedTransientCyclePlot as dtcp
import matplotlib.pyplot as plt
import sys

# This is the main user interface to DiscretizedTransientCyclePlot

# here are some parameters which the user cannot adjust via arguments to the program
paramSteps=512 # number of steps to increment the parameter
samples=128 # number of samples to use for each parameter value

# here, the arguments to the program are assigned to the appropriate variables
# mapkey is a string which determines which map to use
# param is a string which determines which parameter to vary
# paramMin/paramMax are the min/max values of the parameter to use 
# param2val is the value of the parameter which is being held fixed
# paramInc is  the increment size for the varied parameter
# scale is a string which determines if the plot will be linear or log-log
mapkey,param,paramMin,paramMax,param2val,scale=sys.argv[1:]
paramMin,paramMax,param2val=float(paramMin),float(paramMax),float(param2val)
paramInc=float(paramMax-paramMin)/float(paramSteps)

# here the map strings are associated with their  DiscretizedMaps object.
maps = {'logistic':dm.Logistic, 'tent':dm.Tent, 'logisticrand':dm.LogisticRand, 'tentrand':dm.TentRand}
# the map is assigned using the user input mapkey string
map=maps[mapkey]

# the if then statement below considers the case where r is the varied parameter, or N is the varied parameter.
# in both cases, the variables are put in the proper form to  be used as arguments to TCPlot.
if param=='r':
	r=[paramMin,paramMax,paramInc]
	N=param2val	
	print 'Running...'
	dtcp.TCPlot(map,r,N,samples,scale)
	plt.show()
	
elif param=='N':
	N=[paramMin,paramMax,paramInc]
	r=param2val	
	print 'Running...'
	dtcp.TCPlot(map,r,N,samples,scale)
	plt.show()
	
else: raise ValueError, 'Unknown parameter'