smrf.framework package¶
smrf.framework.model_framework module¶
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.
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
-
class
smrf.framework.model_framework.SMRF(config, external_logger=None)[source]¶ Bases:
objectSMRF - Spatial Modeling for Resources Framework
Parameters: configFile (str) – path to configuration file. Returns: 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
initializeDistirbution()
-
create_distributed_threads()[source]¶ Creates the threads for a distributed run in smrf. Designed for smrf runs in memory
- Returns
- t: list of threads for distirbution q: queue
-
distributeData()[source]¶ Wrapper for various distribute methods. If threading was set in configFile, then
distributeData_threaded()will be called. Default will calldistributeData_single().
-
distributeData_single()[source]¶ 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 fromloadData(). The function distributes over each time step, all the variables below.- Steps performed:
- Sun angle for the time step
- Illumination angle
- Air temperature
- Vapor pressure
- Wind direction and speed
- Precipitation
- Solar radiation
- Thermal radiation
- Soil temperature
- Output time step if needed
-
distributeData_threaded()[source]¶ 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 fromloadData(). ADateQueueis initialized forall threading variables. Each variable insmrf.distribute()is passed all the required point data at once using the distribute_thread function. The distribute_thread function iterates overdate_timeand places the distributed values into theDateQueue.
-
initializeDistribution()[source]¶ This initializes the distirbution classes based on the configFile sections for each variable.
initializeDistribution()will initialize the variables within thesmrf.distribute()package and insert into a dictionary ‘distribute’ with variable names as the keys.- Variables that are intialized are:
-
initializeOutput()[source]¶ Initialize the output files based on the configFile section [‘output’]. Currently only
NetCDF filesis supported.
-
loadData()[source]¶ 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:
After loading,
loadData()will callsmrf.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.
-
loadTopo(calcInput=True)[source]¶ Load the information from the configFile in the [‘topo’] section. See
smrf.data.loadTopo.topo()for full description.
-
modules= ['air_temp', 'albedo', 'precip', 'soil_temp', 'solar', 'thermal', 'vapor_pressure', 'wind']¶
-
output(current_time_step, module=None, out_var=None)[source]¶ Output the forcing data or model outputs for the current_time_step.
Parameters: - current_time_step (date_time) – the current time step datetime object
- - (var_name) –
- - –
-
thread_variables= ['cosz', 'azimuth', 'illum_ang', 'air_temp', 'dew_point', 'vapor_pressure', 'wind_speed', 'precip', 'percent_snow', 'snow_density', 'last_storm_day_basin', 'storm_days', 'precip_temp', 'clear_vis_beam', 'clear_vis_diffuse', 'clear_ir_beam', 'clear_ir_diffuse', 'albedo_vis', 'albedo_ir', 'net_solar', 'cloud_factor', 'thermal', 'output', 'veg_ir_beam', 'veg_ir_diffuse', 'veg_vis_beam', 'veg_vis_diffuse', 'cloud_ir_beam', 'cloud_ir_diffuse', 'cloud_vis_beam', 'cloud_vis_diffuse', 'thermal_clear', 'wind_direction']¶
-
-
smrf.framework.model_framework.can_i_run_smrf(config)[source]¶ Function that wraps run_smrf in try, except for testing purposes
Parameters: config – string path to the config file or inicheck UserConfig instance
-
smrf.framework.model_framework.find_pixel_location(row, vec, a)[source]¶ Find the index of the stations X/Y location in the model domain
Parameters: - 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’)
Returns: Pixel value in vec where row[a] is located