The module model_framework contains functions and classes that act as a major wrapper to the underlying packages and modules contained with SMRF. A class instance of SMRF is initialized with a configuration file indicating where data is located, what variables to distribute and how, where to output the distributed data, or run as a threaded application. See the help on the configuration file to learn more about how to control the actions of SMRF.
model_framework
SMRF
Example
The following examples shows the most generic method of running SMRF. These commands will generate all the forcing data required to run iSnobal. A complete example can be found in run_smrf.py
>>> import smrf >>> s = smrf.framework.SMRF(configFile) # initialize SMRF >>> s.loadTopo() # load topo data >>> s.initializeDistribution() # initialize the distribution >>> s.initializeOutput() # initialize the outputs if desired >>> s.loadData() # load weather data and station metadata >>> s.distributeData() # distribute
smrf.framework.model_framework.
Bases: object
object
SMRF - Spatial Modeling for Resources Framework
configFile (str) – path to configuration file.
SMRF class instance.
start_date
start_date read from configFile
end_date
end_date read from configFile
date_time
Numpy array of date_time objects between start_date and end_date
config
Configuration file read in as dictionary
distribute
Dictionary the contains all the desired variables to distribute and is initialized in initializeDistribution()
initializeDistribution()
create_distributed_threads
Creates the threads for a distributed run in smrf. Designed for smrf runs in memory
t: list of threads for distirbution q: queue
distributeData
Wrapper for various distribute methods. If threading was set in configFile, then distributeData_threaded() will be called. Default will call distributeData_single().
distributeData_threaded()
distributeData_single()
distributeData_single
Distribute the measurement point data for all variables in serial. Each variable is initialized first using the smrf.data.loadTopo.Topo() instance and the metadata loaded from loadData(). The function distributes over each time step, all the variables below.
smrf.data.loadTopo.Topo()
loadData()
Sun angle for the time step
Illumination angle
Air temperature
Vapor pressure
Wind direction and speed
Precipitation
Cloud Factor
Solar radiation
Thermal radiation
Soil temperature
Output time step if needed
distributeData_threaded
Distribute the measurement point data for all variables using threading and queues. Each variable is initialized first using the smrf.data.loadTopo.Topo() instance and the metadata loaded from loadData(). A DateQueue is initialized for all threading variables. Each variable in smrf.distribute() is passed all the required point data at once using the distribute_thread function. The distribute_thread function iterates over date_time and places the distributed values into the DateQueue.
DateQueue
all threading variables
smrf.distribute()
initializeDistribution
This initializes the distirbution classes based on the configFile sections for each variable. initializeDistribution() will initialize the variables within the smrf.distribute() package and insert into a dictionary ‘distribute’ with variable names as the keys.
Wind speed and direction
Albedo
Soil Temperature
initializeOutput
Initialize the output files based on the configFile section [‘output’]. Currently only NetCDF files is supported.
NetCDF files
loadData
Load the measurement point data for distributing to the DEM, must be called after the distributions are initialized. Currently, data can be loaded from three different sources:
CSV files MySQL database Gridded data source (WRF)
CSV files
MySQL database
Gridded data source (WRF)
After loading, loadData() will call smrf.framework.model_framework.find_pixel_location() to determine the pixel locations of the point measurements and filter the data to the desired stations if CSV files are used.
smrf.framework.model_framework.find_pixel_location()
loadTopo
Load the information from the configFile in the [‘topo’] section. See smrf.data.loadTopo.Topo() for full description.
modules
output
Output the forcing data or model outputs for the current_time_step.
current_time_step (date_time) – the current time step datetime object
- (var_name) –
- –
post_process
Execute all the post processors
thread_variables
title
A little title to go at the top of the logger file
can_i_run_smrf
Function that wraps run_smrf in try, except for testing purposes
config – string path to the config file or inicheck UserConfig instance
find_pixel_location
Find the index of the stations X/Y location in the model domain
row (pandas.DataFrame) – metadata rows
vec (nparray) – Array of X or Y locations in domain
a (str) – Column in DataFrame to pull data from (i.e. ‘X’)
Pixel value in vec where row[a] is located
run_smrf
Function that runs smrf how it should be operate for full runs.