Example #1
0
def save_pix_IQ(wf, plot=False):
    with open(iop.IQpixel, 'a') as the_file:
        complex_map = proper.prop_shift_center(wf.wfarr)
        pix0 = complex_map[64, 64]
        pix1 = complex_map[100, 100]

        the_file.write('%f, %f, %f, %f\n' % (np.real(pix0), np.imag(pix0), np.real(pix1), np.imag(pix1)))

    if plot:
        quicklook_im(np.real(complex_map))
        quicklook_wf(wf, show=True)
        quicklook_IQ(wf, show=True)
Example #2
0
def simple_telescope(wavelength, gridsize):

    # Define entrance aperture diameter and other quantities
    d_objective = 5.0  # objective diameter in meters
    fl_objective = 20.0 * d_objective  # objective focal length in meters
    fl_eyepiece = 0.021  # eyepiece focal length
    fl_eye = 0.022  # human eye focal length
    beam_ratio = 0.3  # initial beam width/grid width

    # Define the wavefront
    wfo = proper.prop_begin(d_objective, wavelength, gridsize, beam_ratio)

    # print d_objective, wavelength, gridsize, beam_ratio
    # Define a circular aperture
    proper.prop_circular_aperture(wfo, d_objective / 2)

    # proper.prop_propagate(wfo, fl_objective)
    # proper.prop_propagate(wfo, fl_objective)
    # proper.prop_propagate(wfo, fl_objective)

    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()

    # Define entrance
    proper.prop_define_entrance(wfo)
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()

    # proper.prop_propagate(wfo, fl_objective+fl_eyepiece, "eyepiece")
    # # plt.imshow(proper.prop_get_amplitude(wfo))
    # # plt.show()
    #
    # proper.prop_propagate(wfo, fl_objective+fl_eyepiece, "eyepiece")
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()
    #
    # proper.prop_propagate(wfo, fl_objective+fl_eyepiece, "eyepiece")
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()

    # Define a lens
    proper.prop_lens(wfo, fl_objective, "objective")
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()
    # Propagate the wavefront
    proper.prop_propagate(wfo, fl_objective + fl_eyepiece, "eyepiece")
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()
    # Define another lens
    proper.prop_lens(wfo, fl_eyepiece, "eyepiece")
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()
    exit_pupil_distance = fl_eyepiece / (1 - fl_eyepiece /
                                         (fl_objective + fl_eyepiece))
    proper.prop_propagate(wfo, exit_pupil_distance, "exit pupil at eye lens")
    # quicklook_wf(wfo)
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()
    proper.prop_lens(wfo, fl_eye, "eye")
    proper.prop_propagate(wfo, fl_eye, "retina")
    # plt.imshow(proper.prop_get_amplitude(wfo))
    # plt.show()
    quicklook_wf(wfo)
    phase_map = proper.prop_get_phase(wfo)
    amp_map = proper.prop_get_amplitude(wfo)
    # quicklook_im(phase_map)

    amp_map[80:100, 80:100] = 0
    quicklook_im(amp_map, logAmp=True)

    import numpy as np
    wfo.wfarr = proper.prop_shift_center(amp_map * np.cos(phase_map) +
                                         1j * amp_map * np.sin(phase_map))
    # quicklook_wf(wf_array[iw,0])
    proper.prop_propagate(wfo, fl_eye, "retina")
    proper.prop_lens(wfo, fl_eye, "eye")
    quicklook_wf(wfo)

    # End
    (wfo, sampling) = proper.prop_end(wfo)

    return (wfo, sampling)
Example #3
0
def vortex(wfo):
    n = int(proper.prop_get_gridsize(wfo))
    ofst = 0  # no offset
    ramp_sign = 1  # sign of charge is positive
    ramp_oversamp = 11.  # vortex is oversampled for a better discretization

    f_lens = tp.f_lens  #200.0 * tp.diam#658.6 #conf['F_LENS']
    diam = 8  #conf['DIAM']
    charge = 2  #conf['CHARGE']
    pixelsize = 5.0  #conf['PIXEL_SCALE']
    Debug_print = False  #conf['DEBUG_PRINT']

    if charge != 0:
        wavelength = proper.prop_get_wavelength(wfo)
        gridsize = proper.prop_get_gridsize(wfo)

        beam_ratio = pixelsize * 4.85e-9 / (wavelength / diam)
        from Utils.misc import dprint
        dprint((wavelength, gridsize, beam_ratio))
        calib = str(charge) + str('_') + str(int(
            beam_ratio * 100)) + str('_') + str(gridsize)
        my_file = str(tmp_dir + 'zz_perf_' + calib + '_r.fits')

        proper.prop_propagate(wfo, f_lens, 'inizio')  # propagate wavefront
        proper.prop_lens(wfo, f_lens,
                         'focusing lens vortex')  # propagate through a lens
        proper.prop_propagate(wfo, f_lens, 'VC')  # propagate wavefront

        quicklook_wf(wfo)
        if (os.path.isfile(my_file) == True):
            if (Debug_print == True):
                print("Charge ", charge)
            vvc = readfield(tmp_dir, 'zz_vvc_' +
                            calib)  # read the theoretical vortex field
            vvc = proper.prop_shift_center(vvc)
            scale_psf = wfo._wfarr[0, 0]
            psf_num = readfield(tmp_dir,
                                'zz_psf_' + calib)  # read the pre-vortex field
            psf0 = psf_num[0, 0]
            psf_num = psf_num / psf0 * scale_psf
            perf_num = readfield(tmp_dir, 'zz_perf_' +
                                 calib)  # read the perfect-result vortex field
            perf_num = perf_num / psf0 * scale_psf
            wfo._wfarr = (
                wfo._wfarr - psf_num
            ) * vvc + perf_num  # the wavefront takes into account the real pupil with the perfect-result vortex field

        else:  # CAL==1: # create the vortex for a perfectly circular pupil
            if (Debug_print == True):
                print("Charge ", charge)

            wfo1 = proper.prop_begin(diam, wavelength, gridsize, beam_ratio)
            proper.prop_circular_aperture(wfo1, diam / 2)
            proper.prop_define_entrance(wfo1)
            proper.prop_propagate(wfo1, f_lens,
                                  'inizio')  # propagate wavefront
            proper.prop_lens(
                wfo1, f_lens,
                'focusing lens vortex')  # propagate through a lens
            proper.prop_propagate(wfo1, f_lens, 'VC')  # propagate wavefront

            # writefield(tmp_dir, 'zz_psf_' + calib, wfo1.wfarr)  # write the pre-vortex field
            nramp = int(n * ramp_oversamp)  # oversamp
            # create the vortex by creating a matrix (theta) representing the ramp (created by atan 2 gradually varying matrix, x and y)
            y1 = np.ones((nramp, ), dtype=np.int)
            y2 = np.arange(0, nramp, 1.) - (nramp / 2) - int(ramp_oversamp) / 2
            y = np.outer(y2, y1)
            x = np.transpose(y)
            theta = np.arctan2(y, x)
            x = 0
            y = 0
            vvc_tmp = np.exp(1j * (ofst + ramp_sign * charge * theta))
            theta = 0
            vvc_real_resampled = cv2.resize(
                vvc_tmp.real, (0, 0),
                fx=1 / ramp_oversamp,
                fy=1 / ramp_oversamp,
                interpolation=cv2.INTER_LINEAR
            )  # scale the pupil to the pupil size of the simualtions
            vvc_imag_resampled = cv2.resize(
                vvc_tmp.imag, (0, 0),
                fx=1 / ramp_oversamp,
                fy=1 / ramp_oversamp,
                interpolation=cv2.INTER_LINEAR
            )  # scale the pupil to the pupil size of the simualtions
            vvc = np.array(vvc_real_resampled, dtype=complex)
            vvc.imag = vvc_imag_resampled
            vvcphase = np.arctan2(vvc.imag,
                                  vvc.real)  # create the vortex phase
            vvc_complex = np.array(np.zeros((n, n)), dtype=complex)
            vvc_complex.imag = vvcphase
            vvc = np.exp(vvc_complex)
            vvc_tmp = 0.
            # writefield(tmp_dir, 'zz_vvc_' + calib, vvc)  # write the theoretical vortex field

            proper.prop_multiply(wfo1, vvc)
            proper.prop_propagate(wfo1, f_lens, 'OAP2')
            proper.prop_lens(wfo1, f_lens)
            proper.prop_propagate(wfo1, f_lens, 'forward to Lyot Stop')
            proper.prop_circular_obscuration(
                wfo1, 1., NORM=True)  # null the amplitude iside the Lyot Stop
            proper.prop_propagate(wfo1, -f_lens)  # back-propagation
            proper.prop_lens(wfo1, -f_lens)
            proper.prop_propagate(wfo1, -f_lens)
            # writefield(tmp_dir, 'zz_perf_' + calib, wfo1.wfarr)  # write the perfect-result vortex field

            vvc = readfield(tmp_dir, 'zz_vvc_' + calib)
            vvc = proper.prop_shift_center(vvc)
            scale_psf = wfo._wfarr[0, 0]
            psf_num = readfield(tmp_dir,
                                'zz_psf_' + calib)  # read the pre-vortex field
            psf0 = psf_num[0, 0]
            psf_num = psf_num / psf0 * scale_psf
            perf_num = readfield(tmp_dir, 'zz_perf_' +
                                 calib)  # read the perfect-result vortex field
            perf_num = perf_num / psf0 * scale_psf
            wfo._wfarr = (
                wfo._wfarr - psf_num
            ) * vvc + perf_num  # the wavefront takes into account the real pupil with the perfect-result vortex field
        quicklook_wf(wfo)
        proper.prop_propagate(wfo, f_lens, "propagate to pupil reimaging lens")
        proper.prop_lens(wfo, f_lens, "apply pupil reimaging lens")
        proper.prop_propagate(wfo, f_lens, "lyot stop")
        quicklook_wf(wfo)
    return wfo
