Skip to content
Snippets Groups Projects
Commit e0ad3fc9 authored by Felix Kleinert's avatar Felix Kleinert
Browse files

draft uncertainiy boots

parent f1d790ef
No related branches found
No related tags found
8 merge requests!353add developments to release v1.5.0,!352Resolve "release v1.5.0",!351Lukas issue337 bug ci pipeline fails for docs,!350Resolve "upgrade code to TensorFlow V2",!342Include sample-uncertainty to wrf workflow,!339Resolve "Test Set Sample Uncertainty in PostProcessing",!337Resolve "Test Set Sample Uncertainty in PostProcessing",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline #80844 passed
......@@ -481,3 +481,49 @@ class SkillScores:
return monthly_mean
def create_single_bootstrap_realization(data: xr.DataArray) -> xr.DataArray:
"""
Return a bootstraped realization of data
:param data: data from which to draw ONE bootstrap realization
:return: bootstrapped realization of data
"""
num_of_blocks = data.shape[0]
time_block_dim = data.dims[0]
boot_idx = np.random.choice(num_of_blocks, size=num_of_blocks, replace=True)
return data.isel({time_block_dim: boot_idx})
def calculate_average(data: xr.DataArray, **kwargs) -> xr.DataArray:
"""
Calculate mean of data
:param data: data for which to calculate mean
:return: mean of data
"""
axis = kwargs.pop('axis', 0)
return data.mean(axis=axis, **kwargs)
def create_n_bootstrap_realizations(data: xr.DataArray, dim_name_time, dim_name_model, n_boots: int = 1000,
dim_name_boots='boots') -> xr.DataArray:
res_dims = [dim_name_boots]
dims = list(data.dims)
coords = {dim_name_boots: range(n_boots), dim_name_model: data.coords[dim_name_model] }
if len(dims) > 1:
res_dims = res_dims + dims[1:]
res = xr.DataArray(np.nan, dims=res_dims, coords=coords)
for boot in range(n_boots):
res[boot] = (calculate_average(
create_single_bootstrap_realization(data)
))
return res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment