Exemplo n.º 1
0
def plotIsoStaImpedance(ax, loc, array, flag, par='abs',
                        pSym='s', pColor=None, addLabel='', zorder=1):

    appResFact = 1/(8*np.pi**2*10**(-7))
    treshold = 1.0 # 1 meter
    indUniSta = np.sqrt(np.sum((array[['x','y']].view((float,2))-loc)**2,axis=1)) < treshold
    freq = array['freq'][indUniSta]

    if par == 'abs':
        zPlot = np.abs(array[flag][indUniSta])
    elif par == 'real':
        zPlot = np.real(array[flag][indUniSta])
    elif par == 'imag':
        zPlot = np.imag(array[flag][indUniSta])
    elif par == 'res':
        zPlot = (appResFact/freq)*np.abs(array[flag][indUniSta])**2
    elif par == 'phs':
        zPlot = np.arctan2(array[flag][indUniSta].imag,array[flag][indUniSta].real)*(180/np.pi)

    if not pColor:
        if 'xx' in flag:
            lab = 'XX'
            pColor = 'g'
        elif 'xy' in flag:
            lab = 'XY'
            pColor = 'r'
        elif 'yx' in flag:
            lab = 'YX'
            pColor = 'b'
        elif 'yy' in flag:
            lab = 'YY'
            pColor = 'y'

    ax.plot(freq,zPlot,color=pColor,marker=pSym,label=flag+addLabel,zorder=zorder)
Exemplo n.º 2
0
def plotIsoStaImpedance(ax,
                        loc,
                        array,
                        flag,
                        par="abs",
                        pSym="s",
                        pColor=None,
                        addLabel="",
                        zorder=1):

    appResFact = 1 / (8 * np.pi**2 * 10**(-7))
    treshold = 1.0  # 1 meter
    indUniSta = (np.sqrt(
        np.sum((array[["x", "y"]].copy().view(
            (float, 2)) - loc)**2, axis=1)) < treshold)
    freq = array["freq"][indUniSta]

    if par == "abs":
        zPlot = np.abs(array[flag][indUniSta])
    elif par == "real":
        zPlot = np.real(array[flag][indUniSta])
    elif par == "imag":
        zPlot = np.imag(array[flag][indUniSta])
    elif par == "res":
        zPlot = (appResFact / freq) * np.abs(array[flag][indUniSta])**2
    elif par == "phs":
        zPlot = np.arctan2(array[flag][indUniSta].imag,
                           array[flag][indUniSta].real) * (180 / np.pi)

    if not pColor:
        if "xx" in flag:
            lab = "XX"
            pColor = "g"
        elif "xy" in flag:
            lab = "XY"
            pColor = "r"
        elif "yx" in flag:
            lab = "YX"
            pColor = "b"
        elif "yy" in flag:
            lab = "YY"
            pColor = "y"

    ax.plot(freq,
            zPlot,
            color=pColor,
            marker=pSym,
            label=flag + addLabel,
            zorder=zorder)
Exemplo n.º 3
0
def plotIsoStaImpedance(ax,
                        loc,
                        array,
                        flag,
                        par='abs',
                        pSym='s',
                        pColor=None,
                        addLabel='',
                        zorder=1):

    appResFact = 1 / (8 * np.pi**2 * 10**(-7))
    treshold = 1.0  # 1 meter
    indUniSta = np.sqrt(
        np.sum((array[['x', 'y']].view(
            (float, 2)) - loc)**2, axis=1)) < treshold
    freq = array['freq'][indUniSta]

    if par == 'abs':
        zPlot = np.abs(array[flag][indUniSta])
    elif par == 'real':
        zPlot = np.real(array[flag][indUniSta])
    elif par == 'imag':
        zPlot = np.imag(array[flag][indUniSta])
    elif par == 'res':
        zPlot = (appResFact / freq) * np.abs(array[flag][indUniSta])**2
    elif par == 'phs':
        zPlot = np.arctan2(array[flag][indUniSta].imag,
                           array[flag][indUniSta].real) * (180 / np.pi)

    if not pColor:
        if 'xx' in flag:
            lab = 'XX'
            pColor = 'g'
        elif 'xy' in flag:
            lab = 'XY'
            pColor = 'r'
        elif 'yx' in flag:
            lab = 'YX'
            pColor = 'b'
        elif 'yy' in flag:
            lab = 'YY'
            pColor = 'y'

    ax.plot(freq,
            zPlot,
            color=pColor,
            marker=pSym,
            label=flag + addLabel,
            zorder=zorder)
