3
$\begingroup$

I'm trying to write a Python program that will do the following: take an image in fits format and a reg file with a list of regions in the sky, and determine which regions in the list are inside the fits image and which ones are outside. This can be done visually with ds9, but I have no idea of how I can access the fits file and determine the coordinates of the boundary of the image.

Any advice? I don't know much about the fits format, but it won't open with a usual text editor like gedit.

Edit: Now I have a more specific problem. I have four points in the sky defined by their declination and right ascension. Is there a simple way to check if these coordinates belong to the image coded in the fits file?

Edit 2: This is what I see as the header of my fits file: enter image description here

I'm no expert in physics, just a mathematician, so I'm not sure how to proceed from here. Any help would be appreciated...

Edit 3: Something seems to change when I put the terminal in full screen mode. Is there any useful info here? enter image description here

$\endgroup$
  • 1
    $\begingroup$ You should be able to open a fits file with any text editor, like vim, Emacs, or even, god forbid, Word. Only the first part (the "header") which contains information about the data — e.g. the boundaries — will make sense to you, though. The image itself will look like gibberish. For reading the fits file in Python, have a look at astropy. From there is should be a simple for loop. $\endgroup$ – pela Mar 9 '17 at 8:58
  • $\begingroup$ Thank you so much! I could finally open the fits file with vim, no idea why gedit wasn't working. I will have a look at astropy, too! $\endgroup$ – Wild Feather Mar 9 '17 at 9:13
  • $\begingroup$ Just one question... You said I could find the information about the boundary of the image on the header of the fits file. But where, especifically? There are many variables there and I don't understand what all of them mean. $\endgroup$ – Wild Feather Mar 9 '17 at 9:14
  • $\begingroup$ Use the @ symbol and a users name to specifically tag them. They'll get a notification. Otherwise, they won't know you're trying to respond to them. In any case, we can't possibly know what variables are in your fits file header. That's like asking us the meaning of all the words in some random text file without showing us the text file. $\endgroup$ – zephyr Mar 9 '17 at 13:59
  • $\begingroup$ Oh, sorry, I forgot to add the tag. Thank you, @zephyr :) $\endgroup$ – Wild Feather Mar 9 '17 at 16:35
4
$\begingroup$

I personally use Astropy, specifically astropy.io.fits, although I'm not a seasoned user of FITS files and I don't really know their layout. As an example snippet of code, I often load data from FITS files using

from astropy.io import fits
data = fits.open('data_file.fits')[0].data

You'll find more information in the documentation on the FITS module.

$\endgroup$
  • $\begingroup$ Thank you. I'm going to edit my question, since I've had an idea for my program and the problem I'm having is now more specific. $\endgroup$ – Wild Feather Mar 9 '17 at 10:53
1
$\begingroup$
  1. There's no clear answer to this, it would all depend on your specific file, which of course we know nothing about. The information you need is likely going to exist in the fits header though (if it exists at all). I'm assuming you're reading your fits file using the astropy package since you're using Python (if not, definitely check it out). If that is the case, you can read all about looking at the fits file headers in the AstroPy documentation. You'll have to look at the header files and scan through to see if any information included with the fits file tells you precisely where in the sky the image is.
  2. No image is going to be "circular". Images are taken on square CCDs and thus produce square images of the sky. A "regular" image will be square.
$\endgroup$
1
$\begingroup$

There's also a software package, called DS9, which I use for viewing both the image and the header. I edit the headers in Python using astropy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.