I made a lot of notes on image rendering when I was developing the VIRUS and HET footprint display stuff. Since I loose track of these notes ($tdata/T_runs/Image_Render/ex0_n3379/S) I went ahead and collected them here.
README file in $tdata/T_runs/Image_Render/ex0_n3379/S
FILE = ../README.ds9+xpa:
General notes on ds9+xpa and other stuff.
=========================================
Use grab1 to get the N3379 B image (n3379_B.fits)
Some info on this stuff can be seen at:
http://ds9.si.edu/doc/ref/xpa.html
To open ds9:
% ds9_open 800 800
To view the image:
% imlook n3379_B.fits 30
User z2 = 496.890
To make jpeg image file:
xpaset -p ds9 saveimage jpeg a.jpeg 75
To make png image file:
xpaset -p ds9 saveimage a.png
To measure the size of the a.png file:
% identify a.png
a.png PNG 800x591 800x591+0+0 8-bit DirectClass 382KB 0.000u 0:00.000
N.B. identify is ImageMagic routine
>>>>> May be useful for making *.png of a specific size! <<<<
Turn the colorbar off
% xpaset -p ds9 view colorbar no
Turn it back on:
% xpaset -p ds9 view colorbar yes
NOTE: You can use this to turn off all kinds of shit!
To cut a portion of image with WCS preserved:
% getfits -o sub.fits n3379_B.fits 420-1078 839-1269
====================================================================
Image sizes:
What started this exercise was the idea of creating png files that
could easily be fed to python matplotlib codes to make better image
graphics. One of the first things I realized was that I could turn
off some of the ds9 display features and get a much better png file
for embedding in a python plot. In the course of this, I could learn
some things about displaying and printing images at specific scale
sizes (i.e. so many pixels per inch).
-----------------------------------------------------------
I use the image n3379_B.fits
What is the size?
% ccdsize n3379_B.fits
1992 1992
**** So, I have a square image.
To see the image:
% ds9_open 800 800
% imlook n3379_B.fits 30
When do I get a square window? I turn off things:
xpaset -p ds9 view colorbar no
xpaset -p ds9 view magnifier no
xpaset -p ds9 view panner no
xpaset -p ds9 view info no
xpaset -p ds9 view buttons no
When I turn all of these off, I have a viewing window of size
218mm x 205mm and when I use "Zoom to Fit Frame" I see the
excess white space on the x dimension. Moreover, when I used:
xpaset -p ds9 saveimage a.png
I see the excess white space there also. When I use identify:
% identify a.png
a.png PNG 800x751 800x751+0+0 8-bit DirectClass 677KB 0.000u 0:00.000
So, the ds9_open command with 800x800 sets the x dimension
properly. But, because I need the top part of the viewing
error fo the basic ds9 menu bar, how much more Y space do I
need for a squre viewing area?
ds9_open args dx,dy (full,mm) dx,dy (window,mm) dy(banner,mm)
800 800 218 208 218 190 15
800 900 218 234 218 218 15
So, I always have to add on the 15mm in y for the banner. My viewing
are pixel scales are: 800pix/218mm = 3.6697 pix/mm
For a square view of 100 mm on a side:
dx = 100 * 3.6697 = 367
dy = 100 * 3.6697 + 15*3.6697 = 367 + 55 = 422
% ds9_open 367 422
% ds9_views_off
----> complicated by fact that the menu bar wraps!
If I use dx = 150mm, then I get no wrap, and dy_banner = 15mm
So, I derive:
dx = 150 * 3.6697 = 550
dy = 150 * 3.6697 + 15*3.6697 = 550 + 55 = 605
I get: 150mm x 133mm in view area on the screen.
What about the png when I print it?
>>>> Whoa! The png has the same 155x133mm size on the screen, but
when I print it to the paper (on 2 different printers) the
size of the image fills the page! I suspect this is due to
my use of the "Zoom to Fit Frame" option.
So, I will temporarily turn off the zooming in imlook, and print
my N3379 image a number of times using different ds9_window sizes.
Then I'll see what happens with the size of the png image I make.
% ds9_open 800 852
% imlook n3379_B.fits 30
% ds9_views_off (to turn off stuff)
% xpaset -p ds9 saveimage a.png
I try:
--------------------------
ds9_open 550 605
ds9_views_off
imlook n3379_B.fits 30
xpaset -p ds9 saveimage B_550_605.png
--------------------------
ds9_open 600 900
ds9_views_off
imlook n3379_B.fits 30
xpaset -p ds9 saveimage B_600_900.png
I'll cut a small piece (square) of the image
To cut a portion of image with WCS preserved:
% getfits -o sub.fits n3379_B.fits 420-619 740-939
% ds9_open 500 500
% ds9_views_off
% imlook sub.fits 30
% xpaset -p ds9 saveimage c_sub_500_500.png
% identify c_sub_500_500.png
c_sub_500_500.png PNG 500x353
*** The image displayed in the window is square (55mm on a side)
and is 200x200 pixels, as it should be. However, when I make the
png image, all of the extra surrounding white space is included.
This is NOT what I want.
So, I need a way of producing a ds9 display with a window size
that will perfectly match the size of the image (in pixels).
I make the doit script:
It draws a ds9 window with the input ds9_open arguments.
Then I make a png and use identify to get the window size.
input size window size
400 400 400 302 (Wrap)
500 500 500 451 (Wrap)
525 525 525 476 (Wrap)
600 600 600 453
700 700 700 602
800 800 800 702
900 900 900 753
1000 1000 1000 850
With these data I derive:
Ygui = 1.1175 * Ywin + 37.12
% getfits -o sub.fits n3379_B.fits 420-1020 740-1340
dx = 600
dy = 707
% doit 600 707
***** The image looks pretty good, but there is still a white
strip at the top.
==============================================================
What about the display levels?
% xpaget ds9 scale
log
% xpaget ds9 scale limits
196.379 4400.29
However, it is unclear how to set/query the grey-scale levels
BTW, I can make a python plot with:
% gs.py c_sub_600_707.png
% display gs.png
==============================================================
The galaxies are at:
For the full image: n3379_B.fits
X_image Y_image
NGC3379 (E) 974.0 1055.5
NGC3384 (S0) 680.0 1180.5
NGC3389 (Sp) 557.0 925.5
TO DRWA CIRCLES ON THE GALAXIES:
% cat circles.txt
974.0 1055.5 10.0 0.0 0.0 circle red "N3379"
680.0 1180.5 10.0 0.0 0.0 circle red "N3384"
557.0 925.5 10.0 0.0 0.0 circle red "N3389"
To paint circles:
% xymake_circles.py circles.txt >ds9.reg
FILE = ../README.im:
General notes on ImageMagic
===========================
Use grab1 to get the N3379 B image (n3379_B.fits)
% identify n3379_B.fits
n3379_B.fits FITS 1992x1992 1992x1992+0+0 32-bit DirectClass ........
or my own routine:
% ccdsize n3379_B.fits
1992 1992
(faster and easier to read)
I want a smaller image to play with. I use ds9 to find:
>>>> BTW I painted a grid of pixel values with:
Analysis > Coordinate Grid
Because my image has WCS it used Ra,Dec, I set this to Image Pixels with:
Analysis > Coordinate Grid Parameters
Now just viewing the screen I see a good range is:
BLC=400,850 TRC=1000,1250
So, I can cut an image, preserving WCS, with getfits:
% getfits -o sub.fits n3379_B.fits 400-999 850-1249
FILE = ../README.overplot_circles:
To get a fiber set (xyr.arc) in arcsec units
% vir_ifu_fibers.sh VIR_011.all_rot
Note: VIR_011.all_rot was generated with aip.fl.sh and is stored
in scohtm/het+virus/virus_astro/aip_ifu/ref_probs/Set02/VIR_011
The xyr file made is named: fibers.arcsec
To get xyr.pix file from a file with arcsec units:
% circles_trans.sh fibers.arcsec 25.0 1.35 974.0 1055.0 > xyr.pix
To get X,Y,R in pixels (file = xyr.pix) into regions:
% circles_file_ds9.py xyr.pix red 1 > fibers.reg
% lookit
FILE = ../README.overplot_fibers:
Angle = 0.0
PS = 1.35
To plot the IFU (boxes and names)
vir_ifu_pat.sh 100
lsegs_trans.sh vir_ifu_pat.ifu_linesegs 0.0 1.35 1000.0 900.0 > a.pix
lsegs_file_ds9.py a.pix cyan 4 > ifu.reg
text_trans.sh vir_ifu_pat.ifu_names 0.0 1.35 1000.0 900.0 > b.pix
text_file_ds9.py b.pix green 12 > ifu_names.reg
To make the fiber.arcsec or fibers.micron file:
To get a fiber set (xyr.arc) in arcsec units
% vir_ifu_fibers.sh VIR_011.all_rot
To plot some fiber sets .
For now I just grab some X,Y from: ifu_names.reg
text(814.815,714.815) # color=green font="helvetica 12 normal roman" text={032}
text(888.889,714.815) # color=green font="helvetica 12 normal roman" text={042}
text(814.815,640.741) # color=green font="helvetica 12 normal roman" text={031}
text(888.889,640.741) # color=green font="helvetica 12 normal roman" text={041}
vir_ifu_fibers.sh VIR_011.all_rot
For 032
circles_trans.sh fibers.arcsec 0.0 1.35 814.815 714.815 > xyr.pix
circles_file_ds9.py xyr.pix red 1 > fib_032.reg
For 042
circles_trans.sh fibers.arcsec 0.0 1.35 888.889 714.815 > xyr.pix
circles_file_ds9.py xyr.pix red 1 > fib_042.reg
For 031
circles_trans.sh fibers.arcsec 0.0 1.35 814.815 640.741 > xyr.pix
circles_file_ds9.py xyr.pix red 1 > fib_031.reg
For 041
circles_trans.sh fibers.arcsec 0.0 1.35 888.889 640.741 > xyr.pix
circles_file_ds9.py xyr.pix red 1 > fib_041.reg
NOTE: The following works IF I REMOVE "image":
% ls *.reg
fib_031.reg fib_032.reg fib_041.reg fib_042.reg ifu_names.reg ifu.reg
% cat *.reg >AAA
% cat AAA | xpaset ds9 regions -format ds9
FILE = ../README.overplot_ifu:
-------------------------------------------------------------
To get a file of IFU line segments in arcsec units
% vir_ifu_pat.sh 100
NOTE: 100 is the number of arcsec between IFU centers
Files made:
vir_ifu_pat.ifu_names (XY centers and name for all 78 IFUs)
vir_ifu_pat.ifu_linesegs (line segments for ALL 78 IFUs)
-------------------------------------------------------------
To transform X,Y to pixel units for the image frame:
Usage: lsegs_trans.sh file.lsegs 0.0 1.9675 426.0 344.1
arg1 - name of input line segments file
arg2 - rotation angle in degrees (- for CCW, + for CW)
arg3 - scale (arcsec/pixel)
arg4 - Xo in pixels for new frame
arg5 - Yo in pixels for new frame
% lsegs_trans.sh vir_ifu_pat.ifu_linesegs 0.0 1.35 1000.0 900.0 >a.pix
-------------------------------------------------------------
To get a ds9 regions file for overplotting:
usage: lsegs_file_ds9.py [-h] [-v] arg1 arg2 arg3
positional arguments:
arg1 XY file name
arg2 color
arg3 line_width
% lsegs_file_ds9.py a.pix cyan 4 > ifu.reg
-------------------------------------------------------------
To make text names of IFUs
% text_trans.sh vir_ifu_pat.ifu_names 0.0 1.35 1000.0 900.0 > b.pix
% text_file_ds9.py b.pix green 12 >ifu_names.reg
-------------------------------------------------------------
To display the image and the ifu file:
% ds9_open 800 800
% imlook n3379_B.fits 20.0 (20-sigma for z2)
% xpaset -p ds9 zoom to fit (optional)
% cat ifu.reg | xpaset ds9 regions -format ds9
% cat ifu_names.reg | xpaset ds9 regions -format ds9
***** I can stick these into a script (i.e. lookit)
The full set of commands:
% vir_ifu_pat.sh 100
% lsegs_trans.sh vir_ifu_pat.ifu_linesegs 0.0 1.35 1000.0 900.0 >a.pix
% lsegs_file_ds9.py a.pix cyan 2 > ifu.reg
% text_trans.sh vir_ifu_pat.ifu_names 0.0 1.35 1000.0 900.0 > b.pix
% text_file_ds9.py b.pix yellow 10 >ifu_names.reg
FILE = ../README.scale:
I want a quicky plate scale for n3379_B.fits
Using ds9 regions file and RA_DEC_SEP:
10:48:16.05 +12:29:22.1 688.0 810.5
10:47:21.31 +12:37:02.5 1278.0 1153.5
Separation in arc_SECONDS = 924.271729
% xyoff.sh 688.0 810.5 1278.0 1153.5
590.0000 343.0000 682.4581 30.17
dx dy sep angle
# Angle conventions in xyoff.
1) Theta=0 is in +X axis direction.
2) Angles increase in POSITIVE sense CCW
3) Angles increase in NEGATIVE sense CW
4) Upper hemisphere ---> Theta runs 0 to +180 Degrees
5) Lower hemisphere ---> Theta runs 0 to -180 Degrees
So, PS = 924.27 arcsec / 682.46 pixel
= 1.354 arcsec/pix
FILE = ../README.to_make_foot:
To have the IHMP footprint centered on N3379 (X,Y=974.0,1057.0)
===============================================================
For angle = 0.0
% cbf_trans.sh IHMP_foot.cbf 0.0 1.35 974.0 1057.0 >ihmp.pix
% lines_file_ds9.py ihmp.pix red 3 > ihmp.reg
For angle = 60.0
% cbf_trans.sh IHMP_foot.cbf 60.0 1.35 974.0 1057.0 >b.pix
% lines_file_ds9.py b.pix green 3 > b.reg
% ds9 n3379_B.fits &
To make HET guide probe pickle
% het_gp_pickle.sh 8.6 11.0 > q1.cbf
To plot the pickles
% cbf_trans.sh q1.cbf 0.0 1.35 974.0 1057.0 > q1.pix
% lines_file_ds9.py q1.pix green 3 > q1.reg
% cbf_trans.sh q1.cbf 90.0 1.35 974.0 1057.0 > q2.pix
% lines_file_ds9.py q2.pix yellow 3 > q2.reg
% cbf_trans.sh q1.cbf 180.0 1.35 974.0 1057.0 > q3.pix
% lines_file_ds9.py q3.pix magenta 3 > q3.reg
% cbf_trans.sh q1.cbf 270.0 1.35 974.0 1057.0 > q4.pix
% lines_file_ds9.py q4.pix cyan 3 > q4.reg
================================================================
To create IFU regions
% vir_ifu_pat.sh 100 > a
% lsegs_trans.sh a 0.0 1.35 974.0 1057.0 >a.pix
% lsegs_file_ds9.py a.pix green 2 > ifu.reg
% ds9 n3379_B.fits &