Пример #1
0
def showDegCoh(filename, file_h5=None, rel_thresh=1e-4):
    print(">>>>>>")
    print("FILE: " + filename)

    coor, coor_conj, mutual_intensity = loadNumpyFormatCoh(filename)

    print("File Loaded")

    if file_h5 is not None:
        f = h5py.File(file_h5, 'w')
        f["0_coor"] = coor
        f["0_coor_conj"] = coor_conj
        f["0_mutual_intensity"] = mutual_intensity
        # f["0_mesh"] = [xStart, xEnd, xNpNew, yStart, yEnd, yNpNew]

    #-----------------------------------------------------------
    #FROM OLEG'S IGOR MACRO ------------------------------------
    #-----------------------------------------------------------

    nmInMutInt = ScaledMatrix(x_coord=coor,
                              y_coord=coor_conj,
                              z_values=mutual_intensity,
                              interpolator=True)

    xStart = nmInMutInt.offset_x()
    xNp = nmInMutInt.size_x()
    xStep = nmInMutInt.delta_x()
    xEnd = xStart + (xNp - 1) * xStep

    yStart = nmInMutInt.offset_y()
    yNp = nmInMutInt.size_y()
    yStep = nmInMutInt.delta_y()
    yEnd = yStart + (yNp - 1) * yStep

    xNpNew = 2 * xNp - 1
    yNpNew = 2 * yNp - 1

    print("Creating Matrix wInMutCohRes")

    wInMutCohRes = ScaledMatrix(x_coord=numpy.zeros(xNpNew),
                                y_coord=numpy.zeros(yNpNew),
                                z_values=numpy.zeros((xNpNew, yNpNew)),
                                interpolator=False)

    xHalfNp = round(xNp * 0.5)
    yHalfNp = round(yNp * 0.5)

    wInMutCohRes.set_scale_from_steps(axis=0,
                                      initial_scale_value=(xStart -
                                                           xHalfNp * xStep),
                                      scale_step=xStep)
    wInMutCohRes.set_scale_from_steps(axis=1,
                                      initial_scale_value=(yStart -
                                                           yHalfNp * yStep),
                                      scale_step=yStep)

    dimx, dimy = wInMutCohRes.shape()
    for inx in range(0, dimx):
        for iny in range(0, dimy):
            x = wInMutCohRes.get_x_value(inx)
            y = wInMutCohRes.get_y_value(iny)

            wInMutCohRes.set_z_value(
                inx, iny,
                nmInMutInt.interpolate_value(x, y) *
                srwUtiNonZeroIntervB(x, xStart, xEnd) *
                srwUtiNonZeroIntervB(y, yStart, yEnd))

    wInMutCohRes.compute_interpolator()

    print("Done")

    if file_h5 is not None:
        f["1_x"] = wInMutCohRes.get_x_values()
        f["1_y"] = wInMutCohRes.get_y_values()
        f["1_z"] = wInMutCohRes.get_z_values()
        # f["1_mesh"] = [xStart, xEnd, xNpNew, yStart, yEnd, yNpNew]

    print("Creating Matrix wMutCohNonRot")

    wMutCohNonRot = ScaledMatrix(x_coord=nmInMutInt.get_x_values(),
                                 y_coord=nmInMutInt.get_y_values(),
                                 z_values=numpy.zeros(nmInMutInt.shape()),
                                 interpolator=False)

    abs_thresh = rel_thresh * abs(nmInMutInt.interpolate_value(0, 0))

    dimx, dimy = wMutCohNonRot.shape()
    for inx in range(0, dimx):
        for iny in range(0, dimy):
            x = wMutCohNonRot.get_x_value(inx)
            y = wMutCohNonRot.get_y_value(iny)

            wMutCohNonRot.set_z_value(
                inx, iny,
                numpy.abs(wInMutCohRes.interpolate_value(x, y)) / (numpy.sqrt(
                    abs(
                        wInMutCohRes.interpolate_value(x, x) *
                        wInMutCohRes.interpolate_value(y, y))) + abs_thresh))

    wMutCohNonRot.compute_interpolator()

    print("Done")

    if file_h5 is not None:
        f["2_x"] = wMutCohNonRot.get_x_values()
        f["2_y"] = wMutCohNonRot.get_y_values()
        f["2_z"] = wMutCohNonRot.get_z_values()

    print("Creating Matrix nmResDegCoh")

    nmResDegCoh = ScaledMatrix(x_coord=nmInMutInt.get_x_values(),
                               y_coord=nmInMutInt.get_y_values(),
                               z_values=numpy.zeros(nmInMutInt.shape()),
                               interpolator=False)

    xmin = wMutCohNonRot.offset_x()
    nx = wMutCohNonRot.size_x()
    xstep = wMutCohNonRot.delta_x()
    xmax = xmin + (nx - 1) * xstep

    ymin = wMutCohNonRot.offset_y()
    ny = wMutCohNonRot.size_y()
    ystep = wMutCohNonRot.delta_y()
    ymax = ymin + (ny - 1) * ystep

    dimx, dimy = nmResDegCoh.shape()
    for inx in range(0, dimx):
        for iny in range(0, dimy):
            x = nmResDegCoh.get_x_value(inx)
            y = nmResDegCoh.get_y_value(iny)

            nmResDegCoh.set_z_value(
                inx, iny,
                srwUtiInterp2DBilin((x + y), (x - y), wMutCohNonRot, xmin,
                                    xmax, xstep, ymin, ymax, ystep))

    print("Done: plotting Results")

    if file_h5 is not None:
        f["3_x"] = nmResDegCoh.get_x_values()
        f["3_y"] = nmResDegCoh.get_y_values()
        f["3_z"] = nmResDegCoh.get_z_values()
        # f["3_mesh"] = [xmin, xmax, inx, ymin, ymax, iny]
        f.close()
        print("File %s written to disk." % file_h5)

    if filename.endswith("1"):
        xlabel = "(x1+x2)/2 [um]"
        ylabel = "(x1-x2)/2 [um]"
    else:
        xlabel = "(y1+y2)/2 [um]"
        ylabel = "(y1-y2)/2 [um]"

    plot_scaled_matrix(nmResDegCoh, "nmResDegCoh", xlabel, ylabel)
Пример #2
0
def calculate_degree_of_coherence_vs_sum_and_difference_igor_macro(
        coor, coor_conj, mutual_intensity, rel_thresh=1e-4):

    nmInMutInt = ScaledMatrix(x_coord=coor,
                              y_coord=coor_conj,
                              z_values=mutual_intensity,
                              interpolator=True)

    xStart = nmInMutInt.offset_x()
    xNp = nmInMutInt.size_x()
    xStep = nmInMutInt.delta_x()
    xEnd = xStart + (xNp - 1) * xStep

    yStart = nmInMutInt.offset_y()
    yNp = nmInMutInt.size_y()
    yStep = nmInMutInt.delta_y()
    yEnd = yStart + (yNp - 1) * yStep

    xNpNew = 2 * xNp - 1
    yNpNew = 2 * yNp - 1

    print("Creating Matrix wInMutCohRes")

    wInMutCohRes = ScaledMatrix(x_coord=numpy.zeros(xNpNew),
                                y_coord=numpy.zeros(yNpNew),
                                z_values=numpy.zeros((xNpNew, yNpNew)),
                                interpolator=False)

    xHalfNp = round(xNp * 0.5)
    yHalfNp = round(yNp * 0.5)

    wInMutCohRes.set_scale_from_steps(axis=0,
                                      initial_scale_value=(xStart -
                                                           xHalfNp * xStep),
                                      scale_step=xStep)
    wInMutCohRes.set_scale_from_steps(axis=1,
                                      initial_scale_value=(yStart -
                                                           yHalfNp * yStep),
                                      scale_step=yStep)

    dimx, dimy = wInMutCohRes.shape()
    for inx in range(0, dimx):
        for iny in range(0, dimy):
            x = wInMutCohRes.get_x_value(inx)
            y = wInMutCohRes.get_y_value(iny)

            wInMutCohRes.set_z_value(
                inx, iny,
                nmInMutInt.interpolate_value(x, y) *
                srwUtiNonZeroIntervB(x, xStart, xEnd) *
                srwUtiNonZeroIntervB(y, yStart, yEnd))

    wInMutCohRes.compute_interpolator()

    print("Done")

    print("Creating Matrix wMutCohNonRot")

    wMutCohNonRot = ScaledMatrix(x_coord=nmInMutInt.get_x_values(),
                                 y_coord=nmInMutInt.get_y_values(),
                                 z_values=numpy.zeros(nmInMutInt.shape()),
                                 interpolator=False)

    abs_thresh = rel_thresh * abs(nmInMutInt.interpolate_value(0, 0))

    dimx, dimy = wMutCohNonRot.shape()
    for inx in range(0, dimx):
        for iny in range(0, dimy):
            x = wMutCohNonRot.get_x_value(inx)
            y = wMutCohNonRot.get_y_value(iny)

            wMutCohNonRot.set_z_value(
                inx, iny,
                numpy.abs(wInMutCohRes.interpolate_value(x, y)) / (numpy.sqrt(
                    abs(
                        wInMutCohRes.interpolate_value(x, x) *
                        wInMutCohRes.interpolate_value(y, y))) + abs_thresh))

    wMutCohNonRot.compute_interpolator()

    print("Done")
    print("Creating Matrix nmResDegCoh")

    nmResDegCoh = ScaledMatrix(x_coord=nmInMutInt.get_x_values(),
                               y_coord=nmInMutInt.get_y_values(),
                               z_values=numpy.zeros(nmInMutInt.shape()),
                               interpolator=False)

    xmin = wMutCohNonRot.offset_x()
    nx = wMutCohNonRot.size_x()
    xstep = wMutCohNonRot.delta_x()
    xmax = xmin + (nx - 1) * xstep

    ymin = wMutCohNonRot.offset_y()
    ny = wMutCohNonRot.size_y()
    ystep = wMutCohNonRot.delta_y()
    ymax = ymin + (ny - 1) * ystep

    dimx, dimy = nmResDegCoh.shape()
    for inx in range(0, dimx):
        for iny in range(0, dimy):
            x = nmResDegCoh.get_x_value(inx)
            y = nmResDegCoh.get_y_value(iny)

            nmResDegCoh.set_z_value(
                inx, iny,
                srwUtiInterp2DBilin((x + y), (x - y), wMutCohNonRot, xmin,
                                    xmax, xstep, ymin, ymax, ystep))

    return nmResDegCoh.get_x_values(), nmResDegCoh.get_y_values(
    ), nmResDegCoh.get_z_values()