grf

selfisys.grf.primordial_grf(L, N, seedphases, fname_powerspectrum, fname_outputinitialdensity, force_sim=False, return_g=False, verbose=0)[source]

Generate a Gaussian random field from a specified input power spectrum.

Parameters:
  • L (float) – Side length of the simulation box in Mpc/h.

  • N (int) – Grid resolution (number of cells per dimension).

  • seedphases (int) – Seed for random phase generation (for reproducibility).

  • fname_powerspectrum (str) – File path to the input power spectrum.

  • fname_outputinitialdensity (str) – File path to store the generated initial density field.

  • force_sim (bool, optional) – If True, regenerate the GRF even if the output file exists. Default is False.

  • return_g (bool, optional) – If True, return the GRF as a numpy array. Default is False.

  • verbose (int, optional) – Verbosity level (0 = silent, 1 = progress, 2 = detailed). Default is 0.

Raises:
  • OSError – If the power spectrum file cannot be read.

  • RuntimeError – If an unexpected error occurs during power spectrum reading.

Returns:

The GRF data if return_g is True, otherwise None.

Return type:

numpy.ndarray or None