VeraGridEngine.Simulations.Stochastic packageο
Submodulesο
VeraGridEngine.Simulations.Stochastic.latin_hypercube_sampling moduleο
This code was originally published by the following individuals for use with Scilab:
Copyright (C) 2012 - 2013 - Michael Baudin Copyright (C) 2012 - Maria Christopoulou Copyright (C) 2010 - 2011 - INRIA - Michael Baudin Copyright (C) 2009 - Yann Collette Copyright (C) 2009 - CEA - Jean-Marc Martinez
website: forge.scilab.org/index.php/p/scidoe/sourcetree/master/macros
Much thanks goes to these individuals. It has been converted to Python by Abraham Lee.
- VeraGridEngine.Simulations.Stochastic.latin_hypercube_sampling.lhs(n: int, samples: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]] | None = None, criterion: str = 'center', iterations: int = 5)[source]ο
Generate a latin-hypercube design
Parametersο
- nint
The number of factors to generate samples for
- samplesint
The number of samples to generate for each factor (Default: n)
- criterionstr
Allowable values are βcenterβ or βcβ, βmaximinβ or βmβ, βcentermaximinβ or βcmβ, and βcorrelationβ or βcorrβ. If no value given, the design is simply randomized.
- iterationsint
The number of iterations in the maximin and correlations algorithms (Default: 5).
Returnsο
- H2d-array
An n-by-samples design matrix that has been normalized so factor values are uniformly spaced between zero and one.
Exampleο
A 3-factor design (defaults to 3 samples):
>>> lhs(3) array([[ 0.40069325, 0.08118402, 0.69763298], [ 0.19524568, 0.41383587, 0.29947106], [ 0.85341601, 0.75460699, 0.360024 ]])
A 4-factor design with 6 samples:
>>> lhs(4, samples=6) array([[ 0.27226812, 0.02811327, 0.62792445, 0.91988196], [ 0.76945538, 0.43501682, 0.01107457, 0.09583358], [ 0.45702981, 0.76073773, 0.90245401, 0.18773015], [ 0.99342115, 0.85814198, 0.16996665, 0.65069309], [ 0.63092013, 0.22148567, 0.33616859, 0.36332478], [ 0.05276917, 0.5819198 , 0.67194243, 0.78703262]])
A 2-factor design with 5 centered samples:
>>> lhs(2, samples=5, criterion='center') array([[ 0.3, 0.5], [ 0.7, 0.9], [ 0.1, 0.3], [ 0.9, 0.1], [ 0.5, 0.7]])
A 3-factor design with 4 samples where the minimum distance between all samples has been maximized:
>>> lhs(3, samples=4, criterion='maximin') array([[ 0.02642564, 0.55576963, 0.50261649], [ 0.51606589, 0.88933259, 0.34040838], [ 0.98431735, 0.0380364 , 0.01621717], [ 0.40414671, 0.33339132, 0.84845707]])
A 4-factor design with 5 samples where the samples are as uncorrelated as possible (within 10 iterations):
>>> lhs(4, samples=5, criterion='correlate', iterations=10)
VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_driver moduleο
- class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_driver.StochasticPowerFlowDriver(grid: MultiCircuit, options: PowerFlowOptions, mc_tol=0.001, batch_size=100, sampling_points=10000, opf_time_series_results=None, simulation_type: StochasticPowerFlowType = StochasticPowerFlowType.LatinHypercube)[source]ο
Bases:
DriverTemplate- batch_sizeο
- max_sampling_pointsο
- mc_tolο
- name = 'Stochastic Power Flow'ο
- opf_time_series_resultsο
- optionsο
- poolο
- returned_resultsο
- run_single_thread_mc(use_lhs: bool = False) StochasticPowerFlowResults | None[source]ο
Run the stochastic sampling loop in the current thread.
- Parameters:
use_lhs β Whether Latin Hypercube sampling must be used.
- Returns:
StochasticPowerFlowResults when the study can be executed, otherwise
None.
- simulation_typeο
- tpe = 'Stochastic Power Flow'ο
VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_input moduleο
- class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_input.StochasticPowerFlowInput[source]ο
Bases:
object- get(n_samples: int = 0, use_latin_hypercube: bool = False) ndarray[tuple[Any, ...], dtype[complex128]][source]ο
Generate stochastic samples for the grid injections.
- Parameters:
n_samples β number of samples
use_latin_hypercube β use Latin Hypercube to sample
- Returns:
CxMat (p.u.)
- get_at(x: ndarray) ndarray[tuple[Any, ...], dtype[complex128]][source]ο
Get samples at x :param x: values in [0, 1] to sample the CDF :return: CxVec
- has_profile_samples() bool[source]ο
Check whether the input contains at least one time-series sample.
- Returns:
Truewhen stochastic samples can be generated.
- n: intο
- regression_model: KNeighborsRegressor | Noneο
VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_results moduleο
- class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_results.StochasticPowerFlowResults(n, m, p, bus_names, branch_names, bus_types)[source]ο
Bases:
ResultsTemplate- CLASS_DATA_VARIABLES = {'S_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'Sbr_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'V_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'branch_names': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'bus_names': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'bus_types': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'error_series': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'l_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'l_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loading': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loading_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loss_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loss_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'losses': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'losses_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'points_number': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 's_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 's_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'sbranch': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'v_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'v_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'voltage': <VeraGridEngine.Simulations.results_template.ResultsProperty object>}ο
- CLASS_RESULTS_DECLARATIONS = (<VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>)ο
- LOCAL_RESULTS_DECLARATIONS = (<VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>)ο
- S_pointsο
- Sbr_pointsο
- V_pointsο
- append_batch(mcres)[source]ο
Append a batch (a StochasticPowerFlowResults object) to this object @param mcres: StochasticPowerFlowResults object @return:
- branch_namesο
- bus_namesο
- bus_typesο
- error_seriesο
- get_index_loading_cdf(max_val=1.0)[source]ο
Find the elements where the CDF is greater or equal to a value :param max_val: value to compare :return: indices, associated probability
- l_avg_convο
- l_std_convο
- loadingο
- loading_pointsο
- loss_avg_convο
- loss_std_convο
- lossesο
- losses_pointsο
- mdl(result_type: ResultTypes) ResultsTable[source]ο
Plot the results :param result_type: :return:
- points_numberο
- query_voltage(power_array)[source]ο
Fantastic function that allows to query the voltage from the sampled points without having to run power Sf Args:
power_array: power Injections vector
Returns: Interpolated voltages vector
- s_avg_convο
- s_std_convο
- sbranchο
- v_avg_convο
- v_std_convο
- voltageο