sábado, 7 de marzo de 2026

Lectura de archivos fits desde consola de Linux y cómo usar esta información en scripts


Los ficheros fits archivos generados normalmente por las aplicaciones de captura de astrofotografía y usan un estándar de forma que son compatibles independientemente del programa/cámara que los haya generado.

Estos archivos no solo contienen la imagen obtenida por la cámara sino toda una serie de información relevante y que se añade a los datos de imagen. Son los denominados metadatos.

Los programas que procesan estos archivos usan estos metadatos para conocer por ejemplo, el tipo de imagen o la fecha en la que se realizó la captura.

En Linux tenemos una aplicación que permite acceder a esta información desde consola y así poderlo utilizar en nuestros propios scripts.

La utilidad se llama fitsheader y podemos instalarla así:

sudo apt install astropy-utils

Si lo ejecutamos pasándole como parámetro un archivo fits nos devolverá todos los metadatos disponibles:

fitsheader NGC_1893_1-2_final.fit 
# HDU 0 in NGC_1893_1-2_final.fit:
SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                  -32 / number of bits per data pixel                  
NAXIS   =                    3 / number of data axes                            
NAXIS1  =                 3856 / length of data axis 1                          
NAXIS2  =                 2180 / length of data axis 2                          
NAXIS3  =                    3 / length of data axis 3                          
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 
BZERO   =                   0. / Offset data range to that of unsigned short    
BSCALE  =                   1. / Default scaling factor                         
MIPS-FLO=                   0. / Lower visualization cutoff                     
PROGRAM = 'Siril 1.4.2'        / Software that created this HDU                 
DATE    = '2026-03-02T16:46:07' / UTC date that FITS file was created           
DATE-OBS= '2026-03-01T19:30:56.242000' / YYYY-MM-DDThh:mm:ss observation start, 
IMAGETYP= 'Light Frame'        / Type of image                                  
ROWORDER= 'BOTTOM-UP'          / Order of the rows in image array               
EXPTIME =                  90. / [s]  Exposure time duration                    
TELESCOP= 'Askar 71F 490@F\6.9' / Telescope used to acquire this image          
FOCALLEN=                 490. / [mm]  Focal length                             
CENTALT =             76.57907 / [deg] Altitude of telescope                    
CENTAZ  =             238.0605 / [deg] Azimuth of telescope                     
XBINNING=                    1 / Camera binning mode                            
YBINNING=                    1 / Camera binning mode                            
XPIXSZ  =                  2.9 / [um] Pixel X axis size                         
YPIXSZ  =                  2.9 / [um] Pixel Y axis size                         
INSTRUME= 'PlayerOne CCD Uranus-C' / Instrument name                            
CCD-TEMP=                 16.9 / [degC] CCD temperature                         
GAIN    =                  210 / Sensor gain                                    
OFFSET  =                   25 / Sensor gain offset                             
STACKCNT=                   42 / Stack frames                                   
LIVETIME=                3780. / [s] Exposure time after deadtime correction    
EXPSTART=     2461101.29767324 / [JD] Exposure start time (standard Julian date)
EXPEND  =      2461101.4302674 / [JD] Exposure end time (standard Julian date)  
OBJECT  = 'NGC 1893'           / Name of the object of interest                 
AIRMASS =             1.028037 / Airmass at frame center (Gueymard 1993)        
SITELAT =             41.37033 / [deg] Observation site latitude                
SITELONG=             2.087111 / [deg] Observation site longitude               
OBJCTRA = '5 22 56.49'         / [H M S] Image center Right Ascension           
OBJCTDEC= '33 23 26.88'        / [D M S] Image center Declination               
RA      =             80.73539 / [deg] Image center Right Ascension             
DEC     =              33.3908 / [deg] Image center Declination                 
HISTORY mean stacking with winsorized sigma clipping rejection (low=3.000 high=3
HISTORY .000), additive+scaling normalized input, normalized output, no image we
HISTORY ighting, equalized RGB, filter all                                      
HISTORY TOP-DOWN mirror                                                         
FRAME   = 'Light   '           / Frame Type                                     
APTDIA  =            7.100E+01 / Telescope diameter (mm)                        
SCALE   =         1.220959E+00 / arcsecs per pixel                              
PIERSIDE= 'EAST    '           / East, looking West                             
RADECSYS= 'FK5     '           / RADECSYS                                       
SECPIX1 =     1.2209592238E+00 / SECPIX1                                        
SECPIX2 =     1.2209592238E+00 / SECPIX2                                        
COMMENT Generated by INDI 
                 

Para ver un campo determinado de un archivo

fitsheader f95502336.fits | grep DATE-OBS

DATE-OBS= '2025-12-31T00:06:53.275' / UTC start date of observation 

Donde DATE-OBS es uno de los campos disponibles en los metadatos de la imagen

Con esta utilidad podemos hacer cosas tan interesantes como crear una lista con los archivos disponibles en una fecha específica:

grep -l 'DATE-OBS.*2025-12-31' *.fits > yesterday.list

Por ejemplo, si queremos separar una lista de fits según el tipo -light, biases, darks o flats-

  • Copiamos los archivos de la lista anterior a una carpeta

mkdir yesterdayxargs -a yesterday.list

cp --update=none -t yesterday

 cd yesterday 

  • Ahora separamos frames según el IMAGETYP: 'Light Frame', 'Bias Frame', 'Dark Frame', 'Flat Frame'
  • Buscamos las darks y las copiamos a una carpeta con ese nombre
mkdir darks
 
for f in *.fits; do
  fitsheader "$f" | grep -q 'IMAGETYP.*Dark' &&
  cp --update=none "$f" darks/
done 

  • Lo mismo para biases

mkdir biases 
 
for f in *.fits; do
  fitsheader "$f" | grep -q 'IMAGETYP.*Bias' &&
  cp --update=none "$f" biases/
done  

  • Y repetimos para flats

mkdir flats 
 
for f in *.fits; do
  fitsheader "$f" | grep -q 'IMAGETYP.*Flat frame' &&
  cp --update=none "$f" flats/ 
done   

No hay comentarios:

Publicar un comentario

Cómo limpiar la lente objetivo de tu refractor

Con el uso, las condiciones climáticas -viento, humedad- y entorno -polvo- nuestra lente objetivo acaba por acumular suciedad. En este post ...