Provides a set of file I/O routines.
Copyright © 2019, SDSS-IV/MaNGA Pipeline Group
- mangadap.util.fileio.channel_dictionary(hdu, ext, prefix='C')
Construct a dictionary of the channels in a MAPS file.
- mangadap.util.fileio.channel_units(hdu, ext, prefix='U')
Construct an array with the channel units.
- mangadap.util.fileio.compress_file(ifile, overwrite=False, rm_original=False)
Compress a file using gzip. The output file has the same name as the input file with ‘.gz’ appended.
Any existing file will be overwritten if overwrite is true.
An error is raised if the input file name already has ‘.gz’ appended to the end.
Create a symlink to the input file in the provided directory. If relative_symlink is True (default), the path to the file is relative to the directory with the symlink.
- mangadap.util.fileio.init_record_array(shape, dtype)
Utility function that initializes a record array using a provided input data type. For example:
dtype = [ ('INDX', int, (2,) ), ('VALUE', float) ]
Defines two columns, one named INDEX with two integers per row and the one named VALUE with a single float element per row. See numpy.recarray.
tuple) – Shape of the output array.
list) – List of the tuples that define each element in the record array.
Zeroed record array
- Return type:
- mangadap.util.fileio.read_template_spectrum(filename, data_ext=0, ivar_ext=None, sres_ext=None, log10=False)
Read a template spectrum.
Template spectra are “raw format” files with template data and are, at minimum, expected to have the following components:
hdu.header['CRVAL1'] hdu.header['CRPIX1'] hdu.header['CDELT1'] hdu[data_ext].data
The latter has the flux data. If
log10is true, the wavelength solution above is expected to be in log wavelengths.
str) – Name of the fits file to read.
str, optional) – Name of the extension with the flux data.
str, optional) – Name of the extension with the inverse variance data. If None, no inverse data are returned.
str, optional) – Name of the extension with the spectral resolution (:math:R=lambda/deltalambda`) measurements. If None, no spectral resolution data are returned.
bool, optional) – Flag the WCS wavelength coordinates as being in base-10 log wavelength, instead of linear. Default is to assume linear.
Up to four vectors with the wavelength, flux, inverse variance (if ivar_ext is provided), and spectral resolution (if sres_ext is provided) of the template spectrum.
- Return type:
ValueError – Raised if fits file is not one-dimensional.
KeyError – Raised if various header keywords or extension names are not available.
- mangadap.util.fileio.readfits_1dspec(filename, log10=False)
Read a 1D fits spectrum and return two vectors with the wavelength and flux.
str) – Name of the file to read.
Two numpy.float64 arrays with the wavelength and flux read for the spectrum.
- Return type:
ValueError – Raised if the input fits file has more than one extension or its primary extension has more than two dimensions.
Return the string representation of the dimensions for the fits table column based on the provided record array element.
The shape is inverted because the first element is supposed to be the most rapidly varying; i.e. the shape is supposed to be written as row-major, as opposed to the native column-major order in python.
Return the string representation of a fits binary table data type based on the provided record array element.
- mangadap.util.fileio.wavelength_vector(npix, header, log10=False)
Return a vector with wavelength coordinates drawn from the WCS coordinates in the header. The function uses CRVAL1, CRPIX1, CDELT1.
- mangadap.util.fileio.writefits_1dspec(ofile, crval1, cdelt1, flux, hdr=None, overwrite=False)
Write a simple one-dimensional spectrum.
str) – Name of the file to write.
float) – (Log base 10 of the) Initial wavelength, which is included in the header with the keyword ‘CRVAL1’; ‘CRPIX1’ is always set to 1.
float) – The change in (log base 10) wavelength per pixel, which is included in the header with the keywords ‘CDELT1’ and ‘CD1_1’; ‘CRPIX1’ is always set to 1.
flux (numpy.ndarray) – Vector of the flux values.
hdr (astropy.io.fits.Header, optional) – Include sampling data in this header instead of beginning with an empty header.
bool, optional) – Flag to overwrite any existing file of the same name.