PrecipitationDistribution
(mean_storm_duration=0.0, mean_interstorm_duration=0.0, mean_storm_depth=0.0, total_t=0.0, delta_t=None, random_seed=0, **kwds)[source]¶Bases: landlab.core.model_component.Component
Generate precipitation events.
This component can generate a random storm duration, interstorm duration, precipitation intensity or storm depth from a Poisson distribution when given a mean value.
Construction:
PrecipitationDistribution(mean_storm_duration=0.0,
mean_interstorm_duration=0.0,
mean_storm_depth=0.0, total_t=0.0,
delta_t=0.0, random_seed=0)
Parameters:  mean_storm_duration : float
mean_interstorm_duration : float
mean_storm_depth : float
total_t : float, optional
delta_t : float, optional
random_seed : int or float, optional


Examples
>>> from landlab.components.uniform_precip import PrecipitationDistribution
>>> import numpy as np
>>> np.random.seed(np.arange(10))
To use hardcoded values for mean storm, mean interstorm, mean depth, model run time and delta t... Say we use 1.5 for mean storm, 15 for mean interstorm, 0.5 for mean depth, 100 for model run time and 1 for delta t...
>>> precip = PrecipitationDistribution(mean_storm_duration = 1.5,
... mean_interstorm_duration = 15.0, mean_storm_depth = 0.5,
... total_t = 100.0, delta_t = 1.)
>>> for (dt, rate) in precip.yield_storm_interstorm_duration_intensity():
... pass # and so on
elapsed_time
¶Get the elapsed time recorded by the module.
This will be particularly useful in the midst of a yield loop.
get_interstorm_event_duration
()[source]¶Generate interstorm events.
This method takes one argument, the mean_interstorm_duration parameter. (In Eagleson (1978), this parameter was called Tb.)
This method is modeled identically to get_precipitation_event_duration()
This method finds a random value for interstorm_duration based on the poisson distribution about the mean. This is accomplished using the expovariate function from the “random” standard library.
Returns:  float


get_precipitation_event_duration
()[source]¶This method is the storm generator.
This method has one argument: the mean_storm_duration parameter. (In Eagleson (1978), this parameter was called Tr.)
It finds a random storm_duration value based on the poisson distribution about the mean. This is accomplished using the expovariate function from the “random” standard library.
Returns:  float


get_storm_depth
()[source]¶Generate storm depth.
Storm depth is used to generate a realistic intensity for different storm events.
(In Eagleson (1978) this parameter was called “h”)
This method requires storm_duration, mean_storm_duration and the mean_storm_depth. Storm_duration is generated through the initialize() or update() method.
Numpy has a random number generator to get values from a given Gamma distribution. It takes two arguments, alpha (or the shape parameter), which is the generated over the mean event and beta (or the scale parameter), which is the mean value These are all arguments in the function, which returns storm depth.
Returns:  float


get_storm_intensity
()[source]¶Get the storm intensity.
This method draws storm intensity out of the storm depth generated by get_storm_depth.
This method requires the storm_depth and storm_duration and is the same as the parameter (“i”) in Eagleson (1978), but instead of being drawn from Poission, this is drawn from the Gamma distribution of (h), as \(h = i * Tr\).
Returns:  float


get_storm_time_series
()[source]¶Get a time series of storms.
This method creates a time series of storms based on storm_duration, and interstorm_duration. From these values it will calculate a complete time series.
The storm_time_series returned by this method is made up of sublists, each comprising of three subparts (e.g. [[x,y,z], [a,b,c]]) where x and a are the beginning times of a precipitation event, y and b are the ending times of the precipitation event and z and c represent the average intensity (mm/hr) of the storm lasting from x to y and a to be, respectively.
Returns:  array


seed_generator
(seedval=0)[source]¶Seed the randomnumber generator.
The examples illustrate: (1) that we can get the same sequence again by reseeding with the
same value (the default is zero)
Examples
>>> precip = PrecipitationDistribution(mean_storm_duration = 1.5,
... mean_interstorm_duration = 15.0, mean_storm_depth = 0.5,
... total_t = 100.0, delta_t = 1.)
>>> round(precip.storm_duration, 2)
2.79
>>> round(precip.interstorm_duration, 2)
21.28
>>> round(precip.storm_depth, 2)
2.45
>>> round(precip.intensity, 2)
0.88
>>> precip.seed_generator() # reseed and get same sequence again
>>> round(precip.get_precipitation_event_duration(), 2)
2.79
>>> round(precip.get_interstorm_event_duration(), 2)
21.28
>>> round(precip.get_storm_depth(), 2)
2.45
>>> round(precip.get_storm_intensity(), 2)
0.88
>>> precip = PrecipitationDistribution(mean_storm_duration = 1.5,
... mean_interstorm_duration = 15.0, mean_storm_depth = 0.5,
... total_t = 100.0, delta_t = 1., random_seed=1)
>>> round(precip.storm_duration, 2) # diff't vals with diff't seed
0.22
>>> round(precip.interstorm_duration, 2)
28.2
>>> round(precip.storm_depth, 4)
0.0012
>>> round(precip.intensity, 4)
0.0054
update
()[source]¶Update the storm values.
If new values for storm duration, interstorm duration, storm depth and intensity are needed, this method can be used to update those values one time.
Examples
>>> from landlab.components import PrecipitationDistribution
>>> precip = PrecipitationDistribution(mean_storm_duration=1.5,
... mean_interstorm_duration=15.0, mean_storm_depth=0.5,
... total_t=100.0, delta_t=1)
Additionally, if we wanted to update several times, a loop could be utilized to accomplish this. Say we want 5 storm_durations; this pseudocode represents a way to accomplish this...
>>> storm_duration_list = []
>>> i = 0
>>> while i < 4:
... storm_duration_list.append(precip.storm_duration)
... precip.update()
... i += 1
yield_storm_interstorm_duration_intensity
(subdivide_interstorms=False)[source]¶Iterator for a time series of storms.
This method is intended to be equivalent to get_storm_time_series, but instead offers a generator functionality. This will be useful in cases where the whole sequence of storms and interstorms doesn’t need to be stored, where we can save memory this way.
The method keeps track of the delta_t such that if a storm needs to be generated longer than this supplied model timestep, the generator will return the storm in “chunks”, until there is no more storm duration. e.g., storm of intensity 1. is 4.5 long, the delta_t is 2., the generator yields (2.,1.) > (2.,1.) > (0.5,1.) > ...
If delta_t is None or not supplied, no subdivision occurs.
Once a storm has been generated, this method will follow it with the next interstorm, yielded as (interstorm_duration, 0.). Note that the interstorm will NOT be subdivided according to delta_t unless you set the flag subdivide_interstorms to True.
The method will keep yielding until it reaches the RUN_TIME, where it will terminate.
Notes
One recommended procedure is to instantiate the generator, then call instance.next() repeatedly to get the sequence.