Exemplo n.º 1
0
    def generate_flatmap(self, phase, a=None, b=None, c=None):
        """generates flatmap with a certain phase for this speckle"""
	# s_amp = DM.amplitudemodel(self.intensity, self.krad, a=a, b=b, c=c)
	# with the new attributes of speckle2 class object	
	s_amp = DM.amplitudemodel(self.amplitude, self.kmod, a=a, b=b, c=c)
	# print 's_amp: ', s_amp, 'self.kmod: ', self.krad, 'phase: ', phase
	#return DM.make_speckle_kxy(self.kvecx, self.kvecy, s_amp, phase)
	return DM.make_speckle_kxy(self.kx, self.ky, s_amp, phase)
Exemplo n.º 2
0
def run(configfilename, configspecfile):
    #configfilename = 'speckle_null_config.ini'
    config = ConfigObj(configfilename, configspec=configspecfile)
    val = Validator()
    check = config.validate(val)
    hardwareconfigfile = 'speckle_instruments.ini'
    p3k = hardware.P3K_COM('P3K_COM', configfile=hardwareconfigfile)

    time.sleep(0.1)
    kvecr = config['CALSPOTS']['wafflekvec']
    DMamp = config['CALSPOTS']['waffleamp']
    additionmapx = DM.make_speckle_kxy(kvecr, 0, DMamp, 0)
    additionmapy = DM.make_speckle_kxy(0, kvecr, DMamp, 0)
    additionmap = additionmapx + additionmapy
    textmap = DM.text_to_flatmap('hi gene!', 30)
    print("sending new flatmap to p3k")
    initial_flatmap = p3k.grab_current_flatmap()
    status = p3k.load_new_flatmap((initial_flatmap + additionmap))
Exemplo n.º 3
0
def test_recenter():
    configfilename = 'speckle_null_config.ini'
    config = ConfigObj(configfilename)
    configfilename = 'speckle_null_config.ini'
    hardwareconfigfile = 'speckle_instruments.ini'
    configspecfile = 'speckle_null_config.spec'
    config = ConfigObj(configfilename, configspec=configspecfile)
    val = Validator()
    check = config.validate(val)
    
    pharo = hardware.PHARO_COM('PHARO', 
                configfile = hardwareconfigfile)
    p3k = hardware.P3K_COM('P3K_COM', configfile = hardwareconfigfile)
    #LOAD CURRENT FLATMAP 
    print("\n\nBeginning DM REGISTRATION\n\n")
    time.sleep(2)
    print("Retrieving bgd, flat, badpix")
    bgds = flh.setup_bgd_dict(config)
    
    use_centoffs = config['NULLING']['cent_off']

    initial_flatmap = p3k.grab_current_flatmap()
    p3k.safesend2('hwfp dm=off')
    
    DMamp = 33
    kvecr = 33
    
    additionmapx = DM.make_speckle_kxy(kvecr, 0,DMamp , 0) 
    additionmapy = DM.make_speckle_kxy(0,kvecr, DMamp, 0) 
    additionmap = additionmapx + additionmapy 

    print ("sending new flatmap to p3k")
    status = p3k.load_new_flatmap((initial_flatmap + additionmap))
    while True:
        image = pharo.take_src_return_imagedata(exptime = 4) 
        dm_reg_autorun(image, configfilename, configspecfile)
        time.sleep(2)
    pass    
Exemplo n.º 4
0
 def generate_flatmap(self, speck_phase):
     """generates flatmap with a certain phase for this speckle"""
     # print 'intensity', self.intensity
     # ans = raw_input('press enter')
     s_amp = DM.amplitudemodel(self.intensity, self.krad, **self.abc)
     # print 'self.intensity:', self.intensity, 's_amp: ', s_amp, 'speck_phase: ', speck_phase#, 'x', self.xcentroid, 'y', self.ycentroid, 'kx', self.kvecx, 'ky', self.kvecy, 'self.krad: ', self.krad,
     self.s_amp = s_amp
     # print s_amp
     if np.isnan(self.s_amp):
         print('commented this out. needs checking')
         exit()
         # ipdb.set_trace()
     # phase = phase - 1.9378 # got this offset by measuring phase (with quicklook_wf) when input phase is 0
     dm_phase = speck_phase + 1.9377
     if dm_phase >= np.pi: dm_phase = dm_phase - (2 * np.pi)
     return DM.make_speckle_kxy(self.kvecx, self.kvecy, s_amp, dm_phase)
Exemplo n.º 5
0
def speckle_killer(wf, phase_map):
    # with open(iop.phase_ideal, 'rb') as handle:
    #     phase_ideal = pickle.load(handle)

    # quicklook_im(phase_map, logAmp=False)

    ijofinterest = skv3.identify_bright_points(proper.prop_get_amplitude(wf),
                                               controlregion)
    xyofinterest = [p[::-1] for p in ijofinterest]
    print(xyofinterest, len(xyofinterest))
    if len(xyofinterest) == 0:
        y = int(np.random.uniform(fp.controlregion[0], fp.controlregion[1]))
        x = int(np.random.uniform(fp.controlregion[2], fp.controlregion[3]))
        xyofinterest = [(y, x)]
    if len(xyofinterest) < fp.max_specks:
        fp.max_specks = len(xyofinterest)
    print(fp.max_specks)
    fps = skv3.filterpoints(xyofinterest,
                            max=fp.max_specks,
                            rad=fp.exclusionzone)
    print(fps)

    null_map = np.zeros((tp.ao_act, tp.ao_act))
    for speck in fps:
        print(speck)
        kvecx, kvecy = DM.convert_pixels_kvecs(speck[0],
                                               speck[1],
                                               tp.grid_size / 2,
                                               tp.grid_size / 2,
                                               angle=0,
                                               lambdaoverd=fp.lod)
        dm_phase = phase_map[speck[1], speck[0]]
        s_amp = proper.prop_get_amplitude(wf)[speck[1], speck[0]] * 5.3

        null_map += -DM.make_speckle_kxy(kvecx, kvecy, s_amp,
                                         dm_phase)  #+s_ideal#- 1.9377
    null_map /= len(fps)

    area_sum = np.sum(proper.prop_get_amplitude(wf) * controlregion)
    print(area_sum)
    with open(iop.measured_var, 'ab') as handle:
        pickle.dump(area_sum, handle, protocol=pickle.HIGHEST_PROTOCOL)

    return null_map
Exemplo n.º 6
0
 def generate_flatmap(self, phase):
     """generates flatmap with a certain phase for this speckle"""
     s_amp = DM.amplitudemodel(self.intensity, self.krad, **self.abc)
     print 's_amp: ', s_amp, 'self.krad: ', self.krad, 'phase: ', phase
     return DM.make_speckle_kxy(self.kvecx, self.kvecy, s_amp, phase)
Exemplo n.º 7
0
    xypixels = []
    ximcoords, yimcoords = np.meshgrid(np.arange(firstim.shape[0]),
                                       np.arange(firstim.shape[1]))

    actual_kvector_array = []
    intensity_array = []

    for kvecr in kr:
        if not intconf['auto']:
            title.set_text("Click on the 4 spots, then hit enter.  Kr: " +
                           str(kvecr))
        if intconf['auto']:
            title.set_text("Kr: " + str(kvecr))
        #Check this line
        additionmapx = DM.make_speckle_kxy(kvecr, 0, DMamp, 0)
        additionmapy = DM.make_speckle_kxy(0, kvecr, DMamp, 0)
        additionmap = additionmapx + additionmapy
        #ipdb.set_trace()
        #THIS NEEDS TO BE UNCOMMENTED ONCE THE FUNCTION IS WRITTEN
        #AS WELL AS PHARO!!
        status = p3k.load_new_flatmap(initial_flatmap + additionmap)
        #ipdb.set_trace()

        im = pharo.take_src_return_imagedata(exptime=exp) - firstim

        w3.set_data(additionmap)
        w1.set_data(np.log(np.abs(im)))
        plt.draw()
        plt.pause(0.01)
        if not intconf['auto']:
Exemplo n.º 8
0
import sn_hardware as hardware
import flatmapfunctions as FM
from validate import Validator
import flatmapfunctions as fmf
import dm_functions as DM
import time

if __name__ == "__main__":
    configfilename = 'speckle_null_config.ini'
    hardwareconfigfile = 'speckle_instruments.ini'
    configspecfile = 'speckle_null_config.spec'
    p3k = hardware.P3K_COM('P3K_COM', configfile=hardwareconfigfile)

    time.sleep(1)
    additionmap = 0
    phases = np.array([25, 133, 78, 224]) * np.pi / 180
    kvecx = [11, 9, 18, 22]
    kvecy = [13, 7, 9, 4]
    amps = [15, 6, 10, 25]

    for idx, _ in enumerate(phases):
        map = DM.make_speckle_kxy(kvecx[idx], kvecy[idx], amps[idx],
                                  phases[idx])
        additionmap += map

    print("sending new flatmap to p3k")
    initial_flatmap = p3k.grab_current_flatmap()
    status = p3k.load_new_flatmap((initial_flatmap + additionmap))

    print("NOW GO RUN MAKE_CENTS!!!!!")
Exemplo n.º 9
0
def run(configfilename, configspecfile):
    #configfilename = 'speckle_null_config.ini'
    #config = ConfigObj(configfilename)
    #configfilename = 'speckle_null_config.ini'
    hardwareconfigfile = 'speckle_instruments.ini'
    #configspecfile = 'speckle_null_config.spec'
    config = ConfigObj(configfilename, configspec=configspecfile)
    val = Validator()
    check = config.validate(val)
    print "\n\n\n"
    print "This program performs DM registration"
    print "It takes a background image, then an image with satellites"
    print "It subtracts the two, asks you to click on the satellites and then figures out lambda/d, the center and rotation of the image"
    print "It then saves these values to the configuration file "+configfilename
    print "At the end, it reloads the initial flatmap, undoing the satellites"
    print "\n\n\n"
    
    apmask = False
    if not apmask:
        aperturemask = np.ones((66,66))
    if apmask:
        aperturemask = dm.annularmask(66, 12, 33) 

    #pharo = hardware.PHARO_COM('PHARO', 
    #            configfile = hardwareconfigfile)
    #p3k = hardware.P3K_COM('P3K_COM', configfile = hardwareconfigfile)
    
    pharo = hardware.fake_pharo()
    p3k   = hardware.fake_p3k()
    #LOAD CURRENT FLATMAP 
    print("\n\nBeginning DM REGISTRATION\n\n")
    time.sleep(2)
    print("Retrieving bgd, flat, badpix")
    #bgds = flh.setup_bgd_dict(config)
    
    fake_bgds = {'bkgd':np.zeros((1024, 1024)), 
            'masterflat':np.ones((1024, 1024)),
            'badpix': np.zeros((1024, 1024))}
    print "WARNING: USING FAKE BGDS"
    bgds = fake_bgds.copy() 
    
    use_centoffs = config['NULLING']['cent_off']

    if use_centoffs == False:
        initial_flatmap = p3k.grab_current_flatmap()
        p3k.safesend2('hwfp dm=off')
    if use_centoffs == True:
        initial_centoffs= p3k.grab_current_centoffs()
        p3k.safesend2('hwfp dm=on')
    
    #status = p3k.load_new_flatmap(FM.convert_hodm_telem(initial_flatmap))
    firstim = pharo.take_src_return_imagedata(exptime = 4)
    print("\nComputing satellites")
    if use_centoffs:
        DMamp = 10
    else:
        DMamp = 33
    kvecr = 33
    additionmapx = DM.make_speckle_kxy(kvecr, 0,DMamp , 0) 
    additionmapy = DM.make_speckle_kxy(0,kvecr, DMamp, 0) 
    additionmap = additionmapx + additionmapy 

    additionmap = additionmap*aperturemask
    print ("sending new flatmap to p3k")
    if use_centoffs == False:
        status = p3k.load_new_flatmap((initial_flatmap + additionmap))
    if use_centoffs == True:
        status = p3k.load_new_centoffs((initial_centoffs + 
                            fmf.convert_flatmap_centoffs(additionmap)))
    image = pharo.take_src_return_imagedata(exptime = 4) 

    image_res = image-firstim
    spotcenters = get_satellite_centroids(image_res)
    
    print spotcenters
    c =find_center(spotcenters)
    a =find_angle(spotcenters)
    
    config['IM_PARAMS']['centerx'] = c[0]
    config['IM_PARAMS']['centery'] = c[1]
    config['IM_PARAMS']['angle']  = a 
    config['CALSPOTS']['spot10oclock'] = [np.round(x) for x in spotcenters[0]]
    config['CALSPOTS']['spot1oclock'] = [np.round(x) for x in spotcenters[1]]
    config['CALSPOTS']['spot4oclock'] = [np.round(x) for x in spotcenters[2]]
    config['CALSPOTS']['spot7oclock'] = [np.round(x) for x in spotcenters[3]]
    #cyclesperap = int(config['AOSYS']['dmcyclesperap'])
    lambdaoverd = get_lambdaoverd(spotcenters, kvecr)
    config['IM_PARAMS']['lambdaoverd'] = lambdaoverd
   
    print "Image center: " , c
    print "DM angle: ", a
    print "lambda/D: ", str(lambdaoverd)
    config.write() 
    
    print "RELOADING INITIAL FLATMAP"
    if use_centoffs == False:
        status = p3k.load_new_flatmap(initial_flatmap)
    if use_centoffs == True:
        status = p3k.load_new_centoffs(initial_centoffs)