how can i read a use a fits file?

3 visualizaciones (últimos 30 días)
majid husseini
majid husseini el 9 de Feb. de 2021
Respondida: Asvin Kumar el 12 de Feb. de 2021
1) reads spectrum array from this file;
2) reads keywords from the header of this file and using these keywords computes the wavelength array according to the formula I provided;
3) plots on the screen spectrum vs. wavelength for the wavelength
file contains the header and a single array (spectrum). Wavelengths can be calculated from the keywords NAXIS1, CDELT1, CRVAL1 in the header:
Wavelength = exp( array[0:NAXIS1-1] * CDELT1+CRVAL1 )
"array[0:NAXIS1-1]" is an integer array from 0 to NAXIS1-1 with a step of 1.

Respuesta aceptada

Asvin Kumar
Asvin Kumar el 12 de Feb. de 2021
I think what you're looking for are the fitsread and fitsinfo functions.
There are examples in the doc pages for the both the functions. Here's another: https://www.mathworks.com/help/matlab/import_export/importing-flexible-image-transport-system-fits-files.html
As mentioned in the fitsinfo doc page, the keywords NAXIS1, CDELT1, CRVAL1 which you're looking for are under the Keywords property of the PrimaryData structure in the returned info structure.
Here's an example adapted from the one linked above:
info = fitsinfo('tst0012.fits')
info =
struct with fields:
Filename: '/local-ssd/asvenkat/MATLAB/toolbox/matlab/demos/tst0012.fits'
FileModDate: '13-Mar-2001 05:07:46'
FileSize: 109440
Contents: {1×5 cell}
PrimaryData: [1×1 struct]
BinaryTable: [1×1 struct]
Unknown: [1×1 struct]
Image: [1×1 struct]
AsciiTable: [1×1 struct]
info.PrimaryData.Keywords
ans =
25×3 cell array
{'SIMPLE' } {'T' } {' Standard FITS file …'}
{'BITPIX' } {[ -32]} {' No. of bits per pixel …'}
{'NAXIS' } {[ 2]} {' No. of axes in matrix …'}
{'NAXIS1' } {[ 102]} {' No. of pixels in X …'}
{'NAXIS2' } {[ 109]} {' No. of pixels in Y …'}
{'EXTEND' } {'T' } {' There may be FITS extensions …'}
{'BLOCKED'} {'T' } {' The file may be blocked …'}
{0×0 char } {0×0 char } {0×0 char }
{'CDELT1' } {[ 3.1000]} {' Coordinate increment …'}
{'CRVAL1' } {[ 1.2991e+03]} {' Coordinate of reference pixel …'}
{'CRPIX1' } {[ 12.3000]} {' Reference pixel in X …'}
{0×0 char } {0×0 char } {0×0 char }
{'CDELT2' } {[ -0.1700]} {' Coordinate increment …'}
{'CRVAL2' } {[ -102.4000]} {' Coordinate of reference pixel …'}
{'CRPIX2' } {[ -2.0318e+03]} {' Reference pixel in Y …'}
{0×0 char } {0×0 char } {0×0 char }
{'OBJECT' } {'Wave 32-bit FP'} {' Name of image …'}
{'ORIGIN' } {'ESO' } {' File was prepared at ESO-Garching …'}
{'DATE' } {'20/08/92' } {' Creation data of this file …'}
{0×0 char } {0×0 char } {0×0 char }
{'COMMENT'} {0×0 char } {' This test file was created by P.Grosbol, ES…'}
{0×0 char } {0×0 char } {0×0 char }
{'COMMENT'} {0×0 char } {' Simple 32-bit FP sine wave pattern for test…'}
{0×0 char } {0×0 char } {0×0 char }
{'END' } {0×0 char } {0×0 char }

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by