Exemplo n.º 4
0
def plotPsudoSectNSDiff(
    ax,
    sectDict,
    arrayList,
    flag,
    par="abs",
    colorbar=True,
    colorNorm="SymLog",
    cLevel=None,
    contour=True,
    mask=None,
    useLog=False,
):
    def sortInArr(arr):
        return np.sort(arr, order=["freq", "x", "y", "z"])

    # Find the index for the slice
    indSect0 = np.where(
        sectDict.values()[0] == arrayList[0][sectDict.keys()[0]])
    indSect1 = np.where(
        sectDict.values()[0] == arrayList[1][sectDict.keys()[0]])
    # Extract and sort the mats
    arr0 = sortInArr(arrayList[0][indSect0])
    arr1 = sortInArr(arrayList[1][indSect1])

    # Define the plot axes
    if "x" in sectDict.keys()[0]:
        x0 = arr0["y"]
        x1 = arr1["y"]
    else:
        x0 = arr0["x"]
        x1 = arr1["x"]
    y0 = arr0["freq"]
    y1 = arr1["freq"]

    if par == "abs":
        if useLog:
            zPlot = (np.log10(np.abs(arr0[flag])) - np.log10(np.abs(
                arr1[flag]))) / np.log10(np.abs(arr1[flag]))
        else:
            zPlot = (np.abs(arr0[flag]) - np.abs(arr1[flag])) / np.abs(
                arr1[flag])
        if mask:
            maskInd = np.logical_or(
                np.abs(arr0[flag]) < 1e-3,
                np.abs(arr1[flag]) < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap("RdYlBu")  # seismic)
    elif par == "ares":
        arF = 1 / (8 * np.pi**2 * 10**(-7))
        if useLog:
            zPlot = (np.log10(
                (arF / arr0["freq"]) * np.abs(arr0[flag])**2) - np.log10(
                    (arF / arr1["freq"]) * np.abs(arr1[flag])**2)) / np.log10(
                        (arF / arr1["freq"]) * np.abs(arr1[flag])**2)
        else:
            zPlot = ((arF / arr0["freq"]) * np.abs(arr0[flag])**2 -
                     (arF / arr1["freq"]) * np.abs(arr1[flag])**2) / (
                         (arF / arr1["freq"]) * np.abs(arr1[flag])**2)
        if mask:
            maskInd = np.logical_or(
                np.abs(arr0[flag]) < 1e-3,
                np.abs(arr1[flag]) < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap("Spectral")  # seismic)

    elif par == "aphs":
        if useLog:
            zPlot = (np.log10(
                np.arctan2(arr0[flag].imag, arr0[flag].real) *
                (180 / np.pi)) - np.log10(
                    np.arctan2(arr1[flag].imag, arr1[flag].real) *
                    (180 / np.pi))) / np.log10(
                        np.arctan2(arr1[flag].imag, arr1[flag].real) *
                        (180 / np.pi))
        else:
            zPlot = (np.arctan2(arr0[flag].imag, arr0[flag].real) *
                     (180 / np.pi) -
                     np.arctan2(arr1[flag].imag, arr1[flag].real) *
                     (180 / np.pi)) / (
                         np.arctan2(arr1[flag].imag, arr1[flag].real) *
                         (180 / np.pi))
        if mask:
            maskInd = np.logical_or(
                np.abs(arr0[flag]) < 1e-3,
                np.abs(arr1[flag]) < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap("Spectral")  # seismic)
    elif par == "real":
        if useLog:
            zPlot = (np.log10(arr0[flag].real) -
                     np.log10(arr1[flag].real)) / np.log10(arr1[flag].real)
        else:
            zPlot = (arr0[flag].real - arr1[flag].real) / arr1[flag].real
        if mask:
            maskInd = np.logical_or(arr0[flag].real < 1e-3,
                                    arr1[flag].real < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap("Spectral")  # ('Spectral')

    elif par == "imag":
        if useLog:
            zPlot = (np.log10(arr0[flag].imag) -
                     np.log10(arr1[flag].imag)) / np.log10(arr1[flag].imag)
        else:
            zPlot = (arr0[flag].imag - arr1[flag].imag) / arr1[flag].imag
        if mask:
            maskInd = np.logical_or(arr0[flag].imag < 1e-3,
                                    arr1[flag].imag < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap("Spectral")  # ('RdYlBu')

    if cLevel:
        zMax = np.log10(cLevel[1])
        zMin = np.log10(cLevel[0])
    else:
        zMax = np.ceil(np.log10(np.abs(zPlot).max()))
        zMin = np.floor(np.log10(np.abs(zPlot).min()))

    if colorNorm == "SymLog":
        level = np.concatenate((
            -np.logspace(
                zMax, zMin - 0.125, (zMax - zMin) * 8 + 1, endpoint=True),
            np.logspace(zMin - 0.125,
                        zMax, (zMax - zMin) * 8 + 1,
                        endpoint=True),
        ))
        clevel = np.concatenate((
            -np.logspace(zMax, zMin, (zMax - zMin) * 1 + 1, endpoint=True),
            np.logspace(zMin, zMax, (zMax - zMin) * 1 + 1, endpoint=True),
        ))
        plotNorm = colors.SymLogNorm(np.abs(level).min(), linscale=0.1)
    elif colorNorm == "Lin":
        if cLevel:
            level = np.arange(cLevel[0], cLevel[1] + 0.1,
                              (cLevel[1] - cLevel[0]) / 50.0)
            clevel = np.arange(cLevel[0], cLevel[1] + 0.1,
                               (cLevel[1] - cLevel[0]) / 10.0)
        else:
            level = np.arange(zPlot.min(), zPlot.max(),
                              (zPlot.max() - zPlot.min()) / 50.0)
            clevel = np.arange(zPlot.min(), zPlot.max(),
                               (zPlot.max() - zPlot.min()) / 10.0)
        plotNorm = colors.Normalize()
    elif colorNorm == "Log":
        level = np.logspace(zMin - 0.125,
                            zMax, (zMax - zMin) * 8 + 1,
                            endpoint=True)
        clevel = np.logspace(zMin, zMax, (zMax - zMin) * 2 + 1, endpoint=True)
        plotNorm = colors.LogNorm()
    if contour:
        cs = ax.tricontourf(
            x0,
            y0,
            zPlot * 100,
            levels=level * 100,
            cmap=cmap,
            norm=plotNorm,
            extend="both",
        )  # ,extend='both')
    else:
        uniX, uniY = np.unique(x0), np.unique(y0)
        X, Y = np.meshgrid(np.append(uniX - 25, uniX[-1] + 25),
                           np.append(uniY - 25, uniY[-1] + 25))
        cs = ax.pcolor(X,
                       Y,
                       np.reshape(zPlot, (len(uniY), len(uniX))),
                       cmap=cmap,
                       norm=plotNorm)
    if colorbar:
        csB = plt.colorbar(cs, cax=ax.cax, ticks=clevel * 100, format="%1.2e")
        # csB.on_mappable_changed(cs)
        ax.set_title(flag + " " + par + " diff", fontsize=8)
        return cs, csB
    return cs, None
Exemplo n.º 5
0
def plotPsudoSectNSimpedance(
    ax,
    sectDict,
    array,
    flag,
    par="abs",
    colorbar=True,
    colorNorm="None",
    cLevel=None,
    contour=True,
):

    indSect = np.where(sectDict.values()[0] == array[sectDict.keys()[0]])

    # Define the plot axes
    if "x" in sectDict.keys()[0]:
        x = array["y"][indSect]
    else:
        x = array["x"][indSect]
    y = array["freq"][indSect]

    if par == "abs":
        zPlot = np.abs(array[flag][indSect])
        cmap = plt.get_cmap("OrRd_r")  # seismic')
        if cLevel:
            level = np.logspace(0, -5, 31, endpoint=True)
            clevel = np.logspace(0, -4, 5, endpoint=True)
        else:
            level = np.linspace(zPlot.min(), zPlot.max(), 100, endpoint=True)
            clevel = np.linspace(zPlot.min(), zPlot.max(), 10, endpoint=True)

    elif par == "ares":
        zPlot = np.abs(array[flag][indSect])**2 / (8 * np.pi**2 * 10**(-7) *
                                                   array["freq"][indSect])
        cmap = plt.get_cmap("RdYlBu")  # seismic)
        if cLevel:
            zMax = np.log10(cLevel[1])
            zMin = np.log10(cLevel[0])
        else:
            zMax = np.ceil(np.log10(np.abs(zPlot).max()))
            zMin = np.floor(np.log10(np.abs(zPlot).min()))
        level = np.logspace(zMin, zMax, (zMax - zMin) * 8 + 1, endpoint=True)
        clevel = np.logspace(zMin, zMax, (zMax - zMin) * 2 + 1, endpoint=True)
        plotNorm = colors.LogNorm()

    elif par == "aphs":
        zPlot = np.arctan2(array[flag][indSect].imag,
                           array[flag][indSect].real) * (180 / np.pi)
        cmap = plt.get_cmap("RdYlBu")  # seismic)
        if cLevel:
            zMax = cLevel[1]
            zMin = cLevel[0]
        else:
            zMax = np.ceil(zPlot).max()
            zMin = np.floor(zPlot).min()
        level = np.arange(zMin, zMax + 0.1, 1)
        clevel = np.arange(zMin, zMax + 0.1, 10)
        plotNorm = colors.Normalize()

    elif par == "real":
        zPlot = np.real(array[flag][indSect])
        cmap = plt.get_cmap("Spectral")  # ('RdYlBu')
        if cLevel:
            zMax = np.log10(cLevel[1])
            zMin = np.log10(cLevel[0])
        else:
            zMax = np.ceil(np.log10(np.abs(zPlot).max()))
            zMin = np.floor(np.log10(np.abs(zPlot).min()))
        level = np.concatenate((
            -np.logspace(
                zMax, zMin - 0.125, (zMax - zMin) * 8 + 1, endpoint=True),
            np.logspace(zMin - 0.125,
                        zMax, (zMax - zMin) * 8 + 1,
                        endpoint=True),
        ))
        clevel = np.concatenate((
            -np.logspace(zMax, zMin, (zMax - zMin) * 1 + 1, endpoint=True),
            np.logspace(zMin, zMax, (zMax - zMin) * 1 + 1, endpoint=True),
        ))
        plotNorm = colors.SymLogNorm(np.abs(level).min(), linscale=0.1)
    elif par == "imag":
        zPlot = np.imag(array[flag][indSect])
        cmap = plt.get_cmap("Spectral")  # ('RdYlBu')

        if cLevel:
            zMax = np.log10(cLevel[1])
            zMin = np.log10(cLevel[0])
        else:
            zMax = np.ceil(np.log10(np.abs(zPlot).max()))
            zMin = np.floor(np.log10(np.abs(zPlot).min()))
        level = np.concatenate((
            -np.logspace(
                zMax, zMin - 0.125, (zMax - zMin) * 8 + 1, endpoint=True),
            np.logspace(zMin - 0.125,
                        zMax, (zMax - zMin) * 8 + 1,
                        endpoint=True),
        ))
        clevel = np.concatenate((
            -np.logspace(zMax, zMin, (zMax - zMin) * 1 + 1, endpoint=True),
            np.logspace(zMin, zMax, (zMax - zMin) * 1 + 1, endpoint=True),
        ))
        plotNorm = colors.SymLogNorm(np.abs(level).min(), linscale=0.1)

    if colorNorm == "SymLog":
        plotNorm = colors.SymLogNorm(np.abs(level).min(), linscale=0.1)
    elif colorNorm == "Lin":
        plotNorm = colors.Normalize()
    elif colorNorm == "Log":
        plotNorm = colors.LogNorm()
    if contour:
        cs = ax.tricontourf(x,
                            y,
                            zPlot,
                            levels=level,
                            cmap=cmap,
                            norm=plotNorm)  # ,extend='both')
    else:
        uniX, uniY = np.unique(x), np.unique(y)
        X, Y = np.meshgrid(np.append(uniX - 25, uniX[-1] + 25),
                           np.append(uniY - 25, uniY[-1] + 25))
        cs = ax.pcolor(X,
                       Y,
                       np.reshape(zPlot, (len(uniY), len(uniX))),
                       cmap=cmap,
                       norm=plotNorm)
    if colorbar:
        csB = plt.colorbar(cs, cax=ax.cax, ticks=clevel, format="%1.2e")
        # csB.on_mappable_changed(cs)
        ax.set_title(flag + " " + par, fontsize=8)
        return cs, csB
    return cs, None
Exemplo n.º 6
0
    def cannyEdgeDetectorFilter(self, img, sigma=1, t_low=0.01, t_high=0.2):

        im = img.convert('L')
        img = np.array(im, dtype=float)

        # 1) Convolve gaussian kernel with gradient
        # gaussian kernel
        halfSize = 3 * sigma
        maskSize = 2 * halfSize + 1
        mat = np.ones((maskSize, maskSize)) / (float)(2 * np.pi * (sigma**2))
        xyRange = np.arange(-halfSize, halfSize + 1)
        xx, yy = np.meshgrid(xyRange, xyRange)
        x2y2 = (xx**2 + yy**2)
        exp_part = np.exp(-(x2y2 / (2.0 * (sigma**2))))
        gSig = mat * exp_part

        gx, gy = self.drogEdgeDetectorFilter(gSig, ret_grad=True, pillow=False)

        # 2) Magnitude and Angles
        # apply kernels for Ix & Iy
        Ix = cv2.filter2D(img, -1, gx)
        Iy = cv2.filter2D(img, -1, gy)

        # compute magnitude
        mag = np.sqrt(Ix**2 + Iy**2)

        # normalize magnitude image
        normMag = my_Normalize(mag)

        # compute orientation of gradient
        orient = np.arctan2(Iy, Ix)

        # round elements of orient
        orientRows = orient.shape[0]
        orientCols = orient.shape[1]

        # 3) Non maximum suppression
        for i in range(0, orientRows):
            for j in range(0, orientCols):
                if normMag[i, j] > t_low:
                    # case 0
                    if (orient[i, j] > (-np.pi / 8) and orient[i, j] <=
                        (np.pi / 8)):
                        orient[i, j] = 0
                    elif (orient[i, j] > (7 * np.pi / 8)
                          and orient[i, j] <= np.pi):
                        orient[i, j] = 0
                    elif (orient[i, j] >= -np.pi and orient[i, j] <
                          (-7 * np.pi / 8)):
                        orient[i, j] = 0
                    # case 1
                    elif (orient[i, j] > (np.pi / 8) and orient[i, j] <=
                          (3 * np.pi / 8)):
                        orient[i, j] = 3
                    elif (orient[i, j] >= (-7 * np.pi / 8) and orient[i, j] <
                          (-5 * np.pi / 8)):
                        orient[i, j] = 3
                    # case 2
                    elif (orient[i, j] > (3 * np.pi / 8) and orient[i, j] <=
                          (5 * np.pi / 8)):
                        orient[i, j] = 2
                    elif (orient[i, j] >= (-5 * np.pi / 4) and orient[i, j] <
                          (-3 * np.pi / 8)):
                        orient[i, j] = 2
                    # case 3
                    elif (orient[i, j] > (5 * np.pi / 8) and orient[i, j] <=
                          (7 * np.pi / 8)):
                        orient[i, j] = 1
                    elif (orient[i, j] >= (-3 * np.pi / 8) and orient[i, j] <
                          (-np.pi / 8)):
                        orient[i, j] = 1

        mag = normMag
        mag_thin = np.zeros(mag.shape)
        for i in range(mag.shape[0] - 1):
            for j in range(mag.shape[1] - 1):
                if mag[i][j] < t_low:
                    continue
                if orient[i][j] == 0:
                    if mag[i][j] > mag[i][j - 1] and mag[i][j] >= mag[i][j +
                                                                         1]:
                        mag_thin[i][j] = mag[i][j]
                if orient[i][j] == 1:
                    if mag[i][j] > mag[i - 1][j + 1] and mag[i][j] >= mag[
                            i + 1][j - 1]:
                        mag_thin[i][j] = mag[i][j]
                if orient[i][j] == 2:
                    if mag[i][j] > mag[i - 1][j] and mag[i][j] >= mag[i +
                                                                      1][j]:
                        mag_thin[i][j] = mag[i][j]
                if orient[i][j] == 3:
                    if mag[i][j] > mag[i - 1][j - 1] and mag[i][j] >= mag[
                            i + 1][j + 1]:
                        mag_thin[i][j] = mag[i][j]

        # 4) Thresholding and edge linking

        result_binary = np.zeros(mag_thin.shape)

        tHigh = t_high
        tLow = t_low
        # forward scan
        for i in range(0, mag_thin.shape[0] - 1):  # rows
            for j in range(0, mag_thin.shape[1] - 1):  # columns
                if mag_thin[i][j] >= tHigh:
                    if mag_thin[i][j + 1] >= tLow:  # right
                        mag_thin[i][j + 1] = tHigh
                    if mag_thin[i + 1][j + 1] >= tLow:  # bottom right
                        mag_thin[i + 1][j + 1] = tHigh
                    if mag_thin[i + 1][j] >= tLow:  # bottom
                        mag_thin[i + 1][j] = tHigh
                    if mag_thin[i + 1][j - 1] >= tLow:  # bottom left
                        mag_thin[i + 1][j - 1] = tHigh

        # backwards scan
        for i in range(mag_thin.shape[0] - 2, 0, -1):  # rows
            for j in range(mag_thin.shape[1] - 2, 0, -1):  # columns
                if mag_thin[i][j] >= tHigh:
                    if mag_thin[i][j - 1] > tLow:  # left
                        mag_thin[i][j - 1] = tHigh
                    if mag_thin[i - 1][j - 1]:  # top left
                        mag_thin[i - 1][j - 1] = tHigh
                    if mag_thin[i - 1][j] > tLow:  # top
                        mag_thin[i - 1][j] = tHigh
                    if mag_thin[i - 1][j + 1] > tLow:  # top right
                        mag_thin[i - 1][j + 1] = tHigh

        # fill in result_binary
        for i in range(0, mag_thin.shape[0] - 1):  # rows
            for j in range(0, mag_thin.shape[1] - 1):  # columns
                if mag_thin[i][j] >= tHigh:
                    result_binary[i][j] = 255  # set to 255 for >= tHigh

        img = Image.fromarray(result_binary)
        return img
Exemplo n.º 7
0
def plotPsudoSectNSDiff(ax,sectDict,arrayList,flag,par='abs',colorbar=True,colorNorm='SymLog',cLevel=None,contour=True,mask=None,useLog=False):

    def sortInArr(arr):
        return np.sort(arr,order=['freq','x','y','z'])
    # Find the index for the slice
    indSect0 = np.where(sectDict.values()[0]==arrayList[0][sectDict.keys()[0]])
    indSect1 = np.where(sectDict.values()[0]==arrayList[1][sectDict.keys()[0]])
    # Extract and sort the mats
    arr0 = sortInArr(arrayList[0][indSect0])
    arr1 = sortInArr(arrayList[1][indSect1])

    # Define the plot axes
    if 'x' in sectDict.keys()[0]:
        x0 = arr0['y']
        x1 = arr1['y']
    else:
        x0 = arr0['x']
        x1 = arr1['x']
    y0 = arr0['freq']
    y1 = arr1['freq']


    if par == 'abs':
        if useLog:
            zPlot = (np.log10(np.abs(arr0[flag])) - np.log10(np.abs(arr1[flag])))/np.log10(np.abs(arr1[flag]))
        else:
            zPlot = (np.abs(arr0[flag]) - np.abs(arr1[flag]))/np.abs(arr1[flag])
        if mask:
            maskInd = np.logical_or(np.abs(arr0[flag])< 1e-3,np.abs(arr1[flag]) < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap('RdYlBu')#seismic)
    elif par == 'ares':
        arF = 1/(8*np.pi**2*10**(-7))
        if useLog:
            zPlot = (np.log10((arF/arr0['freq'])*np.abs(arr0[flag])**2) - np.log10((arF/arr1['freq'])*np.abs(arr1[flag])**2))/np.log10((arF/arr1['freq'])*np.abs(arr1[flag])**2)
        else:
            zPlot = ((arF/arr0['freq'])*np.abs(arr0[flag])**2 - (arF/arr1['freq'])*np.abs(arr1[flag])**2)/((arF/arr1['freq'])*np.abs(arr1[flag])**2)
        if mask:
            maskInd = np.logical_or(np.abs(arr0[flag])< 1e-3,np.abs(arr1[flag]) < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap('Spectral')#seismic)

    elif par == 'aphs':
        if useLog:
            zPlot = (np.log10(np.arctan2(arr0[flag].imag,arr0[flag].real)*(180/np.pi)) - np.log10(np.arctan2(arr1[flag].imag,arr1[flag].real)*(180/np.pi)) )/np.log10(np.arctan2(arr1[flag].imag,arr1[flag].real)*(180/np.pi))
        else:
            zPlot = ( np.arctan2(arr0[flag].imag,arr0[flag].real)*(180/np.pi) - np.arctan2(arr1[flag].imag,arr1[flag].real)*(180/np.pi) )/(np.arctan2(arr1[flag].imag,arr1[flag].real)*(180/np.pi))
        if mask:
            maskInd = np.logical_or(np.abs(arr0[flag])< 1e-3,np.abs(arr1[flag]) < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap('Spectral')#seismic)
    elif par == 'real':
        if useLog:
            zPlot = (np.log10(arr0[flag].real) - np.log10(arr1[flag].real))/np.log10(arr1[flag].real)
        else:
            zPlot = (arr0[flag].real - arr1[flag].real)/arr1[flag].real
        if mask:
            maskInd = np.logical_or(arr0[flag].real< 1e-3,arr1[flag].real < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap('Spectral') #('Spectral')

    elif par == 'imag':
        if useLog:
            zPlot = (np.log10(arr0[flag].imag) - np.log10(arr1[flag].imag))/np.log10(arr1[flag].imag)
        else:
            zPlot = (arr0[flag].imag - arr1[flag].imag)/arr1[flag].imag
        if mask:
            maskInd = np.logical_or(arr0[flag].imag< 1e-3,arr1[flag].imag < 1e-3)
            zPlot = np.ma.array(zPlot)
            zPlot[maskInd] = mask
        cmap = plt.get_cmap('Spectral') #('RdYlBu')

    if cLevel:
        zMax = np.log10(cLevel[1])
        zMin = np.log10(cLevel[0])
    else:
        zMax = (np.ceil(np.log10(np.abs(zPlot).max())))
        zMin = (np.floor(np.log10(np.abs(zPlot).min())))


    if colorNorm=='SymLog':
        level = np.concatenate((-np.logspace(zMax,zMin-.125,(zMax-zMin)*8+1,endpoint=True),np.logspace(zMin-.125,zMax,(zMax-zMin)*8+1,endpoint=True)))
        clevel = np.concatenate((-np.logspace(zMax,zMin,(zMax-zMin)*1+1,endpoint=True),np.logspace(zMin,zMax,(zMax-zMin)*1+1,endpoint=True)))
        plotNorm = colors.SymLogNorm(np.abs(level).min(),linscale=0.1)
    elif colorNorm=='Lin':
        if cLevel:
            level = np.arange(cLevel[0],cLevel[1]+.1,(cLevel[1] - cLevel[0])/50.)
            clevel = np.arange(cLevel[0],cLevel[1]+.1,(cLevel[1] - cLevel[0])/10.)
        else:
            level = np.arange(zPlot.min(),zPlot.max(),(zPlot.max() - zPlot.min())/50.)
            clevel = np.arange(zPlot.min(),zPlot.max(),(zPlot.max() - zPlot.min())/10.)
        plotNorm = colors.Normalize()
    elif colorNorm=='Log':
        level = np.logspace(zMin-.125,zMax,(zMax-zMin)*8+1,endpoint=True)
        clevel = np.logspace(zMin,zMax,(zMax-zMin)*2+1,endpoint=True)
        plotNorm = colors.LogNorm()
    if contour:
        cs = ax.tricontourf(x0,y0,zPlot*100,levels=level*100,cmap=cmap,norm=plotNorm,extend='both')#,extend='both')
    else:
        uniX,uniY = np.unique(x0),np.unique(y0)
        X,Y = np.meshgrid(np.append(uniX-25,uniX[-1]+25),np.append(uniY-25,uniY[-1]+25))
        cs = ax.pcolor(X,Y,np.reshape(zPlot,(len(uniY),len(uniX))),cmap=cmap,norm=plotNorm)
    if colorbar:
        csB = plt.colorbar(cs,cax=ax.cax,ticks=clevel*100,format='%1.2e')
        # csB.on_mappable_changed(cs)
        ax.set_title(flag+' '+par + ' diff',fontsize=8)
        return cs, csB
    return cs,None
Exemplo n.º 8
0
def plotPsudoSectNSimpedance(ax,sectDict,array,flag,par='abs',colorbar=True,colorNorm='None',cLevel=None,contour=True):

    indSect = np.where(sectDict.values()[0]==array[sectDict.keys()[0]])

    # Define the plot axes
    if 'x' in sectDict.keys()[0]:
        x = array['y'][indSect]
    else:
        x = array['x'][indSect]
    y = array['freq'][indSect]

    if par == 'abs':
        zPlot = np.abs(array[flag][indSect])
        cmap = plt.get_cmap('OrRd_r')#seismic')
        if cLevel:
            level = np.logspace(0,-5,31,endpoint=True)
            clevel = np.logspace(0,-4,5,endpoint=True)
        else:
            level = np.linspace(zPlot.min(),zPlot.max(),100,endpoint=True)
            clevel = np.linspace(zPlot.min(),zPlot.max(),10,endpoint=True)

    elif par == 'ares':
        zPlot = np.abs(array[flag][indSect])**2/(8*np.pi**2*10**(-7)*array['freq'][indSect])
        cmap = plt.get_cmap('RdYlBu')#seismic)
        if cLevel:
            zMax = np.log10(cLevel[1])
            zMin = np.log10(cLevel[0])
        else:
            zMax = (np.ceil(np.log10(np.abs(zPlot).max())))
            zMin = (np.floor(np.log10(np.abs(zPlot).min())))
        level = np.logspace(zMin,zMax,(zMax-zMin)*8+1,endpoint=True)
        clevel = np.logspace(zMin,zMax,(zMax-zMin)*2+1,endpoint=True)
        plotNorm = colors.LogNorm()

    elif par == 'aphs':
        zPlot = np.arctan2(array[flag][indSect].imag,array[flag][indSect].real)*(180/np.pi)
        cmap = plt.get_cmap('RdYlBu')#seismic)
        if cLevel:
            zMax = cLevel[1]
            zMin = cLevel[0]
        else:
            zMax = (np.ceil(zPlot).max())
            zMin = (np.floor(zPlot).min())
        level = np.arange(zMin,zMax+.1,1)
        clevel = np.arange(zMin,zMax+.1,10)
        plotNorm = colors.Normalize()

    elif par == 'real':
        zPlot = np.real(array[flag][indSect])
        cmap = plt.get_cmap('Spectral') #('RdYlBu')
        if cLevel:
            zMax = np.log10(cLevel[1])
            zMin = np.log10(cLevel[0])
        else:
            zMax = (np.ceil(np.log10(np.abs(zPlot).max())))
            zMin = (np.floor(np.log10(np.abs(zPlot).min())))
        level = np.concatenate((-np.logspace(zMax,zMin-.125,(zMax-zMin)*8+1,endpoint=True),np.logspace(zMin-.125,zMax,(zMax-zMin)*8+1,endpoint=True)))
        clevel = np.concatenate((-np.logspace(zMax,zMin,(zMax-zMin)*1+1,endpoint=True),np.logspace(zMin,zMax,(zMax-zMin)*1+1,endpoint=True)))
        plotNorm = colors.SymLogNorm(np.abs(level).min(),linscale=0.1)
    elif par == 'imag':
        zPlot = np.imag(array[flag][indSect])
        cmap = plt.get_cmap('Spectral') #('RdYlBu')

        if cLevel:
            zMax = np.log10(cLevel[1])
            zMin = np.log10(cLevel[0])
        else:
            zMax = (np.ceil(np.log10(np.abs(zPlot).max())))
            zMin = (np.floor(np.log10(np.abs(zPlot).min())))
        level = np.concatenate((-np.logspace(zMax,zMin-.125,(zMax-zMin)*8+1,endpoint=True),np.logspace(zMin-.125,zMax,(zMax-zMin)*8+1,endpoint=True)))
        clevel = np.concatenate((-np.logspace(zMax,zMin,(zMax-zMin)*1+1,endpoint=True),np.logspace(zMin,zMax,(zMax-zMin)*1+1,endpoint=True)))
        plotNorm = colors.SymLogNorm(np.abs(level).min(),linscale=0.1)

    if colorNorm=='SymLog':
        plotNorm = colors.SymLogNorm(np.abs(level).min(),linscale=0.1)
    elif colorNorm=='Lin':
        plotNorm = colors.Normalize()
    elif colorNorm=='Log':
        plotNorm = colors.LogNorm()
    if contour:
        cs = ax.tricontourf(x,y,zPlot,levels=level,cmap=cmap,norm=plotNorm)#,extend='both')
    else:
        uniX,uniY = np.unique(x),np.unique(y)
        X,Y = np.meshgrid(np.append(uniX-25,uniX[-1]+25),np.append(uniY-25,uniY[-1]+25))
        cs = ax.pcolor(X,Y,np.reshape(zPlot,(len(uniY),len(uniX))),cmap=cmap,norm=plotNorm)
    if colorbar:
        csB = plt.colorbar(cs,cax=ax.cax,ticks=clevel,format='%1.2e')
        # csB.on_mappable_changed(cs)
        ax.set_title(flag+' '+par,fontsize=8)
        return cs, csB
    return cs,None