worst package
Submodules
worst.constants module
worst.sci module
Fit GEV using scipy and compare to known upper bound.
- worst.sci.bg_pdf(z, z_star, beta, gamma)
Upper bound known GEV probability density function.
- worst.sci.evt_fig_scipy(z_star=7, beta=1, gamma=-0.2, ex_seed=42, ex_num=50, min_samp=20, max_samp=1000, samp_steps=100, seed_steps=1000, save_fig_path='/home/docs/checkouts/readthedocs.org/user_builds/worstsurge/checkouts/stable/img/evt_fig_scipy.pdf', color_true='black', color_max_known='#1b9e77', color_max_unknown='#d95f02')
Fit GEV using scipy with or without knowing an upper bound.
Plot the systematic comparison of what difference it makes for the 1 in 100 and 1 in 500 year return values when fitting a GEV distribution to data sampled from a known upper bound GEV distribution, varying the random seed and the number of samples to plot how the sampling error decreases in each case.
- Parameters:
z_star (float, optional) – Upper bound. Defaults to 7.
beta (float, optional) – Scale. Defaults to 1.
gamma (float, optional) – Shape. Defaults to -0.2.
ex_seed (int, optional) – Example fit seed for (a). Defaults to 42.
ex_num (int, optional) – Example number. Defaults to 50.
min_samp (int, optional) – Minimum number of samples. Defaults to 20.
max_samp (int, optional) – Maximum number of samples. Defaults to 1000.
samp_steps (int, optional) – How many different sample sizes to choose. Defaults to 100.
seed_steps (int, optional) – _description_. Defaults to 1000.
save_fig_path (str, optional) – Defaults to os.path.join(FIGURE_PATH, “evt_fig_scipy.pdf”).
color_true (str, optional) – _description_. Defaults to “black”.
color_max_known (str, optional) – _description_. Defaults to “#1b9e77”.
color_max_unknown (str, optional) – _description_. Defaults to “#d95f02”.
- worst.sci.fit_seeds(z_star, beta, gamma, seeds=array([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1001, 1011, 1021, 1031, 1041, 1051, 1061, 1071, 1081, 1091, 1101, 1111, 1121, 1131, 1141, 1151, 1161, 1171, 1181, 1191, 1201, 1211, 1221, 1231, 1241, 1251, 1261, 1271, 1281, 1291, 1301, 1311, 1321, 1331, 1341, 1351, 1361, 1371, 1381, 1391, 1401, 1411, 1421, 1431, 1441, 1451, 1461, 1471, 1481, 1491, 1501, 1511, 1521, 1531, 1541, 1551, 1561, 1571, 1581, 1591, 1601, 1611, 1621, 1631, 1641, 1651, 1661, 1671, 1681, 1691, 1701, 1711, 1721, 1731, 1741, 1751, 1761, 1771, 1781, 1791, 1801, 1811, 1821, 1831, 1841, 1851, 1861, 1871, 1881, 1891, 1901, 1911, 1921, 1931, 1941, 1951, 1961, 1971, 1981, 1991, 2002, 2012, 2022, 2032, 2042, 2052, 2062, 2072, 2082, 2092, 2102, 2112, 2122, 2132, 2142, 2152, 2162, 2172, 2182, 2192, 2202, 2212, 2222, 2232, 2242, 2252, 2262, 2272, 2282, 2292, 2302, 2312, 2322, 2332, 2342, 2352, 2362, 2372, 2382, 2392, 2402, 2412, 2422, 2432, 2442, 2452, 2462, 2472, 2482, 2492, 2502, 2512, 2522, 2532, 2542, 2552, 2562, 2572, 2582, 2592, 2602, 2612, 2622, 2632, 2642, 2652, 2662, 2672, 2682, 2692, 2702, 2712, 2722, 2732, 2742, 2752, 2762, 2772, 2782, 2792, 2802, 2812, 2822, 2832, 2842, 2852, 2862, 2872, 2882, 2892, 2902, 2912, 2922, 2932, 2942, 2952, 2962, 2972, 2982, 2992, 3003, 3013, 3023, 3033, 3043, 3053, 3063, 3073, 3083, 3093, 3103, 3113, 3123, 3133, 3143, 3153, 3163, 3173, 3183, 3193, 3203, 3213, 3223, 3233, 3243, 3253, 3263, 3273, 3283, 3293, 3303, 3313, 3323, 3333, 3343, 3353, 3363, 3373, 3383, 3393, 3403, 3413, 3423, 3433, 3443, 3453, 3463, 3473, 3483, 3493, 3503, 3513, 3523, 3533, 3543, 3553, 3563, 3573, 3583, 3593, 3603, 3613, 3623, 3633, 3643, 3653, 3663, 3673, 3683, 3693, 3703, 3713, 3723, 3733, 3743, 3753, 3763, 3773, 3783, 3793, 3803, 3813, 3823, 3833, 3843, 3853, 3863, 3873, 3883, 3893, 3903, 3913, 3923, 3933, 3943, 3953, 3963, 3973, 3983, 3993, 4004, 4014, 4024, 4034, 4044, 4054, 4064, 4074, 4084, 4094, 4104, 4114, 4124, 4134, 4144, 4154, 4164, 4174, 4184, 4194, 4204, 4214, 4224, 4234, 4244, 4254, 4264, 4274, 4284, 4294, 4304, 4314, 4324, 4334, 4344, 4354, 4364, 4374, 4384, 4394, 4404, 4414, 4424, 4434, 4444, 4454, 4464, 4474, 4484, 4494, 4504, 4514, 4524, 4534, 4544, 4554, 4564, 4574, 4584, 4594, 4604, 4614, 4624, 4634, 4644, 4654, 4664, 4674, 4684, 4694, 4704, 4714, 4724, 4734, 4744, 4754, 4764, 4774, 4784, 4794, 4804, 4814, 4824, 4834, 4844, 4854, 4864, 4874, 4884, 4894, 4904, 4914, 4924, 4934, 4944, 4954, 4964, 4974, 4984, 4994, 5005, 5015, 5025, 5035, 5045, 5055, 5065, 5075, 5085, 5095, 5105, 5115, 5125, 5135, 5145, 5155, 5165, 5175, 5185, 5195, 5205, 5215, 5225, 5235, 5245, 5255, 5265, 5275, 5285, 5295, 5305, 5315, 5325, 5335, 5345, 5355, 5365, 5375, 5385, 5395, 5405, 5415, 5425, 5435, 5445, 5455, 5465, 5475, 5485, 5495, 5505, 5515, 5525, 5535, 5545, 5555, 5565, 5575, 5585, 5595, 5605, 5615, 5625, 5635, 5645, 5655, 5665, 5675, 5685, 5695, 5705, 5715, 5725, 5735, 5745, 5755, 5765, 5775, 5785, 5795, 5805, 5815, 5825, 5835, 5845, 5855, 5865, 5875, 5885, 5895, 5905, 5915, 5925, 5935, 5945, 5955, 5965, 5975, 5985, 5995, 6006, 6016, 6026, 6036, 6046, 6056, 6066, 6076, 6086, 6096, 6106, 6116, 6126, 6136, 6146, 6156, 6166, 6176, 6186, 6196, 6206, 6216, 6226, 6236, 6246, 6256, 6266, 6276, 6286, 6296, 6306, 6316, 6326, 6336, 6346, 6356, 6366, 6376, 6386, 6396, 6406, 6416, 6426, 6436, 6446, 6456, 6466, 6476, 6486, 6496, 6506, 6516, 6526, 6536, 6546, 6556, 6566, 6576, 6586, 6596, 6606, 6616, 6626, 6636, 6646, 6656, 6666, 6676, 6686, 6696, 6706, 6716, 6726, 6736, 6746, 6756, 6766, 6776, 6786, 6796, 6806, 6816, 6826, 6836, 6846, 6856, 6866, 6876, 6886, 6896, 6906, 6916, 6926, 6936, 6946, 6956, 6966, 6976, 6986, 6996, 7007, 7017, 7027, 7037, 7047, 7057, 7067, 7077, 7087, 7097, 7107, 7117, 7127, 7137, 7147, 7157, 7167, 7177, 7187, 7197, 7207, 7217, 7227, 7237, 7247, 7257, 7267, 7277, 7287, 7297, 7307, 7317, 7327, 7337, 7347, 7357, 7367, 7377, 7387, 7397, 7407, 7417, 7427, 7437, 7447, 7457, 7467, 7477, 7487, 7497, 7507, 7517, 7527, 7537, 7547, 7557, 7567, 7577, 7587, 7597, 7607, 7617, 7627, 7637, 7647, 7657, 7667, 7677, 7687, 7697, 7707, 7717, 7727, 7737, 7747, 7757, 7767, 7777, 7787, 7797, 7807, 7817, 7827, 7837, 7847, 7857, 7867, 7877, 7887, 7897, 7907, 7917, 7927, 7937, 7947, 7957, 7967, 7977, 7987, 7997, 8008, 8018, 8028, 8038, 8048, 8058, 8068, 8078, 8088, 8098, 8108, 8118, 8128, 8138, 8148, 8158, 8168, 8178, 8188, 8198, 8208, 8218, 8228, 8238, 8248, 8258, 8268, 8278, 8288, 8298, 8308, 8318, 8328, 8338, 8348, 8358, 8368, 8378, 8388, 8398, 8408, 8418, 8428, 8438, 8448, 8458, 8468, 8478, 8488, 8498, 8508, 8518, 8528, 8538, 8548, 8558, 8568, 8578, 8588, 8598, 8608, 8618, 8628, 8638, 8648, 8658, 8668, 8678, 8688, 8698, 8708, 8718, 8728, 8738, 8748, 8758, 8768, 8778, 8788, 8798, 8808, 8818, 8828, 8838, 8848, 8858, 8868, 8878, 8888, 8898, 8908, 8918, 8928, 8938, 8948, 8958, 8968, 8978, 8988, 8998, 9009, 9019, 9029, 9039, 9049, 9059, 9069, 9079, 9089, 9099, 9109, 9119, 9129, 9139, 9149, 9159, 9169, 9179, 9189, 9199, 9209, 9219, 9229, 9239, 9249, 9259, 9269, 9279, 9289, 9299, 9309, 9319, 9329, 9339, 9349, 9359, 9369, 9379, 9389, 9399, 9409, 9419, 9429, 9439, 9449, 9459, 9469, 9479, 9489, 9499, 9509, 9519, 9529, 9539, 9549, 9559, 9569, 9579, 9589, 9599, 9609, 9619, 9629, 9639, 9649, 9659, 9669, 9679, 9689, 9699, 9709, 9719, 9729, 9739, 9749, 9759, 9769, 9779, 9789, 9799, 9809, 9819, 9829, 9839, 9849, 9859, 9869, 9879, 9889, 9899, 9909, 9919, 9929, 9939, 9949, 9959, 9969, 9979, 9989, 10000]), nums=array([990, 1190, 1430, 1718, 2065, 2482, 2983, 3585, 4309, 5179, 6224, 7480, 8990, 10804, 12985, 15605, 18755, 22540, 27089, 32556, -26410, -18513, -9023, 2382, 16089, 32562, -13176, 10617, -26324, 8041, -16194, -32093, 27560, -31819, -11194, 26819, 20195, -26851, 21823, -24299, -26826, 23043, 4807, -3288, 14029, 9578, 5417, 28058, -21711, 25473], dtype=int16))
- Return type:
DataArray
- worst.sci.get_evt_fit_data(z_star, beta, gamma, seeds, nums, load=True)
- Return type:
DataArray
- worst.sci.gev_pdf(z, alpha, beta, gamma)
Generalized extreme value probability density function.
- worst.sci.plot_ex(z_star, beta, gamma, ex_seed, ex_num, color_true, color_max_known, color_max_unknown, ax=None)
- worst.sci.try_fit(z_star=7, beta=4, gamma=-0.1, n=40, seed=42, quantiles=[0.01, 0.005])
- Return type:
- worst.sci.try_fits(z_star=7, beta=1, gamma=-0.3, seed=100, nums=[20, 22, 25, 27, 30, 33, 35, 40, 50, 60, 75, 100, 200, 500, 1000])
- Return type:
DataArray
worst.tens module
Tensorflow optimization for the worst-case analysis of random variables.
Sometimes breaks for no clear reason; in that case fit is retried 9 further times. It is very unlikely that the optimization will fail 10 times in a row, so this should be sufficient.
- worst.tens.fit_gev_upper_bound_known(data, z_star, opt_steps=1000, lr=0.01, beta_guess=1.0, gamma_guess=-0.1, verbose=False)
Fit a Generalized Extreme Value distribution to data when the upper bound is known.
- Parameters:
data (np.ndarray) – Data to fit the GEV distribution to.
z_star (float) – Known upper bound.
opt_steps (int, optional) – Optimization steps. Defaults to 1000.
lr (float, optional) – Learning rate. Defaults to 0.01.
beta_guess (float, optional) – Initial scale. Defaults to 1.0.
gamma_guess (float, optional) – Initial concentration. Defaults to -0.1.
verbose (bool, optional) – Print progress. Defaults to False.
- Returns:
Estimated alpha, beta, gamma.
- Return type:
- worst.tens.fit_gev_upper_bound_not_known(data, opt_steps=1000, lr=0.01, alpha_guess=0.0, beta_guess=1.0, gamma_guess=-0.1, force_weibull=False, verbose=False)
Fit a Generalized Extreme Value distribution to data when the upper bound is not known.
- Parameters:
data (np.ndarray) – Data to fit the GEV distribution to.
opt_steps (int, optional) – Optimization steps. Defaults to 1000.
lr (float, optional) – Learning rate. Defaults to 0.01.
alpha_guess (float, optional) – Initial location. Defaults to 0.0.
beta_guess (float, optional) – Initial scale. Defaults to 1.0.
gamma_guess (float, optional) – Initial concentration. Defaults to -0.1.
force_weibull (bool, optional) – Force gamma<0. Defaults to False.
verbose (bool, optional) – Print progress. Defaults to False.
- Returns:
Estimated alpha, beta, gamma.
- Return type:
- worst.tens.gen_data(alpha, beta, gamma, n=1000)
Generate data from a Generalized Extreme Value distribution.
worst.utils module
Worst.utils.py
- worst.utils.alpha_from_z_star_beta_gamma(z_star, beta, gamma)
Calculate the location parameter of the Weibull class GEV distribution.
- Parameters:
- Returns:
The location parameter of the GEV distribution, alpha.
- Return type:
- worst.utils.bg_cdf(z, z_star, beta, gamma)
CDF of the Weibull class GEV distribution with a known upper bound.
- Parameters:
- Returns:
The CDF of the GEV distribution for different z values.
- Return type:
np.ndarray
- worst.utils.plot_rp(alpha, beta, gamma, color='blue', label='', ax=None, plot_alpha=0.8)
Plot the return period vs return value curve for the given parameters.
- Parameters:
alpha (float) – The location parameter.
beta (float) – The scale parameter.
gamma (float) – The shape parameter.
color (str, optional) – The color of the line. Defaults to “blue”.
label (str, optional) – The line label. Defaults to “”.
ax (Optional[matplotlib.axes.Axes], optional) – The axes to add the figure too. Defaults to None.
plot_alpha (float, optional) – Transparency parameter of line. Defaults to 0.8.
- Return type:
- worst.utils.plot_sample_points(data, color='black', ax=None, label='Sampled data points')
Plot the sample points on the return period vs return value curve.
- Parameters:
data (np.ndarray) – The sample points to plot.
color (str, optional) – The color of the points. Defaults to “black”.
ax (Optional[matplotlib.axes.Axes], optional) – The axes to add the figure too. Defaults to None.
label (str, optional) – The label of the points. Defaults to “Sampled data points”.
- Return type:
- worst.utils.retry_wrapper(max_retries=10)
Retry wrapper. If a function fails flakeily, then wrap with this to retry it a few times.
Puts the function in a try except block and retries it a max_retries times if unsuccesful.
- Parameters:
max_retries (int, optional) – Number of retries. Defaults to 10.
- Returns:
Wrapper function to recall the function in case of failure.
- Return type:
callable
- Example::
>>> @retry_wrapper(max_retries=5) ... def my_function(): ... # Some code that will fail ... assert False >>> try: ... my_function() ... except Exception as e: ... print(e) Exception: Retrying my_function 1/5 Exception: Retrying my_function 2/5 Exception: Retrying my_function 3/5 Exception: Retrying my_function 4/5 Exception: Retrying my_function 5/5 Max retries exceeded for function my_function
- worst.utils.z_star_from_alpha_beta_gamma(alpha, beta, gamma)
Calculate the upper bound of the Weibull class GEV distribution.
- Parameters:
- Returns:
The upper bound of the GEV distribution, z_star.
- Return type:
worst.vary_gamma_beta module
Vary the shape and scale parameters of the GEV distribution.
- worst.vary_gamma_beta.get_fit_da(config)
Get fit xr.DataArray.
- Parameters:
config (DictConfig) – Hydra config object.
- Returns:
DataArray with the fit data.
- Return type:
xr.DataArray
- worst.vary_gamma_beta.plot_diff(ds, config, figure_name)
Plot difference.
- worst.vary_gamma_beta.plot_fit_da(config, da)
Plot fit xr.DataArray.
- Parameters:
config (DictConfig) – Hydra config object.
da (xr.DataArray) – DataArray with the fit data.
- Return type:
- worst.vary_gamma_beta.plot_fit_primary_var(ds, config, figure_name)
Plot fit primary variable.
worst.vary_noise module
Vary noise of the upper bound, see how big the noise has to get before its no longer valuable.
We want to see what would happen if our method of determining the potential height is inaccurate, and so there is some random noise. Surely the information about the upper bound becomes less valuable as it becomes less certain. We choose one value of scale (beta), shape (gamma) and assymptote (z_star) for the GEV we are sampling, with a fixed sample size, n_s. Then we follow two ways of fitting the GEV b: one where we directly fit beta, gamma, and z_star by minimizing the negative log likelihood (upper bound unknown) (II). The other by fitting beta and gamma while assuming a value of the upper bound (upper bound known). In this second fitting method (I) we assume that our calculation of the upper bound is the true value with some Gaussian error added on whose standard deviation sigma_{z_star} is varied. For each resample we select a sample of n_s, and we also select a new calculated value of hat{z_star} to assume for the second fitting method. As before we resample the true GEV distribution N_r=600 times, repeating this for each value of sigma_{z_star}. In the case where hat{z_star} is smaller than the maximum of the datapoints, we replace hat{z_star} with max( ec{z}), so that $hat{z_star}^{prime}=mathrm{max}left(mathrm{max}left( ec{z} ight), hat{z_star} ight)$ as the fit would otherwise be impossible. This is equivalent to calculating the potential height, but then replacing this with the highest observation if that is higher.
Caption: An experiment into the effect of uncertainty in the upper bound on its usefulness in improving our estimation of high return values. Panels (a) and (b) show the 1 in 100 and 1 in 500 year return values respsectively for the original GEV (black line). The mean, 5% and 95% intervals are calculated by resampling $N_r=600$ times, with $N_s=50$ samples each time, and refitting with model fit methods (I) and (II). Fitting method (II) does not depend on z_sigma_star, and so this is only conducted once. The solid lines in panels are (a) and (b) are the means and the shaded areas are the 5% to 95% model envelopes. Panel (c) summarises the relative evolution of the 5% to 95% range of fitting method (II) divided by fitting method (I) as z_star_sigma decreases, showing that the advantage of method (I) declines with greater z_star_sigma.
The first two figure panels (a) and (b) show the mean and the 5%-95% envelopes for the 1 in 100 and 1 in 500 year return values (RV) for fitting methods (I) and (II), as we change the standard deviation in the calculated upper bound z_star_sigma for method (I). As shown in the two panels, an estimate of the upper bound (I) reduces the bias in the mean estimate, leads to a smaller 5%-95% envelope. As z_star_sigma progresses from 0~m to 5~m (where the scale is 1~m), the range of (I) approaches (II). To show this quantitatively, in panel (c) we can see that the ratio between the 5%-95% confidence envelopees begins larger for the 1 in 500 year events than the 1 in 100 year events, as knowing the upper bound has a larger effect on our estimation of longer return period return values as before. Both converge towards one as the standard deviation in the calculated upper bound increases and the information becomes less informative. This might be surprising because it suggests that knowing the upper bound in this set up, even with a large standard deviation, improves the return value estimate. This could be because if the calculated upper bound is too low, then it is likely to be replaced by the maximum of the samples, and if it is too high, then the shape and scale parameters can change to compensate and achieve good long period RV, but this could be studied further. We have still assumed that the observations are i.i.d. and therefore ignore non-stationarity in the observations created by climate change.
Overall, this suggests that even with a moderate uncertainty in the potential height of the storm surge, we could expect it to improve relevant risk estimates. Therefore, we argue that we have shown that calculating the potential height could usefully augment observations.
- worst.vary_noise.get_fit_ds(config)
Get fit xr.Dataset.
- Parameters:
config (DictConfig) – Hydra config object.
- Returns:
Dataset with the fit data.
- Return type:
xr.Dataset
- worst.vary_noise.plot_fit_ds(config, ds)
Plot fit ds.
- Parameters:
config (DictConfig) – Config.
ds (xr.Dataset) – Dataset.
- Return type:
- worst.vary_noise.process_noise(config, da)
Process noise.
- Parameters:
config (DictConfig) – config.
da (xr.DataArray) – dataarray
- Returns:
dataset with mean, standard deviation etc.
- Return type:
xr.Dataset
- worst.vary_noise.run_vary_noise(config)
Run vary gamma beta experiment.
Keep z_star constant and vary beta and gamma, and see how the fits change.
- Parameters:
config (DictConfig) – Hydra config object.
- Return type:
- worst.vary_noise.true_ds(config)
True dataset.
- Parameters:
config (DictConfig) – includes parameters of GEV.
- Return type:
Dataset- Returns:
xr.Dataset
- worst.vary_noise.try_fit_no_upperbound(z_star, beta, gamma, ns, seed, config, quantiles=[0.01, 0.002])
Try fit no upperbound (fit type (II)).
worst.vary_samples_ns module
Make figure showing the effect of the number of samples on the EVT fits.
- worst.vary_samples_ns.evt_fig_tens(z_star=7, beta=1, gamma=-0.2, ex_seed=57, ex_num=50, min_samp=20, max_samp=1000, samp_steps=26, seed_steps=600, color_true='black', color_max_known='#1b9e77', color_max_unknown='#d95f02', load=True)
Plot the EVT fits for the known upper bound and the unbounded case.
- Parameters:
z_star (float, optional) – Upper bound. Defaults to 7m.
beta (float, optional) – Scale parameter. Defaults to 1m.
gamma (float, optional) – Shape parameter. Defaults to -0.2.
ex_seed (int, optional) – Example seed. Defaults to 57.
ex_num (int, optional) – Example number of samples. Defaults to 50.
min_samp (int, optional) – Minimum number of samples. Defaults to 20.
max_samp (int, optional) – Maximum number of samples. Defaults to 1000.
samp_steps (int, optional) – Number of different samples. Defaults to 500.
seed_steps (int, optional) – Number of different seeds. Defaults to 20.
color_true (str, optional) – Color or original GEV. Defaults to “black”.
color_max_known (str, optional) – Color of GEV with max known. Defaults to “#1b9e77”.
color_max_unknown (str, optional) – Color of GEV with unknown max. Defaults to “#d95f02”.
load (bool, optional) – reload if data exists or recalculate. Defaults to True for reload.
- Return type:
- worst.vary_samples_ns.fit_for_seeds(z_star, beta, gamma, seeds=array([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1001, 1011, 1021, 1031, 1041, 1051, 1061, 1071, 1081, 1091, 1101, 1111, 1121, 1131, 1141, 1151, 1161, 1171, 1181, 1191, 1201, 1211, 1221, 1231, 1241, 1251, 1261, 1271, 1281, 1291, 1301, 1311, 1321, 1331, 1341, 1351, 1361, 1371, 1381, 1391, 1401, 1411, 1421, 1431, 1441, 1451, 1461, 1471, 1481, 1491, 1501, 1511, 1521, 1531, 1541, 1551, 1561, 1571, 1581, 1591, 1601, 1611, 1621, 1631, 1641, 1651, 1661, 1671, 1681, 1691, 1701, 1711, 1721, 1731, 1741, 1751, 1761, 1771, 1781, 1791, 1801, 1811, 1821, 1831, 1841, 1851, 1861, 1871, 1881, 1891, 1901, 1911, 1921, 1931, 1941, 1951, 1961, 1971, 1981, 1991, 2002, 2012, 2022, 2032, 2042, 2052, 2062, 2072, 2082, 2092, 2102, 2112, 2122, 2132, 2142, 2152, 2162, 2172, 2182, 2192, 2202, 2212, 2222, 2232, 2242, 2252, 2262, 2272, 2282, 2292, 2302, 2312, 2322, 2332, 2342, 2352, 2362, 2372, 2382, 2392, 2402, 2412, 2422, 2432, 2442, 2452, 2462, 2472, 2482, 2492, 2502, 2512, 2522, 2532, 2542, 2552, 2562, 2572, 2582, 2592, 2602, 2612, 2622, 2632, 2642, 2652, 2662, 2672, 2682, 2692, 2702, 2712, 2722, 2732, 2742, 2752, 2762, 2772, 2782, 2792, 2802, 2812, 2822, 2832, 2842, 2852, 2862, 2872, 2882, 2892, 2902, 2912, 2922, 2932, 2942, 2952, 2962, 2972, 2982, 2992, 3003, 3013, 3023, 3033, 3043, 3053, 3063, 3073, 3083, 3093, 3103, 3113, 3123, 3133, 3143, 3153, 3163, 3173, 3183, 3193, 3203, 3213, 3223, 3233, 3243, 3253, 3263, 3273, 3283, 3293, 3303, 3313, 3323, 3333, 3343, 3353, 3363, 3373, 3383, 3393, 3403, 3413, 3423, 3433, 3443, 3453, 3463, 3473, 3483, 3493, 3503, 3513, 3523, 3533, 3543, 3553, 3563, 3573, 3583, 3593, 3603, 3613, 3623, 3633, 3643, 3653, 3663, 3673, 3683, 3693, 3703, 3713, 3723, 3733, 3743, 3753, 3763, 3773, 3783, 3793, 3803, 3813, 3823, 3833, 3843, 3853, 3863, 3873, 3883, 3893, 3903, 3913, 3923, 3933, 3943, 3953, 3963, 3973, 3983, 3993, 4004, 4014, 4024, 4034, 4044, 4054, 4064, 4074, 4084, 4094, 4104, 4114, 4124, 4134, 4144, 4154, 4164, 4174, 4184, 4194, 4204, 4214, 4224, 4234, 4244, 4254, 4264, 4274, 4284, 4294, 4304, 4314, 4324, 4334, 4344, 4354, 4364, 4374, 4384, 4394, 4404, 4414, 4424, 4434, 4444, 4454, 4464, 4474, 4484, 4494, 4504, 4514, 4524, 4534, 4544, 4554, 4564, 4574, 4584, 4594, 4604, 4614, 4624, 4634, 4644, 4654, 4664, 4674, 4684, 4694, 4704, 4714, 4724, 4734, 4744, 4754, 4764, 4774, 4784, 4794, 4804, 4814, 4824, 4834, 4844, 4854, 4864, 4874, 4884, 4894, 4904, 4914, 4924, 4934, 4944, 4954, 4964, 4974, 4984, 4994, 5005, 5015, 5025, 5035, 5045, 5055, 5065, 5075, 5085, 5095, 5105, 5115, 5125, 5135, 5145, 5155, 5165, 5175, 5185, 5195, 5205, 5215, 5225, 5235, 5245, 5255, 5265, 5275, 5285, 5295, 5305, 5315, 5325, 5335, 5345, 5355, 5365, 5375, 5385, 5395, 5405, 5415, 5425, 5435, 5445, 5455, 5465, 5475, 5485, 5495, 5505, 5515, 5525, 5535, 5545, 5555, 5565, 5575, 5585, 5595, 5605, 5615, 5625, 5635, 5645, 5655, 5665, 5675, 5685, 5695, 5705, 5715, 5725, 5735, 5745, 5755, 5765, 5775, 5785, 5795, 5805, 5815, 5825, 5835, 5845, 5855, 5865, 5875, 5885, 5895, 5905, 5915, 5925, 5935, 5945, 5955, 5965, 5975, 5985, 5995, 6006, 6016, 6026, 6036, 6046, 6056, 6066, 6076, 6086, 6096, 6106, 6116, 6126, 6136, 6146, 6156, 6166, 6176, 6186, 6196, 6206, 6216, 6226, 6236, 6246, 6256, 6266, 6276, 6286, 6296, 6306, 6316, 6326, 6336, 6346, 6356, 6366, 6376, 6386, 6396, 6406, 6416, 6426, 6436, 6446, 6456, 6466, 6476, 6486, 6496, 6506, 6516, 6526, 6536, 6546, 6556, 6566, 6576, 6586, 6596, 6606, 6616, 6626, 6636, 6646, 6656, 6666, 6676, 6686, 6696, 6706, 6716, 6726, 6736, 6746, 6756, 6766, 6776, 6786, 6796, 6806, 6816, 6826, 6836, 6846, 6856, 6866, 6876, 6886, 6896, 6906, 6916, 6926, 6936, 6946, 6956, 6966, 6976, 6986, 6996, 7007, 7017, 7027, 7037, 7047, 7057, 7067, 7077, 7087, 7097, 7107, 7117, 7127, 7137, 7147, 7157, 7167, 7177, 7187, 7197, 7207, 7217, 7227, 7237, 7247, 7257, 7267, 7277, 7287, 7297, 7307, 7317, 7327, 7337, 7347, 7357, 7367, 7377, 7387, 7397, 7407, 7417, 7427, 7437, 7447, 7457, 7467, 7477, 7487, 7497, 7507, 7517, 7527, 7537, 7547, 7557, 7567, 7577, 7587, 7597, 7607, 7617, 7627, 7637, 7647, 7657, 7667, 7677, 7687, 7697, 7707, 7717, 7727, 7737, 7747, 7757, 7767, 7777, 7787, 7797, 7807, 7817, 7827, 7837, 7847, 7857, 7867, 7877, 7887, 7897, 7907, 7917, 7927, 7937, 7947, 7957, 7967, 7977, 7987, 7997, 8008, 8018, 8028, 8038, 8048, 8058, 8068, 8078, 8088, 8098, 8108, 8118, 8128, 8138, 8148, 8158, 8168, 8178, 8188, 8198, 8208, 8218, 8228, 8238, 8248, 8258, 8268, 8278, 8288, 8298, 8308, 8318, 8328, 8338, 8348, 8358, 8368, 8378, 8388, 8398, 8408, 8418, 8428, 8438, 8448, 8458, 8468, 8478, 8488, 8498, 8508, 8518, 8528, 8538, 8548, 8558, 8568, 8578, 8588, 8598, 8608, 8618, 8628, 8638, 8648, 8658, 8668, 8678, 8688, 8698, 8708, 8718, 8728, 8738, 8748, 8758, 8768, 8778, 8788, 8798, 8808, 8818, 8828, 8838, 8848, 8858, 8868, 8878, 8888, 8898, 8908, 8918, 8928, 8938, 8948, 8958, 8968, 8978, 8988, 8998, 9009, 9019, 9029, 9039, 9049, 9059, 9069, 9079, 9089, 9099, 9109, 9119, 9129, 9139, 9149, 9159, 9169, 9179, 9189, 9199, 9209, 9219, 9229, 9239, 9249, 9259, 9269, 9279, 9289, 9299, 9309, 9319, 9329, 9339, 9349, 9359, 9369, 9379, 9389, 9399, 9409, 9419, 9429, 9439, 9449, 9459, 9469, 9479, 9489, 9499, 9509, 9519, 9529, 9539, 9549, 9559, 9569, 9579, 9589, 9599, 9609, 9619, 9629, 9639, 9649, 9659, 9669, 9679, 9689, 9699, 9709, 9719, 9729, 9739, 9749, 9759, 9769, 9779, 9789, 9799, 9809, 9819, 9829, 9839, 9849, 9859, 9869, 9879, 9889, 9899, 9909, 9919, 9929, 9939, 9949, 9959, 9969, 9979, 9989, 10000], dtype=int16), nums=array([990, 1190, 1430, 1718, 2065, 2482, 2983, 3585, 4309, 5179, 6224, 7480, 8990, 10804, 12985, 15605, 18755, 22540, 27089, 32556, -26410, -18513, -9023, 2382, 16089, 32562, -13176, 10617, -26324, 8041, -16194, -32093, 27560, -31819, -11194, 26819, 20195, -26851, 21823, -24299, -26826, 23043, 4807, -3288, 14029, 9578, 5417, 28058, -21711, 25473], dtype=int16))
Fit for different seeds.
- Parameters:
- Returns:
Return values for the quantiles for the true GEV, the GEV with the known upper bound, and the GEV with no upper bound.
- Return type:
xr.DataArray
- worst.vary_samples_ns.get_evt_fit_data(z_star, beta, gamma, seeds, nums, load=True)
Either load or calculate the EVT fit 1 in 100 year and 1 in 500 year events.
- Parameters:
- Returns:
Return values for the quantiles for the true GEV, the GEV with the known upper bound, and the GEV with no upper bound.
- Return type:
xr.DataArray
- worst.vary_samples_ns.plot_ex(z_star, beta, gamma, ex_seed, ex_num, color_true, color_max_known, color_max_unknown, ax=None, fig_path='/home/docs/checkouts/readthedocs.org/user_builds/worstsurge/checkouts/stable/img/worst/evt_fit_ex_tens.pdf')
Plot single example fit.
- Parameters:
z_star (float) – Upper bound.
beta (float) – Scale parameter.
gamma (float) – Shape parameter.
ex_seed (int) – Example seed.
ex_num (int) – Example number of samples.
color_true (str) – Color of original GEV.
color_max_known (str) – Color of known upper bound GEV.
color_max_unknown (str) – Color of unknown upper bound GEV.
ax (matplotlib.axes.Axes, optional) – Axes. Defaults to None.
fig_path (str, optional) – Figure path to save to. Defaults to os.path.join(FIGURE_PATH, “evt_fit_ex_tens.pdf”).
- Return type:
- worst.vary_samples_ns.try_fit(z_star=7, beta=4, gamma=-0.1, ns=40, seed=42, quantiles=[0.01, 0.002])
Try fitting the GEV distributions to some data, and calculate the return values for some quantiles.
- Parameters:
z_star (float, optional) – Upper bound of GEV. Defaults to 7.
beta (float, optional) – Scale. Defaults to 4.
gamma (float, optional) – Concentration. Defaults to -0.1.
ns (int, optional) – Number of data samples. Defaults to 40.
seed (int, optional) – Random seed. Defaults to 42.
quantiles (List[float], optional) – Quantiles to get. Defaults to [1 / 100, 1 / 500].
- Returns:
- Return values for the quantiles for the true GEV,
the GEV with the known upper bound, and the GEV with no upper bound.
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray]
- worst.vary_samples_ns.try_fits(z_star=7, beta=1, gamma=-0.3, seed=100, nums=[20, 22, 25, 27, 30, 33, 35, 40, 50, 60, 75, 100, 200, 500, 1000])
Try fitting the GEV distributions to some data, and calculate the return values for some quantiles.
- Parameters:
z_star (float, optional) – Upper bound. Defaults to 7.
beta (float, optional) – Scale. Defaults to 1.
gamma (float, optional) – Shape. Defaults to -0.3.
seed (float, optional) – Seed. Defaults to 100.
nums (List[int], optional) – Number of samples. Defaults to [20, 22, 25, 27, 30, 33, 35, 40, 50, 60, 75, 100, 200, 500, 1000].
- Returns:
Return values for the quantiles for the true GEV,
- Return type:
xr.DataArray