<p>You can upload your FITS files to <a href="http://astrometry.net" rel="nofollow noreferrer">astrometry.net</a> (or use an API) and get the coordinates. You can optionally get new FITS files back with the coordinates included in the metadata. From there you will be able to proceed with your processing.</p>

<p>And, instead of uploading everything, you can also install a copy of the astrometry.net package locally if you're running Linux.</p>

CC BY-SA 3.0
2017-12-01T03:15:52.750Z
2017-12-01T03:15:52.750Z
Mick
<p>I did this exercise with IRAF by the functions geomap and geotran. There is PYRAF version of the IRAF, but I have never tried the python version. Using these routines, you can find the tranformation equation regardless of the header. What you need to know is some standard objects of known WCS and pixel coordinates.</p>

CC BY-SA 4.0
2018-06-06T13:31:58.867Z
2018-06-06T13:31:58.867Z
Kornpob Bhirombhakdi
<p>I'm trying to convert some pixel coordinates I have into WCS coordinates, ideally into a WCS region for use in some further analysis.</p>

<p>So far I've been able to load and parse a NuSTAR FITS file, do some analysis to make my selections and get the pixel coordinates for the image. For example, after my analysis I would end up having selected a rectangle of <code>x</code> values from pixels 480 to 518, and <code>y</code> values from 478 to 516.</p>

<p>After that I tried to use the astropy WCS module to convert them, but it doesn't seem to find the required data in the header to actually do the conversion and just says that pixel 480 gives coordinate 480. That or I'm just doing something wrong.</p>

<p>So I looked through the FITS header myself, found that some keys (<code>TCRPX</code>, <code>TCRVL</code>, <code>TCDLT</code>) give the reference pixel, reference pixel degree coordinate and pixel axis scale values.</p>

<p>But now I'm really stuck since what I need to get is a region file like those produced by ds9, in the format of:</p>

