Skip to content

Instantly share code, notes, and snippets.

@aquatiko
Created July 27, 2019 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquatiko/be993b67fa1093d4bef221a4a8e7ba85 to your computer and use it in GitHub Desktop.
Save aquatiko/be993b67fa1093d4bef221a4a8e7ba85 to your computer and use it in GitHub Desktop.
Basic UI panel AstroImageView
using AstroImages, GtkReactive, Gtk.ShortNames, Graphics, Gtk, Colors, IntervalSets, Cairo
using AstroImages: render
using WCS, FITSIO
function ui(img::AstroImage, indx = 1)
header = WCS.to_header(img.wcs[indx])
win = Window("Image", 700,700)
g = Grid()
push!(win, g)
toolbar = Toolbar()
headerbtn = ToolButton("Header")
set_gtk_property!(headerbtn, :label, "Header")
set_gtk_property!(headerbtn, :is_important, true)
closebtn = ToolButton("Close")
set_gtk_property!(closebtn, :label, "Close")
set_gtk_property!(closebtn, :is_important, true)
map(w->push!(toolbar,w),[headerbtn,closebtn])
g[1:2,1] = toolbar
c = canvas(UserUnit)
g[1:2,2] = c
l1pixel = Label("Physical Coordinate X =")
l2pixel = Label("Physical Coordinate Y =")
g[1,3] = l1pixel
g[2,3] = l2pixel
l1world = Label("World Coordinate X =")
l2world = Label("World Coordinate Y =")
g[1,4] = l1world
g[2,4] = l2world
lvalue = Label("Value = ")
g[1:2,5] = lvalue
signal_connect(headerbtn, :clicked) do widget
new_win = Window("Header",400,500)
txt = Label("Header")
push!(new_win,txt)
GAccessor.text(txt,header)
GAccessor.line_wrap(txt,true)
showall(new_win)
end
signal_connect(closebtn, :clicked) do widget
destroy(win)
end
set_gtk_property!(g, :column_homogeneous, true)
set_gtk_property!(g, :column_spacing, 15)
set_gtk_property!(c, :expand, true)
rimg = render(img)
img24 = Matrix(UInt32[reinterpret(UInt32, convert(RGB24, rimg[i,j])) for i = 1:size(rimg,1), j = size(rimg,2):-1:1]')
fv = XY(0.0..size(img24,2), 0.0..size(img24,1))
zr = Signal(ZoomRegion(fv, fv))
surf = Cairo.CairoRGBSurface(img24)
map(c.mouse.motion) do btn
xu, yu = btn.position.x.val, btn.position.y.val
world_coord = pix_to_world(WCS.from_header(header)[1], [xu, yu])
GAccessor.text(l1pixel ,"Pixel Coordinate X = $(round(xu, digits = 2))")
GAccessor.text(l2pixel ,"Pixel Coordinate Y = $(round(yu, digits = 2))")
GAccessor.text(l1world ,"World Coordinate X = $(round(world_coord[1], digits = 2))"*"°")
GAccessor.text(l2world ,"World Coordinate Y = $(round(world_coord[2], digits = 2))"*"°")
if xu >= 1 && yu >= 1
GAccessor.text(lvalue ,"Value = $(img.data[indx][Int(round(xu)),Int(round(yu))])")
else
GAccessor.text(lvalue, "Value = ")
end
end
draw(c, zr) do widget, r
ctx = getgc(widget)
set_coordinates(ctx, r)
rectangle(ctx, BoundingBox(r.currentview))
set_source(ctx, surf)
fill(ctx)
end
showall(win)
end
ui(AstroImage("data/casa_0.5-1.5keV.fits")) # load your own fits file to try out and make sure of dependencies above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment