FRBHost Class
The FRBHost class represents the host galaxy of an FRB. It inherits from
FRBGalaxy and stores photometry, redshifts, morphology, nebular line
measurements, and derived physical properties.
Overview
The FRBHost class provides methods to:
Load host galaxy data from the repository
Access photometric measurements and derived quantities
Calculate nebular properties (SFR, extinction)
Interface with SED fitting tools (CIGALE, EAZY)
Retrieve spectra from the specDB archive
Loading Host Galaxies
by_frb
The recommended way to load a host galaxy is through its associated FRB:
from frb.frb import FRB
# Load the FRB first
frb = FRB.by_name('FRB20180924B')
# Get the host galaxy
host = frb.grab_host()
# Print basic info
print(host)
# <FRBHost: 21:44:25.25 -40:54:00.80, FRB=FRB20180924B z=0.3212>
Alternatively, use the FRBHost.by_frb() class method directly:
from frb.frb import FRB
from frb.galaxies.frbgalaxy import FRBHost
frb = FRB.by_name('FRB20180924B')
host = FRBHost.by_frb(frb)
from_json
Load from a specific JSON file:
from frb.frb import FRB
from frb.galaxies.frbgalaxy import FRBHost
frb = FRB.by_name('FRB20180924B')
host = FRBHost.from_json(frb, '/path/to/FRB20180924B_host.json')
Key Attributes
Host galaxies have several attribute dictionaries containing measurements and derived quantities.
Coordinates
# Host galaxy coordinates
host.coord
# <SkyCoord (ICRS): (ra, dec) in deg (321.60521, -40.90022)>
# Associated FRB
host.frb.frb_name
# 'FRB20180924B'
# Host name
host.name
# 'HG20180924B'
Redshift
# Best redshift
host.z
# 0.3212
# Redshift error
host.z_err
# Full redshift dict
host.redshift
# {'z': 0.3212, 'z_spec': 0.3212, 'z_FRB': 0.3212}
Photometry
Photometric measurements are stored in the photom dict:
# All photometry
host.photom
# {'SDSS_u': 21.45, 'SDSS_u_err': 0.15, 'SDSS_g': 20.23, ...}
# Individual bands
host.photom['SDSS_r']
host.photom['SDSS_r_err']
# Fluxes (in mJy) are also stored
host.photom['SDSS_r_flux']
host.photom['SDSS_r_flux_err']
Derived Quantities
Physical properties derived from SED fitting or spectroscopy:
# All derived quantities
host.derived
# {'Mstar': 1.2e10, 'Mstar_err': 2e9, 'SFR_photom': 1.5, ...}
# Stellar mass (solar masses)
host.derived['Mstar']
# Star formation rate (Msun/yr)
host.derived['SFR_photom'] # From SED fitting
host.derived['SFR_nebular'] # From emission lines
# Extinction
host.derived['AV_nebular']
host.derived['EBV_photom']
Nebular Emission Lines
Emission line fluxes (erg/s/cm^2):
# All line measurements
host.neb_lines
# {'Halpha': 1.2e-16, 'Halpha_err': 1e-17, '[OIII] 5007': 5e-17, ...}
# Individual lines
host.neb_lines['Halpha']
host.neb_lines['Hbeta']
host.neb_lines['[NII] 6584']
Morphology
Galaxy structural parameters (typically from GALFIT):
host.morphology
# {'reff_ang': 0.85, 'reff_kpc': 3.2, 'n': 1.5, 'b/a': 0.7, ...}
# Effective radius
host.morphology['reff_ang'] # arcsec
host.morphology['reff_kpc'] # kpc
# Sersic index
host.morphology['n']
Offsets
Angular and physical offsets between FRB and host:
host.offsets
# {'ang_avg': 0.5, 'ang_best': 0.45, 'physical': 2.1, ...}
# Physical offset in kpc
host.offsets['physical']
host.offsets['physical_err']
Calculating Derived Quantities
Nebular SFR
Calculate star formation rate from emission lines:
# First calculate extinction (optional but recommended)
host.calc_nebular_AV(method='Ha/Hb')
print(f"AV = {host.derived['AV_nebular']}")
# Calculate SFR from H-alpha
host.calc_nebular_SFR(method='Ha')
print(f"SFR = {host.derived['SFR_nebular']} Msun/yr")
Line Luminosities
Calculate emission line luminosities:
Lum, Lum_err = host.calc_nebular_lum('Halpha')
print(f"L(Ha) = {Lum}")
Halo DM
Calculate the halo contribution to DM:
DM_halo = host.calc_dm_halo()
print(f"DM_halo = {DM_halo}")
Retrieving Spectra
If spectra are available in the specDB archive:
# Get spectrum and metadata
meta, spec = host.get_metaspec()
# meta is an astropy Table with spectrum info
print(meta)
# spec is an XSpectrum1D object
spec.wavelength # Wavelength array
spec.flux # Flux array
# Get all spectra (if multiple exist)
meta, spec = host.get_metaspec(return_all=True)
# Specify instrument
meta, spec = host.get_metaspec(instr='MUSE')
Running SED Fitting
CIGALE
Run CIGALE SED fitting directly:
host.run_cigale(
data_file='cigale_input.fits',
config_file='pcigale.ini',
wait_for_input=False,
save_sed=True,
plot=True,
outdir='cigale_output/'
)
Parse CIGALE results:
host.parse_cigale('cigale_output/results.txt')
print(host.derived['Mstar'])
print(host.derived['SFR_photom'])
Parsing External Results
GALFIT
Parse GALFIT output for morphology:
host.parse_galfit('galfit_output.fits')
print(host.morphology['reff_kpc'])
print(host.morphology['n'])
pPXF
Parse pPXF spectral fitting results:
host.parse_ppxf('ppxf_results.ecsv')
print(host.neb_lines['Halpha'])
Building a Table of Hosts
Create a pandas DataFrame with all host galaxy properties:
from frb.galaxies import utils
# Build the table
host_tbl, tbl_units = utils.build_table_of_hosts()
# View columns
print(host_tbl.columns.tolist())
# ['Host', 'FRBname', 'RA_host', 'DEC_host', 'FRBobj', 'Mstar', 'SFR_photom', ...]
# Filter by stellar mass
massive_hosts = host_tbl[host_tbl['Mstar'] > 1e10]
# Get hosts with spectroscopic redshifts
spec_z = host_tbl[host_tbl['z_spec'].notna()]
# Merge with FRB table
from frb.frb import build_table_of_frbs
frb_tbl, _ = build_table_of_frbs()
import pandas as pd
merged = pd.merge(frb_tbl, host_tbl, left_on='FRB', right_on='FRBname')
Default columns include data from:
derived: Mstar, SFR_photom, SFR_nebular, AV_nebular, M_r, etc.
photom: All photometric bands and fluxes
neb_lines: Emission line fluxes
offsets: Angular and physical offsets
morphology: Structural parameters
redshift: z, z_spec, z_phot, z_FRB
Listing All Hosts
from frb.galaxies.utils import list_of_hosts
# Get all hosts
frbs, hosts = list_of_hosts()
print(f"Number of hosts: {len(hosts)}")
# Iterate
for frb, host in zip(frbs, hosts):
print(f"{frb.frb_name}: z={host.z}, Mstar={host.derived.get('Mstar', 'N/A')}")
Loading PATH Results
Load probabilistic association results:
from frb.galaxies import utils
path_tbl = utils.load_PATH()
print(path_tbl.columns)
# ['FRB', 'RA', 'Dec', 'P_Ox', 'P_O', 'ang_size', ...]
Writing to JSON
Save a host galaxy object:
host.write_to_json(path='./output/')
# Writes to FRB20180924B_host.json
Setting Redshifts
# Set spectroscopic redshift
host.set_z(0.3212, 'spec', err=0.0001)
# Set photometric redshift
host.set_z(0.35, 'phot', err=0.05)
API Reference
FRBGalaxy (Parent Class)
- class frb.galaxies.frbgalaxy.FRBGalaxy(ra, dec, frb, cosmo=None)[source]
Bases:
objectParent class for galaxies in FRB fields
Simple object to hold key observable and derived quantities
Warning: Generating hundreds of these objects will likely be slow. Especially SkyCoord generation. A new class will be warranted for that
- Parameters:
- classmethod from_dict(frb, idict, override: bool = False, **kwargs)[source]
Instantiate from a dict
- Parameters:
Returns:
- classmethod from_json(frb, json_file, verbose: bool = True, **kwargs)[source]
- Parameters:
frb (frb.FRB)
json_file
**kwargs
- Returns:
FRBGalaxy or None
- property z_err
Return the redshift error of the galaxy
- Returns:
redshift or nadda
- Return type:
float or None
- calc_nebular_lum(line)[source]
Calculate the line luminosity Applies dust extinction if self.derived[‘AV_nebular’] is filled
Mainly a wrapper to nebular.calc_lum()
- Parameters:
line (str) – Name of the line
- calc_nebular_AV(method='Ha/Hb', min_AV=None, **kwargs)[source]
Calculate an A_V extinction from a pair of Nebular lines
Mainly a wrapper to nebular.calc_dust_extinct
self.derived[‘AV_nebular’] is filled
- Parameters:
Returns:
- calc_nebular_SFR(method='Ha', **kwargs)[source]
Calculate a SFR from a nebular line
Mainly a wrapper to nebular.calc_SFR
self.derived[‘AV_nebular’] is filled with units SFR/yr
- Parameters:
method (str) – Method to use, e.g. ‘Ha’ for Halpha
**kwargs – passed to nebular.calc_SFR
Returns:
- calc_tot_uncert()[source]
Calculate total uncertainty in arcsec of FRB localization + Host localization in the reference frame of the FRB
- Returns:
uncerta, uncertb [arcsec]
- Return type:
- parse_photom(phot_tbl, max_off=<Quantity 1. arcsec>, overwrite=True, EBV=None)[source]
Parse photometry from an input table
Fills the self.photom dict
Also fills fluxes in mJy
- Parameters:
Returns:
- run_cigale(data_file='cigale_in.fits', config_file='pcigale.ini', wait_for_input=False, save_sed=True, plot=True, outdir='out', **kwargs)[source]
Generates the input data file for CIGALE given the photometric points and redshift of a galaxy
- Parameters:
ID – str, optional An ID for the galaxy. If none, “GalaxyA” is assigned.
data_file (str, optional) – Root name for the photometry data file generated used as input to CIGALE
config_file (str, optional) – Root name for the file where CIGALE’s configuration is generated
wait_for_input (bool, optional) – If true, waits for the user to finish editing the auto-generated config file before running.
save_sed (bool, optional) – Saves the best fit SED if true
plot (bool, optional) – Plots the best fit SED if true
cores (int, optional) – Number of CPU cores to be used. Defaults to all cores on the system.
outdir (str, optional) – Path to the many outputs of CIGALE If not supplied, the outputs will appear in a folder named out/
- kwargs: These are passed into gen_cigale_in() and _initialise()
- sed_modules (list of ‘str’, optional):
A list of SED modules to be used in the PDF analysis. If this is being input, there should be a corresponding correct dict for sed_modules_params.
- sed_module_params (dict, optional):
A dict containing parameter values for the input SED modules. Better not use this unless you know exactly what you’re doing.
- get_metaspec(instr=None, return_all=False, specdb_file=None)[source]
Return the meta data and spectra for this FRBGalaxy from the specDB
If there is more than one spectrum, the code returns the first unless return_all=True
- Parameters:
- Returns:
meta data, spectra
- Return type:
astropy.table.Table, linetools.spectra.XSpectrum1D
- parse_cigale(cigale_file, sfh_file=None, overwrite=True)[source]
Parse the output file from CIGALE
Read into self.derived
- Parameters:
Returns:
- parse_galfit(galfit_file, overwrite=True, twocomponent=False)[source]
- Parse an output GALFIT file
or a gallight JSON file
Loaded into self.morphology
- Parameters:
galfit_file (str) – processed ‘out.fits’ file produced by frb.galaxies.galfit.run. Contains a binary table with fit parameters. Or a JSON file from gallight
overwrite (bool, optional) – Need to overwrite the object’s attributes?
twocomponent (bool, optional) – Should the morphology attribute generated contain fit parameters of two components?
- parse_ppxf(ppxf_file, overwrite=True, format='ascii.ecsv')[source]
Parse an output pPXF file generated by our custom run
Loaded into self.lines
- Parameters:
Returns:
- vet_all()[source]
Vette all of the main dicts
- Parameters:
dict
valid_defs
- Returns:
True = passed
- Return type:
- make_outfile()[source]
Auto-generate an output name for the class
- Returns:
Output filename
- Return type:
FRBHost Class
- class frb.galaxies.frbgalaxy.FRBHost(ra, dec, frb, z_frb=None, **kwargs)[source]
Bases:
FRBGalaxyChild of FRBGalaxy specific for an FRB host
- calc_dm_halo(**kwargs)[source]
Calculate the Halo contribution to the host DM given the host stellar mass in its derived properties dict and the FRB coordinates.
- Parameters:
**kwargs – Passed to dm_host.dm_host_halo
- Returns:
Halo contribution to the DM in pc/cm^3
- Return type:
DM_halo (float)
- make_outfile()[source]
Overloads the parent method for Host specific naming
Naming is FRBXXXXXX_host.json with XXXXXXX supplied by self.frb
- Returns:
Name of the default outfile
- Return type:
Utility Functions
- frb.galaxies.utils.build_table_of_hosts(attrs: list = None)[source]
Generate a Pandas table of FRB Host galaxy data. These are slurped from the ‘derived’, ‘photom’, and ‘neb_lines’ dicts of each host object
- Warning: As standard, missing values are given NaN in the Pandas table
Be careful!
Note
RA, DEC are given as RA_host, DEC_host to avoid conflict with the FRB table
Args:
- Returns:
Table of data on FRB host galaxies, dict of their units
- Return type:
pd.DataFrame, dict
See Also
FRB Class - FRB class documentation
FRB Galaxies - Galaxy analysis overview
Database - Database utilities