def find_slope_niter(): stream = 'rtcCentBuf' threshold = 1.0 for star_id in range(1,1+nstars): star = Star(star_id) ok = star.setup(self.Cam) if(ok): slope_niter = find_niter(stream,threshold) if(slope_niter[0] != -1): star.slope_iter = slope_niter[0] FITS.Write(slope_niter[1],self.Cam.rawdata_path + self.Cam.name+'_slopes_noscreen_led_%d.fits'%(star_id),writeMode='a') else: print 'Relax threshold'
def bgImage_exptime_calibration(self,star_id): ''' Determines, sets and save the bgImage for star_id. exptime is saved on the files name. INPUT star_id[int] ''' #2-3 bgImage & exptime iteration star = Star(star_id) star.setup(self.Cam) exptime = numpy.round(self.Cam.initexptime) self.c.Set('bgImage',None) self.c.Set(self.Cam.exptime,int(exptime)) bgImage = self.grab('rtcPxlBuf',self.niter) self.c.Set('bgImage',bgImage) self.bbbc.star_on(star_id) auxImage = self.grab('rtcCalPxlBuf',self.niter) self.bbbc.star_off(star_id) auxImageMax = auxImage.max() print 'auxImageMax: ', auxImageMax relativemax = 0.7 threshold = 0.05 while(numpy.absolute(auxImageMax/self.sat-relativemax)>threshold): # The while condition is set so that the maximum value found in the image # is around 60% of the saturation value print "exptime: ", print exptime print 'auxImageMax: ', print str(100*auxImageMax/self.sat)+'%' exptime = float(exptime)*(self.sat*float(relativemax))/auxImageMax if(exptime>=self.maxexptime): # Protection exptime = self.maxexptime auxImageMax = self.sat*relativemax self.c.Set(self.Cam.exptime,int(exptime)) elif(exptime<1.0): exptime = 1.0 auxImageMax = self.sat*relativemax self.c.Set(self.Cam.exptime,int(exptime)) else: self.c.Set('bgImage',None) self.c.Set(self.Cam.exptime,int(exptime)) bgImage = self.grab('rtcPxlBuf',self.niter) self.c.Set('bgImage',bgImage) self.bbbc.star_on(star_id) auxImage = self.grab('rtcCalPxlBuf',self.niter) self.bbbc.star_off(star_id) auxImageMax = numpy.amax(auxImage) print "Final exptime: ", print exptime print 'Final auxImageMax: ', print str(100*auxImageMax/self.sat)+'%' self.c.Set('bgImage',None) bgImage = self.grab('rtcPxlBuf',self.Cam.bg_iter) self.c.Set('bgImage',bgImage) self.bbbc.flush_all_leds() self.bbbc.star_on(star_id) auxImage = self.grab('rtcCalPxlBuf',self.niter) self.bbbc.star_off(star_id) self.c.Set('bgImage',bgImage) #Saving values found and removing previous values files = os.listdir(self.Cam.bg_path) files = [s for s in files if 'led_%d_'%(star_id) in s] if(files!=[]): for file_name in files: os.remove(self.Cam.bg_path + file_name) FITS.Write(bgImage,self.Cam.bg_path + self.Cam.name+'_bg_led_%d_exptime_%d.fits'%(star_id,int(exptime)),writeMode='w') FITS.Write(auxImage.reshape((self.Cam.pxly,self.Cam.pxlx)),self.Cam.bg_path + self.Cam.name+'_aux_led_%d_exptime_%d.fits'%(star_id,int(exptime)),writeMode='w')