diff --git a/src/tools21cm/gaussian_random_field.py b/src/tools21cm/gaussian_random_field.py index f04ee2e..cc11b74 100644 --- a/src/tools21cm/gaussian_random_field.py +++ b/src/tools21cm/gaussian_random_field.py @@ -62,7 +62,7 @@ def make_gaussian_random_field(dims, box_dims, power_spectrum, random_seed=None) return map_real -def make_gaussian_random_field_like_field(input_field, box_dims, random_seed=None): +def make_gaussian_random_field_like_field(input_field, box_dims, kbins=10, random_seed=None): ''' Generate a Gaussian random field with the same power spectrum as the input field. @@ -71,6 +71,7 @@ def make_gaussian_random_field_like_field(input_field, box_dims, random_seed=Non * input_field (numpy array): The field to take the power spectrum from * box_dims (float or tuple): The dimensions of the input_field in cMpc + * kbins (int): The number of bins in k-space * random_seed (int): the seed for the random number generation Returns: @@ -82,18 +83,18 @@ def make_gaussian_random_field_like_field(input_field, box_dims, random_seed=Non at low k. Use with care. ''' - ps_k = _get_ps_func_for_field(input_field, box_dims) + ps_k = _get_ps_func_for_field(input_field, box_dims, kbins=kbins) random_field = make_gaussian_random_field(input_field.shape, box_dims, \ power_spectrum=ps_k, random_seed=random_seed) return random_field -def _get_ps_func_for_field(input_field, box_dims): +def _get_ps_func_for_field(input_field, box_dims, kbins=10): ''' Return ps(k) for the specified field. For internal use. ''' ps_input, k_input, n_modes = power_spectrum_1d(input_field, \ - box_dims=box_dims, kbins=10, return_n_modes=True) + box_dims=box_dims, kbins=kbins, return_n_modes=True) ps_k = interp1d(k_input[n_modes>0], ps_input[n_modes>0], kind='linear', \ bounds_error=False, fill_value=0.) return ps_k