Example #4
0
def speck_killing_loop(wfo):
    #configfilename = 'speckle_null_config.ini'
    #config = ConfigObj(configfilename)
    configfilename = tp.FPWFSdir + 'speckle_null_config_Rupe.ini'
    hardwareconfigfile = tp.FPWFSdir + 'speckle_instruments.ini'
    configspecfile = tp.FPWFSdir + 'speckle_null_config.spec'
    print(configfilename)
    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)
    camera = hardware.camera()
    ao = hardware.ao()
    apmask = False
    if not apmask:
        aperturemask = np.ones((66, 66))
    if apmask:
        aperturemask = dm.annularmask(66, 12, 33)

    # nulled_field = None
    im_params = config['IM_PARAMS']
    null_params = config['NULLING']
    abc = config['INTENSITY_CAL']['abc']

    use_centoffs = config['NULLING']['cent_off']

    #bgds = flh.setup_bgd_dict(config)
    fake_bgds = {
        'bkgd': np.zeros((tp.grid_size, tp.grid_size)),
        'masterflat': np.ones((tp.grid_size, tp.grid_size)),
        'badpix': np.zeros((tp.grid_size, tp.grid_size))
    }
    print("WARNING: USING FAKE BGDS")
    bgds = fake_bgds.copy()
    # controlregion = pf.open(tp.FPWFSdir+config['CONTROLREGION']['filename'])[0].data
    # controlregion = controlregion[512-int(tp.grid_size/2):512+int(tp.grid_size/2), 512-int(tp.grid_size/2):512+int(tp.grid_size/2)]
    # controlregion = np.roll(controlregion, 15)
    # controlregion[:,0:70] = 0
    # controlregion[:80] = 0
    # controlregion[-80:] = 0
    controlregion = np.zeros((tp.grid_size, tp.grid_size))
    controlregion[50:80, 35:50] = 1
    boarder = get_ctrlrgnBoarder(controlregion)

    quicklook_im(controlregion, logAmp=False)
    # plt.show(block=True)

    #Notes==>scale exptime in snr
    exp = config['INTENSITY_CAL']['exptime']
    #Setup
    # initial_flatmap = ao.grab_current_flatmap()
    # initial_centoffs= ao.grab_current_centoffs()

    defaultim = np.ones((tp.grid_size, tp.grid_size))

    vertsx = config['CONTROLREGION']['verticesx']
    vertsy = config['CONTROLREGION']['verticesy']

    # plt.ion()
    fig = plt.figure(figsize=(12, 12))
    ax1 = plt.subplot2grid((4, 4), (0, 0), rowspan=2, colspan=2)
    ax2 = plt.subplot2grid((4, 4), (0, 2), rowspan=2, colspan=2)
    ax3 = plt.subplot2grid((4, 4), (3, 0))
    ax4 = plt.subplot2grid((4, 4), (2, 2), rowspan=2, colspan=2)
    #ax5 = plt.subplot2grid((4,4),(3,2))
    # ax1b =plt.subplot2grid((4,4),(0, 0), rowspan =2, colspan = 2)

    title = fig.suptitle('Speckle destruction')
    ax1.set_title('Image')
    ax2.set_title('Control region')
    ax3.set_title('RMS in region')
    ax4.set_title('Image')
    #ax5.set_title('Intensity')

    w1 = ax1.imshow(np.log10(np.abs(defaultim)) + boarder,
                    origin='lower',
                    interpolation='nearest')
    current_cmap = cm.get_cmap()
    current_cmap.set_bad(color='white')
    # w1b = ax1b.imshow(boarder*10, origin='lower', interpolation = 'none')
    # ax1.set_xlim(min(vertsx), max(vertsx))
    # ax1.set_ylim(min(vertsy), max(vertsy))
    #ax1.set_ylim(int(im_params['centery'])-25, int(im_params['centery']+50))

    w2 = ax2.imshow(np.log(np.abs(controlregion * defaultim)),
                    origin='lower',
                    interpolation='nearest')
    # ax2.set_xlim(min(vertsx), max(vertsx))
    # ax2.set_ylim(min(vertsy), max(vertsy))

    w3 = ax3.plot([], [])
    ax3.set_xlim(0, 10)

    w4, = ax4.plot(np.abs(defaultim[64]))
    # w4 = ax4.imshow(np.log10(np.abs(defaultim))+boarder, origin='lower', interpolation = 'nearest')
    current_cmap = cm.get_cmap()
    current_cmap.set_bad(color='white')

    N_iterations = 10
    itcounter = []
    maxfluxes = []
    meanfluxes = []
    totalfluxes = []
    rmsfluxes = []
    #w5 = ax5.plot(np.arange(10)*0, np.arange(10)*0)
    # w4 = ax4.imshow(np.log(camera.take_src_return_imagedata(exptime =exp)[242:758, 242:758]), origin='lower', interpolation = 'nearest')

    plt.show()
    tstamp = time.strftime("%Y%m%d-%H%M%S").replace(' ', '_')

    cubeoutputdir = os.path.join(null_params['outputdir'], tstamp)
    if not os.path.exists(cubeoutputdir):
        os.makedirs(cubeoutputdir)

    print(configfilename)
    result_imagecube = output_imagecube(N_iterations,
                                        tp.grid_size,
                                        filepath=os.path.join(
                                            cubeoutputdir,
                                            'test_' + tstamp + '.fits'),
                                        comment='fun',
                                        configfile=configfilename)

    clean_imagecube = output_imagecube(N_iterations,
                                       tp.grid_size,
                                       filepath=os.path.join(
                                           cubeoutputdir,
                                           'test_clean_' + tstamp + '.fits'),
                                       comment='fun',
                                       configfile=configfilename)

    cal_imagecube = output_imagecube(4,
                                     tp.grid_size,
                                     filepath=os.path.join(
                                         cubeoutputdir,
                                         'test_cals_' + tstamp + '.fits'),
                                     comment='fun',
                                     configfile=configfilename)
    cal_imagecube.update(controlregion)
    cal_imagecube.update(bgds['bkgd'])
    cal_imagecube.update(bgds['masterflat'])
    cal_imagecube.update(bgds['badpix'])

    ####MAIN LOOP STARTS HERE#####
    print("BEGINNING NULLING LOOP")

    for iteration in range(N_iterations):
        # quicklook_wf(wfo)
        itcounter.append(iteration)

        if use_centoffs == False:
            current_flatmap = ao.grab_current_flatmap()
        if use_centoffs == True:
            current_centoffs = ao.grab_current_centoffs()
        # quicklook_im(current_flatmap, logAmp=False, show=True)
        print("Taking image of speckle field")
        # if nulled_field != None:
        #     raw_im = nulled_field
        # else:
        raw_im = camera.take_src_return_imagedata(wfo, exptime=exp)

        result_imagecube.update(raw_im)
        field_im = pre.equalize_image(raw_im, **bgds)
        clean_imagecube.update(field_im)

        field_ctrl = field_im * controlregion
        # print np.shape(field_im), np.shape(controlregion), np.shape(field_ctrl)
        # plt.figure()
        # plt.imshow(field_im)
        # plt.figure()
        # plt.imshow(controlregion)
        # plt.figure()
        # plt.imshow(field_ctrl)
        # plt.show(block=True)

        meanfluxes.append(np.mean(field_ctrl[field_ctrl > 0]))
        maxfluxes.append(np.max(field_ctrl[field_ctrl > 0]))
        totalfluxes.append(np.sum(field_ctrl))
        rmsfluxes.append(
            np.std(field_ctrl[field_ctrl > 0]) /
            config['NULLING']['referenceval'])

        ax3.plot(itcounter, rmsfluxes)
        #w5 = plt.plot(itcounter, maxfluxes)
        #w5 = plt.plot(itcounter, totalfluxes)
        ax1.set_title('Iteration: ' + str(iteration) + ',  Mean: ' +
                      str(meanfluxes[iteration]) + ',  Max: ' +
                      str(maxfluxes[iteration]))
        w1.set_data(np.log(np.abs(field_ctrl)) + boarder)

        w1.autoscale()
        plt.draw()
        plt.pause(0.02)

        if iteration > 0:
            try:
                printstats(field_im, speckleslist)
            except:
                pass
            flh.writeout(current_flatmap, 'latestiteration.fits')

        # ans = raw_input('Do you want to run a speckle nulling iteration[Y/N]?')
        ans = 'Y'
        if ans == 'N':
            flatmapans = eval(
                input('Do you want to reload the' +
                      'flatmap/centoffs you started with[Y/N]?'))
            if flatmapans == 'Y':
                print("Reloading initial flatmap/centoffs")

                if use_centoffs == False:
                    status = ao.load_new_flatmap((initial_flatmap))
                if use_centoffs == True:
                    status = ao.load_new_centoffs((initial_centoffs))
                #ao.load_new_flatmap(initial_flatmap)
            break

        print(('Iteration ' + str(iteration) + ' total_intensity: ' +
               str(np.sum(field_ctrl))))
        #return a list of points
        print("computing interesting bright spots")

        #note indices and coordinates are reversed
        ijofinterest = identify_bright_points(field_ctrl, controlregion)
        xyofinterest = [p[::-1] for p in ijofinterest]

        print(("computed ", str(len(xyofinterest)), " bright spots"))
        max_specks = config['DETECTION']['max_speckles']

        #if len(xyofinterest)>50:
        #    xyofinterest = xyofinterest[0:49]

        if len(xyofinterest) < max_specks:
            max_specks = len(xyofinterest)

        fps = filterpoints(xyofinterest,
                           max=max_specks,
                           rad=config['NULLING']['exclusionzone'])
        print(fps)
        print("creating speckle objects")
        speckleslist = [speckle(field_im, xy[0], xy[1], config) for xy in fps]
        speckleslist = [x for x in speckleslist if (x.intensity) > 0]
        #old way--filter the speckles
        #speckleslist =[speckle(field_im, xy[0], xy[1], config) for xy in xyofinterest]
        #speckleslist = filterspeckles(speckleslist, max = max_specks)
        phases = null_params['phases']
        # phases = [-np.pi/2.,0,np.pi/2.,np.pi]
        for idx, phase in enumerate(phases):
            print(("Phase ", phase))
            phaseflat = 0
            allspeck_aps = 0
            #put in sine waves at speckle locations
            for speck in speckleslist:
                #XXX
                # phaseflat= phaseflat+speck.generate_flatmap(phase)
                phaseflat = speck.generate_flatmap(phase)
                # quicklook_im(speck.generate_flatmap(phase), logAmp=False)
                allspeck_aps = allspeck_aps + speck.aperture
            print('here')
            ax2.set_title('Phase: ' + str(phase))
            if idx == 0:
                # w1.set_data( (allspeck_aps*field_ctrl)-0.95*field_ctrl)
                w1.set_data(
                    np.log(np.abs((allspeck_aps * field_im) -
                                  0.95 * field_im)) + boarder)
                w1.autoscale()
                plt.draw()
            #w1.set_data(field_ctrl); w1.autoscale(); plt.draw()

            phaseflat = phaseflat * aperturemask
            # plt.figure()
            # plt.imshow(allspeck_aps)
            # plt.show()
            # ans = raw_input('press enter')
            wf_temp = copy.copy(wfo)
            if use_centoffs == False:
                status = ao.load_new_flatmap(current_flatmap + phaseflat,
                                             wf_temp)
            # if use_centoffs == True:
            #     status = ao.load_new_centoffs(current_centoffs+
            #                  fmf.convert_flatmap_centoffs(phaseflat))
            tp.variable = proper.prop_get_phase(wf_temp)[20, 20]
            print(('speck phase', tp.variable, 'intensity',
                   proper.prop_get_amplitude(wf_temp)[20, 20]))
            # plt.show(block=True)
            # quicklook_wf(wf_temp, show=True)

            phaseim = camera.take_src_return_imagedata(wf_temp, exptime=exp)
            # quicklook_im(phaseim, show=True)
            phaseim = pre.equalize_image(phaseim, **bgds)
            # quicklook_im(phaseim, show=True)
            w2.set_data(np.log(np.abs(phaseim * controlregion)))
            w2.autoscale()
            plt.draw()
            plt.pause(0.02)

            # w4.set_data(range(128), np.sum(np.eye(tp.grid_size)*proper.prop_get_amplitude(wf_temp),axis=1))#ax4.plot(range(128),  proper.prop_get_amplitude(wf_temp)[20])#np.abs(field_im[20]))#+boarder)
            w4.set_data(
                list(range(128)),
                proper.prop_get_amplitude(wf_temp)[64]
            )  # ax4.plot(range(128),  proper.prop_get_amplitude(wf_temp)[20])#np.abs(field_im[20]))#+boarder)
            ax4.set_xlim([0, 128])
            ax4.set_ylim([0, 0.2])

            print("recomputing intensities")
            for speck in speckleslist:
                phase_int = speck.recompute_intensity(phaseim)
                speck.phase_intensities[idx] = phase_int

            print((speck.phase_intensities))
            time.sleep(3)
        # if use_centoffs == False:
        #     ao.load_new_flatmap(current_flatmap, wf_temp)
        # # if use_centoffs == True:
        # #     ao.load_new_centoffs(current_centoffs)

        if config['NULLING']['null_gain'] == False:
            defaultgain = config['NULLING']['default_flatmap_gain']

            nullmap = generate_phase_nullmap(speckleslist, defaultgain, phases)
            nullmap = nullmap * aperturemask
            if use_centoffs == False:
                # ao.load_new_flatmap(current_flatmap + nullmap, wfo)
                ao.load_new_flatmap(nullmap, wfo)
            # FPWFS.quicklook_wf(wfo)
            # camera.take_src_return_imagedata(wfo, exptime=exp)
            # if use_centoffs == True:
            #     ao.load_new_centoffs(current_centoffs+ fmf.convert_flatmap_centoffs(nullmap))

        # ans = raw_input('press enter')
        if config['NULLING']['null_gain'] == True:
            ##NOW CALCULATE GAIN NULLS

            print("DETERMINING NULL GAINS")
            gains = config['NULLING']['amplitudegains']
            for idx, gain in enumerate(gains):
                print("Checking optimal gains")
                nullmap = generate_phase_nullmap(speckleslist, gain, phases)
                nullmap = nullmap * aperturemask

                wf_temp = copy.copy(wfo)
                if use_centoffs == False:
                    ao.load_new_flatmap(current_flatmap + nullmap, wf_temp)
                # if use_centoffs == True:
                #     ao.load_new_centoffs(current_centoffs+ fmf.convert_flatmap_centoffs(nullmap))

                ampim = camera.take_src_return_imagedata(wf_temp, exptime=exp)
                # quicklook_wf(wf_temp)
                ampim = pre.equalize_image(ampim, **bgds)
                w2.set_data(np.log(np.abs(ampim * controlregion)))
                ax2.set_title('Gain: ' + str(gain))
                w2.autoscale()
                plt.draw()
                plt.pause(0.02)
                for speck in speckleslist:
                    amp_int = speck.recompute_intensity(ampim)
                    speck.gain_intensities[idx] = amp_int
                print((speck.gain_intensities))
                w4.set_data(
                    list(range(128)),
                    proper.prop_get_amplitude(wf_temp)[64]
                )  #ax4.plot(range(128),  proper.prop_get_amplitude(wf_temp)[20])#np.abs(field_im[20]))#+boarder)
                ax4.set_xlim([0, 128])
                ax4.set_ylim([0, 0.2])
            for speck in speckleslist:
                speck.compute_null_gain()
            supernullmap = generate_super_nullmap(speckleslist, phases)
            print(
                "Loading supernullmap now that optimal gains have been found!")
            supernullmap = supernullmap * aperturemask
            if use_centoffs == False:
                # ao.load_new_flatmap(current_flatmap + supernullmap, wfo)
                ao.load_new_flatmap(supernullmap, wfo)
            # FPWFS.quicklook_wf(wfo)
            # quicklook_im(supernullmap,logAmp=False, show=True)

            # camera.take_src_return_imagedata(wfo, exptime=exp)
            # if use_centoffs == True:
            #     ao.load_new_centoffs(current_centoffs+ fmf.convert_flatmap_centoffs(supernullmap))
            #ao.load_new_flatmap(supernullmap)
            # w3.set_data(nullmap)

            # plt.draw()
        # w4.set_data(np.log(np.abs(field_im))+boarder)
        # plt.draw()
        # w4.autoscale();
        # quicklook_im(field_im, logAmp=False)
        quicklook_wf(wfo)
        plt.show(block=True)

        # ans = raw_input('press enter')
        # try:
        #     check = raw_input("would you like to continue?: ")
        # except EOFError:
        #     print ("Error: EOF or empty input!")
        #     check = ""
        # print check
        plt.show(block=False)
Example #5
0
                                 calib)  # read the perfect-result vortex field
            perf_num = perf_num / psf0 * scale_psf
            wfo._wfarr = (
                wfo._wfarr - psf_num
            ) * vvc + perf_num  # the wavefront takes into account the real pupil with the perfect-result vortex field
        quicklook_wf(wfo)
        proper.prop_propagate(wfo, f_lens, "propagate to pupil reimaging lens")
        proper.prop_lens(wfo, f_lens, "apply pupil reimaging lens")
        proper.prop_propagate(wfo, f_lens, "lyot stop")
        quicklook_wf(wfo)
    return wfo


wfo = proper.prop_begin(tp.diam, tp.band[0], tp.grid_size, tp.beam_ratio)
proper.prop_circular_aperture(wfo, tp.diam / 2)
proper.prop_define_entrance(wfo)
# proper.prop_zernikes(wfo, [2, 3], np.array([3,3])*1e-6)

vortex(wfo)
# quicklook_wf(wfo)
proper.prop_circular_aperture(wfo, 0.75, NORM=True)
quicklook_wf(wfo)

proper.prop_propagate(wfo, tp.f_lens)
proper.prop_lens(wfo, tp.f_lens)

# quicklook_wf(wfo)
(wframe, sampling) = proper.prop_end(wfo)
print np.sum(phot.aper_phot(wframe, 0, 5, plot=True))
quicklook_im(wframe, logAmp=True)
quicklook_im(phot.aper_phot(wframe, 0, 5))