ERIS Pipeline Reference Manual 1.8.15
sc_conv.c File Reference
#include <sc_conv.h>

Go to the source code of this file.

Functions

cpl_error_code sc_conv_checkfitsformat (int *fitsformat, const char *filename)
 
cpl_error_code sc_conv_setcolnames (cpl_array *colnames, const cpl_parameterlist *parlist)
 
cpl_error_code sc_conv_setextnames_varr (cpl_table *extnames, const scvarr *vecdat, const cpl_parameterlist *parlist)
 
cpl_error_code sc_conv_setextnames_iarr (cpl_table *extnames, const sciarr *imadat, const cpl_parameterlist *parlist)
 
cpl_error_code sc_conv_varr2tarr (sctarr *tabdat, const scvarr *vecdat, const cpl_table *extnames)
 
double sc_conv_getwcskey (const cpl_propertylist *plist, const char *key)
 
cpl_error_code sc_conv_modtable (sctarr *tabdat, const cpl_parameterlist *parlist)
 
cpl_error_code sc_conv_readprepfits (sctarr *tabdat, const cpl_parameterlist *parlist)
 
cpl_error_code sc_conv_results2tarr (sctarr *tabdat, cpl_table *results)
 
cpl_error_code sc_conv_erasemaskcol (sctarr *tabdat, const cpl_parameterlist *parlist)
 
cpl_error_code sc_conv_resultstarr2varr (scvarr *vecdat, const cpl_table *extnames, const sctarr *tabdat)
 
cpl_error_code sc_conv_getmaskval (double maskval[2], const sctarr *tabdat, const cpl_table *extnames)
 
cpl_error_code sc_conv_iarr2varr_sci (scvarr *vecdat, cpl_vector *selpix, const sciarr *imadat, const cpl_table *extnames, const double minrelprofflux)
 
cpl_error_code sc_conv_iarr2varr_sky (scvarr *vecdat, const sciarr *imadat, const cpl_table *extnames, const double lowpixfrac, const cpl_vector *selpix)
 
cpl_error_code sc_conv_ascii_read (sctarr *tabdat, const char *filename, const cpl_array *colnames)
 
cpl_error_code sc_conv_ascii_write (const char *filename, const sctarr *tabdat)
 
cpl_error_code sc_conv_tarr_init (sctarr *tabdat, const int next)
 
cpl_error_code sc_conv_tarr_read (sctarr *tabdat, const char *filename)
 
cpl_error_code sc_conv_tarr_write (const char *filename, const sctarr *tabdat)
 
cpl_error_code sc_conv_tarr_delete (sctarr *tabdat)
 
cpl_error_code sc_conv_varr_init (scvarr *vecdat, const int next)
 
cpl_error_code sc_conv_varr_read (scvarr *vecdat, const char *filename)
 
cpl_error_code sc_conv_varr_write (const char *filename, const scvarr *vecdat)
 
cpl_error_code sc_conv_varr_delete (scvarr *vecdat)
 
cpl_error_code sc_conv_iarr_init (sciarr *imadat, const int next)
 
cpl_error_code sc_conv_iarr_read (sciarr *imadat, const char *filename)
 
cpl_error_code sc_conv_iarr_write (const char *filename, const sciarr *imadat)
 
cpl_error_code sc_conv_iarr_delete (sciarr *imadat)
 

Detailed Description

Routines for conversion of files

Author
Stefan Noll & ESO In-Kind Team Innsbruck
Since
16 Apr 2013
Date
31 Jan 2014

Definition in file sc_conv.c.

Function Documentation

◆ sc_conv_ascii_read()

cpl_error_code sc_conv_ascii_read ( sctarr tabdat,
const char *  filename,
const cpl_array *  colnames 
)

Fills CPL table of a sctarr structure by data read from an ASCII file. The number and names of the expected columns are provided by a CPL array. Header lines in the ASCII file are allowed if they are marked by '#'.

INPUT:

Parameters
filenamepath and name of input ASCII file
colnamesCPL array of column names for reading of ASCII file

OUTPUT:

Parameters
tabdatsctarr structure with data of ASCII file

ERRORS:

  • No data
  • File opening failed
  • Unexpected file structure

Definition at line 2114 of file sc_conv.c.

References sc_basic_readline(), sc_conv_tarr_delete(), sc_conv_tarr_init(), SC_LENLINE, SC_MAXLEN, and SC_MAXPAR.

◆ sc_conv_ascii_write()

cpl_error_code sc_conv_ascii_write ( const char *  filename,
const sctarr tabdat 
)

Writes the table data of an sctarr structure into an ASCII file. Only one extension is allowed. The column names are written into a header line starting with '#'. The routine supports the column types STRING, INT, FLOAT, and DOUBLE.

INPUT:

Parameters
filenamepath and name of output ASCII file
tabdatsctarr structure with tabulated data

ERRORS:

  • Invalid object structure
  • No data
  • File opening failed
  • see subroutines

Definition at line 2238 of file sc_conv.c.

References SC_LENLINE, and SC_MAXLEN.

◆ sc_conv_checkfitsformat()

cpl_error_code sc_conv_checkfitsformat ( int *  fitsformat,
const char *  filename 
)

Identifies the FITS type (table or image) by means of the header keyword XTENSION of the first FITS extension. If an extension is not present, the image format is assumed. The keyword NAXIS is used to distinguish between 1D, 2D, and 3D images. The routine returns 0 for non-FITS format (e.g. ASCII), 1 for FITS table, 2 for 1D FITS image, 3 for 2D FITS image, 4 for 3D FITS image, and -1 in the case of errors. It is assumed that all extensions have the same FITS type.

INPUT:

Parameters
filenamepath and name of input FITS file

OUTPUT:

Parameters
fitsformatflag for FITS format

ERRORS:

  • File opening failed
  • Unexpected file structure

Definition at line 47 of file sc_conv.c.

Referenced by sc_conv_iarr_read(), sc_conv_tarr_read(), and sc_conv_varr_read().

◆ sc_conv_erasemaskcol()

cpl_error_code sc_conv_erasemaskcol ( sctarr tabdat,
const cpl_parameterlist *  parlist 
)

Erases the integer mask column for SKYCORR in an sctarr structure. The column was created by sc_conv_modtable.

INPUT:

Parameters
tabdatsctarr structure with read data
parlistgeneral CPL parameter list

OUTPUT:

Parameters
tabdatsctarr structure without integer mask column

ERRORS:

  • No data
  • Invalid object structure

Definition at line 1206 of file sc_conv.c.

References SC_DEFMASKCOL, SC_LENLINE, and SC_MAXLEN.

◆ sc_conv_getmaskval()

cpl_error_code sc_conv_getmaskval ( double  maskval[2],
const sctarr tabdat,
const cpl_table *  extnames 
)

Gets the bad (maskval[0]) and good (maskval[1]) mask values from an :sctarr structure containing the data of the FITS table prepared for SKYCORR.

INPUT:

Parameters
tabdatsctarr structure with input data
extnamesCPL table with FITS extension numbers and names

OUTPUT:

Parameters
maskvalarray for bad and good mask value

ERRORS:

  • Invalid object structure
  • No data

Definition at line 1412 of file sc_conv.c.

References SC_DEFMASKCOL, SC_LENLINE, and SC_MAXLEN.

Referenced by sc_conv_resultstarr2varr().

◆ sc_conv_getwcskey()

double sc_conv_getwcskey ( const cpl_propertylist *  plist,
const char *  key 
)

Retrieves a FITS WCS key from a property list

INPUT:

Parameters
plistcpl_propertylist
keykey to retrieve

RETURN:

  • FITS WCS key

ERRORS:

  • CPL_ERROR_DATA_NOT_FOUND: key does not exist

Definition at line 669 of file sc_conv.c.

Referenced by sc_conv_varr2tarr().

◆ sc_conv_iarr2varr_sci()

cpl_error_code sc_conv_iarr2varr_sci ( scvarr vecdat,
cpl_vector *  selpix,
const sciarr imadat,
const cpl_table *  extnames,
const double  minrelprofflux 
)

Fills CPL vectors and CPL property lists of a scvarr structure by data read from a 2D FITS image with optional extensions for error, mask, and wavelength, and added in spatial direction. The image data is provided by a sciarr structure. The extension numbers and names are given by a CPL table. Extensions are not read if names are missing or wrong.

The flux summation only considers pixels with a flux of the spatial slit profile relative to the maximum value above a given minimum. Morover, only good pixels are added if a mask extension is provided. If pixels along the spatial direction are not considered, the summed flux is corrected by means of a model of the spatial flux distribution. The latter is derived from a projection of the 2D spectrum. If errors exist, they are added quadratically. Possible correlations of the pixels are not considered.

The effective number of pixels that are added up for each wavelength is output by means of an CPL vector. These data can be used to extract a corresponding 1D sky spectrum.

INPUT:

Parameters
selpixempty CPL vector
imadatsciarr structure with data of 2D FITS image
extnamesCPL table with FITS extension numbers and names
minrelproffluxminimum relative profile flux

OUTPUT:

Parameters
vecdatscvarr structure with summed data of 2D FITS image
selpixvector of effective pixel numbers

ERRORS:

  • Invalid input parameter(s)
  • No data
  • Invalid object structure
  • Invalid object value(s)
  • see subroutines

Definition at line 1515 of file sc_conv.c.

References sc_basic_getmaskval_image(), sc_conv_varr_delete(), sc_conv_varr_init(), SC_MAXLEN, and SC_TOL.

◆ sc_conv_iarr2varr_sky()

cpl_error_code sc_conv_iarr2varr_sky ( scvarr vecdat,
const sciarr imadat,
const cpl_table *  extnames,
const double  lowpixfrac,
const cpl_vector *  selpix 
)

Fills CPL vectors and CPL property lists of a scvarr structure by data read from a 2D FITS image with optional extensions for error, mask, and wavelength, and median-averaged in spatial direction. The image data is provided by a sciarr structure. The extension numbers and names are given by a CPL table. Extensions are not read if names are missing or wrong.

The median calculation only considers good pixels provided that a mask extension is provided. The input parameter lowpixfrac allows one to take a pixel in the sorted pixel list which deviates from the middle one (0.5). Values below 0.5 (full available range: 0 to 1) reduce the influence of spectra of bright objects on the calculation of the background median flux. The output flux is scaled to equal the sky flux for the input effective number of pixels provided by a CPL vector for each wavelength.

INPUT:

Parameters
imadatsciarr structure with data of 2D FITS image
extnamesCPL table with FITS extension numbers and names
lowpixfraccolumn-specific fraction of pixels with flux below selected pixel
selpixCPL vector of effective pixel numbers

OUTPUT:

Parameters
vecdatscvarr structure with median-averaged data of 2D FITS image

ERRORS:

  • Invalid input parameter(s)
  • Invalid object value(s)
  • No data
  • Invalid object structure
  • see subroutines

Definition at line 1843 of file sc_conv.c.

References sc_basic_getmaskval_image(), sc_conv_varr_delete(), sc_conv_varr_init(), SC_MAXLEN, and SC_MIN.

◆ sc_conv_iarr_delete()

cpl_error_code sc_conv_iarr_delete ( sciarr imadat)

Deletes an sciarr structure, which contains an array of CPL images and CPL property lists.

INPUT:

Parameters
imadatsciarr structure with 2D FITS image data

ERRORS:

  • none

Definition at line 2758 of file sc_conv.c.

◆ sc_conv_iarr_init()

cpl_error_code sc_conv_iarr_init ( sciarr imadat,
const int  next 
)

Initialises array of CPL images and CPL property lists as sciarr structure depending on the input number of FITS extensions.

INPUT:

Parameters
nextnumber of FITS extensions

OUTPUT:

Parameters
imadatempty sciarr structure for 2D FITS image data

ERRORS:

  • none

Definition at line 2650 of file sc_conv.c.

Referenced by sc_conv_iarr_read().

◆ sc_conv_iarr_read()

cpl_error_code sc_conv_iarr_read ( sciarr imadat,
const char *  filename 
)

Reads a 2D FITS image with an arbritrary number of extensions and puts the data into an sciarr structure consisting of an array of CPL images and CPL property lists.

INPUT:

Parameters
filenamepath and name of input 2D FITS image

OUTPUT:

Parameters
imadatsciarr structure with 2D FITS image data

ERRORS:

  • File opening failed
  • Unexpected file structure

Definition at line 2674 of file sc_conv.c.

References sc_conv_checkfitsformat(), sc_conv_iarr_init(), and SC_MAXLEN.

◆ sc_conv_iarr_write()

cpl_error_code sc_conv_iarr_write ( const char *  filename,
const sciarr imadat 
)

Writes data of an sciarr structure into a 2D FITS image. The number of FITS extensions depends on the content of the sciarr structure.

INPUT:

Parameters
filenamepath and name of output 2D FITS image
imadatsciarr structure with 2D FITS image data

ERRORS:

  • none

Definition at line 2724 of file sc_conv.c.

◆ sc_conv_modtable()

cpl_error_code sc_conv_modtable ( sctarr tabdat,
const cpl_parameterlist *  parlist 
)

Modifies data in sctarr structure in order to be consistent with requirements of SKYCORR. Only the first table extension is considered. The routine creates a column with the integer mask values 0 (rejected) and 1 (ok). By default, it is expected that input mask values agree with this definition. If other values are found, 0 is assumed to be ok and all other values cause pixel rejection. Possible nan in the flux and error columns are substituted by zero flux and indicated by mask = 0. The same is performed for negative errors. Finally, unreliable fluxes at the edges (defined by SC_EDGEFRAC) are masked.

INPUT:

Parameters
tabdatsctarr structure with read data
parlistgeneral CPL parameter list

OUTPUT:

Parameters
tabdatsctarr structure with modified data

ERRORS:

  • No data
  • Invalid object structure

Definition at line 787 of file sc_conv.c.

References SC_DEFFLUXCOL, SC_DEFLAMCOL, SC_DEFMASKCOL, SC_EDGEFRAC, SC_LENLINE, SC_MAXFLUXFAC, and SC_MAXLEN.

◆ sc_conv_readprepfits()

cpl_error_code sc_conv_readprepfits ( sctarr tabdat,
const cpl_parameterlist *  parlist 
)

Fills CPL table of a new sctarr structure by data read from a FITS table prepared for SKYCORR.

INPUT:

Parameters
parlistgeneral CPL parameter list

OUTPUT:

Parameters
tabdatsctarr structure with data of FITS file

ERRORS:

Definition at line 1067 of file sc_conv.c.

References sc_basic_abspath(), sc_conv_tarr_read(), and SC_MAXLEN.

◆ sc_conv_results2tarr()

cpl_error_code sc_conv_results2tarr ( sctarr tabdat,
cpl_table *  results 
)

Writes results from SKYCORR into an sctarr structure that already contains data from the input file. A new table column "scflux" is created, which contains the data from the "scflux" column of the results data table. If columns named "scdflux" and "scmask" exist in the results data table, they are also copied by using the same names for the output table.

INPUT:

Parameters
tabdatsctarr structure with data of FITS file prepared for SKYCORR
resultsCPL table with results of SKYCORR

OUTPUT:

Parameters
tabdatinput sctarr structure extended for SKYCORR results

ERRORS:

  • No data
  • Invalid object structure
  • Inconsistent data grids

Definition at line 1122 of file sc_conv.c.

References SC_MAXLEN.

◆ sc_conv_resultstarr2varr()

cpl_error_code sc_conv_resultstarr2varr ( scvarr vecdat,
const cpl_table *  extnames,
const sctarr tabdat 
)

Writes sky subtracted spectrum from SKYCORR into an scvarr structure representing a FITS image of the same format as the input data file.

INPUT:

Parameters
vecdatscvarr structure with data of input 1D FITS image
extnamesCPL table with FITS extension numbers and names
tabdatsctarr structure with input data and SKYCORR results

OUTPUT:

Parameters
vecdatscvarr structure with applied sky subtraction

ERRORS:

  • No data
  • Invalid object structure
  • Invalid object value(s)
  • Inconsistent data grids

Definition at line 1268 of file sc_conv.c.

References sc_conv_getmaskval(), and SC_MAXLEN.

◆ sc_conv_setcolnames()

cpl_error_code sc_conv_setcolnames ( cpl_array *  colnames,
const cpl_parameterlist *  parlist 
)

Gets column names for ASCII file from the general parameter list. The mandatory columns are wavelength and flux. Optionally, error and mask can also be provided. If this is not the case, this is indicated by 'NULL' in the parameter structure.

INPUT:

Parameters
colnamesempty CPL array for strings
parlistgeneral CPL parameter list

OUTPUT:

Parameters
colnamesCPL array of column names for reading of ASCII file

ERRORS:

  • none

Definition at line 164 of file sc_conv.c.

◆ sc_conv_setextnames_iarr()

cpl_error_code sc_conv_setextnames_iarr ( cpl_table *  extnames,
const sciarr imadat,
const cpl_parameterlist *  parlist 
)

Prepares CPL table with FITS extension numbers and names of a sciarr structure. Extension names are provided by the columns parameter of the driver file. The name "NONE" will be replaced by the default label for the data type.

INPUT:

Parameters
extnamesempty CPL table
imadatsciarr structure with data of 1D FITS image
parlistgeneral CPL parameter list

OUTPUT:

Parameters
extnamesCPL table with FITS extension numbers and names

ERRORS:

  • Invalid object structure
  • see subroutines

Definition at line 372 of file sc_conv.c.

References SC_DEFFLUXCOL, SC_DEFLAMCOL, SC_LENLINE, and SC_MAXLEN.

◆ sc_conv_setextnames_varr()

cpl_error_code sc_conv_setextnames_varr ( cpl_table *  extnames,
const scvarr vecdat,
const cpl_parameterlist *  parlist 
)

Prepares CPL table with FITS extension numbers and names of a scvarr structure. Extension names are provided by the columns parameter of the driver file. The name "NONE" will be replaced by the default label for the data type.

INPUT:

Parameters
extnamesempty CPL table
vecdatscvarr structure with data of 1D FITS image
parlistgeneral CPL parameter list

OUTPUT:

Parameters
extnamesCPL table with FITS extension numbers and names

ERRORS:

  • Invalid object structure
  • see subroutines

Definition at line 228 of file sc_conv.c.

References SC_DEFFLUXCOL, SC_DEFLAMCOL, SC_LENLINE, and SC_MAXLEN.

◆ sc_conv_tarr_delete()

cpl_error_code sc_conv_tarr_delete ( sctarr tabdat)

Deletes an sctarr structure, which contains an array of CPL tables and CPL property lists.

INPUT:

Parameters
tabdatsctarr structure with FITS table data

ERRORS:

  • none

Definition at line 2476 of file sc_conv.c.

Referenced by sc_conv_ascii_read(), and sc_conv_varr2tarr().

◆ sc_conv_tarr_init()

cpl_error_code sc_conv_tarr_init ( sctarr tabdat,
const int  next 
)

Initialises array of CPL tables and CPL property lists as sctarr structure depending on the input number of FITS extensions.

INPUT:

Parameters
nextnumber of FITS extensions

OUTPUT:

Parameters
tabdatempty sctarr structure for FITS table data

ERRORS:

  • none

Definition at line 2361 of file sc_conv.c.

Referenced by sc_conv_ascii_read(), sc_conv_tarr_read(), and sc_conv_varr2tarr().

◆ sc_conv_tarr_read()

cpl_error_code sc_conv_tarr_read ( sctarr tabdat,
const char *  filename 
)

