Esempio n. 1
0
def save_profile_from_sdf(fname, nprofiles=3, direction='V', savecsv=True):

    data, pixelsize, headerdic = wpu.load_sdf_file(fname)

    saveFileSuf = fname.replace('.sdf', '')


    if 'V' in direction:

        xvec = wpu.realcoordvec(data.shape[0], pixelsize[0])[np.newaxis]
        data2save = np.c_[xvec.T]

        for j in np.linspace(0, np.shape(data)[1] - 1, nprofiles + 2, dtype=int):
            data2save = np.c_[data2save, data[:, j]]
    else:

        xvec = wpu.realcoordvec(data.shape[1], pixelsize[1])[np.newaxis]
        data2save = np.c_[xvec.T]

        for i in np.linspace(0, np.shape(data)[0] - 1, nprofiles + 2, dtype=int):
            data2save = np.c_[data2save, data[i, :]]


    if savecsv:

        wpu.save_csv_file(data2save,
                          wpu.get_unique_filename(saveFileSuf +
                                                  '_profiles_V', 'csv'),
                                                  headerList='bla')

    return data2save, headerdic
Esempio n. 2
0
    fname2save = fname.split('.')[0].split('/')[-1] + '_fit'

    data_dir = fname.rsplit('/', 1)[0]
    print(fname)
    print(data_dir)
    os.chdir(data_dir)
    os.makedirs('residuals', exist_ok=True)
    os.chdir('residuals')

    wpu.log_this(preffname=fname.split('.')[0].split('/')[-1] + '_fit',
                 inifname=inifname)

    # %% Load Input File

    if fname.split('.')[-1] == 'sdf':
        thickness, pixelSize, headerdic = wpu.load_sdf_file(fname)
        xx, yy = wpu.realcoordmatrix(thickness.shape[1], pixelSize[1],
                                     thickness.shape[0], pixelSize[0])

    elif fname.split('.')[-1] == 'pickle':

        thickness, xx, yy = load_pickle_surf(fname, False)

        thickness *= 1e-6
        #            thickness *= -1.0 # minus1 here
        xx *= 1e-6
        yy *= 1e-6
        pixelSize = [np.mean(np.diff(xx[0, :])), np.mean(np.diff(yy[:, 0]))]

    else:
        wpu.print_red('ERROR: Wrong file type!')
Esempio n. 3
0
import numpy as np

import matplotlib.pyplot as plt

import wavepy.utils as wpu

data, pixelsize, headerdic = wpu.load_sdf_file(fname)
Esempio n. 4
0
                         (nColours - 1)).astype(int)

    colorIndex[np.isnan(z)] = 1
    colorMap = jet_vals[colorIndex[:, :]]

    return colorMap


if __name__ == '__main__':
    # %%

    dataFilename = easyqt.get_file_names()

    if len(dataFilename) == 1:
        dataFilename = dataFilename[0]
        dataZ, pixelSize, headerdic = wpu.load_sdf_file(dataFilename)
    else:

        y, x = np.mgrid[-1:1:100j, -1:1:100j]
        dataZ = np.sinc(10 * x**2) * np.exp(-y**2 / .5**2)

        pixelSize = [1 / 2, 1]

# %%

    plot_surf_fast(dataZ,
                   pixelSize,
                   style='rainbow',
                   ratio_x_y=1.0,
                   scaling_z=1.0)
