zfinder package

Submodules

zfinder.fft module

Module for finding the redshift of a source using the fourier transform method.

zfinder.fft.calc_fft_params(transition, ffreq, fflux, dz, x0)[source]

Find the best fitting parameters for the FFT

zfinder.fft.double_damped_sinusoid(x, a, s, z, nu, f)[source]

FFT Fitting function

zfinder.fft.fft(frequency, flux)[source]

Performs the fast fourier transform on the frequency and flux axis

Parameters

frequencylist

Frequency axis values found with fits2flux get_freq()

fluxlist

Flux axis values found with fit2flux get_flux()

Returns

ffreq, ffluxlist

The Fourier Transformed frequency and flux axes respectively

zfinder.fft.fft_per_pixel(transition, frequency, all_flux, z_start=0, dz=0.01, z_end=10, size=3)[source]

Perform the FFT fitting method on all flux values

zfinder.fft.fft_zfind(transition, frequency, flux, uncertainty=1, z_start=0, dz=0.01, z_end=10, verbose=True, parallel=True)[source]

Finds the best redshift by performing the fast fourier transform on the flux data. The chi-squared is caclulated at every redshift by iterating through delta-z. The most likely redshift corresponds to the minimum chi-squared.

Parameters

z_startint, optional

The first value in the redshift list. Default = 0

dzfloat, optional

The change in redshift. Default = 0.01

z_endint, optional

The final value in the redshift list. Default = 10

verbosebool, optional

If True, print progress. Default = False

Returns

zlist

The list of redshifts that was used to calculate the chi-squared

chi2list

A list of calculated chi-squared values

zfinder.finder module

Class for finding the redshift of a source in a FITS file. Exports data to csv files and plots figures.

class zfinder.finder.zfinder(fitsfile, ra, dec, aperture_radius, transition, bkg_radius=50, beam_tolerance=1, showfig=True, savefig=True, export=True)[source]

Bases: object

zfinder is used to find the redshift of a fits image via two different methods:

template fits gaussian functions to the data to find redshift and

zfft performs the fast fourier transform on the flux data to find redshift.

These methods will create and save a series of plots and csv files with raw data by default. Can be changed with the showfig and export parameters.

If running in a .py file, you may need to add the following to your code. Otherwise, jupyter notebooks should work fine.

>>> if __name__ == '__main__':
>>>     source = zfinder(fitsfile, ra, dec, aperture_radius, transition)

Parameters

fitsfile.fits

A .fits image file

ralist

Right ascension of the target [h, m, s]

declist

Declination of the target [d, m, s, esign]

aperture_radiusfloat

Radius of the aperture to use over the source (pixels)

transitionfloat

The first transition frequency of the target element or molecule (GHz)

bkg_radiusfloat, optional

Radius of the background annulus (pixels). Default=50

beam_tolerancefloat, optional

The tolerance of the beam area (arcsec). Default=1

showfigbool, optional

If True, show the figures. Default=True

savefigbool, optional

If True, save the figures. Default=True

exportbool, optional

If True, export the data to csv files. Default=True

Methods

get_freq()

Caclulate the frequency axis

get_flux()

For every frequency channel, find the flux and associated uncertainty at a position

get_all_flux()

Get the flux values for all ra and dec coordinates

template()

Performs the template redshift finding method

template_pp()

Performs the template redshift finding method in a square around the target ra and dec

fft()

Performs the fft redshift finding method

fft_pp()

Performs the fft redshift finding method in a square around the target ra and dec

fft_uncert()

Calculates the uncertainty on the fft flux.

Examples

>>> from zfinder import zfinder
>>>
>>> fitsfile = '0856_cube_c0.4_nat_80MHz_taper3.fits'
>>> ra = '08:56:14.8'
>>> dec = '02:24:00.6'
>>> aperture_radius = 3
>>> transition = 115.2712
>>> z_start = 0
>>> dz = 0.001
>>> z_end = 10
>>> 
>>> source = zfinder(fitsfile, ra, dec, aperture_radius, transition)
>>> source.template(z_start, dz, z_end)
>>> source.fft(z_start, dz, z_end)
>>>
>>> # Once redshift is found, narrow down the redshift range and run per pixel methods
>>> aperture_radius_pp = 0.5
>>> size = 15
>>> z_start = 5.4
>>> dz = 0.001
>>> z_end = 5.7
>>> source.fft_pp(size, z_start, dz, z_end, aperture_radius_pp)
>>> source.template_pp(size, z_start, dz, z_end, aperture_radius_pp)
fft(z_start=0, dz=0.001, z_end=10, sigma=1, verbose=True, parallel=True, uncertainty=False)[source]

Perform the fft redshift finding method

Parameters

z_startfloat, optional

The starting redshift to search from. Default=0

dzfloat, optional

The step size of the redshift search. Default=0.001

z_endfloat, optional

The ending redshift to search to. Default=10

sigmafloat, optional

The significance level to calculate the redshift uncertainty. Default=1

verbosebool, optional

If True, print progress. Default=True

parallelbool, optional

If True, use multiprocessing. Default=True

uncertaintylist, bool, optional

A list of the uncertainty values calculated by zfinder.fft_uncert. If True, read the uncertainty values from the csv file. If False, no uncertainty values will be used for redshift calculation

Returns

zfloat

Best fit redshift

z_uncerttuple(float, float)

Lower and upper uncertainty on the best fit redshift

fft_pp(size, z_start=0, dz=0.01, z_end=10, aperture_radius_pp=0.5, flux_limit=0.001, contfile=None)[source]

Performs the fft redshift finding method in a square around the target ra and dec

Not recommended for very large redshift search ranges. Remember to narrow down the redshift range before using this method. Recommended to have 100-300 redshifts to check per pixel.

z_start = 5.4, dz = 0.001, z_end = 5.7 is a good range for GLEAM J0856.

z_start = 4.28, dz = 0.0001, z_end = 4.31 is a good range for SPT 0345-47.

Parameters

sizeint

The size of a square (centred on ra and dec) to calculate redshifts in (pixels). size=15 is 15x15 pixels

z_startfloat, optional

The starting redshift to search from. Default=0

dzfloat, optional

The step size of the redshift search. Default=0.01

z_endfloat, optional

The ending redshift to search to. Default=10

aperture_radius_ppfloat, optional

Radius of the aperture to use over the source (pixels). Default=0.5

flux_limitfloat, optional

The minimum flux value to calculate redshifts for. Default=0.001 If contfile is specified, this is the minimum continuum flux.

contfilestr, optional

The fits file containing the continuum data. Default=None

fft_uncert(n=100, radius=50, min_spread=1)[source]

Doc string here

get_all_flux(all_ra, all_dec, aperture_radius=None)[source]

Get the flux values for all ra and dec coordinates

Paramters

all_ralist

A list of all ra coordinates

all_declist

A list of all dec coordinates

aperture_radiusfloat

Radius of the aperture to use over the source (pixels). If None, use the aperture_radius

get_flux(verbose=True, parallel=True)[source]

For every frequency channel, find the flux and associated uncertainty at a position

Paramters

verbosebool, optional

If True, print progress. Default=True

parallelbool, optional

If True, use multiprocessing. Default=True

Returns

fluxlist

A list of flux values from each frequency channel

f_uncertlist

A list of flux uncertainty values for each flux measurement

get_freq()[source]

Caclulate the frequency axis list (x-axis) of the flux

static read_fft_uncert(filename='fft_uncertainty.csv')[source]

Read the fft uncertainty csv file

template(z_start=0, dz=0.001, z_end=10, sigma=1, verbose=True, parallel=True)[source]

Perform the template redshift finding method

Parameters

z_startfloat, optional

The starting redshift to search from. Default=0

dzfloat, optional

The step size of the redshift search. Default=0.01

z_endfloat, optional

The ending redshift to search to. Default=10

sigmafloat, optional

The significance level to calculate the redshift uncertainty. Default=1

verbosebool, optional

If True, print progress. Default=True

parallelbool, optional

If True, use multiprocessing. Default=True

Returns

zfloat

Best fit redshift

z_uncerttuple(float, float)

Lower and upper uncertainty on the best fit redshift

template_pp(size, z_start=0, dz=0.001, z_end=10, aperture_radius_pp=0.5, flux_limit=0.001, contfile=None)[source]

Performs the template redshift finding method in a square around the target ra and dec.

Not recommended for very large redshift search ranges. Remember to narrow down the redshift range before using this method. Recommended to have 100-300 redshifts to check per pixel.

z_start = 5.4, dz = 0.001, z_end = 5.7 is a good range for GLEAM J0856.

z_start = 4.28, dz = 0.0001, z_end = 4.31 is a good range for SPT 0345-47.

Parameters

sizeint

The size of a square (centred on ra and dec) to calculate redshifts in (pixels). size=15 is 15x15 pixels

z_startfloat, optional

The starting redshift to search from. Default=0

dzfloat, optional

The step size of the redshift search. Default=0.01

z_endfloat, optional

The ending redshift to search to. Default=10

aperture_radius_ppfloat, optional

Radius of the aperture to use over the source (pixels). Default=0.5

flux_limitfloat, optional

The minimum flux value to calculate redshifts for. Default=0.001 If contfile is specified, this is the minimum continuum flux.

contfilestr, optional

The fits file containing the continuum data. Default=None

zfinder.flux module

Helper functions for calculating fluxes from FITS files

zfinder.flux.calc_beam_area(bin_hdu, tolerance=1)[source]

Caclulate the corrected beam area (from Jy/beam to Jy)

zfinder.flux.mp_flux_jobs(data, aperture, annulus, bkg_radius, pix2deg, beam_area, verbose)[source]

Process the flux arrays using multiprocessing

zfinder.flux.process_channel_data(channel, aperture, annulus, bkg_radius, pix2deg, barea)[source]

Function for processing channels in get_flux()

zfinder.flux.serial_flux_jobs(data, aperture, annulus, bkg_radius, pix2deg, beam_area, verbose)[source]

Process the flux arrays serially

zfinder.plotter module

Class to plot the results of the zfinder

class zfinder.plotter.Plotter(showfig=True, savefig=False)[source]

Bases: object

Class to plot the results of zfinder. Includes methods of plotting exported csv data

Parameters

showfigbool, optional

Whether to show the figure after plotting. Default is True.

savefigbool, optional

Whether to save the figure after plotting. Default is True.

Attributes

unit_prefixesdict

Dictionary of unit prefixes for plotting

Methods

calc_best_z()

Calculate the best redshift

plot_chi2()

Plot the chi-squared vs redshift

plot_template_flux()

Plot the template flux

plot_fft_flux()

Plot the fft flux

plot_heatmap()

Plot a heatmap of the redshifts

export_template_data()

Export the Template fit data to a csv file

export_fft_data()

Export the FFT data to a csv file

plot_chi2_fromcsv()

Plot the chi-squared vs redshift from a csv file

plot_template_flux_fromcsv()

Plot the template flux from a csv file

plot_fft_flux_fromcsv()

Plot the fft flux from a csv file

plot_heatmap_fromcsv()

Plot a heatmap of the redshifts from a csv file

Examples

>>> # After csv files exported with zfinder
>>> source = Plotter()
>>> source.plot_chi2_fromcsv('template.csv')
>>> source.plot_template_flux_fromcsv()
>>> 
>>> source.plot_chi2_fromcsv('fft.csv')
>>> source.plot_fft_flux_fromcsv()
>>> 
>>> source.plot_heatmap_fromcsv('template_per_pixel.csv')
>>> source.plot_heatmap_fromcsv('fft_per_pixel.csv')
calc_best_z(z, chi2, title=None)[source]

Calculate the best redshift

Parameters

zlist

Array of redshifts

chi2list

Array of chi-squared values

Returns

best_zfloat

The best redshift

plot_chi2(z, dz, chi2, title)[source]

Plot the chi-sqaured vs redshift

plot_chi2_fromcsv(filename)[source]

Plot the chi-squared vs redshift from a csv file

plot_coords(x_centre, y_centre, x_coords, y_coords, radius, fitsfile=None)[source]
plot_coords_fromcsv(filename='fft_uncertainty.csv')[source]

Plot the distribution of random points from a csv file

plot_fft_flux(transition, frequency, ffreq, fflux)[source]

Plot the fft flux

Parameters

transitionfloat

The transition frequency

frequencylist

Array of frequencies

ffreqlist

Array of fft frequencies

ffluxlist

Array of fft fluxes

plot_fft_flux_fromcsv(filename='fft.csv')[source]

Plot the fft flux from a csv file

plot_heatmap(ra, dec, hdr, data, size, z, title, aperture_radius, flux_limit, export=False, subsize=None, contfile=None)[source]

Plot a heatmap of the redshifts

Parameters

ralist[string]

Target right ascension

declist[string]

Target declination

hdrastropy.io.fits.header.Header

The header of the fits file

dataastropy.io.fits.hdu.image.PrimaryHDU

The data of the fits file

sizeint

The size of the square in pixels

zlist

Array of redshifts

titlestring

The title method of the plot. Either ‘Template’ or ‘FFT’

aperture_radiusfloat

The radius of the aperture in pixels

flux_limitfloat

The flux limit to mask the velocities

exportbool, optional

Whether to export the redshifts to a csv file. Default is True.

subsizeint, optional

Plot a smaller heatmap of the redshifts. Default is None.

plot_heatmap_fromcsv(filename, subsize=None, flux_limit=None, contfile=None)[source]

Plot a heatmap of the redshifts from a csv file

plot_template_flux(transition, frequency, freq_exp, flux, flux_exp)[source]

Plot the template flux

Parameters

transitionfloat

The transition frequency

frequencylist

Array of frequencies

freq_expint

The exponent of the frequency

fluxlist

Array of fluxes

flux_expint

The exponent of the flux

plot_template_flux_fromcsv(filename='template.csv')[source]

Plot the template flux from a csv file

unit_prefixes = {-24: 'y', -21: 'z', -18: 'a', -15: 'f', -12: 'p', -9: 'n', -6: 'μ', -3: 'm', 0: '', 3: 'k', 6: 'M', 9: 'G', 12: 'T', 15: 'P', 18: 'E', 21: 'Z', 24: 'Y'}

zfinder.template module

Module for finding the redshift of a source using the gaussian template shifting method.

zfinder.template.calc_template_params(frequency, flux, observed_transition)[source]
zfinder.template.find_lines(flux)[source]

Create a line finder to find significant points

zfinder.template.gaussf(x, a, s, x0)[source]

Function to fit a sum of gaussians

zfinder.template.template_per_pixel(transition, frequency, all_flux, all_flux_uncertainty, z_start=0, dz=0.01, z_end=10, size=3)[source]

Perform the Template fitting method on all flux values

zfinder.template.template_zfind(transition, frequency, flux, flux_uncertainty=1, z_start=0, dz=0.01, z_end=10, verbose=True, parallel=True)[source]

Using the gaussian template shifting method, calculate the reduced chi-squared at every change in redshift.

Parameters

z_startfloat, optional

The redshift to start calculated chi2 fits at. Default=0

dzfloat, optional

Change in redshift to iterature through. Default=0.01

z_endfloat, optional

Final redshift to start calculating chi2 at. Default=10

verbosebool, optional

If True, print progress. Default=True

Returns

zlist

List of redshift values that were iterated through

chi2list

List of calculated chi-squared values.

Example

>>> z, chi2 = template_zfind()
>>> lowest_index = np.argmin(chi2)
>>> best_fit_redshift = z[lowest_index]

zfinder.uncertainty module

zfinder.uncertainty.quadratic(x, a, b, c)[source]

Fit a quadratic to 3 points closest to the minimum chi-squared

zfinder.uncertainty.solve_quadratic(y, a, b, c)[source]

Solve the quadratic to find x at a certain sigma

zfinder.uncertainty.z_uncert(z, chi2, ssigma)[source]

Caclulate the uncertainty in the best fitting redshift

Parameters

zlist

A list of redshift values

chi2list

A list of chi-squared values

ssigmafloat

The squared significance level of the uncertainty. ssigma = sigma**2

Returns

neg_uncertfloat

The left (- / negative) uncertainty

pos_uncertfloat

The right (+ / positive) uncertainty

zfinder.utils module

Utility functions for zfinder

zfinder.utils.average_zeroes(array)[source]

Average zeroes with left & right values in a list

zfinder.utils.gen_random_coords(n, radius, centre, min_spread)[source]

Generate a list of random x, y tuple coordinates inside a circle.

zfinder.utils.generate_square_pix_coords(size, target_x, target_y, aperture_radius=0.5)[source]

Generate a list of coordinates for a square of pixel coordinates around a target x,y pixel

zfinder.utils.generate_square_world_coords(fitsfile, ra, dec, size, aperture_radius)[source]

Generate a list of coordinates for a square of ra & dec around a target ra & dec

zfinder.utils.get_eng_exponent(number)[source]

Find the nearest power of 3 (lower). In engineering format, exponents are multiples of 3.

zfinder.utils.get_sci_exponent(number)[source]

Find the scientific exponent of a number

zfinder.utils.longest_decimal(numbers)[source]

Find the longest decimal place in a list of numbers

zfinder.utils.radec2str(ra, dec)[source]

Convert RA and DEC to a string

zfinder.utils.wcs2pix(ra, dec, hdr)[source]

Convert RA, DEC to x, y pixel coordinates

Module contents