Python interface to SLEUTH¶
An object oriented wrapper for SLEUTH, an urban growth model.
This module defines the Location class, which is a work unit for SLEUTH.
How to use this module¶
Import it:
import sleuth_automation as sa
Configure it at least with a path to SLEUTH binaries:
sa.configure(sleuth_path='/path/to/sleuth', use_mpi=True, mpi_cores=32)
Create an instance:
l = sa.Location('my_location', '/path/to/my_location')
Calibrate model:
l.calibrate_coarse() l.calibrate_fine() l.calibrate_final()
or calibrate with a single call:
l.sleuth_calibrate()
Predict growth:
l.sleuth_predict(2017, 2060)
Format prediction as TIFF:
l.gif2tif(2017, 2060)
The Location class¶
-
class
sleuth_automation.Location(location, input_path)[source]¶ This class represents the main work unit of the SLEUTH model. Within a location urban growth is simulated. A location should have a name which is just a string and is used for naming output files, and a directory containing GIF files as specified by the SLEUTH documentation.
-
calibrate_coarse(monte_carlo_iterations=50)[source]¶ Run SLEUTH coarse calibration.
Parameters:
- monte_carlo_iterations: iterations for the coarse calibration step.
-
calibrate_final(monte_carlo_iterations=50)[source]¶ Run SLEUTH final calibration.
Parameters:
- monte_carlo_iterations: iterations for the final calibration step.
-
calibrate_fine(monte_carlo_iterations=50)[source]¶ Run SLEUTH fine calibration.
Parameters:
- monte_carlo_iterations: iterations for the fine calibration step.
-
create_scenario_file(params, monte_carlo_iterations)[source]¶ Merges extra parameters to global config and renders them into a SLEUTH scenario file.
Parameters:
- params: extra parameters to merge.
- monte_carlo_iterations: more iterations take a longer time
- to run but add precision.
-
gif2tif(start, end)[source]¶ Convert prediction output from GIF to TIFF.
Will use extent.json and gdal_translate to recover geospatial information lost to GIF format.
Parameters:
- start: beginning of prediction range.
- end: ending of prediction range, inclusive.
Start and end parameters are necessary to figure out paths.
-
sleuth_predict(end, diff=None, brd=None, sprd=None, slp=None, rg=None, monte_carlo_iterations=50)[source]¶ Run SLEUTH prediction step for range enclosed in start, end.
Parameters:
- end: end of temporal range for prediction, beggining is infered from last input
- diff: TODO: see model documentation
- brd: TODO: see model documentation
- sprd: spread
- slp: slope
- rg: TODO: see model documentation
- monte_carlo_iterations: iterations for the prediction step
-
ControlStats module¶
An object representation of a SLEUTH control_stats.log file.
control_stats.log files are the output of calibration steps. They contain the ranges for next calibration or prediction steps. This helper module extracts those ranges for all SLEUTH parameters:
- diff
- brd
- sprd
- slp
- rg
This is helper module will extract parameter ranges into a dictionary that can be rendered into a jinja2 template for the creation of SLEUTH scenario files.
How to use this module¶
Import it:
from controlstats import ControlStats.Create an instance:
cs = ControlStats('/path/to/my_location/output/coarse/control_stats.log'), step=5)
parameter ranges are extracted into the params attribute:
cs.paramscs.paramsis passed toLocation.create_scenario_fileto render scenario files.
ConstrolStats class¶
-
class
sleuth_automation.controlstats.ControlStats(path, step)[source]¶ This class grabs values from a control_stats.log file and calculates ranges for the parameters for next calibration stage.
It will find ranges for:
- diff
- brd
- sprd
- slp
- rg
Including values for start, end and step.
All fetched parameters will be stored into the params property.