«  Sparse Representation (new!)   ::   Contents

PDF storage module

This is the pdf_storage module in some detail, refer to the source code for more information and methods.
pdf_storage.combine_int(Ncoef, Nbase)

combine index of base (up to 62500 bases) and value (16 bits integer with sign) in a 32 bit integer First half of word is for the value and second half for the index

Parameters:
  • Ncoef (int) – Integer with sign to represent the value associated with a base, this is a sign 16 bits integer
  • Nbase (int) – Integer representing the base, unsigned 16 bits integer
Returns:

32 bits integer

pdf_storage.create_gaussian_dict(zfine, mu, Nmu, sigma, Nsigma, cut=1e-05)

Creates a gaussian dictionary only

Parameters:
  • zfine (float) – the x-axis for the PDF, the redshift resolution
  • mu (float) – [min_mu, max_mu], range of mean for gaussian
  • Nmu (int) – Number of values between min_mu and max_mu
  • sigma (float) – [min_sigma, max_sigma], range of variance for gaussian
  • Nsigma (int) – Number of values between min_sigma and max_sigma
  • cut (float) – Lower cut for gaussians
Returns:

Dictionary as numpy array with shape (len(zfine), Nmu*Nsigma)

Return type:

float

pdf_storage.create_voigt_dict(zfine, mu, Nmu, sigma, Nsigma, Nv, cut=1e-05)

Creates a gaussian-voigt dictionary at the same resolution as the original PDF

Parameters:
  • zfine (float) – the x-axis for the PDF, the redshift resolution
  • mu (float) – [min_mu, max_mu], range of mean for gaussian
  • Nmu (int) – Number of values between min_mu and max_mu
  • sigma (float) – [min_sigma, max_sigma], range of variance for gaussian
  • Nsigma (int) – Number of values between min_sigma and max_sigma
  • Nv – Number of Voigt profiles per gaussian at given position mu and sigma
  • cut (float) – Lower cut for gaussians
Returns:

Dictionary as numpy array with shape (len(zfine), Nmu*Nsigma*Nv)

Return type:

float

pdf_storage.errf(P, x, y)

Error function to be minimized during fitting

pdf_storage.fit_multi_gauss(z, pdf, tolerance=1.49e-08)

Fits a multi gaussian function to the pdf, given a tolerance

pdf_storage.get_N(longN)

Extract coefficients fro the 32bits integer, Extract Ncoef and Nbase from 32 bit integer return (longN >> 16), longN & 0xffff

Parameters:longN (int) – input 32 bits integer
Returns:Ncoef, Nbase both 16 bits integer
pdf_storage.get_npeaks(z, pdf)

Get the number of peaks for a given PDF

Parameters:
  • z (float) – the redhisft values of the PDF
  • pdf (float) – the values of the PDF
Returns:

The number of peaks, positions of the local maximums, local minimums and inflexion points

pdf_storage.initial_guess(z, pdf)

Computes a initial guess based on local maxima and minima, it adds an extra gaussian to the number of peaks

pdf_storage.multi_gauss(P, x)

Muti-Gaussian function

Parameters:
  • P (float) – array with values for amplitud, mean and sigma, P=[A0,mu0,sigma0, A1,mu1, sigma1, ...]
  • x (float) – x values
Returns:

The multi gaussian

pdf_storage.read_header(fits_file)

Reads the header from a fits file that stores the sparse indices

Parameters:fits_file (str) – Name of fits file
Returns:Dictionary of header to be used to reconstruct PDF
pdf_storage.reconstruct_pdf(index, vals, zfine, mu, Nmu, sigma, Nsigma, cut=1e-05)

This function reconstruct the pdf from the indices and values and parameters used to create the dictionary with Gaussians only

Parameters:
  • index (int) – List of indices in the dictionary for the selected bases
  • vals (float) – values or coefficients corresponding to the listed indices
  • zfine (float) – redshift values from the original pdf or used during the sparse representation
  • mu (float) – [min_mu, max_mu] values used to create the dictionary
  • Nmu (int) – Number of mu values used to create the dictionary
  • sigma (float) – [min_sigma, mas_sigma] sigma values used to create the dictionary
  • Nsigma (int) – Number of sigma values
  • cut (float) – cut threshold when creating the dictionary
Returns:

the pdf normalized so it sums to one

pdf_storage.reconstruct_pdf_f(index, vals, zfine, mu, Nmu, sigma, Nsigma)

This function returns the reconstructed pdf in a functional analytical form, to be used in a analytical form”

Parameters:
  • index (int) – List of indices in the dictionary for the selected bases
  • vals (float) – values or coefficients corresponding to the listed indices
  • zfine (float) – redshift values from the original pdf or used during the sparse representation
  • mu (float) – [min_mu, max_mu] values used to create the dictionary
  • Nmu (int) – Number of mu values used to create the dictionary
  • sigma (float) – [min_sigma, mas_sigma] sigma values used to create the dictionary
  • Nsigma (int) – Number of sigma values
Returns:

a function representing the pdf

pdf_storage.reconstruct_pdf_int(long_index, header, cut=1e-05)

This function reconstruct the pdf from the integer indices only and the parameters used to create the dictionary with Gaussians and Voigt profiles

Parameters:
  • long_index (int) – List of indices including coefficients (32bits integer array)
  • header (dict) – Dictionary of the fits file header with information used to create dictionary and sparse indices
  • cut (float) – cut threshold when creating the dictionary
Returns:

the pdf normalized so it sums to one

pdf_storage.reconstruct_pdf_v(index, vals, zfine, mu, Nmu, sigma, Nsigma, Nv, cut=1e-05)

This function reconstruct the pdf from the indices and values and parameters used to create the dictionary with Gaussians and Voigt profiles

Parameters:
  • index (int) – List of indices in the dictionary for the selected bases
  • vals (float) – values or coefficients corresponding to the listed indices
  • zfine (float) – redshift values from the original pdf or used during the sparse representation
  • mu (float) – [min_mu, max_mu] values used to create the dictionary
  • Nmu (int) – Number of mu values used to create the dictionary
  • sigma (float) – [min_sigma, mas_sigma] sigma values used to create the dictionary
  • Nsigma (int) – Number of sigma values
  • Nv (int) – Number of Voigt profiles used to create dictionary
  • cut (float) – cut threshold when creating the dictionary
Returns:

the pdf normalized so it sums to one

pdf_storage.sparse_basis(dictionary, query_vec, n_basis, tolerance=None)

Compute sparse representation of a vector given Dictionary (basis) for a given tolerance or number of basis. It uses Cholesky decomposition to speed the process and to solve the linear operations adapted from Rubinstein, R., Zibulevsky, M. and Elad, M., Technical Report - CS Technion, April 2008

Parameters:
  • dictionary (float) – Array with all basis on each column, must has shape (len(vector), total basis) and each column must have euclidean l-2 norm equal to 1
  • query_vec (float) – vector of which a sparse representation is desired
  • n_basis (int) – number of desired basis
  • tolerance (float) – tolerance desired if n_basis is not needed to be fixed, must input a large number for n_basis to assure achieving tolerance
Returns:

indices, values (2 arrays one with the position and the second with the coefficients)

pdf_storage.voigt(x, x_mean, sigma, gamma)

Voigt profile V(x,sig,gam) = Re(w(z)), w(z) Faddeeva function z = (x+j*gamma)/(sigma*sqrt(2))

Parameters:
  • x (float) – the x-axis values (redshift)
  • x_mean (float) – Mean of the gaussian or Voigt
  • sigma (float) – Sigma of the original Gaussian when gamma=0
  • gamma (float) – Gamma parameter for the Lorentzian profile (Voigt)
Returns:

The real values of the Voigt profile at points x

«  Sparse Representation (new!)   ::   Contents