<pre><code># Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
fk5
circle(19:58:21.593,+35:11:57.46,10")
</code></pre>

<p>To then run this through the <code>nuproducts</code> tool.</p>

<p>TL;DR: Does anybody know how to convert the NuSTAR FITS physical pixel coordinates to FK5 coordinates?</p>

<hr>

<p>EDIT: Wrote some <a href="https://github.com/RobertRosca/MPhys-Project-Work/blob/master/FITS%20Coord%20Conversion.jl" rel="nofollow noreferrer">code to extract the coordinates</a>. It converts the pixel to degree fine, but converting the FK5 $\alpha$ angle to sexagesimal doesn't work correctly for... some reason.</p>

<hr>

<p>EDIT2: Everything works now, <a href="https://gist.github.com/RobertRosca/c91a124d29e26ada181b9bdea4d54169" rel="nofollow noreferrer">here's a notebook where I run through it all</a> in case anybody runs into a similar problem. I go through extracting the right-ascension and declination in degrees from the pixel coordinates given by the FITS file, then converting these degrees to sexagesimal (h:m:s) angles. From my tests it seems to work quite well, results are a tad off  due to what I assume are some floating point arithmetic errors.</p>

CC BY-SA 3.0
2017-12-07T12:19:35.100Z
What programming language do you work in? 
Furthermore, it is not entirely clear to me what you want as output, and I am unfamiliar with this 'nuproducts' tool. 
Why are the degrees, in which you have converted the pixel coordinates as you say in the EDIT, unsufficient?
user1991
CC BY-SA 3.0
2017-12-07T12:22:17.123Z
I'm working in Julia now. Basically, NuSTAR data has to be calibrated before it's suitable for scientific analysis and there are a few stages to that calibration, one of the stages requires you to select a source region (as a .reg file, usually created by manually selecting an area using DS9) before you get the final fully calibrated/cleaned data. The FITS files store data as X Y pixel coordinates, but the region file needs to be in WCS, so I convert X, Y to FK5 angles. Problem now is that for converting the angle I get in degrees (which is correct) to hh:mm:ss is different to what DS9 outputs
Robert Rosca
CC BY-SA 3.0
2017-12-07T15:07:25.677Z
How much is the discrepancy between DS9 output and what you get?
user1991
CC BY-SA 3.0
2017-12-07T16:22:22.933Z
Aha, figured out what I did wrong, I was being stupid and converting degrees to h:m:s as if they were angles on a circle, which doesn't work for right-ascension since it goes from -90 to 90, not 0 to 360. Now that I've fixed it ([here's a notebook where it works](https://gist.github.com/RobertRosca/c91a124d29e26ada181b9bdea4d54169)) it's still a bit off around 10^-5, but I guess that's just some floating point errors adding up along the way.
Robert Rosca
<observational-astronomy><coordinate><python><fits-header>
Converting FITS (NuSTAR) coordinates to WCS
Robert Rosca
# Converting FITS (NuSTAR) coordinates to WCS

(Asked by: username_0 on 2017-11-21)

I'm trying to convert some pixel coordinates I have into WCS coordinates, ideally into a WCS region for use in some further analysis.
So far I've been able to load and parse a NuSTAR FITS file, do some analysis to make my selections and get the pixel coordinates for the image. For example, after my analysis I would end up having selected a rectangle of x values from pixels 480 to 518, and y values from 478 to 516.
After that I tried to use the astropy WCS module to convert them, but it doesn't seem to find the required data in the header to actually do the conversion and just says that pixel 480 gives coordinate 480. That or I'm just doing something wrong.
So I looked through the FITS header myself, found that some keys (TCRPX, TCRVL, TCDLT) give the reference pixel, reference pixel degree coordinate and pixel axis scale values.
But now I'm really stuck since what I need to get is a region file like those produced by ds9, in the format of:
# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
fk5
circle(19:58:21.593,+35:11:57.46,10")

To then run this through the nuproducts tool.
TL;DR: Does anybody know how to convert the NuSTAR FITS physical pixel coordinates to FK5 coordinates?

EDIT: Wrote some code to extract the coordinates. It converts the pixel to degree fine, but converting the FK5 $\alpha$ angle to sexagesimal doesn't work correctly for... some reason.

EDIT2: Everything works now, here's a notebook where I run through it all in case anybody runs into a similar problem. I go through extracting the right-ascension and declination in degrees from the pixel coordinates given by the FITS file, then converting these degrees to sexagesimal (h:m:s) angles. From my tests it seems to work quite well, results are a tad off  due to what I assume are some floating point arithmetic errors.

**Tags:** observational-astronomy, coordinate, python, fits-header

> **Comments:**
> **username_1**: What programming language do you work in?  Furthermore, it is not entirely clear to me what you want as output, and I am unfamiliar with this 'nuproducts' tool.  Why are the degrees, in which you have converted the pixel coordinates as you say in the EDIT, unsufficient?  
> **username_0**: I'm working in Julia now. Basically, NuSTAR data has to be calibrated before it's suitable for scientific analysis and there are a few stages to that calibration, one of the stages requires you to select a source region (as a .reg file, usually created by manually selecting an area using DS9) before you get the final fully calibrated/cleaned data. The FITS files store data as X Y pixel coordinates, but the region file needs to be in WCS, so I convert X, Y to FK5 angles. Problem now is that for converting the angle I get in degrees (which is correct) to hh:mm:ss is different to what DS9 outputs  
> **username_1**: How much is the discrepancy between DS9 output and what you get?  
> **username_0**: Aha, figured out what I did wrong, I was being stupid and converting degrees to h:m:s as if they were angles on a circle, which doesn't work for right-ascension since it goes from -90 to 90, not 0 to 360. Now that I've fixed it ([here's a notebook where it works](https://gist.github.com/RobertRosca/c91a124d29e26ada181b9bdea4d54169)) it's still a bit off around 10^-5, but I guess that's just some floating point errors adding up along the way.  

---

## 2 answers

### Answer by username_2 on 2017-12-01. Score: 1

You can upload your FITS files to [astrometry.net](http://astrometry.net) (or use an API) and get the coordinates. You can optionally get new FITS files back with the coordinates included in the metadata. From there you will be able to proceed with your processing.

And, instead of uploading everything, you can also install a copy of the astrometry.net package locally if you're running Linux.


---

### Answer by username_3 on 2018-06-06. Score: 1

I did this exercise with IRAF by the functions geomap and geotran. There is PYRAF version of the IRAF, but I have never tried the python version. Using these routines, you can find the tranformation equation regardless of the header. What you need to know is some standard objects of known WCS and pixel coordinates.


---

