taskGNU Astronomy Utilities - Tasks: task #14409, Polygon vertices from a DS9 region...


You are not allowed to post comments on this tracker with your current authentication level.

task #14409: Polygon vertices from a DS9 region file

Submitted by:  Mohammad Akhlaghi <makhlaghi>
Submitted on:  Thu 16 Mar 2017 10:50:31 PM UTC  
Should Start On:  Thu 16 Mar 2017 03:00:00 PM UTC Should be Finished on:  Thu 16 Mar 2017 03:00:00 PM UTC
Category:  Crop Priority:  5 - Normal
Item Group:  Enhancement Status:  Postponed
Privacy:  Public Percent Complete:  0%
Assigned to:  None Open/Closed:  Open
Effort:  0.00

Thu 16 Mar 2017 10:50:31 PM UTC, original submission:  

Allow users to use a file for polygon vertices instead of having to type all the coordinates in by hand. Typing coordinates (especially for larger number of vertices) can be prone to errors and is frustrating.

However, in GUI tools like SAO DS9, we can easily define a polygon region on the image and save the vertices into a file with specific formats. So when the input is a file name (not a string of numbers), Crop can parse the output of DS9 directly and users don't have to deal with the actual numbers. This will greatly speed up the process and reduces chances of error.

Until then, a script like this can be used to read the DS9 region file (saved in the `ds9' format in `fk5', see P.S. below) and prepare it for Crop (new name for ImageCrop) as a shell variable):

$ v=$(awk 'NR==4' ds9.reg | sed -e's/polygon(//'        \
           -e's/\([^,]*,[^,]*\),/\1:/g' -e's/)//' )
$ astimgcrop --mode=wcs image.fits --polygon=$v

This task was suggested by Guillaume Mahler.


To define a region file in SAO DS9, you can take the following steps: Open the image with DS9 and activate its "Region" mode with "Edit --> click --> Region". Then define the region to be a polygon with "Region --> Shape --> Polygon". Click on the approximate center of the region you want and a small square will appear. By clicking on the vertices of the square you can shrink or expand it, clicking and dragging anywhere on the edges will enable you to define a new vertice.

After the region has been nicely defined, save it as a file with "Region --> Save" Regions. You can then select the name and address of the output file, keep the format as "REG" and press "OK". In the next window, keep format as "ds9" and "Coordinate System" as "fk5". A plain text file (let's call it `ds9.reg') is now created that you can feed into the script above.

Mohammad Akhlaghi <makhlaghi>
Project Administrator


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by makhlaghi (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.5