pulsar_spectra modules

catalogues

Loads all the data required by vcstools from the data directory.

pulsar_spectra.catalogues.all_flux_from_atnf(query=None)[source]

Queries the ATNF database for flux info for all pulsar at all frequencies.

Parameters
querypsrqpy object, optional

A previous psrqpy.QueryATNF query. Can be supplied to prevent performing a new query.

Returns
jname_cat_dictdict

Catalgoues dictionary with the keys in the format jname_cat_dict[jname][ref][‘Frequency MHz’, ‘Flux Density mJy’, ‘Flux Density error mJy’]

'jname'str

The pulsar’s Jname.

'ref'str

The reference label.

'Frequency MHz'

The observing frequency in MHz.

'Flux Density mJy'

The flux density in mJy.

'Flux Density error mJy'

The error of the flux density in mJy.

pulsar_spectra.catalogues.collect_catalogue_fluxes(only_use=None, exclude=None)[source]

Collect the fluxes from all of the catalogues recorded in this repo.

Parameters
only_uselist, optional

A list of reference labels (in the format ‘Author_year’) of all the papers you want to use.

excludelist, optional

A list of reference labels (in the format ‘Author_year’) of all the papers you want to exclude.

Returns
jname_cat_list[jname]dict

Catalgoues dictionary with the keys:

'jname'str

The pulsar’s Jname.

Each dictionary contains a list of lists with the following:

Frequency MHzlist

The observing frequency in MHz.

Flux Density mJylist

The flux density in mJy.

Flux Density error mJylist

The error of the flux density in mJy.

reflist

The reference label (in the format ‘Author_year’).

pulsar_spectra.catalogues.convert_antf_ref(ref_code, ref_dict=None)[source]

Converts an ATNF psrcat reference code to a reference in the format “Author Year”

Parameters
ref_codestr

An ATNF psrcat reference code as found from psrqpy.get_references(updaterefcache=True) and https://www.atnf.csiro.au/research/pulsar/psrcat/psrcat_ref.html.

ref_dictdict, optional

A previous psrqpy.get_references query. Can be supplied to prevent performing a new query.

Returns
refstr

Reference in the format “Author Year”.

pulsar_spectra.catalogues.convert_cat_list_to_dict(jname_cat_list)[source]
Returns
jname_cat_dictdict

Catalgoues dictionary with the keys in the format jname_cat_dict[jname][ref][‘Frequency MHz’, ‘Flux Density mJy’, ‘Flux Density error mJy’]

'jname'str

The pulsar’s Jname.

'ref'str

The reference label.

'Frequency MHz'

The observing frequency in MHz.

'Flux Density mJy'

The flux density in mJy.

'Flux Density error mJy'

The error of the flux density in mJy.

pulsar_spectra.catalogues.flux_from_atnf(pulsar, query=None, ref_dict=None, assumed_error=0.5)[source]

Queries the ATNF database for flux info on a particular pulsar at all frequencies.

Parameters
pulsarstr

The Jname of the pulsar.

querypsrqpy object, optional

A previous psrqpy.QueryATNF query. Can be supplied to prevent performing a new query.

ref_dictdict, optional

A previous psrqpy.get_references query. Can be supplied to prevent performing a new query.

assumed_errorfloat, optional

If no error found, apply this factor to flux to make an assumed error.
Default: 0.5.

Returns
freq_alllist

All frequencies in Hz with flux values on ATNF.

flux_alllist

The flux values corresponding to the freq_all list in mJy.

flux_err_alllist

The uncertainty in the flux_all values.

referenceslist

The reference keys from: https://www.atnf.csiro.au/research/pulsar/psrcat/psrcat_ref.html

pulsar_spectra.catalogues.get_antf_references()[source]

Wrapper for psrqpy.get_references() that ensures the cache is only Updated once.

models

Spectral models from Jankowski et al. 2018 and references within

pulsar_spectra.models.broken_power_law(v, vb, a1, a2, b)[source]

Broken power law:

\[\begin{split}S_v = b \left\{\begin{matrix} x^{a_1} & \mathrm{if} x ≤ x_b \\ x^{a_2}x_b^{a_1-a_2} & \mathrm{otherwise'} \end{matrix}\right.\end{split}\]

where \(x=\frac{v}{1.3e9},x_b=\frac{v_b}{1.3e9}\)

Parameters
vlist

Frequency in Hz.

v_bfloat

The frequency of the break in Hz.

a_1float

The spectral index before the break.

a_2float

The spectral index after the break.

bfloat

Constant.

Returns
S_vlist

The flux density predicted by the model.

pulsar_spectra.models.high_frequency_cut_off_power_law(v, vc, a, b)[source]

Power law with high-frequency cut-off off:

\[S_v = bx^{-2} \left ( 1 - \frac{x}{x_c} \right ), x < x_c\]

where \(x=\frac{v}{1.3e9},x_c=\frac{v_c}{1.3e9}\)

Parameters
vlist

Frequency in Hz.

v_clist

Cut off frequency in Hz.

afloat

The spectral index before the power cut-off.

bfloat

Constant.

Returns
S_vlist

The flux density predicted by the model.

pulsar_spectra.models.log_parabolic_spectrum(v, a, b, c)[source]

Log-parabolic spectrum:

\[\mathrm{log}_{10} S_v = ax^2 + bx +c\]

where \(x=\mathrm{log}_{10} \left ( \frac{v}{1.3e9} \right )\)

Parameters
vlist

Frequency in Hz.

afloat

Curvature parameter.

bfloat

The spectral index for \(a = 0\).

cfloat

Constant.

Returns
S_vlist

The flux density predicted by the model.

pulsar_spectra.models.low_frequency_turn_over_power_law(v, vc, a, b, beta)[source]

power law with low-frequency turn-over:

\[S_v = bx^{a} exp\left ( \frac{a}{\beta} x_c^{-\beta} \right )\]

where \(x=\frac{v}{1.3e9},x_c=\frac{v_c}{1.3e9}\)

Parameters
vlist

Frequency in Hz.

v_clist

Trun-over frequency in Hz.

afloat

The spectral index.

bfloat

Constant.

betafloat

The smoothness of the turn-over.

Returns
S_vlist

The flux density predicted by the model.

pulsar_spectra.models.simple_power_law(v, a, b)[source]

Simple power law:

\[S_v = b x^a\]

where \(x=\frac{v}{1.3e9}\)

Parameters
vlist

Frequency in Hz.

afloat

Spectral Index.

bfloat

Constant.

Returns
S_vlist

The flux density predicted by the model.

spectral_fit

Function used to fit different spectral models to the fluxs_mJy densities of pulsars

pulsar_spectra.spectral_fit.estimate_flux_density(est_freq, model, iminuit_result)[source]

Estimate a pulsar’s flux density using a previous spectra fit.

Parameters
est_freqfloat or list

A single or list of frequencies to estimate flux at (in MHz).

modelfunction

The pulsar spectra model function from pulsar_spectra.models().

miminuit.Minuit

The Minuit class after being fit in pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

Returns
fitted_fluxfloat or list

The estimated flux density of the pulsar at the input frequencies.

fitted_flux_errfloat or list

The estimated flux density errors of the pulsar at the input frequencies.

pulsar_spectra.spectral_fit.find_best_spectral_fit(pulsar, freqs_MHz, fluxs_mJy, flux_errs_mJy, ref_all, plot_all=False, plot_best=False, plot_compare=False, plot_error=True, alternate_style=False, axis=None)[source]

Fit pulsar spectra with iminuit.

Parameters
pulsarstr

The Jname of the pulsar to be fit.

freqs_MHzlist

A list of the frequencies in MHz.

fluxs_mJylist

A list of the flux density in mJy.

flux_errs_mJylist

A list of the uncertainty of the flux density in mJy.

ref_alllist

A list of the reference label (in the format ‘Author_year’).

plot_allboolean, optional

If you want to plot the result of all fits.
Default: False.

plot_bestboolean, optional

If you want to only plot the best fit.
Default: False.

plot_compareboolean, optional

If you want to make a single plot with the result of all fits.
Default: False.

plot_errorboolean, optional

If you want to include the fit error in the plot.
Default: True.

alternate_styleboolean, optional

Plot with the alternate plot style based on Jankowski 2018.
Default: False.

axisAxes, optional

The axes with which the spectrum will be plotted.
Default: None

Returns
modelfunction

The best model functions from pulsar_spectra.models(). Default: pulsar_spectra.models.simple_power_law().

miminuit.Minuit

The Minuit class after being fit in pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

fit_infostr

The string to label the fit with from pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

pulsar_spectra.spectral_fit.iminuit_fit_spectral_model(freqs_MHz, fluxs_mJy, flux_errs_mJy, ref, model=<function simple_power_law>, plot=False, plot_error=True, save_name='fit.png', alternate_style=False, axis=None)[source]

Fit pulsar spectra with iminuit.

Parameters
freqs_MHzlist

A list of the frequencies in MHz.

fluxs_mJylist

A list of the flux density in mJy.

flux_errs_mJylist

A list of the uncertainty of the flux density in mJy.

reflist

A list of the reference label (in the format ‘Author_year’).

modelfunction, optional

One of the model functions from pulsar_spectra.models(). Default: pulsar_spectra.models.simple_power_law().

plotboolean, optional

If you want to plot the result of the fit.
Default: False.

plot_errorboolean, optional

If you want to include the fit error in the plot.
Default: True.

save_namestr, optional

The name of the saved plot.
Default: “fit.png”.

alternate_styleboolean, optional

If you want to use the alternate plot style.
Default: False.

axisAxes, optional

The axes with which the spectrum will be plotted.
None.

Returns
aicfloat

The Akaike information criterion of the fit.

miminuit.Minuit

The Minuit class after being fit in pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

fit_infostr

The string to label the fit with from pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

pulsar_spectra.spectral_fit.plot_fit(freqs_MHz, fluxs_mJy, flux_errs_mJy, ref, model, iminuit_result, fit_info, plot_error=True, save_name='fit.png', alternate_style=False, axis=None)[source]

Create a plot of the pulsar spectral fit.

Parameters
freqs_MHzlist

A list of the frequencies in MHz.

fluxs_mJylist

A list of the flux density in mJy.

flux_errs_mJylist

A list of the uncertainty of the flux density in mJy.

reflist

A list of the reference label (in the format ‘Author_year’).

modelfunction

One of the model functions from pulsar_spectra.models().

iminuit_resultiminuit.Minuit

The Minuit class after being fit in pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

fit_infostr

The string to label the fit with from pulsar_spectra.spectral_fit.iminuit_fit_spectral_model().

plot_errorboolean, optional

If you want to include the fit error in the plot.
Default: True.

save_namestr, optional

The name of the saved plot.
Default: “fit.png”.

alternate_styleboolean, optional

Plot with the alternate plot style based on Jankowski 2018.
Default: False.

axisAxes, optional

The axes with which the spectrum will be plotted.
None.