Skip to content

EPIC Model Simulation Tutorial

This notebook demonstrates how to use the EPIC model with the geoEpic package.

  • If the package is installed in a conda environment, activate it in commond prompt with
    conda activate epic_env
    
  • Set up a GeoEPIC workspace using
    geo_epic workspace -n Test
    
  • Start a Jupyter notebook inside the workspace folder
    cd Test
    jupyter notebook
    

Follow the below lines of code

Import the required classes from geoEpic

from geoEpic.core import Site, EPICModel
from geoEpic.io import ACY, DGN

First create a Site object with the necessary input files.

site = Site(opc = './opc/files/umstead.OPC',
            dly = './weather/NCRDU.DLY',
            sol = './soil/files/umstead.SOL',
            sit = './sites/umstead.SIT')
print(site.site_id)
umstead

Define the EPICModel class

Now Let's create an EPICModel object and specify the start date, duration of the simulation.

model = EPICModel('./model/EPIC1102.exe')
model.start_date = '2015-01-01'
model.duration = 5
model.output_types = ['ACY']

Run the model simulations at the required site

model.run(site)
# Close the model instance
model.close()
# Path to output files is stored in the site.outputs dict
site.outputs
  • EPICModel instance can also be created using a configuration file. Example config file:
    # Model details
    EPICModel: ./model/EPIC1102.exe
    start_year: '2015-01-01'
    duration: 5
    output_types:
      - ACY  # Annual Crop data file
      - DGN  # Daily general output file
    log_dir: ./log
    output_dir: ./output
    
  • This method allows for easier management of model parameters.

Using EPICModel class with Configuration File

model = EPICModel.from_config('./config.yml')
model.run(site)
model.close()

#using with context
with EPICModel.from_config('./config.yml') as model:
    model.run(site)

Examine the outputs

Finally, examine the outputs generated by the model run.

yields = ACY(site.outputs['ACY']).get_var('YLDG')
yields
index YR CPNM YLDG
0 0 2015 CORN 7.175
1 1 2016 CORN 4.735
2 2 2017 CORN 9.072
3 3 2018 CORN 7.829
4 4 2019 CORN 5.434

Plot the simulated Leaf Area Index

import matplotlib.pyplot as plt

lai = DGN(site.outputs['DGN']).get_var('LAI')

plt.figure(figsize=(12, 6))
plt.plot(lai['Date'], lai['LAI'])
plt.title('Leaf Area Index (LAI) Over Time')
plt.xlabel('Date')
plt.ylabel('LAI')
plt.grid(True)
plt.tight_layout()
plt.show()

png