My Coding >
Programming language >
Python >
Python libraries and packages >
Astropy >
Reading FITS files with astropy
Reading FITS files with astropyAbout FITSFITS stands for Flexible Image Transport System, a standard file format widely used in astronomy for storing, transmitting, and processing scientific data, particularly images and tables. The key components of a FITS file are Header Data Units (HDUs). Each FITS file can contain one or more HDUs, and each HDU consists of a header and optional data. About HDUThere are two main types of HDUs:
Reading and displaying FITS fileIn this article, I will show how to extract image data from the FITS file on the example of the SDO telescope. It is possible to download this FITS file here:
First of all, we need to load all required libraries. astropy.io - for reading FITS file and optionally astropy.visualization for improving style of image displaying.
The next step is reading the file and printing the number of HDU blocks inside. FITS file should have a primary HDU block and all other blocks are optional. From this file, we extract the header and data. Now data have an image we will analyze further. It is important to remember to close the opened file
After closing the file, we still can have access to the header and data, and the code given below should not cause any error, but it is not recommended to do this. After closing the file, only the block from the memory is available. And everything else is unavailable. As you know, some astronomical images can be too big to be read completely to the memory. Therefore, I do advise you not to use closed files, but rather extra information prior to closure. The header has all information about an image
This is the correct way of checking the size of the image. You can see that this is a monochrome image, which corresponds to the one-wavelength data collection. 171 Å, as you can see from the header lines WAVELNTH= 171 and WAVEUNIT= 'angstrom'.
Let's display this image with the imshow function.
You should have something like this image:
To make the image fit astronomical standards, it is a good idea to apply astropy_mpl_style from the astropy.visualization library:
Now you will have something like this:
Now we can analyze the intensity along some direction, but this is not very meaningful. For example, this is a slice along x=600. This slice is not good for scientific analysis of the data but can be useful for technical or test purposes.
the result will be similar to this one:
A better way to analyze some features of the image is to use the total intensity of the thin layers of the image. For example, around the area with x=100, I've noticed some bright spots and want to check them. For this, I will do a slice from 50 to 150 and make a sum along axis=0.
The full code at once is given below, and for test purposes, I do advise you to use Jupyter Notebook.
|
Last 10 artitles
9 popular artitles
|
|||||||||||
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |