Fill field with random data. If a seed is specified, the global data is reproducibly generated for any process mesh. Parameters ---------- layout : Layout object, 'c', or 'g', optional Layout for setting field data. Default: current layout.
(self, layout=None, scales=None, seed=None, chunk_size=2**20, distribution='standard_normal', **kw)
| 896 | return data |
| 897 | |
| 898 | def fill_random(self, layout=None, scales=None, seed=None, chunk_size=2**20, distribution='standard_normal', **kw): |
| 899 | """ |
| 900 | Fill field with random data. If a seed is specified, the global data is |
| 901 | reproducibly generated for any process mesh. |
| 902 | |
| 903 | Parameters |
| 904 | ---------- |
| 905 | layout : Layout object, 'c', or 'g', optional |
| 906 | Layout for setting field data. Default: current layout. |
| 907 | scales : number or tuple of numbers, optional |
| 908 | Scales for setting field data. Default: current scales. |
| 909 | seed : int, optional |
| 910 | RNG seed. Default: None. |
| 911 | chunk_size : int, optional |
| 912 | Chunk size for drawing from distribution. Should be less than locally |
| 913 | available memory. Default: 2**20, corresponding to 8 MB of float64. |
| 914 | distribution : str, optional |
| 915 | Distribution name, corresponding to numpy random Generator method. |
| 916 | Default: 'standard_normal'. |
| 917 | **kw : dict |
| 918 | Other keywords passed to the distribution method. |
| 919 | """ |
| 920 | init_layout = self.layout |
| 921 | # Set scales if requested |
| 922 | if scales is not None: |
| 923 | self.preset_scales(scales) |
| 924 | if layout is None: |
| 925 | self.preset_layout(init_layout) |
| 926 | # Set layout if requested |
| 927 | if layout is not None: |
| 928 | self.preset_layout(layout) |
| 929 | # Build global chunked random array (does not require global-sized memory) |
| 930 | shape = tuple(cs.dim for cs in self.tensorsig) + self.global_shape |
| 931 | if self.is_complex: |
| 932 | shape = shape + (2,) |
| 933 | global_data = ChunkedRandomArray(shape, seed, chunk_size, distribution, **kw) |
| 934 | # Extract local data |
| 935 | component_slices = tuple(slice(None) for cs in self.tensorsig) |
| 936 | spatial_slices = self.layout.slices(self.domain, self.scales) |
| 937 | local_slices = component_slices + spatial_slices |
| 938 | local_data = global_data[local_slices] |
| 939 | if self.is_real: |
| 940 | self.data[:] = local_data |
| 941 | else: |
| 942 | self.data.real[:] = local_data[..., 0] |
| 943 | self.data.imag[:] = local_data[..., 1] |
| 944 | |
| 945 | def low_pass_filter(self, shape=None, scales=None): |
| 946 | """ |