dkirkby / randomfield

Generate random fields for cosmology
2 stars 2 forks source link

Calculating power spectrum Pk(k, z != 0) #3

Open kgage opened 8 years ago

kgage commented 8 years ago

Currently, when attempting to get the power spectrum at a redshift other than z=0 raises a CosmoSevereError such as

CosmoSevereError: 

Error in Class: spectra_pk_at_k_and_z(L:683) :error in spectra_pk_at_z(pba, psp, logarithmic, z, spectrum_at_z, spectrum_at_z_ic);
=>spectra_pk_at_z(L:382) :condition (z != 0.) is true; asked z=3.333333e-03 but only P(k,z=0) has been tabulated

CLASS (and therefore classy) has a parameter z_pk that gives the redshifts where the mass power spectrum should be calculated. The calculate_power function in cosmotools.py does not include a line to override the default value of zero if the redshift asked for is nonzero.

This can be fixed by including

class_parameters['z_pk'] = str(z)

in the function definition.

For future reference, the z_pk variable will accept multiple redshift values as a string of comma separated numbers:

"0.0,1.0,2.0,3.0"
kgage commented 8 years ago

It would be possible to change the output of the calculate_power function to allow for calculations of the power spectrum at multiple redshifts. In theory, a dictionary with keys of 'k', num_1, num_2, ... num_n should work. Is this something that should be looked into?

dkirkby commented 8 years ago

Let's fix the existing bug now and keep the multiple-redshift option in mind as a possible future feature (unless there is a reason why we need it now?)