예제 #1
0
    width  = rect.get_width()
    height = rect.get_y()
    # Add 4% padding
    x      = width*1.04 + lowestVal
    y      = height + rect.get_height()/2
    perpAx.text(x, y, txt, ha="left", va="center")

perpAx.set_xlabel(r"$[\mathrm{s}^{-1}]$")
perpAx.set_title(r"$\mathrm{Perpendicular}$")

perpAx.spines["top"]  .set_visible(False)
perpAx.spines["left"] .set_visible(False)
perpAx.spines["right"].set_visible(False)
perpAx.get_yaxis().set_visible(False)

PlotHelper.makePlotPretty(perpAx, xbins=5, legend=False, rotation=45)
perpAx.grid(False)


# Par values
xBarVals = tuple(range(len(perpPerTime)*2))
ionXBarVals = xBarVals[1::2]
elXBarVals  = xBarVals[0::2]

# Find the lowest value
lowestVal = np.min(perpPerTime)
# Pad with 5%
lowestVal = 0.95*lowestVal

# Plot
elRects = parAx.barh(elXBarVals                      ,\
예제 #2
0
                 "edgecolor":"none" ,\
                 "boxstyle" :"round",\
                 "alpha"    :0.9},\
           )

ddtTxt = r"$\partial_t j_\parallel$"
newAx.text(1.4, 0, ddtTxt, color="k",\
           va="center", ha="center", size="x-large",\
           bbox={"facecolor":"white",\
                 "edgecolor":"none" ,\
                 "boxstyle" :"round",\
                 "alpha"    :0.9},\
           )

newAx.set_xlabel(r"$z\;[\mathrm{m}]$")
newAx.set_ylabel(r"$[\mathrm{C}\mathrm{m}^{-2}\mathrm{s}^{-2}]$")

# Create new title
theSplit = suptitle.split("=")
rho = float(theSplit[1].split("$")[2]) * rhoS
t   = eval(theSplit[-1].split("$")[2].\
           replace("{","").replace("}","").replace("\\cdot 10^","e"))/omCI
newAx.set_title((r"$\rho={}\;\mathrm{{m}}\quad"
                 r"\theta=0^{{\circ}}\quad t={}\;\mathrm{{s}}$").\
        format(plotNumberFormatter(rho,0).replace("$",""),\
               plotNumberFormatter(t,0)  .replace("$","")\
        ))

PlotHelper.makePlotPretty(newAx, legend=False)
PlotHelper.savePlot(fig, "jParBalanceNy{}.pdf".format(ny))
예제 #3
0
turbulenceXvals = xBarVals[3::lenMode]
tickVals = tuple(val - 0.5 for val in linearXvals)

# Create the figure
fig, ax = plt.subplots(figsize=SizeMaker.standard(a=0.5, s=0.5))

ax.bar(initXvals, initMeans,\
        yerr=initStds, label="Initial phase")
ax.bar(expandXvals, expandMeans,\
        yerr=expandStds, label="Expand phase")
ax.bar(linearXvals, linearMeans,\
        yerr=linearStds, label="Linear phase")
ax.bar(turbulenceXvals, turbulenceMeans,\
        yerr=turbulenceStds, label="Turbulent phase")

PlotHelper.makePlotPretty(ax)
ax.xaxis.grid(False)
ax.xaxis.set_ticks(tickVals)

n0 = 1e19
nns = n0 / (n0 + np.array([float(nn) for nn in nns])) * 100
tickLabels = tuple(r"${:d}\%$".format(int(np.ceil(nn))) for nn in nns)
ax.xaxis.set_ticklabels(tickLabels)
ax.set_xlabel("$d$")
ax.set_ylabel("RHS iterations per time step")

