Beispiel #1
0
    def _createCube_forTestDataInOpdImages(self):
        tt = '20191210_143625'
        fold = os.path.join(Configuration.OPD_DATA_FOLDER, 'OPDImages', tt,
                            'hdf5')

        hduList = pyfits.open(os.path.join(fold, 'ampVect.fits'))
        self._cmdAmplitude = hduList[0].data
        hduList = pyfits.open(os.path.join(fold, 'modeRange.fits'))
        self._actsVector = hduList[0].data
        hduList = pyfits.open(os.path.join(fold, 'template.fits'))
        vector_of_push_pull = hduList[0].data

        cube = None
        tip_til_det = TipTiltDetrend()
        r = ROI()
        #         for i in range(self._actsVector.shape[0]):
        for i in range(7):
            k = i * vector_of_push_pull.shape[0]
            imaList = []
            for j in range(vector_of_push_pull.shape[0]):
                l = k + j
                file_name = os.path.join(fold, 'img_%04d.h5') % l
                img = self._ic.from4D(file_name)
                roi = r.roiGenerator(img)
                ima_tt = tip_til_det.tipTiltDetrend(img, roi, 3)
                imaList.append(ima_tt)

            image = imaList[0] + imaList[1] - imaList[2]

            if cube is None:
                cube = image
            else:
                cube = np.ma.dstack((cube, image))

        return cube
Beispiel #2
0
    def createCubeFromImageFolder(self, data_file_path=None, tiptilt_detrend=None,
                                  phase_ambiguity=None):
        '''
        Parameters
        ----------
                data_file_path: string
                                measurement data file path

        Other Parameters
        ----------
                ttDetrend: optional
                            in the creation of the cube the images are reduced
                            removing tip tilt on the central segment

                phaseSolve: optional

        Returns
        -------
                cube = masked array [pixels, pixels, number of images]
                        cube from analysis
        '''
        if data_file_path is None:
            data_file_path = self._h5Folder #viene da loadInfoFromIFFsTtFolder
        else:
            data_file_path = data_file_path
        
        where = self._indexReorganization()
        ampl_reorg = self._amplitudeReorganization(self._actsVector,
                                                   self._indexingList,
                                                   self._cmdAmplitude,
                                                   self._nPushPull)
        cube_all_act = []
        for i in range(self._actsVector.shape[0]):
            print(i)
            for k in range(self._nPushPull):
                p = self._nPushPull * i + k
                n = where[p]
                mis_amp = k* self._indexingList.shape[1] + n
                mis_push = (k * self._indexingList.shape[1]+ n) * 2*self._template.shape[0]
                mis_pull = self._template.shape[0] + mis_push
                mis_list = [mis_push, mis_pull]

                pp_images = []
                for mis in mis_list:
                    name = 'img_%04d.h5' %mis
                    file_name = os.path.join(data_file_path, name)
                    image0 = self._ic.from4D(file_name)

#                 image_sum = np.zeros((image_for_dim.shape[0],
#                                       image_for_dim.shape[1]))
                    image_list = [image0]
                    for l in range(1, self._template.shape[0]):
                        name = 'img_%04d.h5' %(mis+l)
                        file_name = os.path.join(data_file_path, name)
                        ima = self._ic.from4D(file_name)
                        image_list.append(ima)

                    image = np.zeros((image0.shape[0], image0.shape[1]))
                    for p in range(1, len(image_list)):
                        #opd2add   = opdtemp[*,*,p]*form[p]+opdtemp[*,*,p-1]*form[p-1]
                        #opd      += opd2add
                        opd2add = image_list[p] * self._template[p] + image_list[p-1] * self._template[p-1]
                        master_mask2add = np.ma.mask_or(image_list[p].mask, image_list[p-1].mask)
                        if p==1:
                            master_mask = master_mask2add
                        else:
                            master_mask = np.ma.mask_or(master_mask, master_mask2add)
                        image += opd2add
                    image = np.ma.masked_array(image, mask=master_mask)
                    #image = image + ima * self._template[l] #sbagliato
                    pp_images.append(image)
                image = pp_images[0] + pp_images[1] #da rivedere molto
                img_if = image / (2 * ampl_reorg[mis_amp] * (self._template.shape[0] - 1))
                if tiptilt_detrend is None:
                    img_if = img_if
                else:
                    r = ROI()
                    roi = r.roiGenerator(img_if)
                    tt = TipTiltDetrend()
                    img_if = tt.tipTiltDetrend(img_if, roi, 3)

                if_push_pull_kth = img_if

                if k == 0:
                    all_push_pull_act_jth = if_push_pull_kth
                else:
                    all_push_pull_act_jth = np.ma.dstack((all_push_pull_act_jth,
                                                          if_push_pull_kth))

            if self._nPushPull == 1:
                if_act_jth = all_push_pull_act_jth
            else:
                if_act_jth = np.ma.mean(all_push_pull_act_jth, axis=2)

            cube_all_act.append(if_act_jth)
        self._cube = np.ma.dstack(cube_all_act)
        return self._cube
