frb.halos - Halo Models

Submodules

frb.halos.hmf - Halo Mass Function

frb.halos.hmf.init_hmf()[source]

Initialize the Aemulus Halo Mass Function

WARNING: This uses the original version which codes Tinker+2008 We may refactor to use the more accurate, new version

Returns:

An Aemulus halo mass function emulator.

Return type:

hmfe (hmf_emulator.hmf_emulator)

frb.halos.hmf.frac_in_halos(zvals, Mlow, Mhigh, rmax=1.0)[source]
Calculate the fraction of matter in collapsed halos

over a mass range and at a given redshift

Note that the fraction of DM associated with these halos will be scaled down by an additional factor of f_diffuse

Requires Aemulus HMF to be installed

Parameters:
  • zvals – ndarray

  • Mlow – float In h^-1 units already so this will be applied for the halo mass function

  • Mhigh – float In h^-1 units already

  • rmax – float Extent of the halo in units of rvir WARNING: This calculation assumes a single concentration for all halos

Returns:

ndarray

rho_halo / rho_m

Return type:

ratios

frb.halos.hmf.halo_incidence(Mlow, zFRB, radius=None, hmfe=None, Mhigh=1e+16, nsample=20, cumul=False)[source]

Calculate the (approximate) average number of intersections to halos of a given minimum mass to a given zFRB.

Requires Aemulus HMF to be installed

Parameters:
  • Mlow – float Mass of minimum halo in Solar masses The code deals with h^-1 factors so that you do not The minimum value is 2e10

  • zFRB – float Redshift of the FRB

  • radius

    Quantity, optional Physical separation from the sightline for the calculation. The calculation will specify this radius as rvir derived from

    Mlow unless this is specified. And this rvir will vary with redshift

  • hmfe (hmf.hmf_emulator, optional) – Halo mass function emulator from Aeumulus

  • Mhigh – float, optional Mass of maximum halo in Solar masses

  • nsammple – int, optional Number of samplings in redshift 20 should be enough

  • cumul – bool, optional Return the cumulative quantities instead

Returns:

If cumul is False Navg: float

Number of average intersections

elif cumul is True zeval: ndarray Ncumul: ndarray

frb.halos.hmf.build_grid(z_FRB=1.0, ntrial=10, seed=12345, Mlow=10000000000.0, r_max=2.0, outfile=None, dz_box=0.1, dz_grid=0.01, f_hot=0.75, verbose=True)[source]

Generate a universe of dark matter halos with DM measurements Mainly an internal function for generating useful output grids.

Requires the Aemulus Halo Mass function

Parameters:
  • z_FRB – float, optional

  • ntrial – int, optional

  • seed – int, optional

  • Mlow – float, optional h^-1 mass

  • r_max – float, optional Extent of the halo in units of rvir

  • outfile – str, optional Write

  • dz_box – float, optional Size of the slice of the universe for each sub-calculation

  • dz_grid – float, optional redshift spacing in the DM grid

  • f_hot – float Fraction of the cosmic fraction of matter in diffuse gas (for DM)

Returns:

ndarray (ntrial, nz) halo_tbl: Table

Table of all the halos intersected

Return type:

DM_grid

frb.halos.models - Halo Models

Module for DM Halo calculations

frb.halos.models.init_hmf()[source]

Initialize the Aemulus Halo Mass Function

WARNING: This uses the original version which codes Tinker+2008 We may refactor to use the more accurate, new version

Returns:

frb.halos.models.frac_in_halos(zvals, Mlow, Mhigh, rmax=1.0)[source]
Calculate the fraction of matter in collapsed halos

over a mass range and at a given redshift

Note that the fraction of DM associated with these halos will be scaled down by an additional factor of f_diffuse

Requires Aemulus HMF to be installed

Parameters:
  • zvals – ndarray

  • Mlow – float In h^-1 units already so this will be applied for the halo mass function

  • Mhigh – float In h^-1 units already

  • rmax – float Extent of the halo in units of rvir WARNING: This calculation assumes a single concentration for all halos

Returns:

ndarray

rho_halo / rho_m

Return type:

ratios

frb.halos.models.halo_incidence(Mlow, zFRB, radius=None, hmfe=None, Mhigh=1e+16, nsample=20, cumul=False)[source]

Calculate the (approximate) average number of intersections to halos of a given minimum mass to a given zFRB.

Requires Aemulus HMF to be installed

Parameters:
  • Mlow – float Mass of minimum halo in Solar masses The code deals with h^-1 factors so that you do not The minimum value is 2e10

  • zFRB – float Redshift of the FRB

  • radius

    Quantity, optional The calculation will specify this radius as rvir derived from

    Mlow unless this is specified. And this rvir will vary with redshift

  • hmfe (hmf.hmf_emulator, optional) – Halo mass function emulator from Aeumulus

  • Mhigh – float, optional Mass of maximum halo in Solar masses

  • nsammple – int, optional Number of samplings in redshift 20 should be enough

  • cumul – bool, optional Return the cumulative quantities instead

Returns:

If cumul is False Navg: float

Number of average intersections

elif cumul is True zeval: ndarray Ncumul: ndarray

frb.halos.models.build_grid(z_FRB=1.0, ntrial=10, seed=12345, Mlow=10000000000.0, r_max=2.0, outfile=None, dz_box=0.1, dz_grid=0.01, f_hot=0.75, verbose=True)[source]

Generate a universe of dark matter halos with DM measurements Mainly an internal function for generating useful output grids.

Requires the Aemulus Halo Mass function

Parameters:
  • z_FRB – float, optional

  • ntrial – int, optional

  • seed – int, optional

  • Mlow – float, optional h^-1 mass

  • r_max – float, optional Extent of the halo in units of rvir

  • outfile – str, optional Write

  • dz_box – float, optional Size of the slice of the universe for each sub-calculation

  • dz_grid – float, optional redshift spacing in the DM grid

  • f_hot – float Fraction of the cosmic fraction of matter in diffuse gas (for DM)

Returns:

ndarray (ntrial, nz) halo_tbl: Table

Table of all the halos intersected

Return type:

DM_grid

frb.halos.models.stellarmass_from_halomass(log_Mhalo, z=0, params=None)[source]

Stellar mass from Halo Mass from Moster+2013 https://doi.org/10.1093/mnras/sts261

Parameters:
  • log_Mhalo (float) – log_10 halo mass in solar mass units.

  • z (float, optional) – halo redshift. Assumed to be 0 by default.

Returns:

log_10 galaxy stellar mass

in solar mass units.

Return type:

log_mstar (float)

frb.halos.models.halomass_from_stellarmass(log_mstar, z=0, randomize=False)[source]

Halo mass from Stellar mass (Moster+2013). Inverts the function stellarmass_from_halomass numerically.

Parameters:
  • log_mstar (float or numpy.ndarray) – log_10 stellar mass in solar mass units.

  • z (float, optional) – galaxy redshift

Returns:

log_10 halo mass

in solar mass units.

Return type:

log_Mhalo (float)

frb.halos.models.stellarmass_from_halomass_kravtsov(log_mhalo)[source]

Stellar mass from Halo Mass from Kravtsov+2018. https://ui.adsabs.harvard.edu/abs/2018AstL…44….8K/abstract

Caution: This relation is valid for low z (z~0). Higher z values may require a scaled relation. :param log_mhalo: log_10 halo mass :type log_mhalo: float

Returns:

log_10 galaxy

Return type:

log_mstar (float)

frb.halos.models.halomass_from_stellarmass_kravtsov(log_mstar)[source]

Inverts the function frb.halos.models.stellarmass_from_halomass_kravtsov. :param log_mstar: log_10 stellar mass :type log_mstar: float or numpy.ndarray

Returns:

log_10 halo mass

Return type:

log_mhalo (float)

class frb.halos.models.ModifiedNFW(log_Mhalo=12.2, c=7.67, f_hot: float = None, log_MCGM: float = None, alpha=0.0, y0=1.0, z=0.0, 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), fb=0.15814118710844152, **kwargs)[source]

Bases: object

Generate a modified NFW model, e.g. Mathews & Prochaska 2017 for the hot, virialized gas.

Parameters:
  • log_Mhalo – float, optional log10 of the Halo mass [dark matter + baryons] (solar masses)

  • log_MCGM – float, optional log10 of the CGM mass (solar masses) If provided, this sets f_hot [this is its only use]

  • c – float, optional concentration of the halo

  • f_hot – float, optional Fraction of the total “expected” baryons in this hot (aka CGM) phase Will likely use this for all diffuse gas

  • alpha – float, optional Parameter to modify NFW profile power-law

  • y0 – float, optional Parameter to modify NFW profile position.

  • z – float, optional Redshift of the halo

  • cosmo – astropy cosmology, optional Cosmology of the universe.

H0

Quantity; Hubble constant

fb

float; Cosmic fraction of baryons (stars+dust+gas) in the entire halo Default to 0.16

r200

Quantity Virial radius

rho0

Quantity Density normalization

M_b

Quantity Mass in baryons of the

__init__(log_Mhalo=12.2, c=7.67, f_hot: float = None, log_MCGM: float = None, alpha=0.0, y0=1.0, z=0.0, 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), fb=0.15814118710844152, **kwargs)[source]
setup_param(cosmo)[source]

Setup key parameters of the model

Parameters:

cosmo – astropy cosmology Cosmology of the universe

fy_dm(y)[source]

Enclosed mass function for the Dark Matter NFW Assumes the NFW profile

Parameters:

y (float or ndarray) – y = c(r/r200)

Returns:

f_y

Return type:

float or ndarray

fy_b(y)[source]

Enclosed mass function for the baryons

Parameters

y: float or ndarray

Returns:

f_y – Enclosed mass

Return type:

float or ndarray

ne(xyz)[source]

Calculate n_e from n_H with a correction for Helium Assume 25% mass is Helium and both electrons have been stripped

Parameters:

xyz (ndarray (3, npoints)) – Coordinate(s) in kpc

Returns:

n_e – electron density in cm**-3

Return type:

float or ndarray

nH(xyz)[source]

Calculate the Hydrogen number density Includes a correction for Helium

Parameters:

xyz (ndarray) – Coordinate(s) in kpc

Returns:

nH – Density in cm**-3

Return type:

float or ndarray

rho_b(xyz)[source]

Mass density in baryons in the halo; modified

Parameters:

xyz (ndarray) – Position (assumes kpc)

Returns:

rho – Density in g / cm**-3

Return type:

Quantity

Ne_Rperp(Rperp, step_size=<Quantity 0.1 kpc>, rmax=1.0, add_units=True, cumul=False)[source]

Calculate N_e at an input impact parameter Rperp Just a simple sum in steps of step_size

This integrates through the entire halo. Use half if this is for the host

Parameters:
  • Rperp (Quantity) – Impact parameter, typically in kpc

  • step_size (Quantity, optional) – Step size used for numerical integration (sum)

  • rmax (float, optional) – Maximum radius for integration in units of r200

  • add_units (bool, optional) – Speed up calculations by avoiding units

  • cumul (bool, optional)

Returns:

  • if cumul

    zval: ndarray (kpc)

    z-values where z=0 is the midplane

    Ne_cumul: ndarray

    Cumulative Ne values (pc cm**-3)

  • else

    Ne: Quantity

    Column density of total electrons

RM_Rperp(Rperp, Bparallel, step_size=<Quantity 0.1 kpc>, rmax=1.0, add_units=True, cumul=False, zmax=None)[source]

Calculate RM at an input impact parameter Rperp Just a simple sum in steps of step_size Assumes a constant Magnetic field

Parameters:
  • Rperp (Quantity) – Impact parameter, typically in kpc

  • (Quantity) (Bparallel) – Magnetic field

  • step_size (Quantity, optional) – Step size used for numerical integration (sum)

  • rmax (float, optional) – Maximum radius for integration in units of r200

  • add_units (bool, optional) – Speed up calculations by avoiding units

  • cumul (bool, optional)

  • zmax (float, optional) – Maximum distance along the sightline to integrate. Default is rmax*rvir

Returns:

  • if cumul

    zval: ndarray (kpc)

    z-values where z=0 is the midplane

    Ne_cumul: ndarray

    Cumulative Ne values (pc cm**-3)

  • else

    RM: Quantity

    Column density of total electrons

mass_r(r, step_size=<Quantity 0.1 kpc>)[source]

Calculate baryonic halo mass (not total) to a given radius Just a simple sum in steps of step_size

Parameters:
  • r (Quantity) – Radius, typically in kpc

  • step_size (Quantity, optional) – Step size used for numerical integration (sum)

Returns:

Mr – Enclosed baryonic mass within r Msun units

Return type:

Quantity

class frb.halos.models.MB04(Rc=<Quantity 167. kpc>, log_Mhalo=12.2, c=7.67, f_hot=0.75, **kwargs)[source]

Bases: ModifiedNFW

Halo based on the Maller & Bullock (2004) model of virialized halo gas.

Parameters:

Rc – Quantity cooling radius

__init__(Rc=<Quantity 167. kpc>, log_Mhalo=12.2, c=7.67, f_hot=0.75, **kwargs)[source]
norm_rhoV()[source]

Normalize the density constant from MB04

Returns:

rho_b(xyz)[source]

Baryonic density profile

Parameters:

xyz – ndarray Position array assumed in kpc

Returns:

class frb.halos.models.YF17(log_Mhalo=12.18, c=7.67, f_hot=0.75, **kwargs)[source]

Bases: ModifiedNFW

  1. Faerman et al (2017) model of the Milky Way

For the un-normalized density profile, we adopt the average of the warm and hot components in

__init__(log_Mhalo=12.18, c=7.67, f_hot=0.75, **kwargs)[source]
setup_yfdensity()[source]

Normalize the density profile from the input mass

Returns:

Initializes self.rhoN, the density normalization

rho_b(xyz)[source]

Calculate the baryonic density

Parameters:

xyz – ndarray Coordinates in kpc

Returns:

Quantity array

Baryonic mass density (g/cm**3)

Return type:

rho

class frb.halos.models.MB15(log_Mhalo=12.18, c=7.67, f_hot=0.75, **kwargs)[source]

Bases: ModifiedNFW

Encodes the Galactic halo profile from Miller & Bregman 2015, ApJ, 800, 14 https://ui.adsabs.harvard.edu/abs/2015ApJ…800…14M/abstract

The default normalization and beta values are taken from their Table 2, last row. The models presented there do not appear to vary too much.

__init__(log_Mhalo=12.18, c=7.67, f_hot=0.75, **kwargs)[source]
nH(xyz)[source]

Calculate the number density of Hydrogen

Parameters:

xyz – ndarray Coordinates in kpc

Returns:

Number density with units of 1/cm**3

Return type:

ndarray

class frb.halos.models.MilkyWay(log_Mhalo=12.18, c=7.67, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]

Bases: ModifiedNFW

Fiducial model for the Galaxy

Halo mass follows latest constraints

Density profile is similar to Maller & Bullock 2004

__init__(log_Mhalo=12.18, c=7.67, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]
class frb.halos.models.M31(log_Mhalo=12.18, c=7.67, alpha=2, y0=2, f_hot=0.75, **kwargs)[source]

Bases: ModifiedNFW

Preferred model for M31

Taking mass from van der Marel 2012

__init__(log_Mhalo=12.18, c=7.67, alpha=2, y0=2, f_hot=0.75, **kwargs)[source]
DM_from_Galactic(scoord, **kwargs)[source]

Calculate DM through M31’s halo from the Sun given a direction

Parameters:
  • scoord – SkyCoord Coordinates of the sightline

  • **kwargs – Passed to Ne_Rperp

Returns:

Quantity

Dispersion measure through M31’s halo

Return type:

DM

DM_from_impact_param_b(bimpact, **kwargs)[source]

Calculate DM through M31’s halo from the Sun given an impact parameter

Parameters:
  • bimpact – Quantity Ratio of the impact parameter to r200

  • **kwargs – Passed to Ne_Rperp

Returns:

Quantity

Dispersion measure through M31’s halo

Return type:

DM

class frb.halos.models.LMC(log_Mhalo=np.float64(11.0), c=12.1, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]

Bases: ModifiedNFW

Preferred model for LMC

Taking data from D’Onghia & Fox ARAA 2016

Mass updated according to

https://ui.adsabs.harvard.edu/abs/2019MNRAS.487.2685E/abstract

__init__(log_Mhalo=np.float64(11.0), c=12.1, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]
class frb.halos.models.SMC(log_Mhalo=np.float64(9.380211241711606), c=15.0, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]

Bases: ModifiedNFW

Preferred model for SMC

Taking data from D’Onghia & Fox ARAA 2016

__init__(log_Mhalo=np.float64(9.380211241711606), c=15.0, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]
class frb.halos.models.M33(log_Mhalo=np.float64(11.698970004336019), c=8.36, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]

Bases: ModifiedNFW

Preferred model for SMC

Taking data from Corbelli 2006

__init__(log_Mhalo=np.float64(11.698970004336019), c=8.36, f_hot=0.75, alpha=2, y0=2, **kwargs)[source]
class frb.halos.models.ICM(log_Mhalo=np.float64(14.698970004336019), c=5, f_hot=0.7, **kwargs)[source]

Bases: ModifiedNFW

Intracluster medium (ICM) model following the analysis of Vikhilnin et al. 2006

We scale the model to the profile fitted to A907

__init__(log_Mhalo=np.float64(14.698970004336019), c=5, f_hot=0.7, **kwargs)[source]
setup_param(cosmo=None)[source]

Setup key parameters of the model

Parameters:

cosmo – astropy cosmology Cosmology of the universe

scale_profile()[source]
a907_nfw()[source]

Code to regenrate the r200 and c200 values for A907 Now hard-coded

ne(xyz)[source]
Parameters:

xyz (ndarray) – Coordinate(s) in kpc

Returns:

n_e – electron density in cm**-3

Return type:

float or ndarray

nH(xyz)[source]

Scale by He

Parameters:

xyz

Returns:

class frb.halos.models.Virgo(log_Mhalo=np.float64(14.880136251483002), **kwargs)[source]

Bases: ICM

Parameterization of Virgo following the Planck Collaboration paper: A&A 596 A101 (2016)

__init__(log_Mhalo=np.float64(14.880136251483002), **kwargs)[source]
setup_param(cosmo=None)[source]

Setup key parameters of the model

ne(xyz)[source]
Parameters:

xyz (ndarray) – Coordinate(s) in kpc

Returns:

n_e – electron density in cm**-3

Return type:

float or ndarray

frb.halos.models.rad3d2(xyz)[source]

Calculate radius squared to x,y,z inputted Assumes the origin is 0,0,0

Parameters:

xyz (Tuple or ndarray)

Returns:

rad3d

Return type:

float or ndarray

frb.halos.photoz - Photo-z Utilities

frb.halos.photoz.get_des_data(coords: SkyCoord, radius: Quantity = <Quantity 15. arcmin>, starbright: float = 17, starflagval: float = 0.9, gaiacat: str = None, write: bool = False, outfile: str = None) Table[source]

Download photometry for galaxies within an FRB field. :param coords: Coordinates of the center of a cone search. :type coords: SkyCoord :param radius: Radius of cone search. :type radius: Quantity, optional :param starbright: Lower limit of r band mag. Objects brighter

than this will be removed.

Parameters:
  • starflagval (float, optional) – Upper limit for a morphology-based classifier flag. Objects more point-like (i.e. higher value) will be filtered out.

  • gaicat (str, optional) – Optional file with gaia catalog of stars within the same search radius. These stars will be removed. Must contain at least two columns: “ra” and “dec”. The values must be in decimal degrees and the column names are case sensitive.

  • write (bool, optional) – Write output table to file?

  • outfile (str, optional) – Path to the output file. If not given and write is True, the table will be written to “photom_cat_J{coords}_{radius}arcmin.fits” in the current working directory.

Returns:

Table of DES galaxies within the search radius.

Return type:

des_data (Table)

frb.halos.photoz.mhalo_lookup_tables(z_grid: list, datafolder: str = 'data', n_cores: int = 8)[source]

For each z in z_grid, produces a fits file containing m_halo values corresponding to a fixed grid of m_star values. The values are produced by sampling the Moster+13 SHMR relation. The fits files can then be used to produce interpolation functions of the moments of the m_halo distribution (e.g. mean, std.dev) as a function of redshift and log_mstar. :param z_grid: List of redshift values to be sampled. :type z_grid: list or np.ndarray :param datafolder: Path to the directory where the results will be stored. :type datafolder: str, optional :param n_cores: Number of CPU threads used for parallel processing. :type n_cores: int, optional

frb.halos.photoz.dm_grid(frb_z: float, n_z: int = 100, n_o: int = 100, n_m: int = 100, max_log_mhalo: float = 12.8, outdir: str = 'data', outfile: str = None) None[source]

Produce DM estimates for a 3D grid of redshift, offsets and log_halo_masses and write them to disk. :param frb_z: frb redshift :type frb_z: float :param n_z: size of the redshift grid. i.e. np.linspace(0, frb_z, n_z) :type n_z: int, optional :param n_o: size of the offset grid. i.e. np.linspace(0, 600, n_o) :type n_o: int, optional :param n_m: size of the log_halo_mass grid. i.e. np.linspace(8, 16, n_m) :type n_m: int, optional :param max_log_mhalo: DM for halo masses larger than this are currently

set to -99.0 to prevent weirdly large DM contributions from galactic halos.

Parameters:
  • outdir (str, optional) – data directory to store results

  • outfile (str, optional) – name of results .npz file (within outdir).

frb.halos.photoz.dm_for_all_galaxies(frb: FRB, input_catfile: str, datafolder: str, n_cores: int = 8, n_gals: int = None)[source]

Produce DM estimates for all the galaxies provided by the user. Creates two files : “DM_halos_zdraws.npz” which contains all the redshift draws used for the DM realizations and “DM_halos_final.npz” which contains the DM realizations themselves. Each row in each of these files corresponds to one galaxy and each z draw corresponds to 1000 DM realizations for a galaxy. :param frb: The FRB object of interest. :type frb: FRB :param input_catfile: Path to the input catalog of photometry. Assumed

to be from DES for now.

Parameters:
  • datafolder (str) – Path to the folder in which results will be saved.

  • n_cores (int, optional) – Number of CPU threads to be used for computation.

  • n_gals (int, optional) – Limit analysis to n_gals galaxies for testing purposes.

frb.halos.utils - Utilities

frb.halos.utils.stellarmass_from_halomass(log_Mhalo, z=0)[source]

Stellar mass from Halo Mass from Moster+2013 https://doi.org/10.1093/mnras/sts261

Parameters:
  • log_Mhalo (float) – log_10 halo mass in solar mass units.

  • z (float, optional) – halo redshift. Assumed to be 0 by default.

Returns:

log_10 galaxy stellar mass

in solar mass units.

Return type:

log_mstar (float)

frb.halos.utils.halomass_from_stellarmass(log_mstar, z=0)[source]

Halo mass from Stellar mass (Moster+2013). Inverts the function stellarmass_from_halomass numerically.

Parameters:
  • log_mstar (float or numpy.ndarray) – log_10 stellar mass in solar mass units.

  • z (float, optional) – galaxy redshift

Returns:

log_10 halo mass

in solar mass units.

Return type:

log_Mhalo (float)