예제 #1
0
def run(configfilename, configspecfile):    
    hardwareconfigfile = 'speckle_instruments.ini'
    config = ConfigObj(configfilename, configspec=configspecfile)
    val = Validator()
    check = config.validate(val)
    
    centx = config['IM_PARAMS']['centerx']
    centy = config['IM_PARAMS']['centery']
    lambdaoverd = config['IM_PARAMS']['lambdaoverd']
    
    regionfilename = config['CONTROLREGION']['filename']
    # pharo = hardware.fake_pharo()
    #Real thing
    
    innerlam = config['CONTROLREGION']['innerannulus'] 
    outerlam = config['CONTROLREGION']['outerannulus'] 
    
    # pharo = hardware.PHARO_COM('PHARO', 
    #             configfile = hardwareconfigfile)
    #LOAD P3K HERE
    pharo = hardware.fake_pharo()
    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() 
    
    firstim = pharo.take_src_return_imagedata(exptime = 4)
    image = pre.equalize_image(firstim, **bgds)
    image = firstim
    ann, verts = define_control_annulus(image, cx = centx, cy = centy, 
                         rad_in = lambdaoverd*innerlam,
                         rad_out= lambdaoverd*outerlam)
    flh.writeout(ann*1.0, regionfilename)
    config['CONTROLREGION']['verticesx'] = [centx]+[x[0] for x in verts]
    config['CONTROLREGION']['verticesy'] = [centy]+[y[1] for y in verts]
    config.write() 
    
    print "Configuration file written to "+config.filename    
예제 #2
0
import dm_functions as DM
import time


def define_control_annulus(image, cx= None, cy = None):
    """SHIFT- Click on the image to define the vertices of a polygon defining a region. May be convex or concave"""
    spots = pre.get_spot_locations(image, 
            comment='SHIFT-click to select IN THIS ORDER, inner radius, and outer radius of the annular region to control')
    xs, ys = np.meshgrid( np.arange(image.shape[1]),
                            np.arange(image.shape[0]))
    rad_in =np.linalg.norm(np.array(spots[0])-np.array([cx, cy])) 
    rad_out =np.linalg.norm(np.array(spots[1])-np.array([cx, cy])) 
    return ( pro.annulus(image, cx, cy, rad_in, rad_out), spots)

if __name__ == "fake__main__":
    pharo = hardware.fake_pharo()
    im = pharo.get_image()
    ann = define_control_annulus(im)
    plt.imshow(ann*im);plt.show()
if __name__ == "__main__":
    #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)
    
    regionfilename = config['CONTROLREGION']['filename']
예제 #3
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)