簡體   English   中英

如何使用pyds9通過python在ds9中將圓形區域的顏色從綠色更改為紅色

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

我正在使用pyds9自動加載擬合圖像(出於與天文學有關的目的)。

我可以配置所有其他設置,例如比例,顏色和縮放級別。 對於每個圖像,我想要做的是在特定位置繪制一個小圓圈以突出顯示該區域。 默認情況下,此顏色為綠色。 如何更改此顏色?

還有辦法改變這個圓的粗細嗎? 我的知名度有問題。 對於所有cmap和比例尺組合,綠色不是清晰可見。 像紅色這樣的東西會更好。

我看着XPAset命令。 有一種方法可以做到。 但是我不知道如何在pyds9中做到這一點。 這是所有XPAset命令的鏈接: http ://ds9.si.edu/ref/xpa.html#regions

xpaset命令是:

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

如何將此xpaset命令轉換為pyds9的d.set()方法?

我的意思是: d.set('regions','fk5; circle(100,100,20") # color=red')

以下是我正在使用的代碼:

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')

[顯然,我不允許在前面的答案中添加注釋,因此這是上面的另一個答案]。

我們對此進行了調查,該區域的“命令”語法似乎有一個錯誤。 相反,您應該使用規范的xpa語法,在該語法中,您將在參數列表中傳遞字符串“ regions”,並在數據緩沖區中傳遞實際的區域字符串。 在unix shell中,將按照以下步驟進行操作:

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

數據將發送到xpaset的stdin,並將參數列表放在目標后面的命令行上。

在python中,操作如下:

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

在這里,第一個參數是參數列表(“區域”),第二個參數是要發送到DS9的數據緩沖區,在這種情況下,它包含區域字符串。

如上所見,您可以使用雙引號指定以弧秒為單位的區域,以弧秒為單位。 您可以查看區域規范以獲得更多語法信息:

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

最后,抱歉,但是無法從Shell或pyds9編輯區域。

這個pyds9命令將起作用:

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

請注意,我只是從xpaset命令語法中刪除了單引號。 正確使用引號有點令人困惑:在xpaset shell命令中,您需要單引號來保護打開的“ {”括號,但是python中不需要。 還要注意,它們全都在一個字符串中(從技術上講,這是region參數列表的一部分-請參閱xpa文檔)。

問候,

埃里克

PS可以考慮以下xpa命令與上面最初使用的命令一樣有效,這可能會使事情更加清楚:

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

在這里,在整個字符串周圍使用單引號可以保護unix外殼的右括號,同時強調參數列表作為單個字符串的本質。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM