def processFullFrame(data_list,
                     pos_seg2,
                     maskbounds,
                     swap_ref,
                     which_null=None):
    global img, dark, dark_per_channel, wl, fichier, rtscan
    global data, spectral_axis, position_outputs, width_outputs, debug
    global spectral_binning, wl_bin_min, wl_bin_max, bandwidth_binning, mode_flux
    global scanrange, scanrange0, wl0, selected_Iminus, mask, data0, scans0

    scans = []
    opds = []
    rtscans = []

    if which_null == None:
        for i in range(6):
            if 'null' + str(i + 1) in data_list[0]:
                which_null = i + 1
                break
    ''' Start the data processing '''
    for f in data_list[:]:
        print("Process of : %s (%d / %d)" %
              (f, data_list.index(f) + 1, len(data_list)))
        fichier = loadmat(f)
        '''Scan range parameters'''

        data0 = fichier['fullScanAllImages']
        if len(data0.shape) == 4:
            nloop = data0.shape[-1]
        else:
            nloop = 1

        rtscan = fichier['curVals'][:, 0]
        rtscan /= rtscan.mean()
        rtscans.append(rtscan)
        scanrange = fichier['memsScanRange'][0]
        scanrange0 = fichier['memsScanRange'][0]
        opd = (scanrange - pos_seg2) * 1000 * 2
        if swap_ref:
            opd = -opd

        opds.append(opd)

        for k in range(nloop)[:]:
            if nloop == 1:
                data = np.transpose(
                    data0,
                    axes=(2, 0,
                          1))  # New order: frame (or OPD), spatial, spectral
            else:
                data = np.transpose(data0[:, :, :, k], axes=(2, 0, 1))

            img = glint_classes.Null(None, nbimg=(0, data.shape[0]))
            img.data = data
            ''' Process frames '''
            if bin_frames:
                img.data = img.binning(img.data,
                                       nb_frames_to_bin,
                                       axis=0,
                                       avg=True)
                img.nbimg = img.data.shape[0]
            img.cosmeticsFrames(np.zeros(dark.shape), no_noise)
            ''' Insulating each track '''
            print('Getting channels')
            img.getChannels(channel_pos,
                            sep,
                            spatial_axis,
                            dark=dark_per_channel)
            ''' Map the spectral channels between every chosen tracks before computing 
            the null depth'''
            img.matchSpectralChannels(wl_to_px_coeff, px_to_wl_coeff)
            ''' Measurement of flux per frame, per spectral channel, per track '''
            img.getSpectralFlux(spectral_axis,
                                position_outputs,
                                width_outputs,
                                mode_flux,
                                debug=debug)
            ''' Measure flux in photometric channels '''
            img.getIntensities(mode=mode_flux)
            if spectral_binning:
                img.spectralBinning(wl_bin_min, wl_bin_max, bandwidth_binning,
                                    wl_to_px_coeff)

            Iminus = np.array([
                img.Iminus1, img.Iminus2, img.Iminus3, img.Iminus4,
                img.Iminus5, img.Iminus6
            ])
            Iminus = Iminus / Iminus.mean(axis=1)[:, None, :]
            print('Null', which_null)
            selected_Iminus = Iminus[which_null - 1].T
            wl = img.wl_scale[0]
            wl0 = wl.copy()
            scans.append(selected_Iminus)

    mask = np.ones_like(scanrange, dtype=np.bool)
    mask[(scanrange < maskbounds[0]) | (scanrange > maskbounds[1])] = False
    scanrange = scanrange[mask]
    scans = np.array(scans)
    rtscans = np.array(rtscans)
    opds = np.array(opds)
    scans0 = scans.copy()
    scans = np.mean(scans, axis=0)
    rtscans = np.mean(rtscans, axis=0)
    opds = np.mean(opds, axis=0)
    return scans[:, mask], rtscans[mask], opds[mask]
 #    var_dark = [] # Variance of dark current (in count) per frame
 #    diff_dark = [] # Different between a pixel value and the average dark current
 
 ''' Define bounds of each track '''
 y_ends = [33, 329] # row of top and bottom-most Track
 sep = (y_ends[1] - y_ends[0])/(16-1)
 channel_pos = np.around(np.arange(y_ends[0], y_ends[1]+sep, sep))
     
 ''' Computing average dark '''
 superDark = np.zeros((344,96))
 superNbImg = 0.
 
 
 for f in dark_list[:]:
     print("Process of : %s (%d / %d)" %(f, dark_list.index(f)+1, len(dark_list)))
     dark = glint_classes.Null(f)
    
     superDark = superDark + dark.data.sum(axis=0)
     superNbImg = superNbImg + dark.nbimg
     
     spatial_axis = np.arange(dark.data.shape[0])
     dark.getChannels(channel_pos, sep, spatial_axis)
     
     try:
         superDarkChannel = superDarkChannel + dark.slices.sum(axis=0)
     except:
         superDarkChannel = dark.slices.sum(axis=0)
           
     if monitor:
         try:
             avg_dark = np.vstack((avg_dark, np.reshape(dark.data.mean(axis=(1,2)), (-1,1))))
 cov = []
 bg_noise = []
 fluxes = np.zeros((1, 4))
 null = []
 null_err = []
 p1 = []
 p2 = []
 p3 = []
 p4 = []
 ''' Start the data processing '''
 nb_frames = 0
 for f in data_list:
     start = time()
     print("Process of : %s (%d / %d)" %
           (f, data_list.index(f) + 1, len(data_list)))
     img = glint_classes.Null(f, nbimg=nb_img)
     ''' Process frames '''
     if bin_frames:
         img.data = img.binning(img.data,
                                nb_frames_to_bin,
                                axis=0,
                                avg=True)
         img.nbimg = img.data.shape[0]
     img.cosmeticsFrames(np.zeros(dark.shape), no_noise)
     ''' Insulating each track '''
     print('Getting channels')
     img.getChannels(channel_pos, sep, spatial_axis, dark=dark_per_channel)
     ''' Map the spectral channels between every chosen tracks before computing 
     the null depth'''
     img.matchSpectralChannels(wl_to_px_coeff, px_to_wl_coeff)
     ''' Measurement of flux per frame, per spectral channel, per track '''
示例#4
0
    dark_per_channel = np.load(output_path + 'superdarkchannel.npy')
    super_img = np.zeros(dark.shape)
    superNbImg = 0.

    spatial_axis = np.arange(dark.shape[0])
    spectral_axis = np.arange(dark.shape[1])
    slices = np.zeros_like(dark_per_channel)
    ''' Define bounds of each track '''
    y_ends = [33, 329]  # row of top and bottom-most Track
    nb_tracks = 16
    sep = (y_ends[1] - y_ends[0]) / (nb_tracks - 1)
    channel_pos = np.around(np.arange(y_ends[0], y_ends[1] + sep, sep))

    print('Averaging frames')
    for f in data_list[:]:
        img = glint_classes.Null(f)
        img.cosmeticsFrames(np.zeros(dark.shape))
        img.getChannels(channel_pos, sep, spatial_axis, dark=dark_per_channel)
        super_img = super_img + img.data.sum(axis=0)
        slices = slices + np.sum(img.slices, axis=0)
        superNbImg = superNbImg + img.nbimg
        if data_list.index(f) % 1000 == 0:
            print(data_list.index(f))

    slices = slices / superNbImg
    super_img = super_img / superNbImg

    plt.figure(0, figsize=(19.2, 10.8))
    plt.clf()
    plt.imshow(super_img - dark, interpolation='none')
    plt.colorbar()
    y_ends = [33, 329]  # row of top and bottom-most Track
    sep = (y_ends[1] - y_ends[0]) / (nb_tracks - 1)
    channel_pos = np.around(np.arange(y_ends[0], y_ends[1] + sep, sep))
    ''' Get the spectrum of photometric channels '''
    nb_frames = 0
    slices_spectrum = np.zeros_like(dark_per_channel)

    if not 'dark' in data_list[0] and not os.path.exists(
            output_path + 'spectra.npy') and activate_estimate_spectrum:
        print('Determining spectrum\n')
        for f in data_list[nb_files_spectrum[0]:nb_files_spectrum[1]]:
            start = time()
            print("Process of : %s (%d / %d)" %
                  (f, data_list.index(f) + 1,
                   len(data_list[nb_files_spectrum[0]:nb_files_spectrum[1]])))
            img_spectrum = glint_classes.Null(f, nbimg=nb_img)
            ''' Process frames '''
            img_spectrum.cosmeticsFrames(np.zeros(dark.shape), no_noise)
            ''' Insulating each track '''
            img_spectrum.getChannels(channel_pos,
                                     sep,
                                     spatial_axis,
                                     dark=dark_per_channel)

            img_spectrum.matchSpectralChannels(wl_to_px_coeff, px_to_wl_coeff)
            img_spectrum.getSpectralFlux(spectral_axis, position_outputs,
                                         width_outputs, mode_flux)

            img_spectrum.getIntensities(mode=mode_flux,
                                        wl_bounds=wavelength_bounds)