Library

class specmatchemp.library.Library(wav=None, library_spectra=None, library_params=None, header={}, wavlim=None, param_mask=None, nso=None)

A container for a library of spectrum and corresponding stellar parameters.

The Library class is a container for the library spectrum and stellar parameters for the library stars. The library is indexed using the library_index column.

library_params

pd.DataFrame – The parameter table, which can be queried directly as a pandas DataFrame.

library_spectra

np.ndarray – 3D array containing the library spectra ordered according to the index column.

wav

np.ndarray – Common wavelength scale for the library spectra.

param_mask

pd.DataFrame – Boolean dataframe with same rows and columns as library_params, marked True for model-independent parameters.

nso

Spectrum – NSO spectrum.

Parameters:
  • wav (np.ndarray, optional) – Wavelength scale for the library spectra.
  • library_params (pd.DataFrame, optional) – Pandas DataFrame containing the parameters for the library stars. It should have the columns specified in LIB_COLS, although values can be np.nan. The library_index of each row should be the index of the specturm in library_spectra.
  • library_spectra (np.ndarray, optional) – 3D array containing the library spectra ordered according to the index column. Each entry contains the spectrum, its uncertainty, and a mask array.
  • header (dict, optional) – Any additional metadata to store with the library.
  • wavlim (tuple, optional) – The upper and lower wavelength limits to be read.
  • param_mask (pd.DataFrame, optional) – Boolean dataframe with same rows and columns as library_params, marked True for model-independent parameters.
  • nso (Spectrum) – NSO spectrum
LIB_COLS = ['lib_index', 'cps_name', 'lib_obs', 'source', 'source_name', 'Teff', 'u_Teff', 'radius', 'u_radius', 'logg', 'u_logg', 'feh', 'u_feh', 'mass', 'u_mass', 'age', 'u_age', 'vsini', 'Plx', 'u_Plx', 'Plx_source', 'Vmag', 'snr']

Columns required in library

STAR_PROPS = ['Teff', 'radius', 'logg', 'feh', 'mass', 'age']

Numeric star properties

append(params, spectra=None, param_mask=None)

Adds spectrum and associated stellar parameters into library.

Parameters:
  • params (pd.Series or pd.DataFrame) – Row(s) to be added to the parameter table. It should have the fields specified in Library.LIB_COLS.
  • spectra (Spectrum, list of Spectrum, or np.ndarray) – Spectra to be added. - If Spectrum objects are provided, they will be interpolated onto the library wavelength scale if not already on it. - If np.ndarray is provided, it must be of shape (len(params), 3, len(library.wav)) and should have already been shifted onto the library wavelength scale.
  • param_mask (pd.Series or pd.DataFrame, optional) – Parameter mask. Must be same length as params.
copy()

Return a deep copy of the library object.

get_index(searchlist)

Searches the library for the given search string. Checks columns lib_obs, cps_name, source_name in order.

Parameters:searchlist (str or list of str) – String to search for.
Returns:Library index of the found star. Returns None if no object found.
Return type:int
get_spectrum(indices)

Returns the spectrum at the given index.

Parameters:indices (int or list) – Library indices of spectrum.
Returns:Spectra at given indices.
Return type:Spectrum or list of Spectrum
plot(paramx, paramy, grouped=False, marker='.', ptlabels=False, plt_kw={})

Create a plot of the library in parameter space

Parameters:
  • paramx (str) – Parameter to plot on the x-axis
  • paramy (str) – Parameter to plot on the y-axis
  • grouped (bool, optional) – Whether to group the stars by source
  • ptlabels (str, optional) – Library column to annotate points with
  • plt_kw (dict, optional) – Additional keyword arguments to pass to pyplot.plot
pop(index)

Removes the spectrum and parameters with the given index from the library.

Parameters:index (int) – Index of spectrum to remove.
Returns:
  • params (pd.Series): Parameters of star
  • spectrum (Spectrum): Spectrum
Return type:(pd.Series, spectrum.Spectrum)
query_params(querystr)

Query the library_params table and return the indices of matching stars.

Parameters:querystr (str) – Query string
Returns:Index or indices of library entries matching the query string.
Return type:int or list of int
remove(indices)

Removes the spectrum and parameters with the given index from the library.

Parameters:index (int or array of ints) – Indices of spectra to remove.
to_csv(path)

Saves library parameters as a CSV file, using Pandas native to_csv function.

Parameters:path (str) – Path to store csv file.
to_hdf(path)

Saves library as a HDF file

Parameters:path (str) – Path to store library
to_tex(path, cols='standard', mode='w')

Outputs library parameters into a tex file.

Parameters:
  • path (str) – Path to store tex file.
  • cols (str or list) – ‘standard’ or list of columns to be used
  • mode (str) – Writing mode to pass to open(), either ‘w’ or ‘a’
wav_cut(minw, maxw, deepcopy=False)

Returns a library with spectra within the given limits.

Parameters:
  • minw (float) – Minimum wavelength
  • maxw (float) – Maximum wavelength
  • deepcopy (bool, optional) – True to return a library with all attributes copied. Default is False.
Returns:

New library object.

Return type:

Library

specmatchemp.library.read_hdf(path=None, wavlim='all', lib_index_subset=None)

Reads in the library from a HDF file.

Parameters:
  • path (str, optional) – path to h5 file containing library. If no path is given, reads in from default directory.
  • wavlim (2-element iterable or str, optional) – The upper and lower wavelength limits to be read. If ‘none’, reads in library without spectra. If ‘all’, reads in complete stored spectra.
  • lib_index_subset (iterable, optional) – Load a subset of the library useful for debuging and testing code. May be a list or a np.s_ object. If passing a list, it must be in strictly increasing order due to the memory access protocol of h5py.
Returns:

Library object

Return type:

Library