Retrieve RA and DEC

104 views
Skip to first unread message

Fede

unread,
Jun 23, 2020, 10:09:03 AM6/23/20
to astrometry

Hi there, I'm using python to recover the coordinates of an image with nova.astrometry offline.
The results are shown in the picture.

How can I save the values of RA and DEC in a tdms file? 

I tried with 

radec = subprocess.call(...)
   with open("RADEC.tdms","w") as radecw:
   radecsave = radec['Field center']
   radecw.write(radecsave)

but it doesn't work. It returns 'int' object is not subscriptable.


Moreover, how can I solve RA and DEC for other point in the picture? As an asteroid or a satellite not in the center of the image?

Thank you.
Schermata 2020-06-23 alle 12.53.17.png

Dustin Lang

unread,
Jun 23, 2020, 10:13:44 AM6/23/20
to Fede, astrometry
subprocess.call() returns the return code of the program (0), not the text printed by the program.

If you want to convert other pixel locations in the image, not the center, then you should read the WCS file that is created, eg with astropy -- wcs_pix2world

cheers,
--dustin


--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/9ab5620f-fcd4-4265-ba39-5ec29b6eaae7o%40googlegroups.com.

Fede

unread,
Jun 23, 2020, 11:21:22 AM6/23/20
to astrometry
Thank you Dustin,
so what should I write in order to get the output as a string of the results of the processing?


Il giorno martedì 23 giugno 2020 16:13:44 UTC+2, Dustin Lang ha scritto:
subprocess.call() returns the return code of the program (0), not the text printed by the program.

If you want to convert other pixel locations in the image, not the center, then you should read the WCS file that is created, eg with astropy -- wcs_pix2world

cheers,
--dustin


On Tue, Jun 23, 2020 at 10:09 AM Fede <federica....@gmail.com> wrote:

Hi there, I'm using python to recover the coordinates of an image with nova.astrometry offline.
The results are shown in the picture.

How can I save the values of RA and DEC in a tdms file? 

I tried with 

radec = subprocess.call(...)
   with open("RADEC.tdms","w") as radecw:
   radecsave = radec['Field center']
   radecw.write(radecsave)

but it doesn't work. It returns 'int' object is not subscriptable.


Moreover, how can I solve RA and DEC for other point in the picture? As an asteroid or a satellite not in the center of the image?

Thank you.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.

Dustin Lang

unread,
Jun 23, 2020, 11:23:05 AM6/23/20
to Fede, astrometry
Read the subprocess page --
Code needing to capture stdout or stderr should use run() instead:


To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/19c6e545-fb43-4363-bf77-cf7f5f70200do%40googlegroups.com.

Fede

unread,
Jul 2, 2020, 8:48:36 AM7/2/20
to astro...@googlegroups.com
Hi Dustin, 
I tried to use wcs_pix2world as you suggested, but the output is exactly the pixels I'm giving as input...


Il giorno martedì 23 giugno 2020 16:13:44 UTC+2, Dustin Lang ha scritto:
subprocess.call() returns the return code of the program (0), not the text printed by the program.

If you want to convert other pixel locations in the image, not the center, then you should read the WCS file that is created, eg with astropy -- wcs_pix2world

cheers,
--dustin


On Tue, Jun 23, 2020 at 10:09 AM Fede <federica....@gmail.com> wrote:

Hi there, I'm using python to recover the coordinates of an image with nova.astrometry offline.
The results are shown in the picture.

How can I save the values of RA and DEC in a tdms file? 

I tried with 

radec = subprocess.call(...)
   with open("RADEC.tdms","w") as radecw:
   radecsave = radec['Field center']
   radecw.write(radecsave)

but it doesn't work. It returns 'int' object is not subscriptable.


Moreover, how can I solve RA and DEC for other point in the picture? As an asteroid or a satellite not in the center of the image?

Thank you.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.

Dustin Lang

unread,
Jul 2, 2020, 8:50:51 AM7/2/20
to Fede, astrometry
You're opening the .wcs file to create the astropy WCS object?

Maybe send your code and example WCS file you're using.


On Thu, Jul 2, 2020 at 8:48 AM Fede <federica.l...@gmail.com> wrote:
Hi Dustin, 
I tried to use wcs_pix2world as you suggested, but the output is exactly the pixel I'm given as input...
To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/6fdb5b0b-d46f-4df7-b91b-61e3f96dada5o%40googlegroups.com.

Leonardo Parisi

unread,
Jul 2, 2020, 9:01:35 AM7/2/20
to Dustin Lang, Fede, astrometry
This script work for me:

---------

import numpy as np
from astropy import wcs
from astropy.io import fits
import sys

hdulist = fits.open(sys.argv[1])

w = wcs.WCS(hdulist[0].header)

for coord in sys.argv[2:]:

  pixels = coord.split(',')

  #lon, lat = w.all_pix2world(float(pixels[0])+0.5, float(pixels[1])+0.5, 1) # pixel coord in FITS references frame
  lon, lat = w.all_pix2world(float(pixels[0])-0.5, float(pixels[1])-0.5, 0) # pixel coord in AstroPy references frame

  print(lon, lat)

-----

you can call as:

python3.7 world2pix.py {Astrometry solved fits file} x1,y1 x2,y2 xn,yn

The important part is in which reference frame the pixels coordinate as given.
In my example I use the standard image references frame with the origin in the top left corner

81183457-7b5d9200-8faf-11ea-951d-93961ef1f297.png
My be Dustin can confirm


Fede

unread,
Jul 3, 2020, 4:10:12 AM7/3/20
to astrometry
from astropy import wcs
from astropy.io import
fits

hdu_list
= fits.open('file')
hdu
= hdu_list[0].header
w
= wcs.WCS(hdu,hdu_list)
coordRA
,coordDEC = w.wcs_pix2world(x,y,1)
print(coordRA,coordDEC)


Where x,y are the px in the fits.



Il giorno giovedì 2 luglio 2020 14:50:51 UTC+2, Dustin Lang ha scritto:
You're opening the .wcs file to create the astropy WCS object?

Maybe send your code and example WCS file you're using.


Dustin Lang

unread,
Jul 3, 2020, 6:21:48 AM7/3/20
to Fede, astrometry
what is the 'file' you are opening?


To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/b1182044-b549-4128-b298-ac31136e9b03o%40googlegroups.com.

Fede

unread,
Jul 3, 2020, 7:07:59 AM7/3/20
to astro...@googlegroups.com
Ok I found the error, I needed to open the wcs file :) thank you!

Dustin Lang

unread,
Jul 3, 2020, 7:18:53 AM7/3/20
to Fede, astrometry
You have to read the staring.wcs file (or wcs.fits from the web site) if you want to run the WCS pixel/world conversions.



On Fri, Jul 3, 2020 at 7:08 AM Fede <federica.l...@gmail.com> wrote:
It is a FITS file, as 'staring.FITS'


--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages