Skip to content

Commit

Permalink
kbins added to GRF for a field
Browse files Browse the repository at this point in the history
  • Loading branch information
sambit-giri committed Oct 16, 2024
1 parent 4961e4b commit 93fbdaf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tools21cm/gaussian_random_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 93fbdaf

Please sign in to comment.