import numpy
import scipy.integrate

"""
Explanation: Lotka-Volterra model implemented in FABM
The equations read:
$$
\begin{aligned}
\dot{x} &= \alpha x - \beta x y \
\dot{y} &= \delta x y - \gamma y 
\end{aligned}
$$
where $x$ represents prey and $y$ represents predator. $ \alpha, \beta, \delta$ and $\gamma$ are model parameters defining the interactions between the spicies.
For further information see. 
The implementation of the Lotka-Volterra equations in FABM was done by Fenjuan Hu when she started her PhD to get familiar with the FABM framework.
Import standard python packages
End of explanation
"""


import pyfabm
#pyfabm.get_version()

"""
Explanation: Import pyfabm - the python module that contains the Fortran based FABM
End of explanation
"""


yaml_file = '../../../../testcases/fabm-au-prey_predator.yaml'
model = pyfabm.Model(yaml_file)
model.findDependency('bottom_depth').value = 1.
model.checkReady(stop=True)
y0 = model.state

"""
Explanation: Configuration
The model configuration is done via the YAML formatted file.
We configure two instances of the Lotka-Volterra model - named LV1 and LV2. 
FABM allows for any number of model instances.
End of explanation
"""


def dy(y,t0):
    model.state[:] = y
    return model.getRates()

"""
Explanation: Model increment
End of explanation
"""


t = numpy.linspace(0,200.,100)
y = scipy.integrate.odeint(dy,model.state,10000*t)

"""
Explanation: Time axis and model integration
End of explanation
"""


import pylab
pylab.plot(t,y)
pylab.title('Time series plots')
pylab.legend([variable.path for variable in model.state_variables])
pylab.show()

pylab.plot(y[:,0],y[:,1])
pylab.plot(y[:,2],y[:,3])
pylab.title('Limit circles')
pylab.show()

"""
Explanation: Plot the results
End of explanation
"""


