简体   繁体   中英

How to change the color of the circular region from green to red in ds9 through python using pyds9

I am using pyds9 to automatically load the fits images (for astronomy-related purposes).

I am able to configure all the other settings like scale, color and zoom level. For each image what I want to do is draw a small circle in a particular location that highlights that region. By default this color is green. How do I change this color?

Also is there a way to change the thickness of this circle? I am having issues with visibility. The green color is not clearly visible for all cmap and scale combination. Something like red would be better.

I looked at the XPAset commands. There is a way to do it. But I can't figure out how to do it in pyds9. Here is the link for all the XPAset commands: http://ds9.si.edu/ref/xpa.html#regions

The xpaset command is :

*$xpaset -p ds9 regions command '{circle 100 100 20 # color=red}'*

How do I translate this xpaset command to pyds9's d.set() method ??

I mean something like : d.set('regions','fk5; circle(100,100,20") # color=red')

Following is the code that I am using:

import ds9

# x is the RA and y is the DEC 
# for describing the location of astronomical objects
x = 200.1324
y = 20.3441

# the four FITS images to be loaded
image_list = ['img1.fits.gz','img2.fits.gz','img3.fits.gz','img4.fits.gz']

#initializing a ds9 window
d = ds9.ds9(target='DS9:*', start=True, verify=True)

for i in range(len(image_list)):
    d.set('frame ' + str(i+1))
    d.set('file ' + image_list[i])
    d.set('cmap bb')
    d.set('cmap invert')
    d.set('scale zscale')
    d.set('scale linear')
    d.set('regions','fk5; circle('+str(x)+','+str(y)+',20")')
    # This previous line draws a green circle with center at (x,y) 
    # and radius of 20 arc-sec. But the color is by default green. 
    # I want to change this to lets say red. How do I do it ???


# arranging the 4 images in tile format
d.set('tile') 
for i in range(len(image_list)):
    d.set('frame ' + str(i+1))
    d.set('zoom to fit')

d.set('saveimage png myimagename.png')

# time to remove all the images from the frames
# so that the some new set of images could be loaded
for i in range(len(image_list)):
    d.set('frame delete')

[Apparently, I'm not permitted to add comments to the previous answer, so here is another answer that goes with the above].

We looked into this, and the region "command" syntax appears to have a bug in it. Instead, you should use canonical xpa syntax, in which you pass the string "regions" in the paramlist and the actual region string in the data buffer. In the unix shell, this would be done as follows:

echo 'fk5; circle 23:23:22.176 +58:50:01.23 9.838" # color=red' | xpaset ds9 regions

The data is sent to xpaset's stdin and the paramlist is placed on the command line, after the target.

In python, this is done as follows:

d.set('regions', 'fk5; circle 23:23:22.176 +58:50:01.23 9.838" # color=red')

Here, the first argument is the paramlist ("regions") and the second argument is the data buffer to send to DS9, in this case containing the region string.

As you see above, you can send a region with arc-second size units using a double-quote to specify arc-seconds. You can look at the regions specification for more syntactic info:

https://www.cfa.harvard.edu/~john/funtools/regions.html

Finally, and sorry, but it's not possible to edit a region from the shell or pyds9.

This pyds9 command will work:

d.set("regions command {circle 512 512 20 # color=red}")

Note that I simply removed the single quotes from your xpaset command syntax. Getting the quotes right is a little confusing: in the xpaset shell command, you need the single quotes to protect the open "{" bracket but this is not needed in python. Also note that it's all in one string (which technically is part of the regions paramlist -- see the xpa documentation).

Regards,

Eric

PS It might make things more clear to consider that the following xpa command works as well as the one you originally used above:

xpaset -p ds9 'regions command {circle 512 512 20 # color=red}'

Here, the use of single quotes around the entire string protects the open bracket from the unix shell, while emphasizing the nature of the paramlist as a single string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM