Couple of API questions

56 views
Skip to first unread message

obser...@stratis.co.uk

unread,
Jan 13, 2019, 12:15:44 PM1/13/19
to astrometry
Starting to use the API from Python for the first time, using the Client script.  I can't find much documentation but the script is fairly easy to understand. However I have a couple of basic questions which maybe someone can help with:

1. If I solve by uploading a FITS file (using Client.upload) how do I then download the solved file, with the FITS header updated with the WCS info?

2. Alternatively, if I solve by uploading an x,y text file of extracted star pixel coords (also using Client.upload) how do I get the WCS info, including distortion coefficients, into the FITS header of my original image file? Which send_request method should I use to retrieve this data and is there a preferred way of updating the FITS headers with it? (I can roll my own but I'm hoping there's an existing function that does this).

Many thanks

Nigel Brooks
Stratis Observatory

Stratis Observatory

unread,
Jan 13, 2019, 2:52:11 PM1/13/19
to astrometry
OK I've solved the downloading - the link to the api documentation on the astrometry.net site at http://nova.astrometry.net/api_help doesn't allow access but I finally found the docs via the readme on github.

I'm still looking for advice on how best to update the wcs in a fits file with what I download from astrometry.net.

I can download the wcs.fits file after solving but I need a Python function that will put that wcs data into a FITS image file (overwriting any wcs that's already there).

Any pointers very gratefully received.

Nigel

Dustin Lang

unread,
Jan 13, 2019, 4:01:20 PM1/13/19
to astrometry
In the Astrometry.net code there is a "new-wcs" program for plugging a WCS header file into an image.

cheers,
--dustin

Stratis Observatory

unread,
Jan 13, 2019, 10:01:07 PM1/13/19
to astrometry
Many thanks Dustin. However as I don't really want to get into C I'll probably roll my own using astropy.WCS class methods which I've been checking out today.

Nigel

Dustin Lang

unread,
Jan 14, 2019, 7:24:44 AM1/14/19
to astrometry
Fair enough; with astropy, you could also work at the FITS header level -- I think you should be able to read in the image (in read/write mode), read in the WCS header, and plug most of the WCS headers into the image header, and write the image to a new out file, and that'll do it.  Omit SIMPLE, BITPIX, NAXIS, NAXIS1, NAXIS2, but keep the rest.

cheers,
--dustin

Stratis Observatory

unread,
Jan 14, 2019, 9:11:25 AM1/14/19
to astrometry
Great minds think alike.  Just what I did earlier.  Seems to work.

def update_wcs(input_image, astrometry_data, output_image=None):
   
# Adds or updates the astrometry data in input_image from
   
# astrometry_data. If output_image is not specified then
   
# input_image is updated in-situ and resaved,
   
# otherwise the updated file is copied to output_image
   
# and input_image is unchanged.
   
#
   
# astrometry_data is assumed to be a minimal FITS file
   
# (e.g. as returned by astrometry.net after plate-solving).
   
#
   
# Mandatory FITS cards are ignored (don't want to change them).
   
# Where other keys match the existing card is updated.
   
# Where astrometry_data contains new keys those cards are added.
   
# All other existing cards in input_image are retained unchanged.
   
#
   
# Input:    input_image         String. File path/name of
   
#                               existing FITS file.
   
#
   
#           astrometry_data     String. File path/name of  
   
#                               FITS file containing astrometry
   
#                               cards in hdu0 header.
   
#          
   
#           output_image        Optional string. File path/name
   
#                               where updated file is to be copied.
   
#
   
# Output:   Updated input_image file (if output_image not
   
#           specified) or updated copy of input_image file
   
#           saved to output_image (overwrites any existing).


   
from astropy.io import fits
    image_file
= fits.open(input_image)
    astrometry_file
= fits.open(astrometry_data)
    new_cards
= list([])
   
for card in astrometry_file[0].header.cards:
       
if (not(card[0] in ['SIMPLE','BITPIX','END']) and
           
not(card[0][:5] == 'NAXIS')):
            new_cards
.append(tuple(card))
    image_file
[0].header.update(new_cards)
   
if output_image is None:
        image_file
.writeto(input_image)
   
else:
        image_file
.writeto(output_image)
   
return
Reply all
Reply to author
Forward
0 new messages