Exemple #1
0
def PT_calibration(n_meas):
    '''
    Parameters
    ----------
        n_meas: int
            number of measurement to store

    Returns
    -------
        dove: string
            data file path of measurement
    '''
    from m4.ground import tracking_number_folder
    from opcua import Client
    server = OpcUaParameters.server
    client = Client(url=server)
    client.connect()

    folder = config.PT_ROOT_FOLDER
    dove, tt = tracking_number_folder.createFolderToStoreMeasurements(folder)

    for i in range(n_meas):
        time.sleep(2)
        temp = client.get_node("ns=7;s=MAIN.i_Temperature_Sensor")
        temp_list = temp.get_value()
        temp_vector = np.array(temp_list.get_value())

        fits_file_name = os.path.join(dove, 'temperature_%04.fits' % i)
        pyfits.writeto(fits_file_name, temp_vector)

        print('Misura %04d' % i)
    return dove
Exemple #2
0
    def saveInfo(self, fits_or_h5):
        """ Save the data in fits format

        Returns
        -------
        tt: string
            tracking number
        """
        store_in_folder = CmdHistory._storageFolder()
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            store_in_folder)

        if fits_or_h5 == 0:
            fits_file_name = os.path.join(dove, 'info.fits')
            header = pyfits.Header()
            header['NPUSHPUL'] = self._nPushPull
            pyfits.writeto(fits_file_name, self._modeVector, header)
            pyfits.append(fits_file_name, self._indexingList, header)
            pyfits.append(fits_file_name, self._cmdMatrix, header)
            pyfits.append(fits_file_name, self._cmdHToApply, header)
            pyfits.append(fits_file_name, self._ampVect, header)
        else:
            fits_file_name = os.path.join(dove, 'info.h5')
            hf = h5py.File(fits_file_name, 'w')
            hf.create_dataset('dataset_1', data=self._modeVector)
            hf.create_dataset('dataset_2', data=self._indexingList)
            hf.create_dataset('dataset_3', data=self._cmdHToApply)
            hf.create_dataset('dataset_4', data=self._ampVect)
            hf.attrs['NPUSHPUL'] = self._nPushPull
            hf.close()
        return tt
Exemple #3
0
    def measureAndAnalysisCalibrationMatrix(self, who, command_amp_vector,
                                            n_push_pull, n_frames):
        '''
        Parameters
        ----------
        who: string
            string indicating the optical element
            on which to perform the calibration
            cal.WHO_PAR_AND_RM for parabola and reference mirror
            cal.WHO_PARABLE for parabola (non implemented)
            cal.WHO_RM for reference mirror (not implemented)
            cal.WHO_M4 for deformable mirror
        command_amp_vector: numpy array [mm]
                            vector containing the amplitude of the
                            commands to give degrees of freedom to
                            calibrate
        n_push_pull: int
                    number of push pull
        n_frames: int
                number of frame for 4D measurement

        Returns
        -------
        tt : string
            tracking number containing measurements and IntMat from analysis
        '''
        self._nPushPull = n_push_pull
        self._commandAmpVector = command_amp_vector

        dove, self.tt = tracking_number_folder.createFolderToStoreMeasurements(
            self._storageFolder())
        self._logger.info('Measure of calibration. Location: %s', self.tt)

        #measurement
        dofIndex_vector = self._logAndDefineDovIndexForCommandMatrixCreation(
            who)
        self._commandMatrix, self._commandList = self.createCmatAndCmdList(
            command_amp_vector, dofIndex_vector)
        self._measureAndStore(self._commandList, dove, n_frames)
        #analysis
        self._createCube(False)  # cubo non normalizzato
        cube = self.getCube()
        self._mask = self._findMask(cube)
        self._intMat = self.getInteractionMatrix()

        self._saveCalibrationInfoAndResultsAsFits(dove)

        #         if self._mixed_method == False:
        #             self._createCube() #cubo normalizzato
        #             cube_norm = self.getCube()
        #             self._mask = self._findMask(cube_norm)
        #             self._intMatNorm = self.getInteractionMatrix(self._mask)
        #             fits_file_name = os.path.join(dove, 'InteractionMatrixNorm.fits')
        #             pyfits.writeto(fits_file_name, self._intMatNorm, overwrite=True)
        return self.tt