def dpc_profile_analysis(fnameH,
                         fnameV,
                         phenergy,
                         grazing_angle=0.0,
                         projectionFromDiv=1.0,
                         nprofiles=1,
                         remove2ndOrder=False,
                         filter_width=0):

    wavelength = wpu.hc / phenergy

    if fnameH is not None:
        diffPhaseH, virtual_pixelsize, _ = wpu.load_sdf_file(fnameH)

    if fnameV is not None:
        diffPhaseV, virtual_pixelsize, _ = wpu.load_sdf_file(fnameV)

    if fnameH is None:
        diffPhaseH = diffPhaseV * np.nan

    if fnameV is None:
        diffPhaseV = diffPhaseH * np.nan
        saveFileSuf = fnameH.rsplit('/', 1)[0] + '/profiles/' +\
                      fnameH.rsplit('/', 1)[1]
        saveFileSuf = saveFileSuf.rsplit('_X')[0] + '_profiles'
    else:
        saveFileSuf = fnameV.rsplit('/', 1)[0] + '/profiles/' +\
                      fnameV.rsplit('/', 1)[1]
        saveFileSuf = saveFileSuf.rsplit('_Y')[0] + '_profiles'

    if not os.path.exists(saveFileSuf.rsplit('/', 1)[0]):
        os.makedirs(saveFileSuf.rsplit('/', 1)[0])

    (dataH, dataV, labels_H, labels_V,
     fit_coefs) = _n_profiles_H_V(diffPhaseH,
                                  diffPhaseV,
                                  virtual_pixelsize,
                                  'DPC [rad/m]',
                                  titleH='WF DPC Horz',
                                  titleV='WF DPC Vert',
                                  saveFileSuf=saveFileSuf,
                                  nprofiles=nprofiles,
                                  remove2ndOrder=remove2ndOrder,
                                  filter_width=filter_width)

    fit_coefsH = np.array(fit_coefs[0])
    fit_coefsV = np.array(fit_coefs[1])

    print(fit_coefsH)
    print(fit_coefsV)

    if __name__ == '__main__':
        wpu.log_this(preffname=saveFileSuf, inifname=inifname)

    if fnameH is not None:

        radii_fit_H = (2 * np.pi / wavelength / fit_coefsH[:][0])

        wpu.print_blue('MESSAGE: Radius H from fit profiles: ')
        print(radii_fit_H)
        wpu.log_this('radius fit Hor = ' + str(radii_fit_H))

        integratedH = integrate_DPC_cumsum(
            dataH,
            wavelength,
            #grazing_angle=grazing_angle,
            xlabel='x',
            labels=labels_H,
            titleStr='Horizontal, ',
            saveFileSuf=saveFileSuf + '_X')

        curv_H = curv_from_height(
            integratedH,
            virtual_pixelsize[0],
            #grazing_angle=grazing_angle,
            #projectionFromDiv=projectionFromDiv,
            xlabel='x',
            labels=labels_H,
            titleStr='Horizontal, ',
            saveFileSuf=saveFileSuf + '_X')

    if fnameV is not None:

        radii_fit_V = (2 * np.pi / wavelength / fit_coefsV[:][0])

        wpu.print_blue('MESSAGE: Radius V from fit profiles: ')
        print(radii_fit_V)
        wpu.log_this('radius fit Vert = ' + str(radii_fit_V))

        integratedV = integrate_DPC_cumsum(dataV,
                                           wavelength,
                                           grazing_angle=grazing_angle,
                                           projectionFromDiv=projectionFromDiv,
                                           xlabel='y',
                                           labels=labels_V,
                                           titleStr='Vertical, ',
                                           saveFileSuf=saveFileSuf + '_Y')

        curv_V = curv_from_height(integratedV,
                                  virtual_pixelsize[1],
                                  grazing_angle=grazing_angle,
                                  projectionFromDiv=projectionFromDiv,
                                  xlabel='y',
                                  labels=labels_V,
                                  titleStr='Vertical, ',
                                  saveFileSuf=saveFileSuf + '_Y')
