def getAlignment(self,w=None): print type(w) if type(w)==type(""): print "notype" data=FITS.Read(w) subapLocation=data[1] self.npxlx=numpy.array(eval(data[0]["parsed"]["npxlx"])) self.npxly=numpy.array(eval(data[0]["parsed"]["npxly"])) self.nsub=numpy.array(eval(data[0]["parsed"]["nsub"])) self.subflag=data[3] else: print "->type" c=controlCorba.controlClient(self.prefix) subapLocation=c.Get("subapLocation") subapLocation.shape=subapLocation.size/6,6 self.subflag=c.Get("subapFlag") self.nsub=c.Get("nsub") self.npxlx=c.Get("npxlx") self.npxly=c.Get("npxly") self.ncam=self.nsub.size self.adjustment.set_upper(self.ncam-1) self.orig=subapLocation.copy() self.pixbuf=gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,self.npxlx[self.cam]*2,self.npxly[self.cam]*2) self.arr=self.pixbuf.get_pixels_array() self.arr[:]=0xff self.img.set_from_pixbuf(self.pixbuf) subapLocation=self.subapToSingle(subapLocation) subapLocation*=2 self.subapLocation=subapLocation self.selected=numpy.ones((self.subapLocation.shape[0],),numpy.int8) self.draw()
def __init__(self, stream, dec, myhostname, cam, decorate=1, normalise=0): if stream in ["rtcPxlBuf", "rtcCalPxlBuf"]: self.dim = 2 else: self.dim = 1 self.win = gtk.Window() #self.win.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN) self.win.set_default_size(300, 300) self.w = self.h = 300 self.win.set_decorated(decorate) #remove the window frame self.cam = cam self.normalise = normalise self.img = gtk.Image() #self.img.set_alignment(0,0) #self.img.set_padding(0,0) self.pixbufImg = None #self.event=gtk.EventBox() #self.event.connect("button-press-event",self.click) #self.event.connect("button-release-event",self.unclick) #self.event.connect("motion-notify-event",self.motion) #self.event.connect("expose-event",self.expose) #box = gtk.ScrolledWindow() #box.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) #box.add_with_viewport(self.img) #v=box lay = gtk.Layout() lay.put(self.img, 0, 0) v = lay #v=gtk.Viewport() #v.add(self.img) #box.set_resize_mode(gtk.RESIZE_PARENT) if self.dim == 2: #if cam==None: # self.pixbuf=gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,512,512) #else: # self.pixbuf=gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,256,256) self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.w - 50, self.h - 50) else: self.pixbuf = None self.c = controlCorba.controlClient(debug=0) self.r = self.c.GetStreamBlock(stream, -1, callback=self.recvdata, myhostname=myhostname, decimate=dec) self.queue = 0 #vbox.pack_start(self.event) self.win.add(v) #self.img) self.win.connect("delete-event", self.quit) lay.connect("size-allocate", self.changeSize, "size allocate") #self.img.connect("size-allocate",self.changeSize,"size allocate img") #self.img.connect("expose-event",self.reSize,"size allocate img") if self.dim == 2: self.img.set_from_pixbuf(self.pixbuf) self.img.queue_draw() self.win.show_all()
def __init__(self, name, prefix="", myhostname=None, testprefix=""): """Initialise the object. name is the name of the stream, prefix is the darc prefix. myhostname can be an IP address (but will be found automagically on linux), and testprefix can be used if you want to add an additional prefix to the shm buffer.""" self.name = name self.decimate = 100 self.prefix = prefix self.testprefix = testprefix self.nstore = 100 self.myhostname = myhostname #self.lock=lock.lock() self.ctrl = controlCorba.controlClient(debug=0, controlName=prefix) while self.ctrl.obj == None: self.ctrl = controlCorba.controlClient(debug=0, controlName=prefix) if self.ctrl.obj == None: time.sleep(1) self.cb = None self.timeDataLastRequested = 0 if self.checkSHM(): #The assumption here is that this shm is old and not written by anyone else... self.cb = buffer.Circular("/" + self.testprefix + self.prefix + self.name) self.cb.lastWritten[0] = -1
def showRaw(self,w): w=gtk.Window() c=controlCorba.controlClient(self.prefix) #f = Figure(figsize=(5,4), dpi=72) bg = c.Get("bgImage") data = bg.reshape(480,640) f = plt.figure(1) plt.imshow(data) plt.gca().invert_yaxis() #plt.show() canvas = FigureCanvas(f) w.add(canvas) w.show_all()
def setAlignment(self,w): c=controlCorba.controlClient(self.prefix) # s=self.makeSubapLocation(allcam=1) fname="%ssubapLocation.fits"%self.prefix data=FITS.Read(fname) subapLocation=data[1] subflag=data[3] pxlcnt=self.count(data[1]) print "set" print "subapLocation" print subapLocation print "subapFlag" print subflag print "pxlCnt" print pxlcnt c.set("subapLocation",subapLocation,swap=1,check=1,copy=1) c.set("subapFlag",subflag,swap=1,check=1,copy=1) c.set("pxlCnt",pxlcnt,swap=1,check=1,copy=1)
sl = subloc[pos] if sl[2] != 0: subimg = list(data[sl[0]:sl[1]:sl[2], sl[3]:sl[4]:sl[5]].ravel()) subimg.sort() thr[pos] = (subimg[-n] + subimg[-n - 1]) / 2. pos += 1 return thr if __name__ == "__main__": if len(sys.argv) > 1: prefix = sys.argv[1] else: prefix = "" ctrl = controlCorba.controlClient(controlName=prefix + "Control", debug=0) y = raw_input("Do you want to do pixel calibration? y/n") if y == "y": y = raw_input( "Do you want to do dark map calibration? If so, please turn of light sources. y/n" ) if y == "y": n = raw_input("Number of frames to average?") n = int(n) ctrl.set("bgImage", None) ctrl.set("flatField", None) ctrl.set("darkNoise", None) ctrl.set("thresholdType", 0) dark = ctrl.AverageImage(n, whole=1) ctrl.set("darkNoise", dark) FITS.Write(dark, "darkNoise.fits")
This script records slope measurements for various different threshold values and algorithms and pixel weightings. It writes the results into a single FITS file, (default tmp.fits, can be specified on the command line), giving a FITS file with multiple header - data units. """ import controlCorba import FITS import sys import time file="tmp.fits" if len(sys.argv)>1: file=sys.argv[1] #Create the corba client c=controlCorba.controlClient() def set(name,val,com="",swap=1,check=1): c.obj.Set(controlCorba.sdata(name),controlCorba.encode([val]),controlCorba.sdata(com),swap,check) #time.sleep(0.01) set("fakeCCDImage",FITS.Read("shimage.fits")[1][0]) FITS.Write(controlCorba.decode(c.obj.AverageCentroids(1)),file) set("thresholdAlgorithm",2) FITS.Write(controlCorba.decode(c.obj.AverageCentroids(1)),file,writeMode="a") set("thresholdAlgorithm",0) FITS.Write(controlCorba.decode(c.obj.AverageCentroids(1)),file,writeMode="a") set("thresholdValue",0)
import FITS import numpy import matplotlib.pyplot as plt import controlCorba #darcmagic get -name=subapLocation --prefix=main #darcmagic get -name=subapFlag --prefix=main #darcmagic get -name=bgImage --prefix=main initial = numpy.zeros((15,15), numpy.int32) print "################" print initial print "################" initial = initial.reshape(225) print initial print "################" c=controlCorba.controlClient("main") subapflag = c.Get("subapFlag") print subapflag print type(subapflag) print subapflag.dtype c.Set("subapFlag",initial,com="",swap=1,check=1,copy=1) print "########### despues del set ##" subapflag = c.Get("subapFlag") print "----------------" pxl = c.Get("pxlCnt") print pxl print type(pxl) print pxl.size print pxl.shape print pxl.reshape(11,11) print "----------------"