fantasy_agn package

fantasy_agn.tools module

class fantasy_agn.tools.make_spec(wav, fl, er, ra=None, dec=None, z=None, name='spectrum')[source]

Bases: spectrum

class fantasy_agn.tools.read_gama_fits(filename)[source]

Bases: spectrum

class fantasy_agn.tools.read_sdss(filename)[source]

Bases: spectrum

class fantasy_agn.tools.read_text(filename)[source]

Bases: spectrum

class fantasy_agn.tools.spectrum[source]

Bases: object

CorRed(redshift=0)[source]

The CorRed function corrects the flux for redshift. It takes in a redshift and corrects the wavelength, flux, and error arrays by that given redshift.

Parameters:
  • self – Used to Reference the class object.

  • redshift=0 – Used to Specify the redshift of the object.

Returns:

The wavelength, flux and error arrays for the object at a redshift of z=0.

DeRedden(ebv=0)[source]

Function for dereddening a flux vector using the parametrization given by [Fitzpatrick (1999)](https://iopscience.iop.org/article/10.1086/316293).

Parameters

ebvfloat, optional
Color excess E(B-V). If not given it will be automatically derived from

Dust map data from [Schlegel, Finkbeiner and Davis (1998)](http://adsabs.harvard.edu/abs/1998ApJ…500..525S), by default 0

crop(xmin=4050, xmax=7300)[source]

The crop function crops the spectrum to a specified wavelength range.

Parameters: xmin (float): The minimum wavelength of the crop region. Default is 4050 Angstroms. xmax (float): The maximum wavelength of the crop region. Default is 7300 Angstroms.

Returns: None, but modifies self in place by cropping it to only include wavelengths between xmin and xmax.

Parameters:
  • self – Used to Reference the object itself.

  • xmin=4050 – Used to Set the lower wavelength limit of the cropped spectrum.

  • xmax=7300 – Used to Select the wavelength range of interest.

Returns:

A new spectrum object with the cropped wavelength range.

fit(model, ntrial=1)[source]

The fit function fits a model to the data. It returns a tuple of (model, fit results).

Parameters:
  • self – Used to Reference the class object.

  • model – Used to Define the model that is used in the fit.

  • ntrial=1 – Used to Specify the number of times we want to repeat the fit.

Returns:

The results of the fit.

fit_host(mask_host=False, custom=False, mask_list=[])[source]

The fit_host function fits a host galaxy and an AGN to the observed spectrum. It takes as input: mask_host (bool): If True, it masks the host emission lines using _host_mask function. Default is False. custom (bool): If True, it masks user defined emission lines using _custom_mask function. Default is False. mask_list ([float]): A list of wavelengths in angstroms that will be masked if custom=True .Default is empty list [].

Returns:

self.(wave,flux,err) : The wavelength array , flux array and error array after fitting for host galaxy and AGN components respectively.

Parameters:
  • self – Used to Access variables that belongs to the class.

  • mask_host=False – Used to Mask the host.

  • custom=False – Used to Mask the host.

  • mask_list=[] – Used to Mask the data points that are not used in the fit.

Returns:

The host and the agn component.

fit_host_sdss(mask_host=False, custom=False, mask_list=[])[source]

The fit_host_sdss function fits a 5 host galaxy eigenspectra and an 10 AGNs eigenspectra to the observed spectrum. It takes as input: mask_host (bool): If True, it masks the host emission lines using _host_mask function. Default is False. custom (bool): If True, it masks user defined emission lines using _custom_mask function. Default is False. mask_list ([float]): A list of wavelengths in angstroms that will be masked if custom=True .Default is empty list [].

Returns:

self.(wave,flux,err) : The wavelength array , flux array and error array after fitting for host galaxy and AGN components respectively.

Parameters:
  • self – Used to Access variables that belongs to the class.

  • mask_host=False – Used to Mask the host.

  • custom=False – Used to Mask the host.

  • mask_list=[] – Used to Mask the data points that are not used in the fit.

Returns:

The host and the agn component.

monte_carlo(nsample=10, save_files=True)[source]

The monte_carlo function performs Monte Carlo resampling of the data by perturbing the flux based on the input error. It returns a dictionary containing the fit parameters and their uncertainties.

Parameters:
  • self – Used to Reference the class object.

  • model – Used to Define the model that is used in the fit.

  • nsample=100 – Used to Specify the number of Monte Carlo samples to generate.

Returns:

A dictionary containing the fit parameters and their uncertainties.

plot()[source]
plot_spec()[source]

The plot_spec function plots the spectra.

Parameters:

self – Used to Access the class attributes.

Returns:

A tuple containing the x and y values for a plot of the spectrum.

rebin(minw=3900, maxw=6800)[source]

The rebin function rebins the spectrum to a smaller wavelength range. The default is 3900-6800 angstroms, but you can specify your own min and max values.

Parameters:
  • self – Used to Reference the object itself.

  • minw=3900 – Used to Set the minimum wavelength of the new array.

  • maxw=6800 – Used to Define the upper limit of the wavelength range to be used for fitting.

Returns:

The new wavelength and flux values for the spectrum.

restore()[source]

Restore the spectra (wave, flux and error) to the one before host removal

save_json(suffix='pars')[source]

The save_json function saves the parameter values in a JSON file. The filename is constructed from the name of the model and either ‘pars’ or ‘samples’.

Parameters:
  • self – Used to Refer to the object itself.

  • suffix='pars' – Used to Specify the name of the file that is saved.

Returns:

A dictionary of the parameter names and values.

show_range()[source]
vac_to_air()[source]

Convert vacuum to air wavelengths :param lam_vac - Wavelength in Angstroms :return: lam_air - Wavelength in Angstroms

fantasy_agn.models module

fantasy_agn.models.automatic_path(s, path_to_models='/home/docs/checkouts/readthedocs.org/user_builds/fantasy-agn/checkouts/latest/fantasy_agn/input', overwrite=True)[source]

The automatic_path function takes a spectrum object and creates a directory with the name of the spectrum. It then saves all models within the input path that fall within the wavelength range of your data to this directory.

Parameters:
  • s – Used to Define the spectrum object.

  • path_to_models=input_path – Used to Specify the path to the models.

  • overwrite=True – Used to Overwrite a model if it already exists.

Returns:

The path to the directory where the.

fantasy_agn.models.create_feii_model(name='feii', fwhm=2000, min_fwhm=1000, max_fwhm=8000, offset=0, min_offset=-3000, max_offset=3000)[source]

The create_feii_model function creates a FeII model with the specified parameters.

Parameters:
  • name='feii' – Used to Name the component.

  • fwhm=2000 – Used to Set the fwhm of the feii emission line.

  • min_fwhm=1000 – Used to Set the minimum value of the fwhm parameter.

  • max_fwhm=8000 – Used to Set the upper limit of the fwhm range.

  • offset=0 – Used to Set the central wavelength of the feii emission line.

  • min_offset=-3000 – Used to Set the minimum value of the offset parameter.

  • max_offset=3000 – Used to Set the maximum offset velocity of the feii emission line.

Returns:

A feii object.

fantasy_agn.models.create_fixed_model(files=[], name='', amplitude=2, fwhm=3000, offset=0, min_offset=-3000, max_offset=3000, min_amplitude=0, max_amplitude=600, min_fwhm=100, max_fwhm=7000)[source]

The create_fixed_model function creates a model that is fixed fwhm for all lines. The function takes as an argument a list of csv files, which contain the information (name and position) of all lines included in the model. It also takes as arguments: name, amplitude, fwhm (km/s), offset (km/s) and min_offset and max_offset (km/s).

Parameters:
  • files=[] – Used to Pass a list of csv files to the model.

  • name='' – Used to Give the model a name.

  • amplitude=2 – Used to Set the initial value of the amplitude parameter.

  • fwhm=3000 – Used to Set the fwhm of the gaussian profile.

  • offset=0 – Used to Shift the lines to the center of each pixel.

  • min_offset=-3000 – Used to Set the minimum value of the offset.

  • max_offset=3000 – Used to Set the maximum offset of the line from its rest position.

  • min_amplitude=0 – Used to Set the minimum value of the amplitude parameter.

  • max_amplitude=600 – Used to Limit the maximum amplitude of the lines.

  • min_fwhm=100 – Used to Set a lower limit to the fwhm parameter.

  • max_fwhm=7000 – Used to Set the maximum value of the fwhm parameter.

:param : Used to Set the initial value of the amplitude parameter. :return: A fixed_lines class object.

fantasy_agn.models.create_input_folder(xmin=4000, xmax=7000, path_to_folder='', overwrite=True)[source]

The create_input_folder function creates a folder in the specified path. The function takes three arguments:

  1. xmin - the minimum value of the range to be used for creating input files, default is 4000

  2. xmax - the maximum value of the range to be used for creating input files, default is 7000

  3. path_to_folder - The path where you want your new folder created. Default is current directory

Parameters:
  • xmin=4000 – Used to Set the minimum value of the x-axis (position or wavelength).

  • xmax=7000 – Used to Limit the maximum value of the x-axis.

  • path_to_folder='' – Used to Specify the path to the folder where you want to save your file.

  • overwrite=True – Used to Overwrite the files in the input folder.

Returns:

The path to the folder where the input files are stored.

fantasy_agn.models.create_line(name='line', pos=4861, ampl=5, min_ampl=0, max_ampl=500, fwhm=1000, min_fwhm=5, max_fwhm=10000, offset=0, min_offset=-3000, max_offset=3000)[source]

The create_line function creates a line with the specified parameters.

Parameters:

name (str): The name of the emission line.

pos (float): The central wavelength of the emission line in Angstroms.

ampl (float): The amplitude of the emission line in units of flux density at

position x=0, i.e., F(x=0) = ampl * continuum_level + offset . Note that this is not an absolute value but depends on how you normalize your spectrum! Default is 5, which means that if your spectrum has a continuum level equal to 1 then F(x=0)=5 and if it’s 0 then F(x=0)=5+offset . If you want to set an absolute flux density rather than relative values, use hard_min and hard_max instead!

min_ampl (float): A lower limit for amplitude above which no lines will be created by create_line(). This can be useful when creating multiple lines from one input parameter because sometimes there are “bumps” or other features in a single spectrum where it makes sense to have multiple lines with different centroids but similar amplitudes so they don’t overlap each other

Parameters:
  • name='line' – Used to Name the line in the model.

  • pos=4861 – Used to Specify the central wavelength of the line.

  • ampl=5 – Used to Set the amplitude of the emission line.

  • min_ampl=0 – Used to Set the lower limit of the amplitude parameter.

  • max_ampl=500 – Used to Set the maximum value that ampl can take.

  • fwhm=1000 – Used to Set the width of the line.

  • min_fwhm=5 – Used to Set the minimum value of the fwhm.

  • max_fwhm=10000 – Used to Set a hard limit on the fwhm.

  • offset=0 – Used to Shift the line center to a different position.

  • min_offset=-3000 – Used to Set the minimum value of the offset.

  • max_offset=3000 – Used to Set the maximum offset of the line.

Returns:

An instance of the emission_line class.

fantasy_agn.models.create_model(files=[], prefix='', default_limits=True, amplitude=2, fwhm=3000, offset=0, min_offset=-3000, max_offset=3000, min_amplitude=0, max_amplitude=600, min_fwhm=100, max_fwhm=7000)[source]

The create_broad_model function creates a model for the broad lines in the data. It takes as input:

filename - The name of the file containing all of your line names and positions.

This should be a csv file with columns named ‘line’, ‘position’. The first row should contain column headers.

prefix - A string that will be added to each component name in your model, e.g., if you give it “broad_”, all components will have names like “broad_[LINE NAME]”.

default_limits - If True, limits on amplitudes, fwhms, offsets are set automatically based on what is reasonable for this dataset (see below). If False, no limits are set except such that min(amplitude) > 0 and max(amplitude) < 100 (this is because some models may not have any amplitude parameters at all).

amplitude - Initial value for amplitudes; see above documentation about how this value might change depending on whether default_limits=True or False.. Default = 2.0 .

fwhm - Initial value for FWHMs; see above documentation about how this value might change depending on whether default_limits=

Parameters:
  • filename='' – Used to Specify the name of the file that contains all of the lines.

  • prefix='' – Used to Give each line a unique name.

  • default_limits=True – Used to Set the limits of the parameters to a default value.

  • amplitude=2 – Used to Set the default amplitude of the lines to 2.

  • fwhm=3000 – Used to Set the default value for the fwhm of each line.

  • offset=0 – Used to Indicate that the offset is not fixed.

  • min_offset=-3000 – Used to Set the minimum value for the offset.

  • max_offset=3000 – Used to Set the upper limit of the offset parameter.

  • min_amplitude=0 – Used to Remove the baseline from the fit.

  • max_amplitude=100 – Used to Set the upper limit of the amplitude to 100.

  • min_fwhm=100 – Used to Remove the noise lines in the spectra.

  • max_fwhm=7000 – Used to Avoid the model to go out of the data range.

Returns:

A model, which is a list of line objects.

fantasy_agn.models.create_tied_model(name='OIII5007', files=[], prefix='', fix_oiii_ratio=True, position=5006.803341, amplitude=2, fwhm=10, offset=0, min_offset=-3000, max_offset=1000, min_amplitude=0, max_amplitude=1000, min_fwhm=0, max_fwhm=10000, included=False)[source]

The create_tied_model function creates a model that is tied to another parameter. It takes the following arguments:

name - The name of the line (e.g., OIII5007) files - A list of csv files containing data for this line (optional) prefix - The prefix used in defining parameters in other functions (default = “”)

If included == True and fix_oiii_ratio==True, then it creates an instance of the OIII_NII class with a reference emission line defined by ref_line.

If included == True and fix_oiii_ratio==False, then it creates an instance of EmissionLine with a reference emission line defined by ref_line.

If included == False and fix_oiii_ratio==True, then it creates an instance of OIII5007 only.

Parameters:
  • name='OIII5007' – Used to Name the emission line.

  • files=[] – Used to Pass a list of csv files to the model.

  • prefix="" – Used to Give a name to the model.

  • fix_oiii_ratio=True – Used to Fix the ratio of oiii5007 to nii6583.

  • position=0 – Used to Define the position of the reference line.

  • amplitude=2 – Used to Set the amplitude of the emission line to 2.

  • fwhm=10 – Used to Set the fwhm of the reference line.

  • offset=0 – Used to Indicate that the line should be fixed to 0.

  • min_offset=-3000 – Used to Set the minimum offset of the line.

  • max_offset=1000 – Used to Set the maximum offset of a line to 1000 km/s.

  • min_amplitude=0 – Used to Avoid the model to go below 0.

  • max_amplitude=1000 – Used to Set a maximum value for the amplitude of the emission line.

  • min_fwhm=0 – Used to Avoid the fwhm of lines to be set to 0.

  • max_fwhm=10000 – Used to Avoid errors when the fwhm is very high.

  • included=False – Used to Create a model without the emission line of interest.

Returns:

A model that is tied to the parameters of a reference line.