Esempio n. 6
0
def dpc_profile_analysis(fnameH, fnameV,
                         phenergy,
                         grazing_angle=0.0, projectionFromDiv=1.0,
                         nprofiles=1,
                         remove1stOrderDPC=False,
                         remove2ndOrder=False,
                         filter_width=0):

    wavelength = wpu.hc/phenergy

    if fnameH is not None:
        diffPhaseH, virtual_pixelsize, _ = wpu.load_sdf_file(fnameH)

    if fnameV is not None:
        diffPhaseV, virtual_pixelsize, _ = wpu.load_sdf_file(fnameV)

    if fnameH is None:
        diffPhaseH = diffPhaseV*np.nan

    if fnameV is None:
        diffPhaseV = diffPhaseH*np.nan
        saveFileSuf = fnameH.rsplit('/', 1)[0] + '/profiles/' +\
                      fnameH.rsplit('/', 1)[1]
        saveFileSuf = saveFileSuf.rsplit('_X')[0] + '_profiles'
    else:
        saveFileSuf = fnameV.rsplit('/', 1)[0] + '/profiles/' +\
                      fnameV.rsplit('/', 1)[1]
        saveFileSuf = saveFileSuf.rsplit('_Y')[0] + '_profiles'

    if not os.path.exists(saveFileSuf.rsplit('/', 1)[0]):
        os.makedirs(saveFileSuf.rsplit('/', 1)[0])

    (dataH, dataV,
     labels_H, labels_V,
     fit_coefs) = _n_profiles_H_V(diffPhaseH,
                                  diffPhaseV,
                                  virtual_pixelsize,
                                  'DPC [rad/m]',
                                  titleH='WF DPC Horz',
                                  titleV='WF DPC Vert',
                                  saveFileSuf=saveFileSuf,
                                  nprofiles=nprofiles,
                                  remove1stOrderDPC=remove1stOrderDPC,
                                  filter_width=filter_width)

    fit_coefsH = np.array(fit_coefs[0])
    fit_coefsV = np.array(fit_coefs[1])

    print(fit_coefsH)
    print(fit_coefsV)

    if __name__ == '__main__':
        wpu.log_this(preffname=saveFileSuf, inifname=inifname)

    if fnameH is not None:

        radii_fit_H = (2*np.pi/wavelength/fit_coefsH[:][0])

        wpu.print_blue('MESSAGE: Radius H from fit profiles: ')
        print(radii_fit_H)
        wpu.log_this('radius fit Hor = ' + str(radii_fit_H))

        integratedH = integrate_DPC_cumsum(dataH, wavelength,
                                           #grazing_angle=grazing_angle,
                                           remove2ndOrder=remove2ndOrder,
                                           xlabel='x',
                                           labels=labels_H,
                                           titleStr='Horizontal, ',
                                           saveFileSuf=saveFileSuf + '_X')

        curv_H = curv_from_height(integratedH, virtual_pixelsize[0],
                                  #grazing_angle=grazing_angle,
                                  #projectionFromDiv=projectionFromDiv,
                                  xlabel='x',
                                  labels=labels_H,
                                  titleStr='Horizontal, ',
                                  saveFileSuf=saveFileSuf + '_X')

    if fnameV is not None:

        radii_fit_V = (2*np.pi/wavelength/fit_coefsV[:][0])

        wpu.print_blue('MESSAGE: Radius V from fit profiles: ')
        print(radii_fit_V)
        wpu.log_this('radius fit Vert = ' + str(radii_fit_V))

        integratedV = integrate_DPC_cumsum(dataV, wavelength,
                                           grazing_angle=grazing_angle,
                                           projectionFromDiv=projectionFromDiv,
                                           remove2ndOrder=remove2ndOrder,
                                           xlabel='y',
                                           labels=labels_V,
                                           titleStr='Vertical, ',
                                           saveFileSuf=saveFileSuf + '_Y')

        curv_V = curv_from_height(integratedV, virtual_pixelsize[1],
                                  grazing_angle=grazing_angle,
                                  projectionFromDiv=projectionFromDiv,
                                  xlabel='y',
                                  labels=labels_V,
                                  titleStr='Vertical, ',
                                  saveFileSuf=saveFileSuf + '_Y')