Exemple #4
0
    def diffOpticalMonitoring(self, n_images, delayshort, delaylong):
        '''
        # Fa due misure poco distanti tra loro e poi aspetta tanto
        Parameters
        ----------
        n_images: int
            number of images to acquire
        delayshort: float
            time gap between images couple
        delaylong: float
            time gap between images couple
        Returns
        ------
        tt: string
            tracking number of measurements
        '''
        store_in_folder = fold_name.OPD_SERIES_ROOT_FOLDER
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            store_in_folder)

        zer_list = []
        temp_list = []
        t0 = time.time()
        for i in range(n_images):
            for i in range(2):
                ti = time.time()
                dt = ti - t0
                masked_ima = self._interf.acquire_phasemap(1)
                temp_vect = self._ott.temperature.getTemperature()
                name = Timestamp.now() + '.fits'
                fits_file_name = os.path.join(dove, name)
                pyfits.writeto(fits_file_name, masked_ima.data)
                pyfits.append(fits_file_name, masked_ima.mask.astype(int))

                coef, mat = zernike.zernikeFit(masked_ima, np.arange(10) + 1)
                vect = np.append(dt, coef)
                zer_list.append(vect)
                temp_list.append(temp_vect)

                fits_file_name = os.path.join(dove, 'zernike.fits')
                pyfits.writeto(fits_file_name,
                               np.array(zer_list),
                               overwrite=True)
                fits_file_name = os.path.join(dove, 'temperature.fits')
                pyfits.writeto(fits_file_name,
                               np.array(temp_list),
                               overwrite=True)
                print('Waiting for next frame in pair')
                time.sleep(delayshort)

            print('Waiting for next iterations')
            time.sleep(delaylong)

        return tt
Exemple #5
0
 def save(self):
     """ Function to save the info file
     """
     store_in_folder = Flattenig._storageFolder()
     dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
         store_in_folder)
     fits_file_name = os.path.join(dove, 'info.fits')
     header = pyfits.Header()
     header['WHO'] = self._who
     pyfits.writeto(fits_file_name, self._command, header)
     pyfits.append(fits_file_name, self._flatteningWf.data, header)
     pyfits.append(fits_file_name, self._flatteningWf.mask.astype(int),
                   header)
     return tt
Exemple #6
0
    def image_acquisition(self, start_point, end_point, n_points):
        """
        Parameters
        ----------
        start_point: int [deg]
                    absolute position in deg for the value of start angle
        end_point: int [deg]
                    absolute position in deg for the value of end angle
        n_points:int
                number of images desired

        Returns
        -------
        tt: string
            tracking number of measurements
        """
        self._logger.info('Images acquisition')
        dove, self.tt = tracking_number_folder.createFolderToStoreMeasurements(
            RotOptAlign._storageFolder())

        total_angle = np.abs(end_point - start_point) / 1.
        self._ott.angleRotator.setPosition(start_point)
        rot_angle = total_angle / n_points
        number_of_image = np.int(total_angle / rot_angle)
        angle_list = []
        self._cube = None

        start_angle = self._ott.angleRotator.getPosition()
        if end_point < start_point:
            direction = -1
        elif end_point > start_point:
            direction = 1

        for k in range(number_of_image + 1):
            #start_angle = self.ott.angle()
            self._ott.angleRotator.setPosition(start_angle +
                                               k * rot_angle * direction)
            angle_list.append(start_angle + k * rot_angle * direction)
            time.sleep(5)
            masked_ima = self._interf.acquire_phasemap(1)
            name = 'Frame_%04d.fits' % k
            self._interf.save_phasemap(dove, name, masked_ima)
            if self._cube is None:
                self._cube = masked_ima
            else:
                self._cube = np.ma.dstack((self._cube, masked_ima))
        self._saveCube(dove)
        self._angles = angle_list
        self._saveAngles(self._angles, self.tt)
        return self.tt
    def noise_analysis_from_hdf5_folder(self,
                                        data_file_path,
                                        tidy_or_shuffle,
                                        template,
                                        n_push_pull=None,
                                        actsVector=None):
        '''
        Parameters
        ----------
            data_file_path: string
                            measurement data folder
            tidy_or_shuffle: int
                            0 for tidy, 1 for shuffle
            template: numpy array
                    vector composed by 1 and -1
        Other Parameters
        ----------------
            actsVector: numpy array, optional
                        vector of actuators or modes
            n_push_pull: int
                        number of push pull

        Returns
        -------
                tt: string
                    tracking number of measurements made
        '''
        an = self._defAnalyzer(data_file_path, tidy_or_shuffle, template,
                               actsVector, n_push_pull)

        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            self._storageFolder())

        self._logger.info('Creating analysis in %s', tt)
        self._cubeFromAnalysis = an.createCubeFromImageFolder(data_file_path)
        fits_file_name = os.path.join(dove, 'Cube.fits')
        pyfits.writeto(fits_file_name, self._cubeFromAnalysis.data)
        pyfits.append(fits_file_name, self._cubeFromAnalysis.mask.astype(int))

        self._saveInfo(dove, tidy_or_shuffle, an._template, an._actsVector,
                       an._nPushPull)

        rms_mean, quad_mean, tilt_mean, ptv_mean = self._rmsFromCube(
            self._cubeFromAnalysis)
        self._saveResults(rms_mean, quad_mean, ptv_mean, dove)
        return tt
Exemple #8
0
    def opticalMonitoring(self, n_images, delay):
        '''
        #monitora

        Parameters
        ----------
        n_images: int
            number of images to acquire
        delay: int [s]
            waiting time (in seconds) between two image acquisitions

        Returns
        ------
        tt: string
            tracking number of measurements
        '''
        store_in_folder = fold_name.OPD_SERIES_ROOT_FOLDER
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            store_in_folder)

        zer_list = []
        temp_list = []
        t0 = time.time()
        for i in range(n_images):
            ti = time.time()
            dt = ti - t0
            masked_ima = self._interf.acquire_phasemap(1)
            temp_vect = self._ott.temperature.getTemperature()
            name = Timestamp.now() + '.fits'
            fits_file_name = os.path.join(dove, name)
            pyfits.writeto(fits_file_name, masked_ima.data)
            pyfits.append(fits_file_name, masked_ima.mask.astype(int))

            coef, mat = zernike.zernikeFit(masked_ima, np.arange(10) + 1)
            vect = np.append(dt, coef)
            zer_list.append(vect)
            temp_list.append(temp_vect)

            fits_file_name = os.path.join(dove, 'zernike.fits')
            pyfits.writeto(fits_file_name, np.array(zer_list), overwrite=True)
            fits_file_name = os.path.join(dove, 'temperature.fits')
            pyfits.writeto(fits_file_name, np.array(temp_list), overwrite=True)

            time.sleep(delay)
        return tt
Exemple #9
0
 def testTtFolder(self):
     store_in_folder = '?'
     dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
         store_in_folder)
Exemple #10
0
    def acquire(self, lambda_vector, exptime=0.7, mask=None):
        '''
        Parameters
        ----------
        lambda_vector: numpy array
                        vector of wavelengths (between 400/700 nm)

        Other Parameters
        ----------------
        exptime: float
            best exposure time for camera for laboratory conditions
        mask: numpy array
            mask for measurements
        Returns
        -------
        tt: string
            tracking number of measurements
        '''
        self._dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            self._storageFolder())
        fits_file_name = os.path.join(self._dove, 'lambda_vector.fits')
        pyfits.writeto(fits_file_name, lambda_vector)

        ## find PSF position ##
        print('Acquiring reference image at 600 nm...')
        self._filter.set_wl(600)
        self._camera.feature('ExposureTimeAbs').value = 1.5 * exptime * 1e6
        img = self._camera.acquire_frame(30 * 1000).buffer_data_numpy()
        if mask is None:
            mask = np.zeros(img.shape)

        reference_image = np.ma.masked_array(img, mask)

        if np.max(reference_image) > 4000:
            print("**************** WARNING: saturation detected!")
        # calcolo il baricentro
        cy, cx = self._baricenterCalculator(reference_image)

        expgain = np.ones(lambda_vector.shape[0])
        expgain[np.where(lambda_vector < 500)] = 8
        expgain[np.where(lambda_vector < 530)] = 4
        expgain[np.where(lambda_vector > 680)] = 3
        expgain[np.where(lambda_vector > 700)] = 8
        expgain[np.where(lambda_vector >= 720)] = 9

        self._logger.info('Acquisition of frames')

        for wl, expg in zip(lambda_vector, expgain):

            print('Acquiring image at %d nm...' % wl)
            self._filter.set_wl(wl)
            self._camera.feature(
                'ExposureTimeAbs').value = exptime * expg * 1e6
            #time.sleep(3 * ExposureTimeAbs / 1e6)
            image = self._camera.acquire_frame(30 * 1000).buffer_data_numpy()
            image = np.ma.masked_array(image, mask)
            #            plot(image)
            #plt.imshow(image)
            #plt.show()

            crop = self._preProcessing(image, cy, cx)
            crop_rot = scin.rotate(crop, 23, reshape=False)
            #plt.figure(figsize=(10,5))
            self.plot2(crop, crop_rot)

            file_name = 'image_%dnm.fits' % wl
            self._saveCameraFrame(file_name, crop)

        print('Saved tracking number:', tt)
        return tt
Exemple #11
0
    def acq_IFFunctions(self,
                        n_push_pull,
                        amplitude_fits_file_name,
                        cmd_matrix_fits_file_name,
                        shuffle=None,
                        template=None):
        '''
        Performs the process of acquiring interferograms

        Parameters
        ----------
             n_push_pull: int
                          number of push pull on the actuator
             amplitude_fits_file_name: string
                                       fits file name
                                       (Example = amp.fits)
             cmd_matrix_fits_file_name: int
                                        fits file name
                                        (Example = modalBase.fits)
        Other Parameters
        ----------------
             shuffle: optional
                      if not indicated, the function create the tidy command
                      history matrix
             template: numpy array, optional
                       vector composed by 1 and -1
                       if not indicated, the function create the vector [1, -1, 1]

        Returns
        -------
                tt: string
                    tracking number of measurements made
        '''
        amplitude, cmd_matrix = self._readTypeFromFitsNameTag(
            amplitude_fits_file_name, cmd_matrix_fits_file_name)

        self._nPushPull = n_push_pull
        if template is None:
            self._template = np.array([1, -1, 1])
        else:
            self._template = template

        self._amplitudeTag = amplitude_fits_file_name
        self._amplitude = amplitude
        self._cmdMatrixTag = cmd_matrix_fits_file_name
        self._cmdMatrix = cmd_matrix

        self._actsVector = np.arange(self._nActs)
        indexing_input = copy.copy(self._actsVector)
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            self._storageFolder())
        self._tt = tt

        #         diagonal_mat = self._diagonalControll(cmd_matrix)
        #         if np.count_nonzero(diagonal_mat -
        #                             np.diag(np.diagonal(diagonal_mat))) == 0:
        #             print('Measure of zonal IF')
        #             self._logger.info("Measurement of zonal influence functions for segment?. Location: %s",
        #                               tt)
        #         else:
        #             print('Measure of global IF')
        #             self._logger.info("Measurement of modal influence functions for segment?. Location: %s",
        #                               tt)

        cmdH = CmdHistory(self._nActs)

        if shuffle is False:
            command_history_matrix_to_apply, self._tt_cmdH = \
                    cmdH.tidyCommandHistoryMaker(self._actsVector,
                                                 amplitude,
                                                 cmd_matrix,
                                                 n_push_pull,
                                                 template)
        if shuffle is True:
            command_history_matrix_to_apply, self._tt_cmdH = \
                    cmdH.shuffleCommandHistoryMaker(self._actsVector,
                                                    amplitude,
                                                    cmd_matrix,
                                                    n_push_pull,
                                                    template)
        self._indexingList = cmdH.getIndexingList()
        #self._saveInfo(dove, 0)
        #self._saveInfoSeparately(dove)

        n_images = 1
        for i in range(command_history_matrix_to_apply.shape[1]):
            for j in range(self._template.shape[0]):
                k = self._template.shape[0] * i + j
                print('Acquisition of image %d' % k)
                self._dm.setActsCommand(command_history_matrix_to_apply[:, i] *
                                        j)  #vecchia setShape
                masked_image = self._interf.acquire_phasemap(n_images)
                file_name = 'image_%04d.fits' % k
                self._interf.save_phasemap(dove, file_name, masked_image)
        return tt
Exemple #12
0
    def scanAstigmComa(self, stepamp, nstep, nframes=10):  # by RB 20210117.
        '''
        Parameters
        ----------
        stepamp: int
            amplitude for tip and tilt
        nstep: int
            number of step measurements
        nframes: int
            number of interferometr's frames

        Returns
        ------
        tt: string
            tracking number of measurements
        '''
        # goal: to measure coma and astigmatism at different PAR position, spanning 500 arcsec
        store_in_folder = fold_name.CALIBRATION_ROOT_FOLDER
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            store_in_folder)
        par2rm = -2.05
        zern_vect = []
        parpos = []
        rmpos = []
        par0 = self._ott.parabola.getPosition()
        rm0 = self._ott.referenceMirror.getPosition()
        n2move = np.array([3, 4])
        thedirection = np.array([-1, 1])
        n_frames_alignment = 3
        tt_for_align = '20210111_152430'

        for k in n2move:
            for v in thedirection:

                for i in range(nstep):
                    par1 = par0.copy()
                    parmove = stepamp * i * v
                    par1[k] += parmove
                    print('Moving PAR[%d] by %d' % (k, parmove))
                    self._ott.parabola.setPosition(par1)
                    rm1 = rm0.copy()
                    rmmove = stepamp * i * v * par2rm
                    rm1[k] += rmmove
                    self._ott.referenceMirror.setPosition(rm1)
                    print('Moving RM[%d] by %d' % (k, rmmove))
                    par_cmd, rm_cmd = self._ottca.par_and_rm_aligner(
                        True, tt_for_align, n_frames_alignment,
                        np.array([0, 1]), np.array([3, 4]))
                    #                     a.ott_alignment(n_frames_alignment, 1,
                    #                                                       np.array([0, 1]),
                    #                                                       np.array([3, 4]),
                    #                                                       tt_for_align)
                    par2 = self._ott.parabola.getPosition()
                    rm2 = self._ott.referenceMirror.getPosition()
                    masked_ima = self._interf.acquire_phasemap(nframes)
                    name = Timestamp.now() + '.fits'
                    fits_file_name = os.path.join(dove, name)
                    pyfits.writeto(fits_file_name, masked_ima.data)
                    pyfits.append(fits_file_name, masked_ima.mask.astype(int))

                    coef, mat = zernike.zernikeFit(masked_ima,
                                                   np.arange(10) + 1)
                    zern_vect.append(coef)
                    parpos.append(par2)
                    rmpos.append(rm2)

                    fits_file_name = os.path.join(dove, 'zernike.fits')
                    pyfits.writeto(fits_file_name,
                                   np.array(zern_vect),
                                   overwrite=True)
                    fits_file_name = os.path.join(dove, 'PAR_positions.fits')
                    pyfits.writeto(fits_file_name,
                                   np.array(parpos),
                                   overwrite=True)
                    fits_file_name = os.path.join(dove, 'RM_positions.fits')
                    pyfits.writeto(fits_file_name,
                                   np.array(rmpos),
                                   overwrite=True)

        self._ott.parabola.setPosition(par0)
        self._ott.referenceMirror.setPosition(rm0)
        return tt
Exemple #13
0
 def rawAcquisition(self, numberOfFrames):
     dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
         self._rawFramesDirectory)
     self._interf.burstFramesToSpecificDirectory(dove, numberOfFrames)
     return tt
Exemple #14
0
    def alignTest(self, tt, n_images, perturbation_vec, pre=False):
        '''
        Parameters
        ---------
        tt: string
            tracking number for the alignment
        n_images: int
            number of frames for the interferometer
        perturbation_vec: numpy array
            np.array([par_focus, par_tilt, par_tip])

        Other Parameters
        ----------------
        pre: boolean
            if True a pre-tiptilt alignment before the 5 dof one

        Returns
        -------
        coeff_matrix: numpy array
            zernike coefficients matrix for all the images
        tt: string
            tracking number of measurements
        '''
        # Homing the system
        self._ottca.par_and_rm_aligner(True, tt, n_images, np.array([0, 1]),
                                       np.array([3, 4]))
        #a.ott_alignment(n_images, 1, np.array([0,1]), np.array([3,4]), tt)
        par0 = self._ott.parabola.getPosition()
        rm0 = self._ott.referenceMirror.getPosition()
        # Set perturbation from perturbation_vec
        focus = perturbation_vec[0]
        tip = perturbation_vec[1]
        tilt = perturbation_vec[2]
        par1 = np.copy(par0)
        par1[2] += focus
        par1[3] += tip
        par1[4] += tilt
        rm1 = np.copy(rm0)
        rm1[3] += -tip * 2.05
        rm1[4] += -tilt * 2.05
        # Initialization
        zern_vec = np.arange(1, 12, 1)
        coeff = []
        # Start image, perturbation and perturbed image
        image = self._interf.acquire_phasemap(n_images)
        pippo = zernike.zernikeFit(image, zern_vec)
        coeff.append(pippo[0])
        self._ott.parabola.setPosition(par1)
        self._ott.referenceMirror.setPosition(rm1)
        image = self._interf.acquire_phasemap(n_images)
        pippo = zernike.zernikeFit(image, zern_vec)
        coeff.append(pippo[0])
        # TipTilt pre-alignment
        if pre is True:
            self._ottca.par_and_rm_aligner(True, tt, n_images, np.array([0,
                                                                         1]),
                                           np.array([3, 4]))
            #a.ott_alignment(n_images, 1, np.array([0,1]), np.array([3,4]), tt)
            image = self._interf.acquire_phasemap(2)
            pippo = zernike.zernikeFit(image, zern_vec)
            coeff.append(pippo[0])
        # First alignment
        self._ottca.par_and_rm_aligner(True, tt, n_images, np.array([0, 1]),
                                       np.array([3, 4]))
        #a.ott_alignment(n_images, 1, np.array([0,1,2,3,4]), np.array([0,1,2,3,4]), tt)
        image = self._interf.acquire_phasemap(2)
        pippo = zernike.zernikeFit(image, zern_vec)
        coeff.append(pippo[0])
        # Second alignment
        self._ottca.par_and_rm_aligner(True, tt, n_images, np.array([0, 1]),
                                       np.array([3, 4]))
        #a.ott_alignment(n_images, 1, np.array([0,1]), np.array([3,4]), tt)
        image = self._interf.acquire_phasemap(n_images)
        pippo = zernike.zernikeFit(image, zern_vec)
        coeff.append(pippo[0])
        # Check image
        image = self._interf.acquire_phasemap(n_images)
        pippo = zernike.zernikeFit(image, zern_vec)
        coeff.append(pippo[0])

        coeff_matrix = np.array(coeff) * 1e9
        parend = self._ott.parabola.getPosition()

        store_in_folder = os.path.join(fold_name.REPEATABILITY_ROOT_FOLDER,
                                       'Alignment')
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            store_in_folder)
        fits_file_name = os.path.join(dove, 'zernike.fits')
        pyfits.writeto(fits_file_name, coeff_matrix, overwrite=True)

        print(parend - par0)
        return coeff_matrix, tt
Exemple #15
0
    def mappingPar(self, shift, n_iter, tt_for_align):
        '''
        Parameters
        ----------
        shift: numpy array
                np.array([shift_par, shift_rm, rot_angle])
        n_iter: int
                number of iterations
        tt_for_align: string
            tracking number for alignment

        Returns
        -------
        tt: string
            tracking number of measurements
        '''
        n_frames_alignment = 1
        par0 = self._ott.parabola.getPosition()
        rm0 = self._ott.referenceMirror.getPosition()
        delta_par = []
        delta_rm = []
        delta_object = []
        delta_object2 = []
        delta_object3 = []

        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            fold_name.MAPPING_TEST_ROOT_FOLDER)
        if shift[2] != 0:
            shift[0] = shift[1] = 0
            object_to_move = 'ANGLE'
        if shift[1] != 0:
            shift[0] = shift[2] = 0
            object_to_move = 'RM'
        if shift[0] != 0:
            shift[1] = shift[0]
            shift[2] = 0
            object_to_move = 'PAR + RM'

        file = open(os.path.join(dove, 'MappingInfo.txt'), "a")
        file.write('Mapping object: ' + object_to_move + '\n')
        file.close()
        slide0 = self._ott.parabolaSlider.getPosition()
        rslide0 = self._ott.referenceMirrorSlider.getPosition()
        angle0 = self._ott.angleRotator.getPosition()
        slide = -1
        rslide = -1
        angle = -1
        for i in range(n_iter):
            if shift[0] != 0:
                slide = self._ott.parabolaSlider.setPosition(slide0 + (
                    (i + 1) * shift[0]))
    #             if slide==0:
    #                 raise Exception('HOMING! PAR WIN')
            if shift[1] != 0:
                rslide = self._ott.referenceMirrorSlider.setPosition(
                    rslide0 + ((i + 1) * shift[1]))

    #             if rslide==0:
    #                 raise Exception('HOMING! RM WIN')
            if shift[2] != 0:
                angle = self._ott.angleRotator.setPosition(angle0 + (
                    (i + 1) * shift[2]))

            time.sleep(5)
            par_cmd, rm_cmd = self._ottca.par_and_rm_aligner(
                True, tt_for_align, n_frames_alignment, np.array([0, 1]),
                np.array([3, 4]))
            #             a.ott_alignment(n_frames_alignment, 1,
            #                                               np.array([0, 1]), np.array([3, 4]),
            #                                               tt_for_align)
            image = self._interf.acquire_phasemap(1)
            name = 'image_%04d.fits' % i
            self._interf.save_phasemap(dove, name, image)
            par = self._ott.parabola.getPosition()
            rm = self._ott.referenceMirror.getPosition()
            delta_par.append(par - par0)
            delta_rm.append(rm - rm0)
            delta_object.append(slide - slide0)
            delta_object2.append(rslide - rslide0)
            delta_object3.append(angle - angle0)

            fits_file_name = os.path.join(dove, 'delta_slide.fits')
            pyfits.writeto(fits_file_name,
                           np.array(delta_object),
                           overwrite=True)
            fits_file_name = os.path.join(dove, 'delta_rslide.fits')
            pyfits.writeto(fits_file_name,
                           np.array(delta_object2),
                           overwrite=True)
            fits_file_name = os.path.join(dove, 'delta_PAR_positions.fits')
            pyfits.writeto(fits_file_name, np.array(delta_par), overwrite=True)
            fits_file_name = os.path.join(dove, 'delta_RM_positions.fits')
            pyfits.writeto(fits_file_name, np.array(delta_rm), overwrite=True)
            fits_file_name = os.path.join(dove, 'delta_ANGLE_positions.fits')
            pyfits.writeto(fits_file_name,
                           np.array(delta_object3),
                           overwrite=True)

        return tt
Exemple #16
0
    def parPistonTest(self, piston_value, deltapos_filepath, amp,
                      tt_for_align):
        '''
        Parameters
        ----------
        piston_value: int
            relative value for the parab piston
        deltapos_filepath: string
            file path for par and rm delta positions
        amp: float
            tip tilt amplitude for par and rm
        tt_for_align: string
            tracking number for alignment

        Returns
        -------
        tt: string
            tracking number of measurements
        '''
        # '/home/m4/pardeltapos.fits'
        hduList = pyfits.open(deltapos_filepath)
        deltapos = hduList[0].data
        dx = deltapos[:, 0] * amp
        dy = deltapos[:, 1] * amp
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            fold_name.PISTON_TEST_ROOT_FOLDER)
        par0 = self._ott.parabola.getPosition()
        rm0 = self._ott.referenceMirror.getPosition()
        n_frames_meas = 10
        n_frames_alignment = 3
        rmcoeff = -2.04

        coef_list = []
        par_list = []
        rm_list = []
        for i in range(dx.size):
            if i == 0:
                print('Iteration 0')
            else:
                print('Iteration %d' % i)
                par_new = par0.copy()
                rm_new = rm0.copy()
                par_new[3] += dx[i]
                rm_new[3] += rmcoeff * dx[i]
                par_new[4] += dy[i]
                rm_new[4] += rmcoeff * dy[i]
                self._ott.parabola.setPosition(par_new)
                self._ott.referenceMirror.setPosition(rm_new)
                par_cmd, rm_cmd = self._ottca.par_and_rm_aligner(
                    True, tt_for_align, n_frames_alignment, np.array([0, 1]),
                    np.array([3, 4]))
#                 a.ott_alignment(n_frames_alignment, 1,
#                                                   np.array([0, 1]),
#                                                   np.array([3, 4]),
#                                                   tt_for_align)

            par = self._ott.parabola.getPosition()
            rm = self._ott.referenceMirror.getPosition()
            par_list.append(par)
            rm_list.append(rm)
            masked_ima0 = self._interf.acquire_phasemap(n_frames_meas)
            par[2] += piston_value
            self._ott.parabola.setPosition(par)
            masked_ima1 = self._interf.acquire_phasemap(n_frames_meas)
            par[2] -= piston_value
            self._ott.parabola.setPosition(par)
            diff = masked_ima1 - masked_ima0
            name = 'diff_%04d.fits' % i
            self._interf.save_phasemap(dove, name, diff)
            coef, mat = zernike.zernikeFit(diff, np.arange(10) + 1)
            coef_list.append(coef)

            fits_file_name = os.path.join(dove, 'Zernike.fits')
            pyfits.writeto(fits_file_name, np.array(coef_list), overwrite=True)
            fits_file_name = os.path.join(dove, 'PAR_Positions.fits')
            pyfits.writeto(fits_file_name, np.array(par_list), overwrite=True)
            fits_file_name = os.path.join(dove, 'RM_Positions.fits')
            pyfits.writeto(fits_file_name, np.array(rm_list), overwrite=True)
        return tt
Exemple #17
0
    def zernikeCommandTest(self, zernike_modes_vector_amplitude):
        '''

        Parameters
        ----------
            zernike_modes_vector_amplitude: numpy array
                                            vector of amplitude of zernike
                                            modes to be test, starting from z=2

        Returns
        -------
                tt: string
                    tracking number for the measurement
                zernikeSurfaceCube: numpy array [512, 512, n_modes]
                    all zernike surface generated on M4
                m4ImagesCube: numpy array [512, 512, n_modes]
                    cube consisting of the 6 images of the segments
        '''
        self._ampVector = zernike_modes_vector_amplitude
        self._dove, self._tt = tracking_number_folder.createFolderToStoreMeasurements(self._storageFolder())

        self._saveMeasurementInfo()
        self._logger.debug('Info file creation')

        self._logger.info('Creation of an list')
        for tt in self._ttListForAn:
            an = self._createAnalyzer(tt)
            self._anList.append(an)

        self._nModes = zernike_modes_vector_amplitude.shape[0]
        for j in range(self._nModes):
            amp = zernike_modes_vector_amplitude[j]
            if amp == 0:
                pass
            else:
                zernike_coeff_array = np.zeros(zernike_modes_vector_amplitude.shape[0])
                zernike_coeff_array[j] = amp
                number_of_zernike_mode = j + 2

                surface_map, total_mode_command = self.singleZernikeCommandTest(zernike_coeff_array,
                                                                                self._anList,
                                                                                number_of_zernike_mode)
                if self._zernikeSurfaceCube is None:
                    self._zernikeSurfaceCube = surface_map
                else:
                    self._zernikeSurfaceCube = np.dstack((self._zernikeSurfaceCube, surface_map))
                #single_zernike_cube = self._singleZernikeModeCubeMeasurementCreator(number_of_zernike_mode)
                single_zernike_cube = self._TESTFUCTIONFORZERNIKECUBE(number_of_zernike_mode, amp)
                cube_name = 'cube_mode%04d.fits' %number_of_zernike_mode
                self._saveSingleZernikeCube(single_zernike_cube, cube_name)

                total_mode_image = self._imageReconstructor(single_zernike_cube)
                piston = self._differentialPistonMeasurement(total_mode_command)
                final_total_mode_image = total_mode_image - piston
                if self._m4ImagesCube is None:
                    self._m4ImagesCube = final_total_mode_image
                else:
                    self._m4ImagesCube = np.ma.dstack((self._m4ImagesCube, final_total_mode_image))


        fits_file_name = os.path.join(self._dove, 'surfCube.fits')
        pyfits.writeto(fits_file_name, self._zernikeSurfaceCube)
        fits_file_name = os.path.join(self._dove, 'm4ImageCube.fits')
        pyfits.writeto(fits_file_name, self._m4ImagesCube.data)
        pyfits.append(fits_file_name, self._m4ImagesCube.mask.astype(int))
        return self._tt, self._zernikeSurfaceCube, self._m4ImagesCube
