frb.dm - Dispersion Measure Module
The frb.dm module provides comprehensive tools for calculating and modeling dispersion measure contributions from various sources along the line of sight to Fast Radio Bursts.
Module Overview
The dispersion measure (DM) is a key observable for FRBs, representing the integrated electron column density along the line of sight:
This module decomposes the total DM into contributions from:
Milky Way: Galactic disk and halo electrons
Intergalactic Medium (IGM): Diffuse cosmic electrons
Host Galaxy: Electrons in the FRB host galaxy
Intervening Systems: Galaxy halos and other structures
Submodules
The DM package contains the following submodules:
frb.dm.igm- Intergalactic Medium calculationsfrb.dm.cosmic- Cosmic dispersion measure modelingfrb.dm.host- Host galaxy DM contributionsfrb.dm.mcmc- MCMC analysis methodsfrb.dm.prob_dmz- DM-redshift probability calculationsfrb.dm.dm_ism_healpix_map.py- DM_ISM Healpix map from NE2001 or the like
frb.dm.igm - Intergalactic Medium
Module for IGM calculations
- frb.dm.igm.fukugita04_dict()[source]
Data from Fukugita 2004, Table 1
- Returns:
data dict.
- Return type:
f04_dict (dict)
- frb.dm.igm.average_He_nume(z, z_HIreion=7.0)[source]
Average number of electrons contributed by He as a function of redshift per He nucleus
- Following Kulkarni, Worseck & Hennawi 2018
- frb.dm.igm.z_from_DM(DM, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), coord=None, corr_nuisance=True)[source]
Report back an estimated redshift from an input IGM DM Any contributions from the Galaxy and/or host need to have been ‘removed’
- Parameters:
DM (Quantity) – Dispersion measure.
cosmo (Cosmology, optional) – Cosmology of the universe. LambdaCDM with the Repo cosmology used by default.
coord (SkyCoord, optional) – If provided, use it to remove the ISM
corr_nuisance (bool, optional) – If True, correct for the MW Halo and the host with 100 DM units.
- Returns:
Redshift
- Return type:
- frb.dm.igm.f_diffuse(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), return_rho: bool = False, perturb_Mstar: float = None)[source]
Calculate the cosmic fraction of baryons in diffuse gas phase based on our empirical knowledge of baryon distributions and their ionization state.
Note that the default values use the standard values from Madau & Dickinson (2014) and Fukugita (2004). The former use a Salpeter IMF for rho_* which is no longer in fashion.
- Parameters:
- Returns:
Diffuse gas baryon fraction. rho_diffuse (Quantity, optional): Physical diffuse gas density.
Returned if return_rho is set to true.
- Return type:
f_diffuse (float, ndarray)
- frb.dm.igm.sigma_fd(z, rel_err_Mstar)[source]
Calculate the uncertainty in the diffuse fraction at a given redshift.
- frb.dm.igm.ne_cosmic(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), mu=1.3333333333333333)[source]
Calculate the average cosmic electron number density as a function of redshift. :param z: Redshift :type z: float or ndarray :param cosmo: Cosmology in :type cosmo: Cosmology, optional :param which the calculations are to be performed.: :param mu: Reduced mass :type mu: float
- Returns:
Average physical number density of electrons in the unverse in cm^-3.
- Return type:
ne_cosmic (Quantity)
- frb.dm.igm.average_DM(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), cumul=False, neval=10000, mu=1.3333333333333333)[source]
Macquart Relation
Calculate the average cosmic DM ‘expected’ based on our empirical knowledge of baryon distributions and their ionization state.
This includes both the IGM and galactic halos, i.e. any and all diffuse gas
- Parameters:
- Returns:
- DM values evaluated at
the required redshifts. An array is returned only if cumul is True.
- zeval (ndarray): evaluation redshifts. Only returned if
cumul is True.
- Return type:
DM (Quantity or Quantity array)
- frb.dm.igm.average_DMhalos(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), f_hot=0.75, rmax=1.0, logMmin=10.3, logMmax=16.0, neval=10000, cumul=False)[source]
Average DM_halos term from halos along the sightline to an FRB
- Parameters:
z (float) – Redshift of the FRB
cosmo (Cosmology) – Cosmology in which the calculations are to be performed.
f_hot (float, optional) – Fraction of the halo baryons in diffuse phase.
rmax (float, optional) – Size of a halo in units of r200
logMmin (float, optional) – Lowest mass halos to consider Cannot be much below 10.3 or the Halo code barfs The code deals with h^-1 factors, i.e. do not impose it yourself
logMmax (float, optional) – Highest halo mass. Default to 10^16 Msun
neval (int, optional) – Number of redshift values between 0 and z the function is evaluated at.
cumul (bool, optional) – Return a cumulative evaluation?
- Returns:
- One value if cumul=False
else evaluated at a series of z
zeval (ndarray): Evaluation redshifts if cumul=True
- Return type:
DM_halos (Quantity or Quantity array)
- frb.dm.igm.average_DMIGM(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), f_hot=0.75, rmax=1.0, logMmin=10.3, neval=10000, cumul=False, return_DMhalos=False)[source]
Estimate DM_IGM in a cumulative fashion
- Parameters:
z (float) – Redshift of the FRB
cosmo (Cosmology, optional) – Cosmology in which the calculations are to be performed. LambdaCDM with the Repo cosmology assumed by default.
f_hot (float, optional) – Fraction of the halo baryons in diffuse phase.
rmax (float, optional) – Size of a halo in units of r200
logMmin (float, optional) –
Lowest mass halos to consider. Cannot be much below 10.3 or the Halo code barfs. The code deals with
h^-1 factors, i.e. do not impose it yourself
neval (int, optional) – Number of redshift values between 0 and z the function is evaluated at.
cumul (bool, optional) – Return a cumulative evaluation?
return_DMHalos (bool, optional) – Also return avgDM_halos?
- Returns:
- DM_IGM (Quantity or Quantity array): One value if cumul=False
else evaluated at a series of z
zeval (ndarray, optional): Evaluation redshifts if cumul=True DM_halos (ndarray, optinal):
- Return type:
- frb.dm.igm.avg_rhoISM(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), perturb_Mstar: float = None)[source]
Co-moving Mass density of the ISM
Interpolates from z=0 values to z=1 where we assume M_ISM = M* and also for z>1
- Parameters:
z (float or ndarray) – Redshift
cosmo (Cosmology, optional) – Cosmology in which the calculations are to be performed. LambdaCDM with defs.frb_cosmo parameters assumed by default.
perturb_Mstar (float, optional) – If provided, scale rho_Mstar by this value. Useful for exploring the uncertainty in f_diffuse
- Returns:
Units of Msun/Mpc^3
- Return type:
rhoISM (Quantity)
- frb.dm.igm.avg_rhoMstar(z, remnants=True)[source]
Return mass density in stars as calculated by Madau & Dickinson (2014).
Note: these authors assumed the Salpeter IMF which is no longer in fashion.
- frb.dm.igm.avg_rhoSFR(z)[source]
Average SFR density
Based on Madau & Dickinson (2014)
- Parameters:
z (float or ndarray) – Redshift
- Returns:
SFR – Units of Msun/yr/Mpc^3
- Return type:
Quantity
- frb.dm.igm.z_to_array(z)[source]
Convert input scalar or array to an array
- Parameters:
z (float or ndarray) – Redshift
- Returns:
z (ndarray)
flg_z (int) – 0 – Input was a scalar 1 – Input was an array
Key Functions
- frb.dm.igm.ne_cosmic(z, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), mu=1.3333333333333333)[source]
Calculate the average cosmic electron number density as a function of redshift. :param z: Redshift :type z: float or ndarray :param cosmo: Cosmology in :type cosmo: Cosmology, optional :param which the calculations are to be performed.: :param mu: Reduced mass :type mu: float
- Returns:
Average physical number density of electrons in the unverse in cm^-3.
- Return type:
ne_cosmic (Quantity)
- frb.dm.igm.z_from_DM(DM, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), coord=None, corr_nuisance=True)[source]
Report back an estimated redshift from an input IGM DM Any contributions from the Galaxy and/or host need to have been ‘removed’
- Parameters:
DM (Quantity) – Dispersion measure.
cosmo (Cosmology, optional) – Cosmology of the universe. LambdaCDM with the Repo cosmology used by default.
coord (SkyCoord, optional) – If provided, use it to remove the ISM
corr_nuisance (bool, optional) – If True, correct for the MW Halo and the host with 100 DM units.
- Returns:
Redshift
- Return type:
frb.dm.cosmic - Cosmic DM Modeling
Utility pieces for DM calculations
- frb.dm.cosmic.DMcosmic_PDF(Delta, C0, sigma, A=1.0, alpha=3.0, beta=3.0)[source]
PDF(Delta) following the McQuinn formalism describing the DM_cosmic PDF
See Macquart+2020 for details
- frb.dm.cosmic.build_C0_spline(max_log10_sigma=0.0, npt=100, ret_all=False, beta=4.0)[source]
Generate a spline of C0 vs sigma values for the McQuinn formalism
frb.dm.host - Host Galaxy Contributions
Methods related to DM in FRB Host Galaxies
- frb.dm.host.dm_host_from_Halpha(z: float, Halpha: Quantity, reff_ang: Quantity, AV: float = None)[source]
Estimate DM_Host from Halpha and angular size (and redshift)
- frb.dm.host.dm_host_from_ssfr(z: float, ssfr: Quantity)[source]
Estimate DM_host from the surface density of SFR
- Parameters:
z (float) – Redshift
ssfr (Quantity) – Surface density of SFR (with units)
- Returns:
DM_host as observed (i.e. includes the 1/1+z term)
- Return type:
Quantity
- frb.dm.host.dm_host_halo(R: Quantity, log10_Mstar: float, z: float, HMR: str = 'Moster', mNFW: ModifiedNFW = None)[source]
Calculate the DM contribution from the host galaxy’s halo
- Parameters:
R (Quantity) – Projected radial distance from the center of the halo
log10_Mstar (float) – Logarithm (base 10) of the stellar mass of the host galaxy
z (float) – Redshift of the host galaxy
HMR (str, optional) – Halo mass relation to use (‘Moster’ or ‘Kravstov’). Default is ‘Moster’
mNFW (models.ModifiedNFW, optional) – Instance of the ModifiedNFW model. If None, a default model will be created. Default is None
- Returns:
DM contribution from the host galaxy’s halo
- Return type:
Quantity
- Raises:
IOError – If the specified halo mass relation (HMR) is not supported
frb.dm.mcmc - MCMC Analysis
Methods for MCMC analysis of the Macquart relation
- frb.dm.mcmc.one_prob(Obh70, F, DM_FRBp, z_FRB, mu=150.0, lognorm_s=1.0, lognorm_floor=0.0, orig=False, beta=4.0)[source]
Calculate the probability for a single FRB
- Parameters:
Obh70 (float) – Value of Omega_b * H_0
F (float) – Feedback parameter
DM_FRBp (np.ndarray) – Values of DM_FRBp for analysis
z_FRB (np.ndarray) – z values for evaluation
mu (float, optional) – Mean of log-normal PDF
lognorm_s (float, optional) – Sigma of log-normal PDF
lognorm_floor (float, optional) – Floor to the log-normal PDF
orig (bool, optional) – if True (not recommended!), use the original approach to calculating sigma
beta (float, optional) – Parameter for DM PDF
- Returns:
Likelihood probability
- Return type:
- frb.dm.mcmc.mcquinn_DM_PDF_grid(Delta_values, C0, sigma, alpha=3.0, beta=3.0)[source]
PDF(Delta) for the McQuinn formalism describing the DM_cosmic PDF
- Parameters:
Returns:
- frb.dm.mcmc.all_prob(Obh70, F, in_DM_FRBp, z_FRB, mu=150.0, lognorm_s=1.0, lognorm_floor=0.0, beta=3.0)[source]
Calculate the probability for a set of FRBs
- Parameters:
Obh70 (float) – Value of Omega_b * H_0
F (float) – Feedback parameter
in_DM_FRBp (np.ndarray) – Values of DM_FRBp for analysis Not used?!
z_FRB (np.ndarray) – z values for evaluation
mu (float, optional) – Mean of log-normal PDF
lognorm_s (float, optional) – Sigma of log-normal PDF
lognorm_floor (float, optional) – Floor to the log-normal PDF
beta (float, optional) – Parameter for DM PDF
- Returns:
Log like-lihood
- Return type:
frb.dm.prob_dmz - DM-Redshift Probabilities
Code for calculations of P(DM|z) and P(z|DM)
- frb.dm.prob_dmz.prob_DMcosmic_FRB(frb, DM_min=0.0, DM_max=5000.0, step=1.0, ISMfrac=0.1, DM_MWhalo=50.0)[source]
Generate P(DM_cosmic) for an input FRP
- Parameters:
frb (
frb.frb.FRB)DM_min (float, optional) – Lowest DM for the calulation
DM_max (float, optional) – Highest DM for the calulation
step (float, optional) – Step size of DM array in units of pc/cm**3
ISMfrac (float, optional) – Fraction of DM_ISM to adopt as the 1-sigma error
DM_MWhalo (float, optional) – Fixed value to use for the MW halo
- Returns:
- numpy.ndarray, numpy.ndarray
DM_cosmic values (units of pc/cm**3), P(DM_cosmic) normalized to unity
- Return type:
- frb.dm.prob_dmz.grid_P_DMcosmic_z(beta=3.0, F=0.31, zvals=None, DM_cosmics=None, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897))[source]
Generate a grid of P(DM_cosmic|z)
- Parameters:
- Returns:
z, DM_cosmic, P(DM_cosmic|z)
- Return type:
- frb.dm.prob_dmz.build_grid_for_repo(outfile: str)[source]
Build a P(DM,z) grid for the Repository
- Parameters:
outfile (str) – Path+filename for output file
- frb.dm.prob_dmz.grab_repo_grid(grid_name)[source]
Grab the grid from the Repository based on the given grid name
- frb.dm.prob_dmz.get_DMcosmic_from_z(zarray, perc=0.5, redo_pdmz_grid=False, DMevals=array([1.00000000e+00, 3.00100100e+00, 5.00200200e+00, 7.00300300e+00, 9.00400400e+00, 1.10050050e+01, 1.30060060e+01, 1.50070070e+01, 1.70080080e+01, 1.90090090e+01, 2.10100100e+01, 2.30110110e+01, 2.50120120e+01, 2.70130130e+01, 2.90140140e+01, 3.10150150e+01, 3.30160160e+01, 3.50170170e+01, 3.70180180e+01, 3.90190190e+01, 4.10200200e+01, 4.30210210e+01, 4.50220220e+01, 4.70230230e+01, 4.90240240e+01, 5.10250250e+01, 5.30260260e+01, 5.50270270e+01, 5.70280280e+01, 5.90290290e+01, 6.10300300e+01, 6.30310310e+01, 6.50320320e+01, 6.70330330e+01, 6.90340340e+01, 7.10350350e+01, 7.30360360e+01, 7.50370370e+01, 7.70380380e+01, 7.90390390e+01, 8.10400400e+01, 8.30410410e+01, 8.50420420e+01, 8.70430430e+01, 8.90440440e+01, 9.10450450e+01, 9.30460460e+01, 9.50470470e+01, 9.70480480e+01, 9.90490490e+01, 1.01050050e+02, 1.03051051e+02, 1.05052052e+02, 1.07053053e+02, 1.09054054e+02, 1.11055055e+02, 1.13056056e+02, 1.15057057e+02, 1.17058058e+02, 1.19059059e+02, 1.21060060e+02, 1.23061061e+02, 1.25062062e+02, 1.27063063e+02, 1.29064064e+02, 1.31065065e+02, 1.33066066e+02, 1.35067067e+02, 1.37068068e+02, 1.39069069e+02, 1.41070070e+02, 1.43071071e+02, 1.45072072e+02, 1.47073073e+02, 1.49074074e+02, 1.51075075e+02, 1.53076076e+02, 1.55077077e+02, 1.57078078e+02, 1.59079079e+02, 1.61080080e+02, 1.63081081e+02, 1.65082082e+02, 1.67083083e+02, 1.69084084e+02, 1.71085085e+02, 1.73086086e+02, 1.75087087e+02, 1.77088088e+02, 1.79089089e+02, 1.81090090e+02, 1.83091091e+02, 1.85092092e+02, 1.87093093e+02, 1.89094094e+02, 1.91095095e+02, 1.93096096e+02, 1.95097097e+02, 1.97098098e+02, 1.99099099e+02, 2.01100100e+02, 2.03101101e+02, 2.05102102e+02, 2.07103103e+02, 2.09104104e+02, 2.11105105e+02, 2.13106106e+02, 2.15107107e+02, 2.17108108e+02, 2.19109109e+02, 2.21110110e+02, 2.23111111e+02, 2.25112112e+02, 2.27113113e+02, 2.29114114e+02, 2.31115115e+02, 2.33116116e+02, 2.35117117e+02, 2.37118118e+02, 2.39119119e+02, 2.41120120e+02, 2.43121121e+02, 2.45122122e+02, 2.47123123e+02, 2.49124124e+02, 2.51125125e+02, 2.53126126e+02, 2.55127127e+02, 2.57128128e+02, 2.59129129e+02, 2.61130130e+02, 2.63131131e+02, 2.65132132e+02, 2.67133133e+02, 2.69134134e+02, 2.71135135e+02, 2.73136136e+02, 2.75137137e+02, 2.77138138e+02, 2.79139139e+02, 2.81140140e+02, 2.83141141e+02, 2.85142142e+02, 2.87143143e+02, 2.89144144e+02, 2.91145145e+02, 2.93146146e+02, 2.95147147e+02, 2.97148148e+02, 2.99149149e+02, 3.01150150e+02, 3.03151151e+02, 3.05152152e+02, 3.07153153e+02, 3.09154154e+02, 3.11155155e+02, 3.13156156e+02, 3.15157157e+02, 3.17158158e+02, 3.19159159e+02, 3.21160160e+02, 3.23161161e+02, 3.25162162e+02, 3.27163163e+02, 3.29164164e+02, 3.31165165e+02, 3.33166166e+02, 3.35167167e+02, 3.37168168e+02, 3.39169169e+02, 3.41170170e+02, 3.43171171e+02, 3.45172172e+02, 3.47173173e+02, 3.49174174e+02, 3.51175175e+02, 3.53176176e+02, 3.55177177e+02, 3.57178178e+02, 3.59179179e+02, 3.61180180e+02, 3.63181181e+02, 3.65182182e+02, 3.67183183e+02, 3.69184184e+02, 3.71185185e+02, 3.73186186e+02, 3.75187187e+02, 3.77188188e+02, 3.79189189e+02, 3.81190190e+02, 3.83191191e+02, 3.85192192e+02, 3.87193193e+02, 3.89194194e+02, 3.91195195e+02, 3.93196196e+02, 3.95197197e+02, 3.97198198e+02, 3.99199199e+02, 4.01200200e+02, 4.03201201e+02, 4.05202202e+02, 4.07203203e+02, 4.09204204e+02, 4.11205205e+02, 4.13206206e+02, 4.15207207e+02, 4.17208208e+02, 4.19209209e+02, 4.21210210e+02, 4.23211211e+02, 4.25212212e+02, 4.27213213e+02, 4.29214214e+02, 4.31215215e+02, 4.33216216e+02, 4.35217217e+02, 4.37218218e+02, 4.39219219e+02, 4.41220220e+02, 4.43221221e+02, 4.45222222e+02, 4.47223223e+02, 4.49224224e+02, 4.51225225e+02, 4.53226226e+02, 4.55227227e+02, 4.57228228e+02, 4.59229229e+02, 4.61230230e+02, 4.63231231e+02, 4.65232232e+02, 4.67233233e+02, 4.69234234e+02, 4.71235235e+02, 4.73236236e+02, 4.75237237e+02, 4.77238238e+02, 4.79239239e+02, 4.81240240e+02, 4.83241241e+02, 4.85242242e+02, 4.87243243e+02, 4.89244244e+02, 4.91245245e+02, 4.93246246e+02, 4.95247247e+02, 4.97248248e+02, 4.99249249e+02, 5.01250250e+02, 5.03251251e+02, 5.05252252e+02, 5.07253253e+02, 5.09254254e+02, 5.11255255e+02, 5.13256256e+02, 5.15257257e+02, 5.17258258e+02, 5.19259259e+02, 5.21260260e+02, 5.23261261e+02, 5.25262262e+02, 5.27263263e+02, 5.29264264e+02, 5.31265265e+02, 5.33266266e+02, 5.35267267e+02, 5.37268268e+02, 5.39269269e+02, 5.41270270e+02, 5.43271271e+02, 5.45272272e+02, 5.47273273e+02, 5.49274274e+02, 5.51275275e+02, 5.53276276e+02, 5.55277277e+02, 5.57278278e+02, 5.59279279e+02, 5.61280280e+02, 5.63281281e+02, 5.65282282e+02, 5.67283283e+02, 5.69284284e+02, 5.71285285e+02, 5.73286286e+02, 5.75287287e+02, 5.77288288e+02, 5.79289289e+02, 5.81290290e+02, 5.83291291e+02, 5.85292292e+02, 5.87293293e+02, 5.89294294e+02, 5.91295295e+02, 5.93296296e+02, 5.95297297e+02, 5.97298298e+02, 5.99299299e+02, 6.01300300e+02, 6.03301301e+02, 6.05302302e+02, 6.07303303e+02, 6.09304304e+02, 6.11305305e+02, 6.13306306e+02, 6.15307307e+02, 6.17308308e+02, 6.19309309e+02, 6.21310310e+02, 6.23311311e+02, 6.25312312e+02, 6.27313313e+02, 6.29314314e+02, 6.31315315e+02, 6.33316316e+02, 6.35317317e+02, 6.37318318e+02, 6.39319319e+02, 6.41320320e+02, 6.43321321e+02, 6.45322322e+02, 6.47323323e+02, 6.49324324e+02, 6.51325325e+02, 6.53326326e+02, 6.55327327e+02, 6.57328328e+02, 6.59329329e+02, 6.61330330e+02, 6.63331331e+02, 6.65332332e+02, 6.67333333e+02, 6.69334334e+02, 6.71335335e+02, 6.73336336e+02, 6.75337337e+02, 6.77338338e+02, 6.79339339e+02, 6.81340340e+02, 6.83341341e+02, 6.85342342e+02, 6.87343343e+02, 6.89344344e+02, 6.91345345e+02, 6.93346346e+02, 6.95347347e+02, 6.97348348e+02, 6.99349349e+02, 7.01350350e+02, 7.03351351e+02, 7.05352352e+02, 7.07353353e+02, 7.09354354e+02, 7.11355355e+02, 7.13356356e+02, 7.15357357e+02, 7.17358358e+02, 7.19359359e+02, 7.21360360e+02, 7.23361361e+02, 7.25362362e+02, 7.27363363e+02, 7.29364364e+02, 7.31365365e+02, 7.33366366e+02, 7.35367367e+02, 7.37368368e+02, 7.39369369e+02, 7.41370370e+02, 7.43371371e+02, 7.45372372e+02, 7.47373373e+02, 7.49374374e+02, 7.51375375e+02, 7.53376376e+02, 7.55377377e+02, 7.57378378e+02, 7.59379379e+02, 7.61380380e+02, 7.63381381e+02, 7.65382382e+02, 7.67383383e+02, 7.69384384e+02, 7.71385385e+02, 7.73386386e+02, 7.75387387e+02, 7.77388388e+02, 7.79389389e+02, 7.81390390e+02, 7.83391391e+02, 7.85392392e+02, 7.87393393e+02, 7.89394394e+02, 7.91395395e+02, 7.93396396e+02, 7.95397397e+02, 7.97398398e+02, 7.99399399e+02, 8.01400400e+02, 8.03401401e+02, 8.05402402e+02, 8.07403403e+02, 8.09404404e+02, 8.11405405e+02, 8.13406406e+02, 8.15407407e+02, 8.17408408e+02, 8.19409409e+02, 8.21410410e+02, 8.23411411e+02, 8.25412412e+02, 8.27413413e+02, 8.29414414e+02, 8.31415415e+02, 8.33416416e+02, 8.35417417e+02, 8.37418418e+02, 8.39419419e+02, 8.41420420e+02, 8.43421421e+02, 8.45422422e+02, 8.47423423e+02, 8.49424424e+02, 8.51425425e+02, 8.53426426e+02, 8.55427427e+02, 8.57428428e+02, 8.59429429e+02, 8.61430430e+02, 8.63431431e+02, 8.65432432e+02, 8.67433433e+02, 8.69434434e+02, 8.71435435e+02, 8.73436436e+02, 8.75437437e+02, 8.77438438e+02, 8.79439439e+02, 8.81440440e+02, 8.83441441e+02, 8.85442442e+02, 8.87443443e+02, 8.89444444e+02, 8.91445445e+02, 8.93446446e+02, 8.95447447e+02, 8.97448448e+02, 8.99449449e+02, 9.01450450e+02, 9.03451451e+02, 9.05452452e+02, 9.07453453e+02, 9.09454454e+02, 9.11455455e+02, 9.13456456e+02, 9.15457457e+02, 9.17458458e+02, 9.19459459e+02, 9.21460460e+02, 9.23461461e+02, 9.25462462e+02, 9.27463463e+02, 9.29464464e+02, 9.31465465e+02, 9.33466466e+02, 9.35467467e+02, 9.37468468e+02, 9.39469469e+02, 9.41470470e+02, 9.43471471e+02, 9.45472472e+02, 9.47473473e+02, 9.49474474e+02, 9.51475475e+02, 9.53476476e+02, 9.55477477e+02, 9.57478478e+02, 9.59479479e+02, 9.61480480e+02, 9.63481481e+02, 9.65482482e+02, 9.67483483e+02, 9.69484484e+02, 9.71485485e+02, 9.73486486e+02, 9.75487487e+02, 9.77488488e+02, 9.79489489e+02, 9.81490490e+02, 9.83491491e+02, 9.85492492e+02, 9.87493493e+02, 9.89494494e+02, 9.91495495e+02, 9.93496496e+02, 9.95497497e+02, 9.97498498e+02, 9.99499499e+02, 1.00150050e+03, 1.00350150e+03, 1.00550250e+03, 1.00750350e+03, 1.00950450e+03, 1.01150551e+03, 1.01350651e+03, 1.01550751e+03, 1.01750851e+03, 1.01950951e+03, 1.02151051e+03, 1.02351151e+03, 1.02551251e+03, 1.02751351e+03, 1.02951451e+03, 1.03151552e+03, 1.03351652e+03, 1.03551752e+03, 1.03751852e+03, 1.03951952e+03, 1.04152052e+03, 1.04352152e+03, 1.04552252e+03, 1.04752352e+03, 1.04952452e+03, 1.05152553e+03, 1.05352653e+03, 1.05552753e+03, 1.05752853e+03, 1.05952953e+03, 1.06153053e+03, 1.06353153e+03, 1.06553253e+03, 1.06753353e+03, 1.06953453e+03, 1.07153554e+03, 1.07353654e+03, 1.07553754e+03, 1.07753854e+03, 1.07953954e+03, 1.08154054e+03, 1.08354154e+03, 1.08554254e+03, 1.08754354e+03, 1.08954454e+03, 1.09154555e+03, 1.09354655e+03, 1.09554755e+03, 1.09754855e+03, 1.09954955e+03, 1.10155055e+03, 1.10355155e+03, 1.10555255e+03, 1.10755355e+03, 1.10955455e+03, 1.11155556e+03, 1.11355656e+03, 1.11555756e+03, 1.11755856e+03, 1.11955956e+03, 1.12156056e+03, 1.12356156e+03, 1.12556256e+03, 1.12756356e+03, 1.12956456e+03, 1.13156557e+03, 1.13356657e+03, 1.13556757e+03, 1.13756857e+03, 1.13956957e+03, 1.14157057e+03, 1.14357157e+03, 1.14557257e+03, 1.14757357e+03, 1.14957457e+03, 1.15157558e+03, 1.15357658e+03, 1.15557758e+03, 1.15757858e+03, 1.15957958e+03, 1.16158058e+03, 1.16358158e+03, 1.16558258e+03, 1.16758358e+03, 1.16958458e+03, 1.17158559e+03, 1.17358659e+03, 1.17558759e+03, 1.17758859e+03, 1.17958959e+03, 1.18159059e+03, 1.18359159e+03, 1.18559259e+03, 1.18759359e+03, 1.18959459e+03, 1.19159560e+03, 1.19359660e+03, 1.19559760e+03, 1.19759860e+03, 1.19959960e+03, 1.20160060e+03, 1.20360160e+03, 1.20560260e+03, 1.20760360e+03, 1.20960460e+03, 1.21160561e+03, 1.21360661e+03, 1.21560761e+03, 1.21760861e+03, 1.21960961e+03, 1.22161061e+03, 1.22361161e+03, 1.22561261e+03, 1.22761361e+03, 1.22961461e+03, 1.23161562e+03, 1.23361662e+03, 1.23561762e+03, 1.23761862e+03, 1.23961962e+03, 1.24162062e+03, 1.24362162e+03, 1.24562262e+03, 1.24762362e+03, 1.24962462e+03, 1.25162563e+03, 1.25362663e+03, 1.25562763e+03, 1.25762863e+03, 1.25962963e+03, 1.26163063e+03, 1.26363163e+03, 1.26563263e+03, 1.26763363e+03, 1.26963463e+03, 1.27163564e+03, 1.27363664e+03, 1.27563764e+03, 1.27763864e+03, 1.27963964e+03, 1.28164064e+03, 1.28364164e+03, 1.28564264e+03, 1.28764364e+03, 1.28964464e+03, 1.29164565e+03, 1.29364665e+03, 1.29564765e+03, 1.29764865e+03, 1.29964965e+03, 1.30165065e+03, 1.30365165e+03, 1.30565265e+03, 1.30765365e+03, 1.30965465e+03, 1.31165566e+03, 1.31365666e+03, 1.31565766e+03, 1.31765866e+03, 1.31965966e+03, 1.32166066e+03, 1.32366166e+03, 1.32566266e+03, 1.32766366e+03, 1.32966466e+03, 1.33166567e+03, 1.33366667e+03, 1.33566767e+03, 1.33766867e+03, 1.33966967e+03, 1.34167067e+03, 1.34367167e+03, 1.34567267e+03, 1.34767367e+03, 1.34967467e+03, 1.35167568e+03, 1.35367668e+03, 1.35567768e+03, 1.35767868e+03, 1.35967968e+03, 1.36168068e+03, 1.36368168e+03, 1.36568268e+03, 1.36768368e+03, 1.36968468e+03, 1.37168569e+03, 1.37368669e+03, 1.37568769e+03, 1.37768869e+03, 1.37968969e+03, 1.38169069e+03, 1.38369169e+03, 1.38569269e+03, 1.38769369e+03, 1.38969469e+03, 1.39169570e+03, 1.39369670e+03, 1.39569770e+03, 1.39769870e+03, 1.39969970e+03, 1.40170070e+03, 1.40370170e+03, 1.40570270e+03, 1.40770370e+03, 1.40970470e+03, 1.41170571e+03, 1.41370671e+03, 1.41570771e+03, 1.41770871e+03, 1.41970971e+03, 1.42171071e+03, 1.42371171e+03, 1.42571271e+03, 1.42771371e+03, 1.42971471e+03, 1.43171572e+03, 1.43371672e+03, 1.43571772e+03, 1.43771872e+03, 1.43971972e+03, 1.44172072e+03, 1.44372172e+03, 1.44572272e+03, 1.44772372e+03, 1.44972472e+03, 1.45172573e+03, 1.45372673e+03, 1.45572773e+03, 1.45772873e+03, 1.45972973e+03, 1.46173073e+03, 1.46373173e+03, 1.46573273e+03, 1.46773373e+03, 1.46973473e+03, 1.47173574e+03, 1.47373674e+03, 1.47573774e+03, 1.47773874e+03, 1.47973974e+03, 1.48174074e+03, 1.48374174e+03, 1.48574274e+03, 1.48774374e+03, 1.48974474e+03, 1.49174575e+03, 1.49374675e+03, 1.49574775e+03, 1.49774875e+03, 1.49974975e+03, 1.50175075e+03, 1.50375175e+03, 1.50575275e+03, 1.50775375e+03, 1.50975475e+03, 1.51175576e+03, 1.51375676e+03, 1.51575776e+03, 1.51775876e+03, 1.51975976e+03, 1.52176076e+03, 1.52376176e+03, 1.52576276e+03, 1.52776376e+03, 1.52976476e+03, 1.53176577e+03, 1.53376677e+03, 1.53576777e+03, 1.53776877e+03, 1.53976977e+03, 1.54177077e+03, 1.54377177e+03, 1.54577277e+03, 1.54777377e+03, 1.54977477e+03, 1.55177578e+03, 1.55377678e+03, 1.55577778e+03, 1.55777878e+03, 1.55977978e+03, 1.56178078e+03, 1.56378178e+03, 1.56578278e+03, 1.56778378e+03, 1.56978478e+03, 1.57178579e+03, 1.57378679e+03, 1.57578779e+03, 1.57778879e+03, 1.57978979e+03, 1.58179079e+03, 1.58379179e+03, 1.58579279e+03, 1.58779379e+03, 1.58979479e+03, 1.59179580e+03, 1.59379680e+03, 1.59579780e+03, 1.59779880e+03, 1.59979980e+03, 1.60180080e+03, 1.60380180e+03, 1.60580280e+03, 1.60780380e+03, 1.60980480e+03, 1.61180581e+03, 1.61380681e+03, 1.61580781e+03, 1.61780881e+03, 1.61980981e+03, 1.62181081e+03, 1.62381181e+03, 1.62581281e+03, 1.62781381e+03, 1.62981481e+03, 1.63181582e+03, 1.63381682e+03, 1.63581782e+03, 1.63781882e+03, 1.63981982e+03, 1.64182082e+03, 1.64382182e+03, 1.64582282e+03, 1.64782382e+03, 1.64982482e+03, 1.65182583e+03, 1.65382683e+03, 1.65582783e+03, 1.65782883e+03, 1.65982983e+03, 1.66183083e+03, 1.66383183e+03, 1.66583283e+03, 1.66783383e+03, 1.66983483e+03, 1.67183584e+03, 1.67383684e+03, 1.67583784e+03, 1.67783884e+03, 1.67983984e+03, 1.68184084e+03, 1.68384184e+03, 1.68584284e+03, 1.68784384e+03, 1.68984484e+03, 1.69184585e+03, 1.69384685e+03, 1.69584785e+03, 1.69784885e+03, 1.69984985e+03, 1.70185085e+03, 1.70385185e+03, 1.70585285e+03, 1.70785385e+03, 1.70985485e+03, 1.71185586e+03, 1.71385686e+03, 1.71585786e+03, 1.71785886e+03, 1.71985986e+03, 1.72186086e+03, 1.72386186e+03, 1.72586286e+03, 1.72786386e+03, 1.72986486e+03, 1.73186587e+03, 1.73386687e+03, 1.73586787e+03, 1.73786887e+03, 1.73986987e+03, 1.74187087e+03, 1.74387187e+03, 1.74587287e+03, 1.74787387e+03, 1.74987487e+03, 1.75187588e+03, 1.75387688e+03, 1.75587788e+03, 1.75787888e+03, 1.75987988e+03, 1.76188088e+03, 1.76388188e+03, 1.76588288e+03, 1.76788388e+03, 1.76988488e+03, 1.77188589e+03, 1.77388689e+03, 1.77588789e+03, 1.77788889e+03, 1.77988989e+03, 1.78189089e+03, 1.78389189e+03, 1.78589289e+03, 1.78789389e+03, 1.78989489e+03, 1.79189590e+03, 1.79389690e+03, 1.79589790e+03, 1.79789890e+03, 1.79989990e+03, 1.80190090e+03, 1.80390190e+03, 1.80590290e+03, 1.80790390e+03, 1.80990490e+03, 1.81190591e+03, 1.81390691e+03, 1.81590791e+03, 1.81790891e+03, 1.81990991e+03, 1.82191091e+03, 1.82391191e+03, 1.82591291e+03, 1.82791391e+03, 1.82991491e+03, 1.83191592e+03, 1.83391692e+03, 1.83591792e+03, 1.83791892e+03, 1.83991992e+03, 1.84192092e+03, 1.84392192e+03, 1.84592292e+03, 1.84792392e+03, 1.84992492e+03, 1.85192593e+03, 1.85392693e+03, 1.85592793e+03, 1.85792893e+03, 1.85992993e+03, 1.86193093e+03, 1.86393193e+03, 1.86593293e+03, 1.86793393e+03, 1.86993493e+03, 1.87193594e+03, 1.87393694e+03, 1.87593794e+03, 1.87793894e+03, 1.87993994e+03, 1.88194094e+03, 1.88394194e+03, 1.88594294e+03, 1.88794394e+03, 1.88994494e+03, 1.89194595e+03, 1.89394695e+03, 1.89594795e+03, 1.89794895e+03, 1.89994995e+03, 1.90195095e+03, 1.90395195e+03, 1.90595295e+03, 1.90795395e+03, 1.90995495e+03, 1.91195596e+03, 1.91395696e+03, 1.91595796e+03, 1.91795896e+03, 1.91995996e+03, 1.92196096e+03, 1.92396196e+03, 1.92596296e+03, 1.92796396e+03, 1.92996496e+03, 1.93196597e+03, 1.93396697e+03, 1.93596797e+03, 1.93796897e+03, 1.93996997e+03, 1.94197097e+03, 1.94397197e+03, 1.94597297e+03, 1.94797397e+03, 1.94997497e+03, 1.95197598e+03, 1.95397698e+03, 1.95597798e+03, 1.95797898e+03, 1.95997998e+03, 1.96198098e+03, 1.96398198e+03, 1.96598298e+03, 1.96798398e+03, 1.96998498e+03, 1.97198599e+03, 1.97398699e+03, 1.97598799e+03, 1.97798899e+03, 1.97998999e+03, 1.98199099e+03, 1.98399199e+03, 1.98599299e+03, 1.98799399e+03, 1.98999499e+03, 1.99199600e+03, 1.99399700e+03, 1.99599800e+03, 1.99799900e+03, 2.00000000e+03]), beta=3.0, F=0.31, cosmo=FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897))[source]
Gives DMcosmic values of zarray, considering the percentile. Default is median (i.e. percentile=0.5)
- Parameters:
zarray (float or np.array) – Redshift value or values If np.array, then it must start from 0
perc (float) – Percentile of the PDF(DM_cosmic) for each z, from 0 to zmax. Default = 0.5
redo_pdmz_grid (bool) – Whether to recompute the DMcosmic-z grid Default is False If True, it will be computational expensive
DMevals (np.array) – Array representing the DMcosmic evaluations of the PDF. Should start with 1. Default = np.linspace(1.,5000.,1000) Changing this only works when redo_pdmz_grid=True
beta (float) – Slope of a galactic halo parameter (See Macquart+2020) Default = 3.0 Changing this only works when redo_pdmz_grid=True
F (float) – Parameter that depends on galaxy feedback (See Macquart+2020) Default = 0.31 Changing this only works when redo_pdmz_grid=True
cosmo (astropy.cosmology object) – Cosmology
- Returns:
zarray (np.array) – z values where the DMcosmic was computed
DMcosmic_array (np.array) – DMcosmic values corresponding to the z_array (in a given percentile)
Detailed Function Documentation
IGM Functions
- frb.dm.prob_dmz.ne_cosmic(z, cosmo=defs.frb_cosmo, mu=4. / 3)
Calculate the average cosmic electron number density as a function of redshift.
This function computes the physical number density of electrons in the universe, accounting for the cosmic baryon density and ionization fraction.
- Parameters:
- Returns:
Average physical number density of electrons in the universe
- Return type:
astropy.units.Quantity
Example:
from frb.dm.igm import ne_cosmic # Calculate electron density at z=1 z = 1.0 n_e = ne_cosmic(z) print(f"Electron density at z={z}: {n_e}")
- frb.dm.prob_dmz.DM_cosmic(z, cosmo=defs.frb_cosmo, cumul=False)
Calculate the cosmic dispersion measure contribution.
Integrates the cosmic electron density from z=0 to the specified redshift, including corrections for cosmological expansion.
- Parameters:
- Returns:
Cosmic dispersion measure or array if cumul=True
- Return type:
astropy.units.Quantity
Example:
from frb.dm.igm import DM_cosmic # Calculate cosmic DM to z=0.5 z_frb = 0.5 dm_cosmic = DM_cosmic(z_frb) print(f"Cosmic DM to z={z_frb}: {dm_cosmic}")
- frb.dm.prob_dmz.z_from_DM(DM, cosmo=defs.frb_cosmo, coord=None, corr_nuisance=True)
Estimate redshift from observed dispersion measure.
Uses the cosmic DM-redshift relation to estimate the redshift of an FRB given its observed dispersion measure, after correcting for Galactic and other contributions.
- Parameters:
DM (astropy.units.Quantity) – Observed dispersion measure
cosmo (astropy.cosmology.Cosmology) – Cosmology
coord (astropy.coordinates.SkyCoord) – Sky coordinates (optional)
corr_nuisance (bool) – Apply corrections for nuisance parameters
- Returns:
Estimated redshift
- Return type:
Example:
from frb.dm.igm import z_from_DM from astropy import units as u # Estimate redshift from DM DM_obs = 500 * u.pc / u.cm**3 z_est = z_from_DM(DM_obs) print(f"Estimated redshift: {z_est:.2f}")
- frb.dm.prob_dmz.DM_halos(z, cosmo, f_hot=0.75, rmax=2., logMmin=10.3, logMmax=16., neval=500, cumul=False)
Calculate dispersion measure contribution from galaxy halos.
Models the DM contribution from hot gas in galaxy halos along the line of sight, using a halo mass function approach.
- Parameters:
z (float) – Redshift of the FRB
cosmo (astropy.cosmology.Cosmology) – Cosmology for calculations
f_hot (float) – Fraction of halo baryons in diffuse phase
rmax (float) – Size of halo in units of r200
logMmin (float) – Log of minimum halo mass (cannot be much below 10.3)
logMmax (float) – Log of maximum halo mass (default: 10^16 Msun)
neval (int) – Number of redshift evaluation points
cumul (bool) – Return cumulative evaluation
- Returns:
DM contribution from halos
- Return type:
astropy.units.Quantity
Utility Functions
- frb.dm.prob_dmz.f_diffuse(z, cosmo=defs.frb_cosmo, return_rho=False)
Calculate the fraction of baryons in the diffuse IGM.
- frb.dm.prob_dmz.sigma_DM_cosmic(DM_cosmic, rel_err_Mstar=0.1)
Calculate uncertainty in cosmic DM due to stellar mass uncertainties.
- Parameters:
DM_cosmic (astropy.units.Quantity) – Cosmic dispersion measure
rel_err_Mstar (float) – Relative error in stellar mass
- Returns:
DM uncertainty
- Return type:
astropy.units.Quantity
Physical Models
Ionization Models
The module includes models for cosmic reionization history:
Hydrogen Reionization: - Reionization redshift: z_HI ~ 6-8 - Affects IGM electron fraction at high redshift
Helium Reionization: - HeII reionization: z_HeII ~ 3-4 - Increases electron density at intermediate redshift
Implementation:
from frb.dm.igm import f_ionization_He
# Calculate helium ionization fraction
z = 3.0
f_He = f_ionization_He(z)
print(f"Helium ionization fraction at z={z}: {f_He}")
Halo Models
Galaxy halo contributions use the halo mass function and hot gas profiles:
Key Parameters: - Halo mass range: 10^10.3 to 10^16 M_sun - Hot gas fraction: ~75% of cosmic baryon fraction - Radial extent: typically 2 × r200
Scaling Relations: - Gas density profiles (e.g., beta models) - Mass-temperature relations - Feedback effects on gas distribution
Usage Examples
Basic DM Analysis
from frb.dm import igm
from astropy import units as u
# Calculate total cosmic DM budget
z_max = 2.0
dm_cosmic_total = igm.DM_cosmic(z_max)
# Calculate contributions at different redshifts
redshifts = [0.1, 0.5, 1.0, 1.5, 2.0]
for z in redshifts:
dm_z = igm.DM_cosmic(z)
print(f"DM(z={z:.1f}) = {dm_z:.0f}")
Redshift Estimation
from frb.dm.igm import z_from_DM
from astropy import units as u
from astropy.coordinates import SkyCoord
# Observed FRB parameters
DM_obs = 750 * u.pc / u.cm**3
coord = SkyCoord(ra=123.45*u.deg, dec=12.34*u.deg)
# Estimate redshift
z_est = z_from_DM(DM_obs, coord=coord)
print(f"Estimated redshift: {z_est:.2f}")
# Calculate expected cosmic DM at this redshift
dm_cosmic_expected = igm.DM_cosmic(z_est)
print(f"Expected cosmic DM: {dm_cosmic_expected:.0f}")
# Calculate excess DM (host + local contributions)
dm_excess = DM_obs - dm_cosmic_expected
print(f"Excess DM: {dm_excess:.0f}")
Halo Contribution Analysis
from frb.dm.igm import DM_halos
from astropy.cosmology import Planck18
# Calculate halo DM contribution
z_frb = 1.0
dm_halos = DM_halos(z_frb, Planck18)
print(f"Halo DM contribution to z={z_frb}: {dm_halos:.1f}")
# Compare different halo parameters
f_hot_values = [0.5, 0.75, 1.0]
for f_hot in f_hot_values:
dm_h = DM_halos(z_frb, Planck18, f_hot=f_hot)
print(f"Halo DM (f_hot={f_hot}): {dm_h:.1f}")
Advanced Usage
Custom Cosmologies
from astropy.cosmology import FlatLambdaCDM
from frb.dm.igm import DM_cosmic
# Define custom cosmology
custom_cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
# Compare DM calculations
z = 1.0
dm_planck = DM_cosmic(z) # Default Planck18
dm_custom = DM_cosmic(z, cosmo=custom_cosmo)
print(f"DM (Planck18): {dm_planck:.0f}")
print(f"DM (Custom): {dm_custom:.0f}")
Monte Carlo Analysis
import numpy as np
from frb.dm.igm import z_from_DM
from astropy import units as u
# Simulate DM uncertainties
DM_mean = 500 * u.pc / u.cm**3
DM_err = 50 * u.pc / u.cm**3
n_trials = 1000
# Generate DM samples
DM_samples = np.random.normal(
DM_mean.value, DM_err.value, n_trials
) * DM_mean.unit
# Calculate redshift distribution
z_samples = [z_from_DM(dm) for dm in DM_samples]
z_mean = np.mean(z_samples)
z_std = np.std(z_samples)
print(f"Redshift: {z_mean:.2f} ± {z_std:.2f}")
Error Handling
The DM module includes robust error handling:
from frb.dm.igm import z_from_DM
from astropy import units as u
try:
# This might fail for very high DM values
z = z_from_DM(10000 * u.pc / u.cm**3)
except ValueError as e:
print(f"DM too high: {e}")
try:
# This might fail for negative DM
z = z_from_DM(-100 * u.pc / u.cm**3)
except ValueError as e:
print(f"Invalid DM: {e}")
Performance Notes
Computational Efficiency: - DM calculations use vectorized numpy operations - Cosmological integrals are cached for repeated calls - Halo mass function integration is optimized for speed
Memory Usage:
- Large redshift arrays may require significant memory
- Use cumul=False for single-point calculations
- Consider chunking for very large datasets
Accuracy: - Integration tolerances balance speed and precision - Default parameters provide ~1% accuracy for most applications - High-precision calculations may require custom tolerances
See Also
Quick Start Guide - Quick start guide
frb.halos Package Documentation - Halo modeling and DM contributions
Galaxies - Galaxy analysis tools
Note
The DM module assumes a standard cosmological model by default. For non-standard cosmologies, explicitly pass the cosmology parameter to relevant functions.