Reads a FITS table with an arbritrary number of extensions and puts the data into an sctarr structure consisting of an array of CPL tables and CPL property lists.

INPUT:

Parameters
filenamepath and name of input FITS table

OUTPUT:

Parameters
tabdatsctarr structure with FITS table data

ERRORS:

  • File opening failed
  • Unexpected file structure

Definition at line 2385 of file sc_conv.c.

References sc_conv_checkfitsformat(), sc_conv_tarr_init(), and SC_MAXLEN.

Referenced by sc_conv_readprepfits().

◆ sc_conv_tarr_write()

cpl_error_code sc_conv_tarr_write ( const char *  filename,
const sctarr tabdat 
)

Writes data of an sctarr structure into a FITS table. The number of FITS extensions depends on the content of the sctarr structure.

INPUT:

Parameters
filenamepath and name of output FITS table
tabdatsctarr structure with FITS table data

ERRORS:

  • none

Definition at line 2442 of file sc_conv.c.

◆ sc_conv_varr2tarr()

cpl_error_code sc_conv_varr2tarr ( sctarr tabdat,
const scvarr vecdat,
const cpl_table *  extnames 
)

Fills CPL tables and CPL property lists of a sctarr structure by data read from a 1D FITS image with optional extensions for error, mask, and wavelength. The image data is provided by a scvarr structure. The extension numbers and names are given by a CPL table. Extensions are not read if names are missing or wrong. Images for different chips have to be converted separately.

INPUT:

Parameters
vecdatscvarr structure with data of 1D FITS image
extnamesCPL table with FITS extension numbers and names

OUTPUT:

Parameters
tabdatsctarr structure with data of FITS table

ERRORS:

  • No data
  • Invalid object structure
  • Invalid object value(s)

Definition at line 516 of file sc_conv.c.

References sc_conv_getwcskey(), sc_conv_tarr_delete(), sc_conv_tarr_init(), and SC_MAXLEN.

◆ sc_conv_varr_delete()

cpl_error_code sc_conv_varr_delete ( scvarr vecdat)

Deletes an scvarr structure, which contains an array of CPL vectors and CPL property lists.

INPUT:

Parameters
vecdatscvarr structure with 1D FITS image data

ERRORS:

  • none

Definition at line 2617 of file sc_conv.c.

Referenced by sc_conv_iarr2varr_sci(), and sc_conv_iarr2varr_sky().

◆ sc_conv_varr_init()

cpl_error_code sc_conv_varr_init ( scvarr vecdat,
const int  next 
)

Initialises array of CPL vectors and CPL property lists as scvarr structure depending on the input number of FITS extensions.

INPUT:

Parameters
nextnumber of FITS extensions

OUTPUT:

Parameters
vecdatempty scvarr structure for 1D FITS image data

ERRORS:

  • none

Definition at line 2509 of file sc_conv.c.

Referenced by sc_conv_iarr2varr_sci(), sc_conv_iarr2varr_sky(), and sc_conv_varr_read().

◆ sc_conv_varr_read()

cpl_error_code sc_conv_varr_read ( scvarr vecdat,
const char *  filename 
)

Reads a 1D FITS image with an arbritrary number of extensions and puts the data into an scvarr structure consisting of an array of CPL vectors and CPL property lists.

INPUT:

Parameters
filenamepath and name of input 1D FITS image

OUTPUT:

Parameters
vecdatscvarr structure with 1D FITS image data

ERRORS:

  • File opening failed
  • Unexpected file structure

Definition at line 2533 of file sc_conv.c.

References sc_conv_checkfitsformat(), sc_conv_varr_init(), and SC_MAXLEN.

◆ sc_conv_varr_write()

cpl_error_code sc_conv_varr_write ( const char *  filename,
const scvarr vecdat 
)

Writes data of an scvarr structure into a 1D FITS image. The number of FITS extensions depends on the content of the scvarr structure.

INPUT:

Parameters
filenamepath and name of output 1D FITS image
vecdatscvarr structure with 1D FITS image data

ERRORS:

  • none

Definition at line 2583 of file sc_conv.c.