Exemple #18
0
    def actsRepeatability(self, n_meas, piston_value, n_frames):
        '''
        Parameters
        ----------
        n_meas: int
            number of measurement for the test
        piston_value: float
            relative value for the parab piston
        n_frames: int
            number of frames for the acquisition measurement

        Returns
        ------
        tt: string
            tracking number of measurements
        '''
        store_in_folder = fold_name.REPEATABILITY_ROOT_FOLDER
        dove, tt = tracking_number_folder.createFolderToStoreMeasurements(
            store_in_folder)

        piston = np.array([0, 0, piston_value, 0, 0, 0])
        pos_par = self._ott.parabola.getPosition()
        pos_rm = self._ott.referenceMirror.getPosition()

        par_list = []
        rm_list = []
        cube = None
        for i in range(n_meas):
            self._ott.parabola.setPosition(pos_par)
            self._ott.referenceMirror.setPosition(pos_rm)
            par0 = self._readActs(OpcUaParameters.PAR1, OpcUaParameters.PAR2,
                                  OpcUaParameters.PAR3)
            rm0 = self._readActs(OpcUaParameters.RM1, OpcUaParameters.RM2,
                                 OpcUaParameters.RM3)
            masked_ima0 = self._interf.acquire_phasemap(n_frames)

            self._ott.parabola.setPosition(pos_par + piston)
            # ott.refflat(pos_rm + piston)

            par1 = self._readActs(OpcUaParameters.PAR1, OpcUaParameters.PAR2,
                                  OpcUaParameters.PAR3)
            rm1 = self._readActs(OpcUaParameters.RM1, OpcUaParameters.RM2,
                                 OpcUaParameters.RM3)
            masked_ima1 = self._interf.acquire_phasemap(n_frames)

            self._ott.parabola.setPosition(pos_par - piston)
            # ott.refflat(pos_rm - piston)

            par2 = self._readActs(OpcUaParameters.PAR1, OpcUaParameters.PAR2,
                                  OpcUaParameters.PAR3)
            rm2 = self._readActs(OpcUaParameters.RM1, OpcUaParameters.RM2,
                                 OpcUaParameters.RM3)
            masked_ima2 = self._interf.acquire_phasemap(n_frames)

            par = np.array([par0, par1, par2])
            rm = np.array([rm0, rm1, rm2])
            cubetto = np.ma.dstack((masked_ima0, masked_ima1, masked_ima2))
            if cube is None:
                cube = cubetto
            else:
                cube = np.ma.dstack((cube, cubetto))

            par_list.append(par)
            rm_list.append(rm)
            pyfits.writeto(os.path.join(dove, 'par.fits'),
                           np.array(par_list),
                           overwrite=True)
            pyfits.writeto(os.path.join(dove, 'rm.fits'),
                           np.array(rm_list),
                           overwrite=True)
            pyfits.writeto(os.path.join(dove, 'images.fits'),
                           cube.data,
                           overwrite=True)
            pyfits.append(os.path.join(dove, 'images.fits'),
                          cube.mask.astype(int),
                          overwrite=True)

        self._ott.parabola.setPosition(pos_par)
        self._ott.referenceMirror.setPosition(pos_rm)
        return tt