0 votes
151 views
Hello, I would like to access the header information from an archived exposure without downloading the image. Is this possible?

Cheers
by | 151 views

1 Answer

0 votes

Hi Aurelio, thanks for reaching out. I assume your question means "... when using the datalab notebook interface".

The two ways to access metadata about images are from the SIA search results themselves (which come as a table). The columns in SIA are populated  by our metadata scraper which reads in the FITS headers. But almost certainly that information is selective, and not all FITS header cards are in that database. For examples how to search for images using SIA, check out for instance this notebook:

https://github.com/astro-datalab/notebooks-latest/blob/master/04_HowTos/SiaService/How_to_use_the_Simple_Image_Access_service.ipynb

The other way to access proper fits header is of course to get them from the file. If a FITS file is directly in your NB area, you could just do:

from astropy.io import fits
header = fits.getheader('D00371352_r_c49_r3539p01_immasked.fits.fz',ext=0)
header

SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                   16 / number of bits per data pixel                  
NAXIS   =                    0 / number of data axes                            
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 
CHECKSUM= '2bG83b972bG72b97'   / HDU checksum updated 2018-10-10T00:14:54       
DATASUM = '         0'         / data unit checksum updated 2018-10-10T00:14:54

This does not copy the entire file.

If the FITS file is in a FIle Service or or a VOSpace instead, we need to fetch the file first and then extract the header. But if you do this on the DL noteboook server, it's pretty quick (and you don't need to make intermediate copies, but can do all in-RAM). Example:

from io import BytesIO
# get the file one time
f = BytesIO(sc.get('des_dr2://dr2_se/finalcut/Y5A1/r3539/20141025/D00371352/p01/red/immask/D00371352_r_c49_r3539p01_immasked.fits.fz'))

# access the header info of ext=0
f.seek(0)
header0 = fits.getheader(f,ext=0)

# or of ext=1
f.seek(0)
header1 = fits.getheader(f,ext=1)

Hope this is helpful. Let us know if you any further questions.

by robertdemo (7.9k points)

415 questions

432 answers

437 comments

635 users

Welcome to Data Lab Help Desk, where you can ask questions and receive answers from other members of the community.

Categories