Simulation
The GeoEPIC package facilitates running simulations and examining outputs, complementing its input file setup capabilities.
Single Site Simulation
Follow these steps to run a simulation for an individual site:
-
Prepare the Site Object: First, create a
Siteobject. This object encapsulates necessary input file references: the crop management file (OPC), weather data file (DLY), soil file (SOL), and site file (SIT). TheSite``` object also keeps track of output files generated during the simulation, like the annual crop yield file (ACY`). -
Configure and Execute the EPIC Model: Next, initialize an
EPICModelobject, providing the path to the EPIC executable file. Configure it with required settings such as the simulation start date, duration (in years), and the types of output files needed (e.g.,ACY,DGN). Execute the simulation by passing theSiteobject to the model'srunmethod. Remember to close the model instance afterwards. The package documentation describes multiple ways to initialize and configure theEPICModel. -
Analyze Simulation Outputs: Finally, examine the outputs. Use the class interfaces provided in the
iomodule (likeACYandDGN) to easily read output files and extract data. These classes integrate with packages likematplotlibfor generating figures.yields = ACY(site.outputs['ACY']).get_var('YLDG') lai = DGN(site.outputs['DGN']).get_var('LAI')The first line above uses theACYclass to get yearly yield values (YLDG) from theACYoutput file. The second line uses theDGNclass to retrieve the simulated daily Leaf Area Index (LAI) from theDGNfile.
Regional Simulation
The Workspace class streamlines managing and running EPIC simulations across many sites, ideal for regional studies. It's best used within a Jupyter notebook environment for interactive results exploration.
-
Initialize the Workspace: Create a
Workspaceobject using two main configuration elements:- A configuration file (e.g.,
config.yml) specifying global settings (model path, dates, directories, etc.). - A
sites_infofile (typically CSV) containing metadata and input file paths for each individual site. You can optionally clear previous logs and outputs before running.
- A configuration file (e.g.,
-
Configure the Workspace (Example
config.yml): The configuration file defines the experiment settings. A template is usually provided.The# Experiment Name EXPName: Kansas Yield Estimation # Model configuration EPICModel: ./model/EPIC1102.exe start_date: '2014-01-01' duration: 6 # years output_types: - ACY # Annual Crop data file - DGN # Daily general output file log_dir: ./log output_dir: ./output # Path to folders containing input files weather_dir: ./weather/Daily soil_dir: ./soil/files site_dir: ./sites opc_dir: ./opc/files # Path to csv file with sites' input files info sites_info: ./info.csv # Select specific sites from the info file select: Random(0.1) # Selects 10% of sites randomly # Timeout for a simulation execution in seconds. timeout: 10sites_infofile referenced here contains paths to site-specific inputs. Theselectoption allows flexible site filtering (e.g.,Random(0.1)for 10% random sampling,Range(0, 1)for all sites). -
Define Custom Post-Processing Routines (Optional): You can attach custom functions to the
Workspaceobject using the@exp.routinedecorator. These functions execute automatically after each site's simulation completes, allowing for automated output processing, variable extraction, analysis, or custom saving.In this example, theimport pandas as pd from geoEpic.core import Workspace from geoEpic.io import DGN, ACY exp = Workspace('./config.yml') exp.output_dir = None # Set to None if you don't want standard EPIC outputs saved @exp.routine def save_lai(site): # This function runs after each site simulation lai = DGN(site.outputs['DGN']).get_var('LAI') lai.to_csv(f'./outputs/{site.site_id}.csv') # Save LAI to a site-specific CSVsave_laifunction is registered as a routine. It reads LAI data from theDGNoutput and saves it to a CSV file named after the site ID. Settingexp.output_dir = Noneprevents the workspace from saving the raw EPIC output files (ACY,DGN, etc.), which is useful if you only need the results from your custom routine. -
Run Multi-Site Simulations: Execute the simulations for all selected sites defined in the workspace configuration. If custom routines are defined, they will run after each site simulation.
Additionally, the
Workspaceprovides@exp.loggerand@exp.objectivedecorators for more advanced logging and objective function evaluation, which are detailed further in the package documentation.