from pyReefCore.model import Model

"""
Explanation: ReefCore library
pyReef-Core is a deterministic, one-dimensional (1-D) numerical model, that simulates the vertical coralgal growth patterns observed in a drill core, as well as the physical, environmental processes that effect coralgal growth. 
The model is capable of integrating ecological processes like coralgal community interactions over centennial-to-millennial scales using predator-prey or Generalised Lotka-Volterra Equations.
End of explanation
"""


# Initialise model
reef = Model()

"""
Explanation: Once the library has been loaded, the model initialisation is done using the following command:
End of explanation
"""


# Define the XmL input file
reef.load_xml('input-case1.xml')

"""
Explanation: XmL input file
The next step consists in defining the initial conditions for our simulation. This is done by using an XmL input file which set the parameters to be used, such as:

the initial community population number $X0$
the intrinsic rate of a population species $\epsilon$
the interaction coefficients among the species association $\alpha$
End of explanation
"""


reef.core.initialSetting(size=(10,4), fname='input',dpi=400)

"""
Explanation: Visualise the initial conditions of your model run can be done using the following command:
End of explanation
"""


reef.run_to_time(-1500,showtime=500.,verbose=False)

"""
Explanation: Model simulation
The core of the code consist in solving the system of ODEs from the GLV equations using the RKF method.
Once a community association population is resolved, carbonate production is calculated using a carbonate production factor. Production factors are specified for the maximum population, and linearly scaled to the actual population.
To run the model for a given time period [years], the following function needs to be called:
End of explanation
"""


from matplotlib.cm import terrain, plasma

nbcolors = len(reef.core.coralH)+10
#colors = cmo.cm.dense(np.linspace(0, 4, nbcolors))
colors = terrain(np.linspace(0, 1, nbcolors))

nbcolors = len(reef.core.layTime)+3
colors2 = cmo.cm.haline_r(np.linspace(0, 1, nbcolors))

"""
Explanation: Results
All the output from the model run can be plotted on the notebook using a series of internal functions presented below.
First one can specify a colormap to use for the plot using one of the matplotlib predefined colormap proposed here: 
- colormaps_reference
End of explanation
"""


reef.plot.communityTime(colors=colors, size=(10,4), font=8, dpi=100,fname='apop_t.pdf')
reef.plot.communityDepth(colors=colors, size=(10,4), font=8, dpi=100, fname ='apop_d.pdf')
reef.plot.accommodationTime(size=(10,4), font=8, dpi=100, fname ='acc_t.pdf')

"""
Explanation: Communities population evolution

with time: reef.plot.communityTime
with depth: reef.plot.communityDepth
End of explanation
"""


#help(reef.plot.drawCore)

reef.plot.drawCore(lwidth = 3, colsed=colors, tstep=20, coltime = colors2, size=(11,15), font=8, dpi=500, 
                   figname='core.pdf')

reef.force.plotsedy

0.004=a*30+0.001

"""
Explanation: Coral synthetic core
The main output of the model consists in the synthetic core which shows the evolution of the coral stratigraphic architecture obtained from the interactions among species and with their environment. The plot is obtained using the following function: 
- reef.plot.drawCore
The user has the option to save: 
- the figure using the figname parameter (figname could either have a .png or .pdf extension)
- the model output as a CSV file using the filename parameter. This will dump all output dataset for further analysis if required.
End of explanation
"""