Beispiel #3
0
    def createCubeFromImageFolder(self,
                                  data_file_path,
                                  tiptilt_detrend=None,
                                  phase_ambiguity=None):
        '''
        Parameters
        ----------
                data_file_path: string
                                measurement data file path

        Other Parameters
        ----------
                ttDetrend: optional
                            in the creation of the cube the images are reduced
                            removing tip tilt on the central segment

                phaseSolve: optional

        Returns
        -------
                cube = masked array [pixels, pixels, number of images]
                        cube from analysis
        '''
        cube_all_act = None
        where = self._indexReorganization()
        ampl_reorg = self._amplitudeReorganization(self._actsVector,
                                                   self._indexingList,
                                                   self._cmdAmplitude,
                                                   self._nPushPull)
        for i in range(self._actsVector.shape[0]):
            for k in range(self._nPushPull):
                p = self._nPushPull * i + k
                n = where[p][0][0]
                mis_amp = k * self._indexingList.shape[1] + n
                mis = k * self._indexingList.shape[1] * self._template.shape[0] \
                        + n * self._template.shape[0]

                name = 'img_%04d.h5' % mis
                file_name = os.path.join(data_file_path, name)
                image_for_dim = self._ic.from4D(file_name)

                image_sum = np.zeros(
                    (image_for_dim.shape[0], image_for_dim.shape[1]))
                for l in range(1, self._template.shape[0]):
                    name = 'img_%04d.h5' % (mis + l)
                    file_name = os.path.join(data_file_path, name)
                    ima = self._ic.from4D(file_name)
                    image = image_sum + ima * self._template[l]
                img_if = image / (2 * ampl_reorg[mis_amp] *
                                  (self._template.shape[0] - 1))
                if tiptilt_detrend is None:
                    img_if = img_if
                else:
                    r = ROI()
                    roi = r.roiGenerator(img_if)
                    tt = TipTiltDetrend()
                    img_if = tt.tipTiltDetrend(img_if, roi, 3)

                if_push_pull_kth = img_if - np.ma.median(img_if)

                if k == 0:
                    all_push_pull_act_jth = if_push_pull_kth
                else:
                    all_push_pull_act_jth = np.ma.dstack(
                        (all_push_pull_act_jth, if_push_pull_kth))

            if self._nPushPull == 1:
                if_act_jth = all_push_pull_act_jth
            else:
                if_act_jth = np.ma.mean(all_push_pull_act_jth, axis=2)

            if cube_all_act is None:
                cube_all_act = if_act_jth
            else:
                cube_all_act = np.ma.dstack((cube_all_act, if_act_jth))
        self._cube = cube_all_act

        return self._cube
Beispiel #4
0
    def createCube(self, tiptilt_detrend=None, phase_ambiguity=None):
        '''
        Other Parameters
        ----------
                ttDetrend: optional
                            in the creation of the cube the images are reduced
                            removing tip tilt on the central segment

                phaseSolve: optional

        Returns
        -------
                cube = masked array [pixels, pixels, number of images]
                        cube from analysis
        '''
        cube_all_act = None
        self._ttData()
        self._logCubeCreation(tiptilt_detrend, phase_ambiguity)
        where = self._indexReorganization()
        #misure_pos, misure_neg = self._splitMeasureFromFits(self._cubeMeasure)
        ampl_reorg = self._amplitudeReorganization(self._actsVector,
                                                   self._indexingList,
                                                   self._cmdAmplitude,
                                                   self._nPushPull)

        for i in range(self._actsVector.shape[0]):
            for k in range(self._nPushPull):
                p = self._nPushPull * i + k
                n = where[p][0][0]
                mis_amp = k * self._indexingList.shape[1] + n
                mis = k * self._indexingList.shape[1] * self._template.shape[0] \
                        + n * self._template.shape[0]

                #img_pos = misure_pos[:,:,mis]
                #img_neg = misure_neg[:,:,mis]
                image_sum = np.zeros(
                    (self._cubeMeasure.shape[0], self._cubeMeasure.shape[1]))
                for l in range(1, self._template.shape[0]):
                    image = image_sum + self._cubeMeasure[:, :, mis +
                                                          l] * self._template[l]
                img_if = image / (2 * ampl_reorg[mis_amp] *
                                  (self._template.shape[0] - 1))
                if tiptilt_detrend is None:
                    img_if = img_if
                else:
                    r = ROI()
                    roi = r.roiGenerator(img_if)
                    tt = TipTiltDetrend()
                    img_if = tt.tipTiltDetrend(img_if, roi, 3)

                if_push_pull_kth = img_if - np.ma.median(img_if)

                if k == 0:
                    all_push_pull_act_jth = if_push_pull_kth
                else:
                    all_push_pull_act_jth = np.ma.dstack(
                        (all_push_pull_act_jth, if_push_pull_kth))

            if self._nPushPull == 1:
                if_act_jth = all_push_pull_act_jth
            else:
                if_act_jth = np.ma.mean(all_push_pull_act_jth, axis=2)

            if cube_all_act is None:
                cube_all_act = if_act_jth
            else:
                cube_all_act = np.ma.dstack((cube_all_act, if_act_jth))
        self._cube = cube_all_act

        return self._cube