smrf.distribute.air_temp.
ta
Bases: smrf.distribute.image_data.image_data
smrf.distribute.image_data.image_data
The ta class allows for variable specific distributions that go beyond the base class.
Air temperature is a relatively simple variable to distribute as it does not rely on any other variables, but has many variables that depend on it. Air temperature typically has a negative trend with elevation and performs best when detrended. However, even with a negative trend, it is possible to have instances where the trend does not apply, for example a temperature inversion or cold air pooling. These types of conditions will have unintended consequences on variables that use the distributed air temperature.
taConfig – The [air_temp] section of the configuration file
config
configuration from [air_temp] section
air_temp
numpy array of the air temperature
stations
stations to be used in alphabetical order
distribute
Distribute air temperature given a Panda’s dataframe for a single time step. Calls smrf.distribute.image_data.image_data._distribute.
smrf.distribute.image_data.image_data._distribute
data – Pandas dataframe for a single time step from air_temp
distribute_thread
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and call smrf.distribute.air_temp.ta.distribute then puts the distributed data into queue['air_temp'].
smrf.distribute.air_temp.ta.distribute
queue['air_temp']
queue – queue dictionary for all variables
data – pandas dataframe for all data, indexed by date time
initialize
Initialize the distribution, solely calls smrf.distribute.image_data.image_data._initialize.
smrf.distribute.image_data.image_data._initialize
topo – smrf.data.loadTopo.Topo instance contain topographic data and infomation
smrf.data.loadTopo.Topo
metadata – metadata Pandas dataframe containing the station metadata from smrf.data.loadData or smrf.data.loadGrid
smrf.data.loadData
smrf.data.loadGrid
output_variables
post_process_variables
variable
smrf.distribute.albedo.
albedo
The albedo class allows for variable specific distributions that go beyond the base class.
The visible (280-700nm) and infrared (700-2800nm) albedo follows the relationships described in Marks et al. (1992) [1]. The albedo is a function of the time since last storm, the solar zenith angle, and grain size. The time since last storm is tracked on a pixel by pixel basis and is based on where there is significant accumulated distributed precipitation. This allows for storms to only affect a small part of the basin and have the albedo decay at different rates for each pixel.
albedoConfig – The [albedo] section of the configuration file
albedo_vis
numpy array of the visible albedo
albedo_ir
numpy array of the infrared albedo
configuration from [albedo] section
min
minimum value of albedo is 0
max
maximum value of albedo is 1
current_time_step – Current time step in datetime object
cosz – numpy array of the illumination angle for the current time step
storm_day – numpy array of the decimal days since it last snowed at a grid cell
Distribute the data using threading and queue
queue – queue dict for all variables
date – dates to loop over
for the given date
Initialize the distribution, calls image_data.image_data._initialize()
topo – smrf.data.loadTopo.Topo instance contain topo data/info
data – data dataframe containing the station data
smrf.distribute.cloud_factor.
cf
The cf class allows for variable specific distributions that go beyond the base class. Cloud factor is a relatively simple variable to distribute as it does not rely on any other variables.
Cloud factor is calculated as the ratio between measured incoming solar radiation and modeled clear sky radiation. A value of 0 means no incoming solar radiation (or very cloudy) and a value of 1 means sunny.
config – The [cloud_factor] section of the configuration file
configuration from [cloud_factor] section
cloud_factor
numpy array of the cloud factor
Distribute cloud factor given a Panda’s dataframe for a single time step. Calls smrf.distribute.image_data.image_data._distribute.
data – Pandas dataframe for a single time step from cloud_factor
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and call smrf.distribute.cloud_factor.cf.distribute then puts the distributed data into queue['cloud_factor'].
smrf.distribute.cloud_factor.cf.distribute
queue['cloud_factor']
smrf.distribute.image_data.
image_data
Bases: object
object
A base distribution method in SMRF that will ensure all variables are distributed in the same manner. Other classes will be initialized using this base class.
class ta(smrf.distribute.image_data): ''' This is the ta class extending the image_data base class '''
variable (str) – Variable name for the class
A smrf.distribute.image_data class instance
smrf.distribute.image_data
The name of the variable that this class will become
[variable_name]
The variable will have the distributed data
[other_attribute]
The distributed data can also be stored as another attribute specified in _distribute
_distribute
Parsed dictionary from the configuration file for the variable
The stations to be used for the variable, if set, in alphabetical order
metadata
The metadata Pandas dataframe containing the station information from smrf.data.loadData or smrf.data.loadGrid
idw
Inverse distance weighting instance from smrf.spatial.idw.IDW
smrf.spatial.idw.IDW
dk
Detrended kriging instance from smrf.spatial.dk.dk.DK
smrf.spatial.dk.dk.DK
grid
Gridded interpolation instance from smrf.spatial.grid.GRID
smrf.spatial.grid.GRID
getConfig
Check the configuration that was set by the user for the variable that extended this class. Checks for standard distribution parameters that are common across all variables and assigns to the class instance. Sets the config and stations attributes.
cfg (dict) – dict from the [variable]
getStations
Determines the stations from the [variable] section of the configuration file.
config (dict) – dict from the [variable]
post_processor
Each distributed variable has the oppurtunity to do post processing on a sub variable. This is necessary in cases where the post proecessing might need to be done on a different timescale than that of the main loop.
Should be redefined in the individual variable module.
smrf.distribute.precipitation.
ppt
The ppt class allows for variable specific distributions that go beyond the base class.
The instantaneous precipitation typically has a positive trend with elevation due to orographic effects. However, the precipitation distribution can be further complicated for storms that have isolated impact at only a few measurement locations, for example thunderstorms or small precipitation events. Some distribution methods may be better suited than others for capturing the trend of these small events with multiple stations that record no precipitation may have a negative impact on the distribution.
The precipitation phase, or the amount of precipitation falling as rain or snow, can significantly alter the energy and mass balance of the snowpack, either leading to snow accumulation or inducing melt [2] [3]. The precipitation phase and initial snow density estimated using a variety of models that can be set in the configuration file.
For more information on the available models, checkout snow.
snow
After the precipitation phase is calculated, the storm information can be determined. The spatial resolution for which storm definitions are applied is based on the snow model thats selected.
The time since last storm is based on an accumulated precipitation mass threshold, the time elapsed since it last snowed, and the precipitation phase. These factors determine the start and end time of a storm that has produced enough precipitation as snow to change the surface albedo.
pptConfig – The [precip] section of the configuration file
time_step – The time step in minutes of the data, defaults to 60
configuration from [precip] section
precip
numpy array of the precipitation
percent_snow
numpy array of the percent of time step that was snow
snow_density
numpy array of the snow density
storm_days
numpy array of the days since last storm
storm_total
numpy array of the precipitation mass for the storm
last_storm_day
numpy array of the day of the last storm (decimal day)
last_storm_day_basin
maximum value of last_storm day within the mask if specified
minimum value of precipitation is 0
maximum value of precipitation is infinite
Distribute given a Panda’s dataframe for a single time step. Calls smrf.distribute.image_data.image_data._distribute.
The following steps are taken when distributing precip, if there is precipitation measured:
Distribute the instantaneous precipitation from the measurement data
precipitation temperature
storm, and precipitation phase threshold
data – Pandas dataframe for a single time step from precip
dpt – dew point numpy array that will be used for
precip_temp – numpy array of the precipitation temperature
ta – air temp numpy array
time – pass in the time were are currently on
wind – station wind speed at time step
temp – station air temperature at time step
az – numpy array for simulated wind direction
dir_round_cell – numpy array for wind direction in discreet increments for referencing maxus at a specific direction
wind_speed – numpy array of wind speed
cell_maxus – numpy array for maxus at correct wind directions
mask – basin mask to apply to the storm days for calculating the last storm day for the basin
distribute_for_marks2017
Specialized distribute function for working with the new accumulated snow density model Marks2017 requires storm total and a corrected precipitation as to avoid precip between storms.
distribute_for_susong1999
Susong 1999 estimates percent snow and snow density based on Susong et al, (1999) [4].
data (pd.DataFrame) – Precipitation mass data
ppt_temp (pd.DataFrame) – Precipitation temperature data
time – Unused
mask (np.array, optional) – Mask the output. Defaults to None.
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and call smrf.distribute.precip.ppt.distribute then puts the distributed data into the queue for:
smrf.distribute.precip.ppt.distribute
post_processor_threaded
smrf.distribute.soil_temp.
ts
The ts class allows for variable specific distributions that go beyond the base class.
Soil temperature is simply set to a constant value during initialization. If soil temperature measurements are available, the values can be distributed using the distribution methods.
soilConfig – The [soil] section of the configuration file
tempDir – location of temp/working directory (default=None)
configuration from [soil] section
soil_temp
numpy array of the soil temperature
No distribution is performed on soil temperature at the moment, method simply passes.
None –
Initialize the distribution and set the soil temperature to a constant value based on the configuration file.
metadata – data Pandas dataframe containing the station data, from smrf.data.loadData or smrf.data.loadGrid
smrf.distribute.solar.
solar
The solar class allows for variable specific distributions that go beyond the base class.
Multiple steps are required to estimate solar radiation:
Terrain corrected clear sky radiation
Adjust solar radiation for vegetation effects
Calculate net radiation using the albedo
The Image Processing Workbench (IPW) includes a utility stoporad to model terrain corrected clear sky radiation over the DEM. Within stoporad, the radiation transfer model twostream simulates the clear sky radiation on a flat surface for a range of wavelengths through the atmosphere [5] [6] [7]. Terrain correction using the DEM adjusts for terrain shading and splits the clear sky radiation into beam and diffuse radiation.
stoporad
twostream
The second step requires sites measuring solar radiation. The measured solar radiation is compared to the modeled clear sky radiation from twostream. The cloud factor is then the measured incoming solar radiation divided by the modeled radiation. The cloud factor can be computed on an hourly timescale if the measurement locations are of high quality. For stations that are less reliable, we recommend calculating a daily cloud factor which divides the daily integrated measured radiation by the daily integrated modeled radiation. This helps to reduce the problems that may be encountered from instrument shading, instrument calibration, or a time shift in the data. The calculated cloud factor at each station can then be distrubted using any of the method available in smrf.spatial. Since the cloud factor is not explicitly controlled by elevation like other variables, the values may be distributed without detrending to elevation. The modeled clear sky radiation (both beam and diffuse) are adjusted for clouds using smrf.envphys.radiation.cf_cloud.
smrf.spatial
smrf.envphys.radiation.cf_cloud
The third step adjusts the cloud corrected solar radiation for vegetation affects, following the methods developed by Link and Marks (1999) [8]. The direct beam radiation is corrected by:
where is the above canopy direct radiation, is the extinction coefficient (), is the canopy height (), is the solar zenith angle, and is the canopy adjusted direct radiation. Adjusting the diffuse radiation is performed by:
where is the diffuse adjusted radiation, is the optical transmissivity of the canopy, and is the above canopy diffuse radiation. Values for and can be found in Link and Marks (1999) [8], measured at study sites in Saskatchewan and Manitoba.
The final step for calculating the net solar radiation requires the surface albedo from smrf.distribute.albedo. The net radiation is the sum of the of beam and diffuse canopy adjusted radiation multipled by one minus the albedo.
smrf.distribute.albedo
config – full configuration dictionary contain at least the sections albedo, and solar
stoporad_in – file path to the stoporad_in file created from smrf.data.loadTopo.Topo
tempDir – location of temp/working directory (default=None, which is the ‘WORKDIR’ environment variable)
albedoConfig
clear_ir_beam
numpy array modeled clear sky infrared beam radiation
clear_ir_diffuse
numpy array modeled clear sky infrared diffuse radiation
clear_vis_beam
numpy array modeled clear sky visible beam radiation
clear_vis_diffuse
numpy array modeled clear sky visible diffuse radiation
numpy array distributed cloud factor
cloud_ir_beam
numpy array cloud adjusted infrared beam radiation
cloud_ir_diffuse
numpy array cloud adjusted infrared diffuse radiation
cloud_vis_beam
numpy array cloud adjusted visible beam radiation
cloud_vis_diffuse
numpy array cloud adjusted visible diffuse radiation
ir_file
temporary file from stoporad for infrared clear sky radiation
metadata for the station data
net_solar
numpy array for the calculated net solar radiation
stoporad_in
file path to the stoporad_in file created from smrf.data.loadTopo.Topo
tempDir
temporary directory for stoporad, will default to the WORKDIR environment variable
WORKDIR
veg_height
numpy array of vegetation heights from smrf.data.loadTopo.Topo
veg_ir_beam
numpy array vegetation adjusted infrared beam radiation
veg_ir_diffuse
numpy array vegetation adjusted infrared diffuse radiation
veg_k
numpy array of vegetation extinction coefficient from smrf.data.loadTopo.Topo
veg_tau
numpy array of vegetation optical transmissivity from smrf.data.loadTopo.Topo
veg_vis_beam
numpy array vegetation adjusted visible beam radiation
veg_vis_diffuse
numpy array vegetation adjusted visible diffuse radiation
vis_file
temporary file from stoporad for visible clear sky radiation
calc_ir
Run stoporad for the infrared bands
min_storm_day – decimal day of last storm for the entire basin, from smrf.distribute.precip.ppt.last_storm_day_basin
smrf.distribute.precip.ppt.last_storm_day_basin
wy_day – day of water year, from radiation_dates
radiation_dates
tz_min_west – time zone in minutes west from UTC, from radiation_dates
wyear – water year, from radiation_dates
cosz – cosine of the zenith angle for the basin, from smrf.envphys.radiation.sunang
smrf.envphys.radiation.sunang
azimuth – azimuth to the sun for the basin, from smrf.envphys.radiation.sunang
calc_net
Calculate the net radiation using the vegetation adjusted radiation. Sets net_solar.
albedo_vis – numpy array for visible albedo, from smrf.distribute.albedo.albedo.albedo_vis
smrf.distribute.albedo.albedo.albedo_vis
albedo_ir – numpy array for infrared albedo, from smrf.distribute.albedo.albedo.albedo_ir
smrf.distribute.albedo.albedo.albedo_ir
calc_vis
Run stoporad for the visible bands
cloud_correct
Correct the modeled clear sky radiation for cloud cover using smrf.envphys.radiation.cf_cloud. Sets cloud_vis_beam and cloud_vis_diffuse.
If the sun is up, i.e. cosz > 0, then the following steps are performed:
cosz > 0
Model clear sky radiation
Cloud correct with smrf.distribute.solar.solar.cloud_correct
smrf.distribute.solar.solar.cloud_correct
smrf.distribute.solar.solar.veg_correct
smrf.distribute.solar.solar.calc_net
If sun is down, then all calculated values will be set to None, signaling the output functions to put zeros in their place.
None
cloud_factor – Numpy array of the domain for cloud factor
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step following the methods outlined in smrf.distribute.solar.solar.distribute. The data queues puts the distributed data into:
smrf.distribute.solar.solar.distribute
distribute_thread_clear
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and model clear sky radiation with stoporad. The data queues puts the distributed data into:
Initialize the distribution, soley calls smrf.distribute.image_data.image_data._initialize. Sets the following attributes:
data – data Pandas dataframe containing the station data, from smrf.data.loadData or smrf.data.loadGrid
Calculate some times based on the date for stoporad
date_time – date time object
tuple containing:
wy_day - day of water year from October 1 wyear - water year tz_min_west - minutes west of UTC for timezone
wy_day - day of water year from October 1
wyear - water year
tz_min_west - minutes west of UTC for timezone
(tuple)
veg_correct
Correct the cloud adjusted radiation for vegetation using smrf.envphys.radiation.veg_beam and smrf.envphys.radiation.veg_diffuse. Sets veg_vis_beam, veg_vis_diffuse, veg_ir_beam, and veg_ir_diffuse.
smrf.envphys.radiation.veg_beam
smrf.envphys.radiation.veg_diffuse
illum_ang – numpy array of the illumination angle over the DEM, from smrf.envphys.radiation.sunang
smrf.distribute.thermal.
th
The th class allows for variable specific distributions that go beyond the base class.
Thermal radiation, or long-wave radiation, is calculated based on the clear sky radiation emitted by the atmosphere. Multiple methods for calculating thermal radition exist and SMRF has 4 options for estimating clear sky thermal radiation. Selecting one of the options below will change the equations used. The methods were chosen based on the study by Flerchinger et al (2009) [9] who performed a model comparison using 21 AmeriFlux sites from North America and China.
The methods follow those developed by Marks and Dozier (1979) [10] that calculates the effective clear sky atmospheric emissivity using the distributed air temperature, distributed dew point temperature, and the elevation. The clear sky radiation is further adjusted for topographic affects based on the percent of the sky visible at any given point.
References: Dilley and O’Brian (1998) [11]
References: Prata (1996) [12]
References: Angstrom (1918) [13] as cityed by Niemela et al (2001) [14]
Fig. 5 The 4 different methods for estimating clear sky thermal radiation for a single time step. As compared to the Mark1979 method, the other methods provide a wide range in the estimated value of thermal radiation.¶
The topographic correct clear sky thermal radiation is further adjusted for cloud affects. Cloud correction is based on fraction of cloud cover, a cloud factor close to 1 meaning no clouds are present, there is little radiation added. When clouds are present, or a cloud factor close to 0, then additional long wave radiation is added to account for the cloud cover. Selecting one of the options below will change the equations used. The methods were chosen based on the study by Flerchinger et al (2009) [9], where .
Cloud correction is based on the relationship in Garen and Marks (2005) [15] between the cloud factor and measured long wave radiation using measurement stations in the Boise River Basin.
References: Unsworth and Monteith (1975) [16]
where the original Kimball et al. (1982) [17] was for multiple cloud layers, which was simplified to one layer. is the cloud temperature and is assumed to be 11 K cooler than .
References: Kimball et al. (1982) [17]
References: Crawford and Duchon (1999) [18] where is the ratio of measured solar radiation to the clear sky irradiance.
The results from Flerchinger et al (2009) [9] showed that the Kimball1982 cloud correction with Dilley1998 clear sky algorthim had the lowest RMSD. The Crawford1999 worked best when combined with Angstrom1918, Dilley1998, or Prata1996.
Fig. 6 The 4 different methods for correcting clear sky thermal radiation for cloud affects at a single time step. As compared to the Garen2005 method, the other methods are typically higher where clouds are present (i.e. the lower left) where the cloud factor is around 0.4.¶
The thermal radiation is further adjusted for canopy cover after the work of Link and Marks (1999) [8]. The correction is based on the vegetation’s transmissivity, with the canopy temperature assumed to be the air temperature for vegetation greater than 2 meters. The thermal radiation is adjusted by
where is the optical transmissivity, is the cloud corrected thermal radiation, is the emissivity of the canopy (0.96), is the Stephan-Boltzmann constant, and is the distributed air temperature.
thermalConfig – The [thermal] section of the configuration file
configuration from [thermal] section
thermal
minimum value of thermal is -600 W/m^2
maximum value of thermal is 600 W/m^2
dem
numpy array for the DEM, from smrf.data.loadTopo.Topo.dem
smrf.data.loadTopo.Topo.dem
veg_type
numpy array for the veg type, from smrf.data.loadTopo.Topo.veg_type
smrf.data.loadTopo.Topo.veg_type
numpy array for the veg height, from smrf.data.loadTopo.Topo.veg_height
smrf.data.loadTopo.Topo.veg_height
numpy array for the veg K, from smrf.data.loadTopo.Topo.veg_k
smrf.data.loadTopo.Topo.veg_k
numpy array for the veg transmissivity, from smrf.data.loadTopo.Topo.veg_tau
smrf.data.loadTopo.Topo.veg_tau
sky_view
numpy array for the sky view factor, from smrf.data.loadTopo.Topo.sky_view
smrf.data.loadTopo.Topo.sky_view
Distribute for a single time step.
The following steps are taken when distributing thermal:
smrf.envphys.core.envphys_c.ctopotherm
Correct the clear sky thermal for the distributed cloud factor
Correct for canopy affects
date_time – datetime object for the current step
air_temp – distributed air temperature for the time step
vapor_pressure – distributed vapor pressure for the time step
dew_point – distributed dew point for the time step
cloud_factor – distributed cloud factor for the time step measured/modeled
distribute_thermal
Distribute given a Panda’s dataframe for a single time step. Calls smrf.distribute.image_data.image_data._distribute. Used when thermal is given (i.e. gridded datasets from WRF). Follows these steps:
Distribute the thermal radiation from point values
Correct for vegetation
data – thermal values
air_temp – distributed air temperature values
distribute_thermal_thread
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and call smrf.distribute.thermal.th.distribute_thermal then puts the distributed data into the queue for thermal. Used when thermal is given (i.e. gridded datasets from WRF).
smrf.distribute.thermal.th.distribute_thermal
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and call smrf.distribute.thermal.th.distribute then puts the distributed data into the queue for thermal.
smrf.distribute.thermal.th.distribute
Initialize the distribution, calls smrf.distribute.image_data.image_data._initialize for gridded distirbution. Sets the following from smrf.data.loadTopo.Topo
smrf.distribute.vapor_pressure.
vp
The vp class allows for variable specific distributions that go beyond the base class
Vapor pressure is provided as an argument and is calculated from coincident air temperature and relative humidity measurements using utilities such as IPW’s rh2vp. The vapor pressure is distributed instead of the relative humidity as it is an absolute measurement of the vapor within the atmosphere and will follow elevational trends (typically negative). Were as relative humidity is a relative measurement which varies in complex ways over the topography. From the distributed vapor pressure, the dew point is calculated for use by other distribution methods. The dew point temperature is further corrected to ensure that it does not exceed the distributed air temperature.
rh2vp
vpConfig – The [vapor_pressure] section of the configuration file
configuration from [vapor_pressure] section
vapor_pressure
numpy matrix of the vapor pressure
dew_point
numpy matrix of the dew point, calculated from vapor_pressure and corrected for dew_point greater than air_temp
minimum value of vapor pressure is 10 Pa
maximum value of vapor pressure is 7500 Pa
The following steps are performed when distributing vapor pressure:
Distribute the point vapor pressure measurements
smrf.envphys.core.envphys_c.cdewpt
Adjust dew point values to not exceed the air temperature
ta – air temperature numpy array that will be used for calculating dew point temperature
Distribute the data using threading and queue. All data is provided and distribute_thread will go through each time step and call smrf.distribute.vapor_pressure.vp.distribute then puts the distributed data into the queue for:
smrf.distribute.vapor_pressure.vp.distribute
Initialize the distribution, calls smrf.distribute.image_data.image_data._initialize. Preallocates the following class attributes to zeros: