src.data_assimilation.utils#
Functions
|
Projection method from 2D array to 3D horizontal slice. |
|
Projection method from 3D horizontal slice to 2D array. |
|
Returns a mask for the underlying cellular and nodal grids padded such that the size of the local subdomain has been accounted for. |
|
|
|
|
|
|
|
|
|
Produce a view from a sliding, striding window over arr. |
|
Classes
|
- class src.data_assimilation.utils.ensemble(input_ensemble=None)#
- __init__(input_ensemble=None)#
- initialise_members(ic, N)#
- set_members(analysis_ensemble, tout)#
- ensemble_spreading(ens, sampler, attributes, loc=0)#
- static members(ensemble)#
- static debug_im(value, n, tout)#
- src.data_assimilation.utils.ensemble_inflation(results, attributes, factor, N, loc=0)#
- src.data_assimilation.utils.set_p2_nodes(analysis, results, N, th, node, ud, loc_c=0, loc_n=2)#
- src.data_assimilation.utils.set_rhoY_cells(analysis, results, N, th, ud, loc_c=0, loc_n=2)#
- src.data_assimilation.utils.boundary_mask(ud, elem, node, pad_X, pad_Y)#
Returns a mask for the underlying cellular and nodal grids padded such that the size of the local subdomain has been accounted for. For ghost cells on wall boundaries, values are 0.0 and 1.0 for periodic.
- src.data_assimilation.utils.sliding_window_view(arr, window_shape, steps)#
Produce a view from a sliding, striding window over arr. The window is only placed in ‘valid’ positions - no overlapping over the boundary.
Parameters#
- arrnumpy.ndarray, shape=(…,[x, (…), z])
The array to slide the window over.
- window_shapeSequence[int]
The shape of the window to raster: [Wx, (…), Wz], determines the length of [x, (…), z]
- stepsSequence[int]
The step size used when applying the window along the [x, (…), z] directions: [Sx, (…), Sz]
Returns#
view of arr, shape=([X, (…), Z], …, [Wx, (…), Wz]), where X = (x - Wx) // Sx + 1
Note#
In general, given:
out = sliding_window_view(arr, window_shape=[Wx, (...), Wz], steps=[Sx, (...), Sz]) out[ix, (...), iz] = arr[..., ix*Sx:ix*Sx+Wx, (...), iz*Sz:iz*Sz+Wz]
This function is taken from: https://gist.github.com/meowklaski/4bda7c86c6168f3557657d5fb0b5395a
Example#
>>> import numpy as np >>> x = np.arange(9).reshape(3,3) >>> x array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> y = sliding_window_view(x, window_shape=(2, 2), steps=(1, 1)) >>> y array([[[[0, 1], [3, 4]], [[1, 2], [4, 5]]], [[[3, 4], [6, 7]], [[4, 5], [7, 8]]]]) >>> np.shares_memory(x, y) True # Performing a neural net style 2D conv (correlation) # placing a 4x4 filter with stride-1 >>> data = np.random.rand(10, 3, 16, 16) # (N, C, H, W) >>> filters = np.random.rand(5, 3, 4, 4) # (F, C, Hf, Wf) >>> windowed_data = sliding_window_view(data, ... window_shape=(4, 4), ... steps=(1, 1)) >>> conv_out = np.tensordot(filters, ... windowed_data, ... axes=[[1,2,3], [3,4,5]]) # (F, H', W', N) -> (N, F, H', W') >>> conv_out = conv_out.transpose([3,0,1,2])
- src.data_assimilation.utils.HSprojector_3t2D(results, elem, dap, N)#
Projection method from 3D horizontal slice to 2D array. For use in data assimilation module.
Parameters#
- resultsnd.array
An array of ensemble size k. Each ensemble member has [Sol,flux,mpv,[window_step,step]].
- dapdata assimilation input class
.
- Nint
ensemble size.
Note#
I will first test this out before extending the DA algorithm to 3D.
- src.data_assimilation.utils.HSprojector_2t3D(results, elem, node, dap, N)#
Projection method from 2D array to 3D horizontal slice. To be used after data assimilation.
- src.data_assimilation.utils.sparse_obs_selector(obs, elem, node, ud, dap)#
- src.data_assimilation.utils.obs_noiser(obs, mask, dap, rloc, elem)#