Example #1
0
    listOfShapes = []
    for kk in range(len(listOfArrays)):
        listOfShapes.append(np.shape(fileContent[0]))

    # use the two differential data
    n_files -= 1
    print(listOfFiles)
    del listOfFiles[2]

# %% define what to do, use of ini file

if 'Height' in headers[-1]:
    what2do = 'Height response function'
else:

    what2do = wpu.get_from_ini_file(inifname, 'Parameters', 'what2do')

    if 'DPC' in what2do:
        choices = [
            'DPC response function',
            'Curvature response function from diff data'
        ]
    else:
        choices = [
            'Curvature response function from diff data',
            'DPC response function'
        ]

    what2do = easyqt.get_choice('Pick one', choices=choices)

wpu.set_at_ini_file(inifname, 'Parameters', 'what2do', what2do)
    vlim10 = np.max(np.abs(diffPhase10))

    # ==========================================================================
    # %% Integration
    # ==========================================================================

    if easyqt.get_yes_or_no('New Crop for Integration?\n' +
                            "(If 'No', the values from last run are used)"):

        idx4crop = ''

    else:

        idx4crop = list(map(int,
                            (wpu.get_from_ini_file(inifname,
                                                   'Parameters',
                                                   'crop integration').split(','))))
    phase, idx4crop = wgi.dpc_integration(diffPhase01, diffPhase10,
                                          virtual_pixelsize,
                                          idx4crop=idx4crop,
                                          saveFileSuf=saveFileSuf,
                                          plotErrorIntegration=True,
                                          shifthalfpixel=True)

    wpu.set_at_ini_file(inifname, 'Parameters', 'crop integration',
                        '{}, {}, {}, {}'.format(idx4crop[0], idx4crop[1],
                                                idx4crop[2], idx4crop[3]))

    phase -= np.mean(phase)  # apply here your favorite offset

def main_single_gr_Talbot(img, imgRef,
                          phenergy, pixelsize, distDet2sample,
                          period_harm, saveFileSuf,
                          unwrapFlag=True,
                          plotFlag=True,
                          saveFigFlag=False):

    global inifname  # name of .ini file

    [period_harm_Vert, period_harm_Hor] = period_harm


    #    img, imgRef = wpu.align_two_images(img, imgRef)

    # Crop

    img_size_o = np.shape(img)

    # take index from ini file
    idx4crop = list(map(int, (wpu.get_from_ini_file(inifname, 'Parameters',
                                                    'Crop').split(','))))

    # Plot Real Image wiht default crop

    tmpImage = wpu.crop_matrix_at_indexes(img, idx4crop)

    plt.figure()
    plt.imshow(tmpImage,
               cmap='viridis',
               extent=wpu.extent_func(tmpImage, pixelsize)*1e6)
    plt.xlabel(r'$[\mu m]$')
    plt.ylabel(r'$[\mu m]$')
    plt.colorbar()

    plt.title('Raw Image with initial Crop', fontsize=18, weight='bold')

    plt.pause(.1)
    # ask if the crop need to be changed
    newCrop = easyqt.get_yes_or_no('New Crop?')

    if saveFigFlag and not newCrop:
        wpu.save_figs_with_idx(saveFileSuf + '_Talbot_image')
    plt.close(plt.gcf())

    if newCrop:

        [colorlimit,
         cmap] = wpu.plot_slide_colorbar(img,
                                         title='SELECT COLOR SCALE,\n' +
                                         'Raw Image, No Crop',
                                         xlabel=r'x [$\mu m$ ]',
                                         ylabel=r'y [$\mu m$ ]',
                                         extent=wpu.extent_func(img,
                                                                pixelsize)*1e6)

        idx4crop = wpu.graphical_roi_idx(img, verbose=True,
                                         kargs4graph={'cmap': cmap,
                                                      'vmin': colorlimit[0],
                                                      'vmax': colorlimit[1]})
        wpu.set_at_ini_file(inifname, 'Parameters', 'Crop',
                            '{}, {}, {}, {}'.format(idx4crop[0], idx4crop[1],
                                                    idx4crop[2], idx4crop[3]))

        img = wpu.crop_matrix_at_indexes(img, idx4crop)

        # Plot Real Image AFTER crop

        plt.imshow(img, cmap='viridis',
                   extent=wpu.extent_func(img, pixelsize)*1e6)
        plt.xlabel(r'$[\mu m]$')
        plt.ylabel(r'$[\mu m]$')
        plt.colorbar()
        plt.title('Raw Image with New Crop', fontsize=18, weight='bold')

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_Talbot_image')
        plt.show(block=True)

    else:
        img = tmpImage

    imgRef = wpu.crop_matrix_at_indexes(imgRef, idx4crop)

    # calculate harmonic position after crop

    period_harm_Vert = int(period_harm_Vert*(idx4crop[1] - idx4crop[0]) /
                           img_size_o[0])
    period_harm_Hor = int(period_harm_Hor*(idx4crop[3] - idx4crop[2]) /
                          img_size_o[1])

    # Obtain harmonic periods from images

    (period_harm_Vert,
     _) = wgi.exp_harm_period(img, [period_harm_Vert,
                                    period_harm_Hor],
                                    harmonic_ij=['1', '0'],
                                    searchRegion=20,
                                    isFFT=False, verbose=True)

    (_,
     period_harm_Horz) = wgi.exp_harm_period(img, [period_harm_Vert,
                                             period_harm_Hor],
                                             harmonic_ij=['0', '1'],
                                             searchRegion=20,
                                             isFFT=False, verbose=True)

    # Calculate everything

    harmPeriod = [period_harm_Vert, period_harm_Hor]

    [int00, int01, int10,
     darkField01, darkField10,
     phaseFFT_01,
     phaseFFT_10] = wgi.single_2Dgrating_analyses(img, imgRef,
                                                  harmonicPeriod=harmPeriod,
                                                  plotFlag=plotFlag,
                                                  unwrapFlag=unwrapFlag,
                                                  verbose=True)

    virtual_pixelsize = [0, 0]
    virtual_pixelsize[0] = pixelsize[0]*img.shape[0]/int00.shape[0]
    virtual_pixelsize[1] = pixelsize[1]*img.shape[1]/int00.shape[1]

    diffPhase01 = phaseFFT_01*virtual_pixelsize[1]/distDet2sample/hc*phenergy
    diffPhase10 = phaseFFT_10*virtual_pixelsize[0]/distDet2sample/hc*phenergy

    return [int00, int01, int10,
            darkField01, darkField10,
            diffPhase01, diffPhase10,
            virtual_pixelsize]
            plt.show(block=False)
            plt.pause(.1)
        else:
            plt.close()

    return outFilesList, allShifts


# %%

inifname = '.align_many_imgs_and_save.ini'

# %%
idx4crop = list(
    map(int,
        (wpu.get_from_ini_file(inifname, 'Parameters', 'Crop').split(','))))
defaults = wpu.load_ini_file(inifname)
deafaultfileName = defaults['Files'].get('Reference')

# %% Load

if len(sys.argv) == 1:
    samplefileName = easyqt.get_file_names("Choose the reference file " +
                                           "for alignment")

    if samplefileName == []:
        samplefileName = deafaultfileName
    else:
        samplefileName = samplefileName[0]
        wpu.set_at_ini_file(inifname, 'Files', 'reference', samplefileName)