PHOEBE spectra

PHOEBE spectra — functions that facilitate spectra manipulation

Synopsis

                    PHOEBE_specrep_tag;
                    PHOEBE_specrep;
extern              PHOEBE_specrep PHOEBE_spectra_repository;
int                 phoebe_spectra_set_repository       (char *rep_name);
int                 phoebe_spectra_free_repository      ();
PHOEBE_spectrum*    phoebe_spectrum_new                 ();
PHOEBE_spectrum*    phoebe_spectrum_new_from_file       (char *filename);
PHOEBE_spectrum*    phoebe_spectrum_new_from_repository (double Teff,
                                                         double logg,
                                                         double met);
PHOEBE_spectrum*    phoebe_spectrum_create              (double ll,
                                                         double ul,
                                                         double R,
                                                         PHOEBE_spectrum_dispersion disp);
PHOEBE_spectrum*    phoebe_spectrum_duplicate           (PHOEBE_spectrum *spectrum);
PHOEBE_vector*      phoebe_spectrum_get_column          (PHOEBE_spectrum *spectrum,
                                                         int col);
int                 phoebe_spectrum_alloc               (PHOEBE_spectrum *spectrum,
                                                         int dim);
int                 phoebe_spectrum_realloc             (PHOEBE_spectrum *spectrum,
                                                         int dim);
int                 phoebe_spectrum_free                (PHOEBE_spectrum *spectrum);
int                 phoebe_spectrum_rebin               (PHOEBE_spectrum **src,
                                                         PHOEBE_spectrum_dispersion disp,
                                                         double ll,
                                                         double ul,
                                                         double R);
int                 phoebe_spectrum_integrate           (PHOEBE_spectrum *spectrum,
                                                         double ll,
                                                         double ul,
                                                         double *result);
int                 phoebe_spectrum_broaden             (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double R);
int                 phoebe_spectrum_crop                (PHOEBE_spectrum *spectrum,
                                                         double ll,
                                                         double ul);
int                 phoebe_spectrum_apply_doppler_shift (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double velocity);
int                 phoebe_spectrum_apply_rotational_broadening
                                                        (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double vsini,
                                                         double ldx);
int                 phoebe_spectrum_set_sampling        (PHOEBE_spectrum *spectrum,
                                                         double Rs);
int                 phoebe_spectrum_set_resolution      (PHOEBE_spectrum *spectrum,
                                                         double R);
int                 phoebe_spectrum_multiply_by         (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double factor);
int                 phoebe_spectrum_dispersion_guess    (PHOEBE_spectrum_dispersion *disp,
                                                         PHOEBE_spectrum *spectrum);
char*               phoebe_spectrum_dispersion_type_get_name
                                                        (PHOEBE_spectrum_dispersion disp);
int                 phoebe_spectra_add                  (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2);
int                 phoebe_spectra_subtract             (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2);
int                 phoebe_spectra_merge                (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2,
                                                         double w1,
                                                         double w2,
                                                         double ll,
                                                         double ul,
                                                         double Rs);
int                 phoebe_spectra_multiply             (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2,
                                                         double ll,
                                                         double ul,
                                                         double R);
int                 phoebe_spectra_divide               (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2);
bool                phoebe_spectra_compare              (PHOEBE_spectrum *spec1,
                                                         PHOEBE_spectrum *spec2);

Description

These are the functions that facilitate spectra manipulation, including the repository I/O.

Details

PHOEBE_specrep_tag

typedef struct {
	char *filename;
	int type;
	int resolution;
	int lambda_min;
	int lambda_max;
	int temperature;
	int metallicity;
	int gravity;
	int alpha;
	int microturbulence;
} PHOEBE_specrep_tag;


PHOEBE_specrep

typedef struct {
	int                 no;
	PHOEBE_specrep_tag *prop;
	PHOEBE_array       *Teffnodes;
	PHOEBE_array       *loggnodes;
	PHOEBE_array       *metnodes;
	PHOEBE_specrep_tag ****table;
} PHOEBE_specrep;


PHOEBE_spectra_repository

extern PHOEBE_specrep PHOEBE_spectra_repository;


phoebe_spectra_set_repository ()

int                 phoebe_spectra_set_repository       (char *rep_name);

Traverses the path rep_name and parses all found filenames for spectra. Filenames must match the predefined format:

T%5dG%2d%c%2dV000K%1dS%2cNV%3c%c.ASC

Only 0 rotational velocity spectra are parsed because PHOEBE uses its internal function for rotational broadening. Where available, this function calls ftw() for traversing the tree; the spectra can then be separated into subdirectories (i.e. Munari et al. 2005) and ftw() will traverse up to 10 subdirectories deep. When ftw() is not available, a simplified parsing function is used that requires the spectra to be all in a single subdirectory.

rep_name :

path to the repository

Returns :

PHOEBE_error_code.

phoebe_spectra_free_repository ()

int                 phoebe_spectra_free_repository      ();

Frees all fields of the spectrum repository. Since PHOEBE currently allows for a single spectrum repository, the function takes no arguments.

Returns :

PHOEBE_error_code.

phoebe_spectrum_new ()

PHOEBE_spectrum*    phoebe_spectrum_new                 ();

Allocates memory for the new spectrum.

Returns :

a newly allocated PHOEBE_spectrum.

phoebe_spectrum_new_from_file ()

PHOEBE_spectrum*    phoebe_spectrum_new_from_file       (char *filename);

Opens a two-column filename and reads its contents to a newly allocated spectrum. The columns are assumed to contain bin centers and fluxes. The function tries to guess the dispersion type and assigns all spectrum fields accordingly.

filename :

spectrum filename

Returns :

a read-in PHOEBE_spectrum.

phoebe_spectrum_new_from_repository ()

PHOEBE_spectrum*    phoebe_spectrum_new_from_repository (double Teff,
                                                         double logg,
                                                         double met);

Queries the spectrum repository and interpolates a spectrum with the passed parameters. If the parameters are out of range for the given repository, NULL is returned. The function uses all available nodes in the repository for the interpolation; if the queried spectrum is missing, the first adjacent spectrum is looked up. The interpolation is linear.

Teff :

effective temperature in K

logg :

surface gravity in cgs units

met :

metallicity in solar abundances

Returns :

a queried PHOEBE_spectrum, or NULL in case of failure.

phoebe_spectrum_create ()

PHOEBE_spectrum*    phoebe_spectrum_create              (double ll,
                                                         double ul,
                                                         double R,
                                                         PHOEBE_spectrum_dispersion disp);

Creates an empty spectrum of resolving power R, sampled on the wavelength interval [ll, ul]. If the dispersion type is PHOEBE_SPECTRUM_DISPERSION_LOG, the resolving power is constant and the dispersion changes throughout the spectrum. If the dispersion type is PHOEBE_SPECTRUM_DISPERSION_LINEAR, the dispersion is constant and the resolving power changes. Dispersion relates to resolving power simply as delta = 1/R.

ll :

lower wavelength limit in angstroms

ul :

upper wavelength limit in angstroms

R :

spectrum resolving power

disp :

spectrum dispersion type

Returns :

a newly created PHOEBE_spectrum.

phoebe_spectrum_duplicate ()

PHOEBE_spectrum*    phoebe_spectrum_duplicate           (PHOEBE_spectrum *spectrum);

Makes a duplicate copy of spectrum.

spectrum :

spectrum to be duplicated

Returns :

a duplicated PHOEBE_spectrum.

phoebe_spectrum_get_column ()

PHOEBE_vector*      phoebe_spectrum_get_column          (PHOEBE_spectrum *spectrum,
                                                         int col);

Allocates a vector and copies the contents of the col-th spectrum column to it. The value of col may be 1 (wavelength) or 2 (flux).

spectrum :

input spectrum

col :

column index

Returns :

PHOEBE_vector, or NULL in case of a failure.

phoebe_spectrum_alloc ()

int                 phoebe_spectrum_alloc               (PHOEBE_spectrum *spectrum,
                                                         int dim);

Allocates memory for spectrum with dimension dim. The spectrum must be initialized with phoebe_spectrum_new().

spectrum :

initialized spectrum

dim :

spectrum dimension

Returns :

PHOEBE_error_code.

phoebe_spectrum_realloc ()

int                 phoebe_spectrum_realloc             (PHOEBE_spectrum *spectrum,
                                                         int dim);

Reallocates memory for spectrum with the new dimension dim. If dim is smaller than the current dimension, spectrum will be truncated. Otherwise all original values are retained.

spectrum :

initialized or allocated spectrum

dim :

new spectrum dimension

Returns :

PHOEBE_error_code.

phoebe_spectrum_free ()

int                 phoebe_spectrum_free                (PHOEBE_spectrum *spectrum);

Frees the allocated space for spectrum.

spectrum :

spectrum to be freed

Returns :

PHOEBE_error_code.

phoebe_spectrum_rebin ()

int                 phoebe_spectrum_rebin               (PHOEBE_spectrum **src,
                                                         PHOEBE_spectrum_dispersion disp,
                                                         double ll,
                                                         double ul,
                                                         double R);

src :

disp :

ll :

ul :

R :

Returns :


phoebe_spectrum_integrate ()

int                 phoebe_spectrum_integrate           (PHOEBE_spectrum *spectrum,
                                                         double ll,
                                                         double ul,
                                                         double *result);

Integrates the spectrum on the wavelength interval [ll, ul] using a simple rectangular rule:

I = \int_ll^ul s (\lambda) d\lambda = \sum s (\lambda) \Delta \lambda

The units of ll and ul must match the units of the passed spectrum.

The sum goes over all covered \Delta \lambda's, taking into account the partial coverage at interval borders.

spectrum :

input spectrum

ll :

lower wavelength interval limit

ul :

upper wavelength interval limit

result :

placeholder for the integral value

Returns :

PHOEBE_error_code.

phoebe_spectrum_broaden ()

int                 phoebe_spectrum_broaden             (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double R);

dest :

src :

R :

Returns :


phoebe_spectrum_crop ()

int                 phoebe_spectrum_crop                (PHOEBE_spectrum *spectrum,
                                                         double ll,
                                                         double ul);

Crops the passed spectrum to the [ll, ul] interval. All other spectrum properties are retained.

spectrum :

spectrum to be cropped

ll :

lower wavelength limit

ul :

upper wavelength limit

Returns :

PHOEBE_error_code.

phoebe_spectrum_apply_doppler_shift ()

int                 phoebe_spectrum_apply_doppler_shift (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double velocity);

Applies a non-relativistic Doppler shift to the spectrum. It does that by first shifting the ranges according to the passed velocity and then rebinning the obtained histogram to the original bins. c=299791 km/s is used for the speed of light.

dest :

a placeholter for the shifted spectrum

src :

original (unshifted) spectrum

velocity :

radial velocity in km/s

Returns :

PHOEBE_error_code.

phoebe_spectrum_apply_rotational_broadening ()

int                 phoebe_spectrum_apply_rotational_broadening
                                                        (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double vsini,
                                                         double ldx);

dest :

src :

vsini :

ldx :

Returns :


phoebe_spectrum_set_sampling ()

int                 phoebe_spectrum_set_sampling        (PHOEBE_spectrum *spectrum,
                                                         double Rs);

spectrum :

Rs :

Returns :


phoebe_spectrum_set_resolution ()

int                 phoebe_spectrum_set_resolution      (PHOEBE_spectrum *spectrum,
                                                         double R);

spectrum :

R :

Returns :


phoebe_spectrum_multiply_by ()

int                 phoebe_spectrum_multiply_by         (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src,
                                                         double factor);

dest :

src :

factor :

Returns :


phoebe_spectrum_dispersion_guess ()

int                 phoebe_spectrum_dispersion_guess    (PHOEBE_spectrum_dispersion *disp,
                                                         PHOEBE_spectrum *spectrum);

Tries to guess the type of the spectrum dispersion by evaluating all bin differences and quotients. If a difference is constant, disp is set to linear dispersion; if a quotient is constant, disp is set to log dispersion; otherwise disp is set to no dispersion. The constancy of the differences and quotients is checked to 1e-6 numerical accuracy.

disp :

placeholder for the guessed dispersion

spectrum :

spectrum for which the dispersion should be guessed

Returns :

PHOEBE_error_code.

phoebe_spectrum_dispersion_type_get_name ()

char*               phoebe_spectrum_dispersion_type_get_name
                                                        (PHOEBE_spectrum_dispersion disp);

Converts the enumerated value to a string.

disp :

enumerated PHOEBE_spectrum_dispersion

Returns :

string

phoebe_spectra_add ()

int                 phoebe_spectra_add                  (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2);

dest :

src1 :

src2 :

Returns :


phoebe_spectra_subtract ()

int                 phoebe_spectra_subtract             (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2);

dest :

src1 :

src2 :

Returns :


phoebe_spectra_merge ()

int                 phoebe_spectra_merge                (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2,
                                                         double w1,
                                                         double w2,
                                                         double ll,
                                                         double ul,
                                                         double Rs);

dest :

src1 :

src2 :

w1 :

w2 :

ll :

ul :

Rs :

Returns :


phoebe_spectra_multiply ()

int                 phoebe_spectra_multiply             (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2,
                                                         double ll,
                                                         double ul,
                                                         double R);

dest :

src1 :

src2 :

ll :

ul :

R :

Returns :


phoebe_spectra_divide ()

int                 phoebe_spectra_divide               (PHOEBE_spectrum **dest,
                                                         PHOEBE_spectrum *src1,
                                                         PHOEBE_spectrum *src2);

dest :

src1 :

src2 :

Returns :


phoebe_spectra_compare ()

bool                phoebe_spectra_compare              (PHOEBE_spectrum *spec1,
                                                         PHOEBE_spectrum *spec2);

Compares spectra spec1 and spec2 by comparing the resolving power, sampling, dispersion, and by evaluating the absolute value of the differences of all elements (both wavelength and flux) and comparing it against PHOEBE_NUMERICAL_ACCURACY.

spec1 :

spectrum 1 to be compared

spec2 :

spectrum 2 to be compared

Returns :

TRUE if the spectra are the same, FALSE otherwise.