# Move legend outside
handles, labels = ax.get_legend_handles_labels()
# Remove old legend
leg = ax.legend()
leg.remove()
예제 #4
0
    axes = (nAx, phiAx, jParAx, omAx, uiAx, sAx, ueAx)
    colors = seqCMap3(np.linspace(0, 1, len(axes)))

    # Recolor the lines
    for ax, color in zip(axes, colors):
        line = ax.get_lines()[0]
        line.set_color(color)
        # NOTE: Using the designated setter gives a comparion error
        line._markerfacecolor = color
        line._markeredgecolor = color

        # To fix the legends, it seems like the easiest to do is to
        # recreate them
        handles, labels = ax.get_legend_handles_labels()
        leg = ax.legend()
        # Remake legend
        leg.remove()
        ax.legend(handles         ,\
                  labels          ,\
                  loc="upper left",\
                 )

    if direction == "radial":
        fileName = "B010RadBous.pdf"
    elif direction == "parallel":
        fileName = "B010ParBous.pdf"

    # Let pdfcrop do the cropping as "tigth" cuts some text
    PlotHelper.savePlot(fig, fileName, crop=False)
    Popen("pdfcrop {0} {0}".format(fileName), shell=True).wait()
예제 #5
0
                     marker = sD[scan]["marker"],\
                     ms     = 7,\
                     alpha  = 0.7,\
                     label  = "$B_0 = {} \mathrm{{T}}$".format(curScan)\
                     )
            sAx.set_ylabel(key.replace("Skewness", r"Skewness \;"))
        elif "kurt" in key.lower():
            kAx.plot(xAxis, sD[scan][key],\
                     ls     = sD[scan]["ls"],\
                     color  = sD[scan]["color"],\
                     marker = sD[scan]["marker"],\
                     alpha  = 0.7,\
                     ms     = 7,\
                     )
            kAx.set_ylabel(key.replace("quadkurtosis", r"; kurtosis \;"))
            kAx.set_xlabel(r"$\rho$ $[m]$")

PlotHelper.makePlotPretty(sAx, rotation=45)
PlotHelper.makePlotPretty(kAx, rotation=45, legend=None)

sAx.legend(bbox_to_anchor=(1.4, 0.5),\
           loc="center",\
           borderaxespad=0.,\
           bbox_transform = sAx.transAxes,\
           )

fig.tight_layout()

fileName = "BScanSkewKurt.pdf"
PlotHelper.savePlot(fig, fileName)
예제 #6
0
def checkModes(path):
    path = path[0]
    defaultCollect = partial(collect,\
                        path=path, xguards=False, yguards=False, info=False)
    unfiltered = defaultCollect("unfiltered")
    filtered = defaultCollect("filtered")
    Lx = defaultCollect("Lx")
    dx = defaultCollect("dx")

    maxRhoInd = unfiltered.shape[0]
    # NOTE: maxRhoInd counts from 0
    indices = (0, int(maxRhoInd / 2) - 1, maxRhoInd - 1)

    filteredDict = {}
    unfilteredDict = {}
    fftFiltered = {}
    fftUnfiltered = {}

    # Print stats
    kMax = np.floor((filtered.shape[-1] / 2) * (2 / 3))
    print(("\n\nMax allowed mode number on outer circumference = Nyquist mode "
            "* Orszag = floor((nz/2)*(2/3)) = floor(({}/2)*(2/3)) = {} ")\
            .format(filtered.shape[-1], kMax)
         )
    lambdaMin = 2 * np.pi * (Lx - dx[0, 0] / 2) / kMax
    print(("\nThis means that the minimum wavelength"
           " lambdaMin = outer circmference/kMax ="
           " 2*pi*(rho-dx/2)/kMax = 2*pi*({}-{}/2)/{} = {}")\
           .format(Lx, dx[0,0], kMax, lambdaMin)
         )
    print("\nThis means that kCurX = floor(cur circumference/lambdaMin)")
    for ind in range(filtered.shape[0]):
        # The first inner point is 0.5*dx from the origin
        x = dx[0, 0] * (ind + 0.5)
        curCirc = 2 * np.pi * x
        kCurXClean = curCirc / lambdaMin
        kCurX = np.floor(curCirc / lambdaMin)
        # Find first index where the value is close to 0
        firstZero\
            = np.where(\
                np.isclose(\
                    np.fft.fft(\
                        filtered[ind, 0, :].flatten().real), 0.0))[0][0]

        print(("Ind={:<3} => x={:<7.2f}=> cur circumference={:<7.2f}"
               " => kCurX={:<2d}, floored from {:<9.6f}. Last value found"
               " on mode {}")\
               .format(ind, x, curCirc, int(kCurX), kCurXClean, firstZero-1)
             )

    for ind in indices:
        unfilteredDict[ind] = unfiltered[ind, 0, :].flatten()
        filteredDict[ind] = filtered[ind, 0, :].flatten()
        fftUnfiltered[ind] = np.fft.fft(unfilteredDict[ind])
        fftFiltered[ind] = np.fft.fft(filteredDict[ind])

    fig = plt.figure()
    axUnfilter = fig.add_subplot(221)
    axFilter = fig.add_subplot(223)
    axFFTUnfilter = fig.add_subplot(222)
    axFFTFilter = fig.add_subplot(224)

    axUnfilter.set_xlabel("Unfiltered")
    axFilter.set_xlabel("Filtered")
    axFFTUnfilter.set_xlabel("FFT Unfiltered")
    axFFTFilter.set_xlabel("FFT Filtered")

    for ind in indices:
        axUnfilter.plot(unfilteredDict[ind].real,
                        "o",
                        alpha=0.5,
                        label="Index {}".format(ind))
        axFilter.plot(filteredDict[ind].real,
                      "o",
                      alpha=0.5,
                      label="Index {}".format(ind))
        axFFTUnfilter.plot(fftUnfiltered[ind].real,
                           "o",
                           alpha=0.5,
                           label="Index {}".format(ind))
        axFFTFilter.plot(fftFiltered[ind].real,
                         "o",
                         alpha=0.5,
                         label="Index {}".format(ind))

    PlotHelper.makePlotPretty(axUnfilter)
    PlotHelper.makePlotPretty(axFilter)
    PlotHelper.makePlotPretty(axFFTUnfilter)
    PlotHelper.makePlotPretty(axFFTFilter)

    plt.show()
