Composites

class CoSpecPy.composites.Composite(name)

Composite Class to handle creation of composites

name

Name given to created Composite. Used in Plotting

Type

str

composite_from_coords(ra, dec, catalogue=None, chunks=1)

Create composite from RA and DEC

Download and create composite spectra from a list of ra and dec positions in degrees. Requires the SDSS DR14 or SDSS DR12 catalogue. If no path provided it will download one.

Parameters
  • ra (list or array) – Right Ascension of objects for composite in degrees

  • dec (list or array) – Declination of objects for composite in degrees

  • catalogue (str, optional) – Path to already existing DR14 or DR12 catalogue

  • chunks (int, optional) – Number of smaller chunks to split download into

composite_from_downloads(download_folder)

Create composite from a directory of downloaded spectra

Given a folder containing SDSS spectra downloads, create the normalised fluxes and store within the class

Parameters

download_folder (string) – Path to the folder where spectra are downloaded as .fits files.

composite_from_speclist(speclist, chunks=1)

Create a composite from speclist

From a valid speclist.txt file cotaining valid SDSS URLs, download all spectra and create a composite.

Parameters
  • speclist (str) – Path to speclist file

  • chunks (int, optional) – Number of smallr chunks to split composite processing into. Useful if disc space is an issue.

composite_from_table(table, chunks=1)

Composite from an Astropy Table

Create a composite from an Astropy table, produces speclist files as an intermediary

Parameters
  • table (Astropy.Table) – Valid astropy Table containing the sample. Must have columns PLATE, MJD and FIBERID.

  • chunks (int, optional) – Number of smaller chunks to split composite processing into. Useful if disc space is an issue.

example_from_downloads(download_folder)

Full example run using the already downloaded list

Run an example composite creation using some default values.

Parameters

download_folder (str) – Path to where the spectra are downloaded in .fits format.

get_composite(samples=1)

Return the averaged composite with bootstrapped uncertainties if chosen

This will collect the normalised fluxes and take the median as the overall composite. If the number of samples is specified it will also calculate the uncertainty through bootstrapping and return this along with the median.

Parameters

samples (int, optional) – Number of bootstrap samples to take.

Returns

tuple containing:

median_flux (array): Array of the composite at each point on the wavelength grid. bootstrap_std (array, optional): Bootstrapped uncertainty at each point on the wavelength grid.

Return type

(tuple)

get_fluxes()

Return the current flux list

Returns

An array containing each normalised spectra as a different

element

Return type

(numpy array)

plot_composite(output_figure=None)

Simple plot of the current composite

Parameters

output_figure (str, optional) – Optional specification for a filename at which to save the composite plot. Will otherwise simply show the plot.

reset_composite()

Reset the flux list to an empty list

save_composite(filename)

Save current set of fluxes to .npy file

Parameters

filename (str) – Output filename for composite. Must be .npy extension.

set_download_handler(handler)

Set the download handler for in-built fetching of spectra

Parameters

handler (DownloadHandler) – Input download handler instance. Will control future SDSS downloads.

set_normalisation(norm_low, norm_high)

Add upper and lower normalisation values

Normalisation is applied by dividing by the average value over a given wavelength range. This sets the upper and lower end of that range.

Parameters
  • norm_low (float) – Lower wavelength for normalisation in Angstrom

  • norm_high (float) – Upper wavelength for normalisation in Angstrom

set_wavelength_grid(w_min, w_max, steps)

Add the common wavelength grid

Creates a numpy linspace which is used to interpolate SDSS spectra. Takes form np.linspace(w_min, w_max, steps). Wavelength is in Angstroms.

Parameters
  • w_min (float) – Minimum wave;ength for grid in Angstroms

  • w_max (float) – Maximum wavelength for grid in Ansgtroms

  • steps (int) – Number of points in the wavelength grid linspace