def curv_from_height(height,
                     virtual_pixelsize,
                     grazing_angle=0.0,
                     projectionFromDiv=1.0,
                     labels=[],
                     xlabel='x',
                     ylabel='Curvature',
                     titleStr='',
                     saveFileSuf=''):

    ls_cycle, lc_cycle = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                              ncurves=height.shape[1] - 1,
                                              cmap_str='gist_rainbow_r')

    if grazing_angle // .00001 > 0:
        projection = 1 / np.sin(grazing_angle) * projectionFromDiv
    else:
        projection = projectionFromDiv

    projected_pixel = virtual_pixelsize * projection
    xvec = wpu.realcoordvec(height.shape[0] - 2, projected_pixel)

    print('projected_pixel')
    print(projected_pixel)

    plt.figure(figsize=(12, 12 * 9 / 16))
    list_curv = [xvec]

    header = [xlabel + ' [m]']

    for j_line in range(1, height.shape[1]):

        curv = np.diff(np.diff(height[:, j_line])) / projected_pixel**2

        if j_line == 1:
            factor_x, unit_x = wpu.choose_unit(xvec)

            #factor_y, unit_y = wpu.choose_unit(curv)

        list_curv.append(curv)
        header.append(labels[j_line - 1])

        plt.plot(xvec * factor_x,
                 curv,
                 next(ls_cycle),
                 c=next(lc_cycle),
                 label=labels[j_line - 1])

    marginx = 0.1 * np.ptp(xvec * factor_x)
    plt.xlim(
        [np.min(xvec * factor_x) - marginx,
         np.max(xvec * factor_x) + marginx])
    plt.xlabel(xlabel + r' [$' + unit_x + ' m$]')
    plt.ylabel(ylabel + r'[$m^{-1}$]')
    plt.legend(loc=0, fontsize=12)

    if grazing_angle // .00001 > 0:

        plt.title(titleStr + 'Mirror Curvature,\n' +
                  'grazing angle {:.2f} mrad,\n'.format(grazing_angle * 1e3) +
                  'projection due divergence = ' +
                  r'$ \times $ {:.2f}'.format(projectionFromDiv))
    else:
        plt.title(titleStr + 'Curvature')

    plt.tight_layout()
    wpu.save_figs_with_idx(saveFileSuf)
    plt.show()

    data2saveV = np.asarray(list_curv).T

    header.append(ylabel + ' [1/m]')

    if grazing_angle // .00001 > 0:
        header.append(', grazing_angle = {:.4g}'.format(grazing_angle))

    if projectionFromDiv // 1 != 1:
        header.append('projection due divergence = ' +
                      '{:.2f}x'.format(projectionFromDiv))

    wpu.save_csv_file(data2saveV,
                      wpu.get_unique_filename(saveFileSuf + '_curv_' + xlabel,
                                              'csv'),
                      headerList=header)

    return np.asarray(list_curv).T
def _n_profiles_H_V(arrayH,
                    arrayV,
                    virtual_pixelsize,
                    zlabel=r'z',
                    titleH='Horiz',
                    titleV='Vert',
                    nprofiles=5,
                    filter_width=0,
                    remove2ndOrder=False,
                    saveFileSuf='',
                    saveFigFlag=True):

    xxGrid, yyGrid = wpu.grid_coord(arrayH, virtual_pixelsize)

    fit_coefs = [[], []]
    data2saveH = None
    data2saveV = None
    labels_H = None
    labels_V = None

    plt.rcParams['lines.markersize'] = 4
    plt.rcParams['lines.linewidth'] = 2

    # Horizontal
    if np.all(np.isfinite(arrayH)):

        plt.figure(figsize=(12, 12 * 9 / 16))

        xvec = xxGrid[0, :]
        data2saveH = np.c_[xvec]
        header = ['x [m]']

        ls_cycle, lc_jet = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                                ncurves=nprofiles,
                                                cmap_str='gist_rainbow_r')

        lc = []
        labels_H = []
        for i, row in enumerate(
                np.linspace(filter_width // 2,
                            np.shape(arrayV)[0] - filter_width // 2 - 1,
                            nprofiles + 2,
                            dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            if filter_width != 0:
                yvec = arrayH[row - filter_width:row + filter_width, :]
                yvec = np.sum(yvec, 0) / filter_width / 2
            else:
                yvec = arrayH[row, :]

            lc.append(next(lc_jet))
            p01 = np.polyfit(xvec, yvec, 1)
            fit_coefs[0].append(p01)

            if remove2ndOrder:
                yvec -= p01[0] * xvec + p01[1]

            plt.plot(xvec * 1e6,
                     yvec,
                     next(ls_cycle),
                     color=lc[i - 1],
                     label=str(row))

            if not remove2ndOrder:
                plt.plot(xvec * 1e6,
                         p01[0] * xvec + p01[1],
                         '--',
                         color=lc[i - 1],
                         lw=3)

            data2saveH = np.c_[data2saveH, yvec]
            header.append(str(row))
            labels_H.append(str(row))

        if remove2ndOrder:
            titleH = titleH + ', 2nd order removed'
        plt.legend(title='Pixel Y', loc=0, fontsize=12)

        plt.xlabel(r'x [$\mu m$]', fontsize=18)
        plt.ylabel(zlabel, fontsize=18)
        plt.title(titleH + ', Filter Width = {:d} pixels'.format(filter_width),
                  fontsize=20)

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_H')

        plt.show(block=False)

        header.append(zlabel +
                      ', Filter Width = {:d} pixels'.format(filter_width))

        wpu.save_csv_file(data2saveH,
                          wpu.get_unique_filename(
                              saveFileSuf + '_WF_profiles_H', 'csv'),
                          headerList=header)

        plt.figure(figsize=(12, 12 * 9 / 16))
        plt.imshow(arrayH,
                   cmap='RdGy',
                   vmin=wpu.mean_plus_n_sigma(arrayH, -3),
                   vmax=wpu.mean_plus_n_sigma(arrayH, 3))
        plt.xlabel('Pixel')
        plt.ylabel('Pixel')
        plt.title(titleH + ', Profiles Position')

        currentAxis = plt.gca()

        _, lc_jet = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                         ncurves=nprofiles,
                                         cmap_str='gist_rainbow_r')

        for i, row in enumerate(
                np.linspace(filter_width // 2,
                            np.shape(arrayV)[0] - filter_width // 2 - 1,
                            nprofiles + 2,
                            dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            currentAxis.add_patch(
                Rectangle((-.5, row - filter_width // 2 - .5),
                          np.shape(arrayH)[1],
                          filter_width,
                          facecolor=lc[i - 1],
                          alpha=.5))
            plt.axhline(row, color=lc[i - 1])

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_H')

        plt.show(block=True)

    # Vertical
    if np.all(np.isfinite(arrayV)):

        plt.figure(figsize=(12, 12 * 9 / 16))

        xvec = yyGrid[:, 0]
        data2saveV = np.c_[xvec]
        header = ['y [m]']

        ls_cycle, lc_jet = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                                ncurves=nprofiles,
                                                cmap_str='gist_rainbow_r')

        lc = []
        labels_V = []
        for i, col in enumerate(
                np.linspace(filter_width // 2,
                            np.shape(arrayH)[1] - filter_width // 2 - 1,
                            nprofiles + 2,
                            dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            if filter_width != 0:
                yvec = arrayV[:, col - filter_width:col + filter_width]
                yvec = np.sum(yvec, 1) / filter_width / 2
            else:
                yvec = arrayV[:, col]

            lc.append(next(lc_jet))
            p10 = np.polyfit(xvec, yvec, 1)
            fit_coefs[1].append(p10)

            if remove2ndOrder:
                yvec -= p10[0] * xvec + p10[1]

            plt.plot(xvec * 1e6,
                     yvec,
                     next(ls_cycle),
                     color=lc[i - 1],
                     label=str(col))

            if not remove2ndOrder:
                plt.plot(xvec * 1e6,
                         p10[0] * xvec + p10[1],
                         '--',
                         color=lc[i - 1],
                         lw=3)

            data2saveV = np.c_[data2saveV, yvec]
            header.append(str(col))
            labels_V.append(str(col))

        if remove2ndOrder:
            titleV = titleV + ', 2nd order removed'

        plt.legend(title='Pixel X', loc=0, fontsize=12)

        plt.xlabel(r'y [$\mu m$]', fontsize=18)
        plt.ylabel(zlabel, fontsize=18)

        plt.title(titleV + ', Filter Width = {:d} pixels'.format(filter_width),
                  fontsize=20)
        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_Y')
        plt.show(block=False)

        header.append(zlabel +
                      ', Filter Width = {:d} pixels'.format(filter_width))

        wpu.save_csv_file(data2saveV,
                          wpu.get_unique_filename(
                              saveFileSuf + '_WF_profiles_V', 'csv'),
                          headerList=header)

        plt.figure(figsize=(12, 12 * 9 / 16))
        plt.imshow(arrayV,
                   cmap='RdGy',
                   vmin=wpu.mean_plus_n_sigma(arrayV, -3),
                   vmax=wpu.mean_plus_n_sigma(arrayV, 3))
        plt.xlabel('Pixel')
        plt.ylabel('Pixel')
        plt.title(titleV + ', Profiles Position')

        currentAxis = plt.gca()

        for i, col in enumerate(
                np.linspace(filter_width // 2,
                            np.shape(arrayH)[1] - filter_width // 2 - 1,
                            nprofiles + 2,
                            dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            currentAxis.add_patch(
                Rectangle((col - filter_width // 2 - .5, -.5),
                          filter_width,
                          np.shape(arrayV)[0],
                          facecolor=lc[i - 1],
                          alpha=.5))
            plt.axvline(col, color=lc[i - 1])

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_Y')

        plt.show(block=True)

    return data2saveH, data2saveV, labels_H, labels_V, fit_coefs
def integrate_DPC_cumsum(data_DPC,
                         wavelength,
                         grazing_angle=0.0,
                         projectionFromDiv=1.0,
                         labels=[],
                         xlabel='x',
                         ylabel='Height',
                         titleStr='',
                         saveFileSuf=''):

    ls_cycle, lc_cycle = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                              ncurves=data_DPC.shape[1] - 1,
                                              cmap_str='gist_rainbow_r')

    if grazing_angle // .00001 > 0:
        projection = 1 / np.sin(grazing_angle) * projectionFromDiv
    else:
        projection = projectionFromDiv

    xvec = data_DPC[:, 0] * projection

    plt.figure(figsize=(12, 12 * 9 / 16))
    list_integrated = [xvec]

    header = [xlabel + ' [m]']

    for j_line in range(1, data_DPC.shape[1]):

        integrated = (
            np.cumsum(data_DPC[:, j_line] - np.mean(data_DPC[:, j_line])) *
            (xvec[1] - xvec[0]))

        integrated *= -1 / 2 / np.pi * wavelength * np.abs(projection)

        # TODO: check here!!

        if j_line == 1:
            factor_x, unit_x = wpu.choose_unit(xvec)
            factor_y, unit_y = wpu.choose_unit(integrated)

        list_integrated.append(integrated)
        header.append(labels[j_line - 1])

        plt.plot(xvec * factor_x,
                 integrated * factor_y,
                 next(ls_cycle),
                 c=next(lc_cycle),
                 label=labels[j_line - 1])

    marginx = 0.1 * np.ptp(xvec * factor_x)
    plt.xlim(
        [np.min(xvec * factor_x) - marginx,
         np.max(xvec * factor_x) + marginx])
    plt.xlabel(xlabel + r' [$' + unit_x + ' m$]')
    plt.ylabel(ylabel + r' [$' + unit_y + ' m$]')
    plt.legend(loc=0, fontsize=12)

    if grazing_angle // .00001 > 0:

        plt.title(titleStr + 'Mirror Height,\n' +
                  'grazing angle {:.2f} mrad,\n'.format(grazing_angle * 1e3) +
                  'projection due divergence = ' +
                  r'$ \times $ {:.2f}'.format(projectionFromDiv))
    else:
        plt.title(titleStr + 'Integration Cumulative Sum')

    plt.tight_layout()
    wpu.save_figs_with_idx(saveFileSuf)
    plt.show()

    data2saveV = np.asarray(list_integrated).T

    header.append(ylabel + ' [m]')

    if grazing_angle // .00001 > 0:
        header.append('grazing_angle = {:.4g}'.format(grazing_angle))

    if projectionFromDiv // 1 != 1:
        header.append('projection due divergence = ' +
                      '{:.2f}x'.format(projectionFromDiv))

    wpu.save_csv_file(data2saveV,
                      wpu.get_unique_filename(
                          saveFileSuf + '_integrated_' + xlabel, 'csv'),
                      headerList=header)

    return np.asarray(list_integrated).T
示例#4
0
        #        data[:,1:] *= np.pi

        list_all_data.append(data)

        xmin = np.min([xmin, np.min(data[:, 0])])

        xmax = np.max([xmax, np.max(data[:, 0])])

    # cant convert list_all_data to array because each array in the list can
    # have different sizes. It is necessary to do the spline to have same
    # vector sizes

    # %%
    lstyle_cycle, lc_cycle = wpu.line_style_cycle(ls=['-', '--'],
                                                  ms=['s', 'o', 'd', '^', 'v'],
                                                  cmap_str='default',
                                                  ncurves=nfiles)

    # %% Plot Raw data

    curve_index = 3

    plt.figure(figsize=(12, 12 * 9 / 16))

    for i in range(0, nfiles, step_files):

        data = list_all_data[i]

        plt.plot(data[:, 0] * 1e3,
                 data[:, curve_index] * 1e9,
                 next(lstyle_cycle),
示例#5
0
def _n_profiles_H_V(arrayH, arrayV, virtual_pixelsize,
                    zlabel=r'z',
                    titleH='Horiz', titleV='Vert',
                    nprofiles=5, filter_width=0,
                    remove1stOrderDPC=False,
                    saveFileSuf='',
                    saveFigFlag=True):

    xxGrid, yyGrid = wpu.grid_coord(arrayH, virtual_pixelsize)

    fit_coefs = [[], []]
    data2saveH = None
    data2saveV = None
    labels_H = None
    labels_V = None

    plt.rcParams['lines.markersize'] = 4
    plt.rcParams['lines.linewidth'] = 2

    # Horizontal
    if np.all(np.isfinite(arrayH)):

        plt.figure(figsize=(12, 12*9/16))

        xvec = xxGrid[0, :]
        data2saveH = np.c_[xvec]
        header = ['x [m]']

        if filter_width != 0:
            arrayH_filtered = uniform_filter1d(arrayH, filter_width, 0)
        else:
            arrayH_filtered = arrayH

        ls_cycle, lc_jet = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                                ncurves=nprofiles,
                                                cmap_str='gist_rainbow_r')

        lc = []
        labels_H = []
        for i, row in enumerate(np.linspace(filter_width//2,
                                            np.shape(arrayV)[0]-filter_width//2-1,
                                            nprofiles + 2, dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            yvec = arrayH_filtered[row, :]

            lc.append(next(lc_jet))
            p01 = np.polyfit(xvec, yvec, 1)
            fit_coefs[0].append(p01)

            if remove1stOrderDPC:
                yvec -= p01[0]*xvec + p01[1]

            plt.plot(xvec*1e6, yvec, next(ls_cycle), color=lc[i-1],
                     label=str(row))

            if not remove1stOrderDPC:
                plt.plot(xvec*1e6, p01[0]*xvec + p01[1], '--',
                         color=lc[i-1], lw=3)

            data2saveH = np.c_[data2saveH, yvec]
            header.append(str(row))
            labels_H.append(str(row))

        if remove1stOrderDPC:
            titleH = titleH + ', 2nd order removed'
        plt.legend(title='Pixel Y', loc=0, fontsize=12)

        plt.xlabel(r'x [$\mu m$]', fontsize=18)
        plt.ylabel(zlabel, fontsize=18)
        plt.title(titleH + ', Filter Width = {:d} pixels'.format(filter_width),
                  fontsize=20)

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_H')

        plt.show(block=False)

        header.append(zlabel + ', Filter Width = {:d} pixels'.format(filter_width))

        wpu.save_csv_file(data2saveH,
                          wpu.get_unique_filename(saveFileSuf +
                                                  '_WF_profiles_H', 'csv'),
                          headerList=header)

        plt.figure(figsize=(12, 12*9/16))
        plt.imshow(arrayH, cmap='RdGy',
                   vmin=wpu.mean_plus_n_sigma(arrayH, -3),
                   vmax=wpu.mean_plus_n_sigma(arrayH, 3))
        plt.xlabel('Pixel')
        plt.ylabel('Pixel')
        plt.title(titleH + ', Profiles Position')

        currentAxis = plt.gca()

        _, lc_jet = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                         ncurves=nprofiles,
                                         cmap_str='gist_rainbow_r')

        for i, row in enumerate(np.linspace(filter_width//2,
                                            np.shape(arrayV)[0]-filter_width//2-1,
                                            nprofiles + 2, dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            currentAxis.add_patch(Rectangle((-.5, row - filter_width//2 - .5),
                                            np.shape(arrayH)[1], filter_width,
                                            facecolor=lc[i-1], alpha=.5))
            plt.axhline(row, color=lc[i-1])

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_H')

        plt.show(block=True)

    # Vertical
    if np.all(np.isfinite(arrayV)):

        plt.figure(figsize=(12, 12*9/16))

        xvec = yyGrid[:, 0]
        data2saveV = np.c_[xvec]
        header = ['y [m]']

        if filter_width != 0:
            arrayV_filtered = uniform_filter1d(arrayV, filter_width, 1)
        else:
            arrayV_filtered = arrayV

        ls_cycle, lc_jet = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                                ncurves=nprofiles,
                                                cmap_str='gist_rainbow_r')

        lc = []
        labels_V = []
        for i, col in enumerate(np.linspace(filter_width//2,
                                            np.shape(arrayH)[1]-filter_width//2-1,
                                            nprofiles + 2, dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue

            yvec = arrayV_filtered[:, col]

            lc.append(next(lc_jet))
            p10 = np.polyfit(xvec, yvec, 1)
            fit_coefs[1].append(p10)

            if remove1stOrderDPC:
                yvec -= p10[0]*xvec + p10[1]

            plt.plot(xvec*1e6, yvec, next(ls_cycle), color=lc[i-1],
                     label=str(col))

            if not remove1stOrderDPC:
                plt.plot(xvec*1e6, p10[0]*xvec + p10[1], '--',
                         color=lc[i-1], lw=3)

            data2saveV = np.c_[data2saveV, yvec]
            header.append(str(col))
            labels_V.append(str(col))

        if remove1stOrderDPC:
            titleV = titleV + ', 2nd order removed'

        plt.legend(title='Pixel X', loc=0, fontsize=12)

        plt.xlabel(r'y [$\mu m$]', fontsize=18)
        plt.ylabel(zlabel, fontsize=18)

        plt.title(titleV + ', Filter Width = {:d} pixels'.format(filter_width),
                  fontsize=20)
        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_Y')
        plt.show(block=False)

        header.append(zlabel + ', Filter Width = {:d} pixels'.format(filter_width))

        wpu.save_csv_file(data2saveV,
                          wpu.get_unique_filename(saveFileSuf +
                                                  '_WF_profiles_V', 'csv'),
                          headerList=header)

        plt.figure(figsize=(12, 12*9/16))
        plt.imshow(arrayV, cmap='RdGy',
                   vmin=wpu.mean_plus_n_sigma(arrayV, -3),
                   vmax=wpu.mean_plus_n_sigma(arrayV, 3))
        plt.xlabel('Pixel')
        plt.ylabel('Pixel')
        plt.title(titleV + ', Profiles Position')

        currentAxis = plt.gca()

        for i, col in enumerate(np.linspace(filter_width//2,
                                            np.shape(arrayH)[1]-filter_width//2-1,
                                            nprofiles + 2, dtype=int)):

            if i == 0 or i == nprofiles + 1:
                continue


            currentAxis.add_patch(Rectangle((col - filter_width//2 - .5, -.5),
                                            filter_width, np.shape(arrayV)[0],
                                            facecolor=lc[i-1], alpha=.5))
            plt.axvline(col, color=lc[i-1])

        if saveFigFlag:
            wpu.save_figs_with_idx(saveFileSuf + '_Y')

        plt.show(block=True)

    return data2saveH, data2saveV, labels_H, labels_V, fit_coefs
示例#6
0
def curv_from_height(height, virtual_pixelsize,
                     grazing_angle=0.0, projectionFromDiv=1.0,
                     labels=[],
                     xlabel='x', ylabel='Curvature',
                     titleStr='', saveFileSuf=''):

    ls_cycle, lc_cycle = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                              ncurves=height.shape[1] - 1,
                                              cmap_str='gist_rainbow_r')

    if grazing_angle//.00001 > 0:
        projection = 1/np.sin(grazing_angle)*projectionFromDiv
    else:
        projection = projectionFromDiv

    projected_pixel = virtual_pixelsize*projection
    xvec = wpu.realcoordvec(height.shape[0]-2, projected_pixel)

    print('projected_pixel')
    print(projected_pixel)

    plt.figure(figsize=(12, 12*9/16))
    list_curv = [xvec]

    header = [xlabel + ' [m]']

    for j_line in range(1, height.shape[1]):

        curv = np.diff(np.diff(height[:, j_line]))/projected_pixel**2

        if j_line == 1:
            factor_x, unit_x = wpu.choose_unit(xvec)

            #factor_y, unit_y = wpu.choose_unit(curv)

        list_curv.append(curv)
        header.append(labels[j_line - 1])

        plt.plot(xvec*factor_x, curv,
                 next(ls_cycle), c=next(lc_cycle),
                 label=labels[j_line - 1])

    marginx = 0.1*np.ptp(xvec*factor_x)
    plt.xlim([np.min(xvec*factor_x)-marginx,
              np.max(xvec*factor_x)+marginx])
    plt.xlabel(xlabel + r' [$' + unit_x + ' m$]')
    plt.ylabel(ylabel + r'[$m^{-1}$]')
    plt.legend(loc=0, fontsize=12)

    if grazing_angle//.00001 > 0:

        plt.title(titleStr + 'Mirror Curvature,\n' +
                  'grazing angle {:.2f} mrad,\n'.format(grazing_angle*1e3) +
                  'projection due divergence = ' +
                  r'$ \times $ {:.2f}'.format(projectionFromDiv))
    else:
        plt.title(titleStr + 'Curvature')

    plt.tight_layout()
    wpu.save_figs_with_idx(saveFileSuf)
    plt.show()

    data2saveV = np.asarray(list_curv).T

    header.append(ylabel + ' [1/m]')

    if grazing_angle//.00001 > 0:
        header.append(', grazing_angle = {:.4g}'.format(grazing_angle))

    if projectionFromDiv//1 != 1:
        header.append('projection due divergence = ' +
                      '{:.2f}x'.format(projectionFromDiv))

    wpu.save_csv_file(data2saveV,
                      wpu.get_unique_filename(saveFileSuf +
                                              '_curv_' + xlabel, 'csv'),
                      headerList=header)

    return np.asarray(list_curv).T
示例#7
0
def integrate_DPC_cumsum(data_DPC, wavelength,
                         grazing_angle=0.0, projectionFromDiv=1.0,
                         remove2ndOrder=False,
                         labels=[],
                         xlabel='x', ylabel='Height',
                         titleStr='', saveFileSuf=''):

    ls_cycle, lc_cycle = wpu.line_style_cycle(['-'], ['o', 's', 'd', '^'],
                                              ncurves=data_DPC.shape[1] - 1,
                                              cmap_str='gist_rainbow_r')

    if grazing_angle//.00001 > 0:
        projection = 1/np.sin(grazing_angle)*projectionFromDiv
    else:
        projection = projectionFromDiv

    xvec = data_DPC[:, 0]*projection

    plt.figure(figsize=(12, 12*9/16))
    list_integrated = [xvec]

    header = [xlabel + ' [m]']

    for j_line in range(1, data_DPC.shape[1]):

        integrated = (np.cumsum(data_DPC[:, j_line] - np.mean(data_DPC[:, j_line]))
                      * (xvec[1]-xvec[0])) # TODO: removed mean 20181020

        #        integrated = (np.cumsum(data_DPC[:, j_line])) * (xvec[1]-xvec[0])

        integrated *= -1/2/np.pi*wavelength*np.abs(projection)

        p02 = np.polyfit(xvec, integrated, 2)
        fitted_pol2 = p02[0]*xvec**2 + p02[1]*xvec + p02[2]

        if remove2ndOrder:

            integrated -= fitted_pol2
            titleStr += 'Removed 2nd order, '

        # TODO: check here!!

        if j_line == 1:
            factor_x, unit_x = wpu.choose_unit(xvec)
            factor_y, unit_y = wpu.choose_unit(integrated)

        list_integrated.append(integrated)
        header.append(labels[j_line - 1])

        lc = next(lc_cycle)
        plt.plot(xvec*factor_x,
                 integrated*factor_y,
                 next(ls_cycle), c=lc,
                 label=labels[j_line - 1])

        if not remove2ndOrder:
            plt.plot(xvec*1e6, (fitted_pol2)*factor_y,
                     '--', color=lc, lw=3)

    marginx = 0.1*np.ptp(xvec*factor_x)
    plt.xlim([np.min(xvec*factor_x)-marginx,
              np.max(xvec*factor_x)+marginx])
    plt.xlabel(xlabel + r' [$' + unit_x + ' m$]')
    plt.ylabel(ylabel + r' [$' + unit_y + ' m$]')
    plt.legend(loc=0, fontsize=12)

    if grazing_angle//.00001 > 0:

        plt.title(titleStr + 'Mirror Height,\n' +
                  'grazing angle {:.2f} mrad,\n'.format(grazing_angle*1e3) +
                  'projection due divergence = ' +
                  r'$ \times $ {:.2f}'.format(projectionFromDiv))
    else:
        plt.title(titleStr + 'Integration Cumulative Sum')

    plt.tight_layout()
    wpu.save_figs_with_idx(saveFileSuf)
    plt.show()

    data2saveV = np.asarray(list_integrated).T

    header.append(ylabel + ' [m]')

    if grazing_angle//.00001 > 0:
        header.append('grazing_angle = {:.4g}'.format(grazing_angle))

    if projectionFromDiv//1 != 1:
        header.append('projection due divergence = ' +
                      '{:.2f}x'.format(projectionFromDiv))

    wpu.save_csv_file(data2saveV,
                      wpu.get_unique_filename(saveFileSuf +
                                              '_integrated_' + xlabel, 'csv'),
                      headerList=header)

    return np.asarray(list_integrated).T