예제 #7
0
data["Arithmetics"]["x"] = xBarVals[0::lenKeys]
data["Communication"]["x"] = xBarVals[1::lenKeys]
data["Input/output"]["x"] = xBarVals[2::lenKeys]
data["Laplace inversions"]["x"] = xBarVals[3::lenKeys]
data["Time solver"]["x"] = xBarVals[4::lenKeys]

tickVals = data["Input/output"]["x"]

# Create the figure
fig, ax = plt.subplots(figsize=SizeMaker.standard(a=0.5, s=0.5))

for key in keys:
    d = data[key]
    ax.bar(d["x"], d["mean"], yerr=d["std"], label=key)

PlotHelper.makePlotPretty(ax)
ax.xaxis.grid(False)
ax.xaxis.set_ticks(tickVals)
ax.xaxis.set_ticklabels(
    ("Initial\nphase", "Expand\nphase", "Linear\nphase", "Turbulent\nphase"))
ax.set_ylabel("$\%$")

# Move legend outside
handles, labels = ax.get_legend_handles_labels()

# Remove old legend
leg = ax.legend()
leg.remove()
fig.legend(handles,\
           labels ,\
           bbox_to_anchor=(1.05, 1.0),\
예제 #8
0
ddtTxt = r"$\partial_t \Omega^D$"
nnAx.text(0.4, 0, ddtTxt, color="k",\
           va="center", ha="center", size=size,\
           bbox={"facecolor":"white",\
                 "edgecolor":"none" ,\
                 "boxstyle" :"round",\
                 "alpha"    :0.9},\
           )

nnAx.set_xlabel(r"$z\;[\mathrm{m}]$")
nnAx.set_ylabel(r"$[\mathrm{m}^{-3}\mathrm{s}^{-2}]$")

nnAx.set_title(r"$d=1\%$")

PlotHelper.makePlotPretty(nnAx, legend=False, rotation=45)
#}}}

#{{{Extract and plot no neutral
nn = 0
path = "../../CSDXMagFieldScanAr/visualizationNormalized/B0_0.06/field1D/vortD-parallel-1D-0.pickle"
with open(path, "rb") as f:
    normalFig = pickle.load(f)

axes = normalFig.get_axes()

for ax in axes[:-1]:
    normalFig.delaxes(ax)

noNeutralAx = axes[-1]
예제 #9
0
    axes = fig.get_axes()

    for nr, ax in enumerate(axes):
        blobOrHole = "b" if nr == 0 else "h"
        l = ax.get_lines()[0]
        time, dens = l.get_data()
        ax.lines.pop()
        data[key][blobOrHole + "Time"] = time
        data[key][blobOrHole + "Dens"] = dens

# Replot
axes = fig.get_axes()

for nr, ax in enumerate(axes):
    blobOrHole = "b" if nr == 0 else "h"
    for key, c in zip(data.keys(), colors):
        ax.plot(data[key][blobOrHole + "Time"],\
                data[key][blobOrHole + "Dens"],\
                color=c,
                label="${}\sigma$".format(key),\
                alpha=0.75)
        if nr == 0:
            leg = ax.legend(loc       = "best",\
                            fancybox  = True  ,\
                            numpoints = 1     ,\
                            )
            leg.get_frame().set_alpha(0.5)

PlotHelper.savePlot(fig, "blobsAndHoles-{}.pdf".format(scan))
예제 #10
0
        yDown = np.array(yDown) - np.array(y)
        yUp = np.array(y) - np.array(yUp)
        yerr = (np.array(yDown), np.array(yUp))

        # Replot
        newAx.errorbar(x                ,\
                       y                ,\
                       color = color    ,\
                       yerr  = yerr     ,\
                       **errorbarOptions)

        newAx.set_ylabel(ax.get_ylabel())

newAxes[0].set_title(fig.texts[0].get_text())
newAxes[1].set_xlabel(reAx.get_xlabel())
PlotHelper.makePlotPretty(newAxes[0], legend=False, rotation=45)
PlotHelper.makePlotPretty(newAxes[1], legend=False, rotation=45)

# Manually set the x and the y as the figure has different coordinates
x = 0.4
y = -0.4

newFig.legend(handles,\
              newLabels,\
              bbox_to_anchor=(x, y),\
              ncol=2,\
              loc="upper center",\
              borderaxespad=0.,\
              bbox_transform = newAxes[1].transAxes,\
             )
turbulenceXvals = xBarVals[3::lenMode]
tickVals        = tuple(val - 0.5 for val in linearXvals)

# Create the figure
fig, ax = plt.subplots(figsize = SizeMaker.standard(a=0.5, s=0.5))

ax.bar(initXvals, initMeans,\
        yerr=initStds, label="Initial phase")
ax.bar(expandXvals, expandMeans,\
        yerr=expandStds, label="Expand phase")
ax.bar(linearXvals, linearMeans,\
        yerr=linearStds, label="Linear phase")
ax.bar(turbulenceXvals, turbulenceMeans,\
        yerr=turbulenceStds, label="Turbulent phase")

PlotHelper.makePlotPretty(ax)
ax.xaxis.grid(False)
ax.xaxis.set_ticks(tickVals)
ax.xaxis.set_ticklabels(B0s)
ax.set_xlabel("$B_0 [T]$")
ax.set_ylabel("RHS iterations\nper time step")

# Move legend outside
handles, labels = ax.get_legend_handles_labels()
# Remove old legend
leg = ax.legend()
leg.remove()
fig.legend(handles,\
           labels ,\
           bbox_to_anchor=(1.05, 1.0),\
           loc="upper left",\
예제 #12
0
    yLabels.append(ax.get_ylabel())
    ax.cla()

    for y, yDown, yUp, color in zip(meanY, yDownY, yUpY, colors):
        yDown = np.array(yDown) - np.array(y)
        yUp = np.array(y) - np.array(yUp)
        yerr = (np.array(yDown), np.array(yUp))

        # Replot
        ax.errorbar(x                ,\
                    y                ,\
                    color = color    ,\
                    yerr  = yerr     ,\
                    **errorbarOptions)

        PlotHelper.makePlotPretty(ax, legend=False, rotation=45)

# Remove x axis on imAx
imAx.set_xticklabels(imAx.get_xticklabels(), visible=False)

# Set proper ticks
reAx.xaxis.set_ticks(x)
reAx.set_xticklabels([r"${:d}\;\%$".format(int(i)) for i in x])

# Set the labels
imAx.set_ylabel(yLabels[0])
reAx.set_ylabel(yLabels[1])
reAx.set_xlabel(r"$\mathrm{Ionization\;degree}$")

PlotHelper.savePlot(fig, "growthRatesNnModes.pdf")
예제 #13
0
    xAxis = ax.get_lines()[0].get_data()[0]

    # Set legend to ylabel
    handles, labels = ax.get_legend_handles_labels()
    yLabel = labels[0]
    xLabel = fig.get_axes()[3].get_xlabel()

    plt.close(fig)

# Make a new figure
fig, ax = plt.subplots(figsize=SizeMaker.standard(s=0.5))

for scan in scans:
    curScan = float(scan[4:])
    ax.plot(xAxis, sD[scan]["line"],\
            ls     = sD[scan]["ls"],\
            color  = sD[scan]["color"],\
            marker = sD[scan]["marker"],\
            ms     = 7,\
            alpha  = 0.7,\
            label  = "$B_0 = {} \mathrm{{T}}$".format(curScan)\
            )

ax.set_ylabel(yLabel)
ax.set_xlabel(xLabel)

PlotHelper.makePlotPretty(ax, rotation=45)

fileName = "BScanPosOfFluct.pdf"
PlotHelper.savePlot(fig, fileName)
예제 #14
0
data["Arithmetics"]["x"] = xBarVals[0::lenKeys]
data["Communication"]["x"] = xBarVals[1::lenKeys]
data["Input/output"]["x"] = xBarVals[2::lenKeys]
data["Laplace inversions"]["x"] = xBarVals[3::lenKeys]
data["Time solver"]["x"] = xBarVals[4::lenKeys]

tickVals = data["Input/output"]["x"]

# Create the figure
fig, ax = plt.subplots(figsize=SizeMaker.standard(a=0.5, s=0.5))

for key in keys:
    d = data[key]
    ax.bar(d["x"], d["mean"], yerr=d["std"], label=key)

PlotHelper.makePlotPretty(ax)
ax.xaxis.grid(False)
ax.xaxis.set_ticks(tickVals)
ax.xaxis.set_ticklabels(
    ("Initial\nphase", "Expand\nphase", "Linear\nphase", "Turbulent\nphase"))
ax.set_ylabel("$\%$")

# Move legend outside
handles, labels = ax.get_legend_handles_labels()

# Remove old legend
leg = ax.legend()
leg.remove()
fig.legend(handles,\
           labels ,\
           bbox_to_anchor=(1.05, 1.0),\
예제 #15
0
    line.set_markersize(7)

handles, labels = axUp.get_legend_handles_labels()

leg = axUp.legend()

# Remove old legend
leg.remove()

fig.legend(handles,\
           labels,\
           bbox_to_anchor=(1.05, 1.0),\
           loc="upper left",\
           borderaxespad=0.,\
           bbox_transform = axUp.transAxes,\
           )

# Tweak the size a bit
fig.set_figwidth(2.0)
fig.set_figheight(4.0)

# Modify title position
t = fig.texts[0]
pos = list(t.get_position())
pos[1] = 1.05
t.set_transform(axUp.transAxes)
t.set_position(pos)
t.set_va("bottom")

PlotHelper.savePlot(fig, "test2.pdf")
예제 #16
0
for nr, (rect, txt) in enumerate(zip(holeRects, yTicks)):
    width  = rect.get_width()
    height = rect.get_y()
    # Add 4% padding
    x      = 0
    y      = height
    ax.text(x, y, txt, ha="center", va="center")

ax.set_xlabel(r"$[\mathrm{s}^{-1}]$")

ax.spines["top"]  .set_visible(False)
ax.spines["left"] .set_visible(False)
ax.spines["right"].set_visible(False)
ax.get_yaxis().set_visible(False)

PlotHelper.makePlotPretty(ax, legend=False, rotation=45)
ax.grid(False)

# Make legend manually
handles = (holeRects[0], blobRects[0])
labels  = ("$\mathrm{Holes}$",\
           "$\mathrm{Blobs}$",\
           )

fig.suptitle(r"$\mathrm{Average\;blobs\;and\;holes\;per\;second}$", y=1.1)
fig.legend(handles                      ,\
           labels                       ,\
           bbox_to_anchor=(1.02, 1.0)   ,\
           loc="upper left"             ,\
           borderaxespad=0.             ,\
           bbox_transform = ax.transAxes,\
예제 #17
0
           )

# Fix labels
old = r"u_{E\times B,\rho}}"
new = r"}\widetilde{u}_{E\times B,\rho}"
ylabel = ax.get_ylabel()
ylabel = ylabel.replace(old, new)
ax.set_ylabel(ylabel)
xlabel = ax.get_xlabel()
xlabel = xlabel.replace(old, new)
ax.set_xlabel(xlabel)

# Add skewness and kurtosis text
# Get the textSize
textPos = (0.5575, 0.935)
# Add text
SKTxt = ax.\
        text(*textPos,\
            "$S \;\;= \;\;{:.2f}$\n $K_E = {:.2f}$".\
            format(PDFStats["skew"], PDFStats["kurtExcess"]),\
            transform = ax.transAxes,\
            ha="left", va="top",\
            bbox={"facecolor":"white", "alpha":0.5, "pad":5},\
            )
SKTxt.set_fontsize(txtSize)

# Resize the figure
_, height = fig.get_size_inches()
fig.set_size_inches((2.70, height * 0.7))
PlotHelper.savePlot(fig, "blobFluxPDF_{}.pdf".format(scan))
예제 #18
0
    # Manually creating the legend
    handles = []
    for scan in scans:
        curScan = float(scan[4:])
        label = "$B_0 = {}$".format(curScan) + r" $\mathrm{T}$"
        handle = mlines.Line2D([], [],\
                       color  = "k"                    ,\
                       marker = sD[scan]["n"]["marker"],\
                       ls     = sD[scan]["n"]["ls"]    ,\
                       ms     = 5                      ,\
                       alpha  = 0.7                    ,\
                       label  =label)
        handles.append(handle)

    # Put legends outside
    sD[scans[0]]["ue"]["ax"].legend(handles=handles,\
                                    ncol=2,\
                                    bbox_to_anchor=(1.15, 0.25),\
                                    loc="upper left",\
                                    borderaxespad=0.,\
                                    bbox_transform =\
                                        sD[scans[0]]["ue"]["ax"].transAxes,\
                                    )

    if direction == "radial":
        fileName = "BScanRad.pdf"
    elif direction == "parallel":
        fileName = "BScanPar.pdf"

    PlotHelper.savePlot(fig, fileName)
예제 #19
0
jPar[ny]["leg"] = factorStr.format(ny * factor)
plt.close(fig)

fig, ax = plt.subplots(figsize=SizeMaker.standard(w=4, a=0.5))

colors = seqCMap2(np.linspace(0, 1, len(nys)))

for ny, color in zip(nys, colors):
    ax.plot(jPar[ny]["data"][0], jPar[ny]["data"][1],\
            label = jPar[ny]["leg"], alpha =0.7,\
            color = color
            )

ax.set_xlabel(r"$z\;[\mathrm{m}]$")
ax.set_ylabel(r"$j_\| \;[\mathrm{Cm}^{-2}\mathrm{s}^{-1}]$")
PlotHelper.makePlotPretty(ax)

# Move legend outside
handles, labels = ax.get_legend_handles_labels()
leg = ax.legend()
leg.remove()
fig.legend(handles,\
           labels ,\
           bbox_to_anchor=(1.05, 1.0),\
           loc="upper left",\
           borderaxespad=0.,\
           bbox_transform = ax.transAxes,\
           )

PlotHelper.savePlot(fig, "jParRipple006.pdf")