Exemple #1
0
def get_average(
    offset,
    nregrid,
    rrange=[0.0, 1.5e18],
    phirange=[0.0, 6.283185307179586],
    zrange=[-1.5e18, 1.5e18],
    function=get,
    filenameout="data",
    type="pvtu",
):
    # load the data:
    pointdata = load(offset, filenameout=filenameout, type=type)
    myaniso = function(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    # Gathering data:
    data = averageNumba(myaniso, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange)

    return {
        "data": data,
        "nregrid": nregrid,
        "rrange": rrange,
        "phirange": phirange,
        "zrange": zrange,
        "offset": offset,
        "filenameout": filenameout,
        "type": type,
    }
Exemple #2
0
def get_average(offset,
                nregrid,
                rrange=[0., 1.5e18],
                phirange=[0., 6.283185307179586],
                zrange=[-1.5e18, 1.5e18],
                function=get,
                filenameout='data',
                type='pvtu'):
    # load the data:
    pointdata = load(offset, filenameout=filenameout, type=type)
    myaniso = function(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    # Gathering data:
    data = averageNumba(myaniso,
                        points,
                        nregrid,
                        rrange=rrange,
                        phirange=phirange,
                        zrange=zrange)

    return {
        'data': data,
        'nregrid': nregrid,
        'rrange': rrange,
        'phirange': phirange,
        'zrange': zrange,
        'offset': offset,
        'filenameout': filenameout,
        'type': type
    }
Exemple #3
0
def plot(offset, nregrid, xrange=[-1.8e18, 1.8e18], yrange=[-1.8e18, 1.8e18], filenameout="data", type="pvtu"):

    nlevels = 256

    path = "movie"

    timescale = 1.05772480719860e-1
    time_start = 212.16
    time = offset * timescale + time_start

    pointdata = load(offset, filenameout=filenameout, type=type)
    aniso = get(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    x = points[:, 0]
    y = points[:, 1]
    z = points[:, 2]

    # this is needed because griddata freaks out otherwise:
    smalldouble = 1.0e-8

    tmp = (xrange[1] - xrange[0]) * smalldouble
    xi = np.linspace(xrange[0] - tmp, xrange[1] + tmp, nregrid[0])
    tmp = (yrange[1] - yrange[0]) * smalldouble
    yi = np.linspace(yrange[0] - tmp, yrange[1] + tmp, nregrid[1])
    data = griddata((x, y), aniso[0], (xi[None, :], yi[:, None]), method="linear")
    mask = griddata((x, y), aniso[1], (xi[None, :], yi[:, None]), method="linear")
    data = np.ma.masked_array(data, mask)

    plt.clf()
    cs = plt.contourf(xi, yi, data, levels=np.arange(nlevels) / float(nlevels - 1))
    cb = plt.colorbar()
    cb.set_ticks(np.arange(11) / 10.0)

    ax = plt.gca()
    ax.set_aspect("equal")

    plt.ylabel("z [cm]")
    plt.xlabel("y [cm]")
    plt.title("".join(["Departure from tor. field,  t=", str(time)[0:5], " yrs"]))

    plt.savefig("".join([path, "/aniso_", str(offset).zfill(4), ".png"]), format="png", transparent=False)

    #    plt.show()
    plt.close()
Exemple #4
0
def get_bcyl(pointdata):

    bx = read.extract(pointdata, "b1", attribute_mode="point")
    by = read.extract(pointdata, "b2", attribute_mode="point")
    bz = read.extract(pointdata, "b3", attribute_mode="point")

    points = ah.vtk2array(pointdata.GetPoints().GetData())

    r = np.sqrt(np.square(points[:, 0]) + np.square(points[:, 1]))
    m = r <= 0.0

    cosphi = np.ma.array(points[:, 0] / r, mask=m, fill_value=0.0)
    sinphi = np.ma.array(points[:, 1] / r, mask=m, fill_value=0.0)

    br = bx * cosphi + by * sinphi
    bphi = by * cosphi - bx * sinphi

    return np.array([br, bphi, bz])
Exemple #5
0
def get_bcyl(pointdata):

    bx = read.extract(pointdata, 'b1', attribute_mode='point')
    by = read.extract(pointdata, 'b2', attribute_mode='point')
    bz = read.extract(pointdata, 'b3', attribute_mode='point')

    points = ah.vtk2array(pointdata.GetPoints().GetData())

    r = np.sqrt(np.square(points[:, 0]) + np.square(points[:, 1]))
    m = r <= 0.

    cosphi = np.ma.array(points[:, 0] / r, mask=m, fill_value=0.)
    sinphi = np.ma.array(points[:, 1] / r, mask=m, fill_value=0.)

    br = bx * cosphi + by * sinphi
    bphi = by * cosphi - bx * sinphi

    return np.array([br, bphi, bz])
Exemple #6
0
def get_bsphere(pointdata):

    bx = read.extract(pointdata, "b1", attribute_mode="point")
    by = read.extract(pointdata, "b2", attribute_mode="point")
    bz = read.extract(pointdata, "b3", attribute_mode="point")

    points = ah.vtk2array(pointdata.GetPoints().GetData())

    x = points[:, 0]
    y = points[:, 1]
    z = points[:, 2]

    rcyl = np.sqrt(np.square(points[:, 0]) + np.square(points[:, 1]))
    r = np.sqrt(np.square(points[:, 0]) + np.square(points[:, 1]) + np.square(points[:, 2]))

    br = 1.0 / r * (x * bx + y * by + z * bz)
    bphi = 1.0 / rcyl * (-y * bx + x * by)
    btheta = 1.0 / r * (1.0 / rcyl * z * x * bx + 1.0 / rcyl * z * y * by - rcyl * bz)

    return {"br": br, "bphi": bphi, "btheta": btheta}
Exemple #7
0
def get_correlation(
    offset,
    nregrid,
    rrange=[0.0, 1.5e18],
    phirange=[0.0, 6.283185307179586],
    zrange=[-1.5e18, 1.5e18],
    functiona=get,
    functionb=fieldstrength,
    filenameout="data",
    type="pvtu",
):
    # load the data:
    pointdata = load(offset, filenameout=filenameout, type=type)
    a = functiona(pointdata)
    b = functionb(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    # Gathering data:
    meanA = averageNumba(a, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange)
    meanB = averageNumba(b, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange)

    stddevA = stddevNumba(a, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange)
    stddevB = stddevNumba(b, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange)

    data = correlationNumba(
        a, b, meanA, meanB, stddevA, stddevB, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange
    )

    return {
        "data": data,
        "nregrid": nregrid,
        "rrange": rrange,
        "phirange": phirange,
        "zrange": zrange,
        "offset": offset,
        "filenameout": filenameout,
        "type": type,
    }
Exemple #8
0
def get_bsphere(pointdata):

    bx = read.extract(pointdata, 'b1', attribute_mode='point')
    by = read.extract(pointdata, 'b2', attribute_mode='point')
    bz = read.extract(pointdata, 'b3', attribute_mode='point')

    points = ah.vtk2array(pointdata.GetPoints().GetData())

    x = points[:, 0]
    y = points[:, 1]
    z = points[:, 2]

    rcyl = np.sqrt(np.square(points[:, 0]) + np.square(points[:, 1]))
    r = np.sqrt(
        np.square(points[:, 0]) + np.square(points[:, 1]) +
        np.square(points[:, 2]))

    br = 1. / r * (x * bx + y * by + z * bz)
    bphi = 1. / rcyl * (-y * bx + x * by)
    btheta = 1. / r * (1. / rcyl * z * x * bx + 1. / rcyl * z * y * by -
                       rcyl * bz)

    return {'br': br, 'bphi': bphi, 'btheta': btheta}
Exemple #9
0
def get1D(
    offset,
    nregrid,
    rrange=[0.0, 1.5e18],
    phirange=[0.0, 6.283185307179586],
    zrange=[-1.5e18, 1.5e18],
    filenameout="data",
    type="pvtu",
):

    # load the data:
    pointdata = load(offset, filenameout=filenameout, type=type)
    aniso = get(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    # Gathering data:
    datarz = average(aniso, points, nregrid, rrange=rrange, phirange=phirange, zrange=zrange)

    rsrange = [0.0, np.sqrt(rrange[1] ** 2 + np.max(zrange) ** 2)]

    # create r and z arrays:
    r = np.linspace(rrange[0], rrange[1], nregrid[0])
    z = np.linspace(zrange[0], zrange[1], nregrid[2])
    rr, zz = np.meshgrid(r, z)
    rr = np.reshape(rr, -1)
    zz = np.reshape(zz, -1)

    # create rs_i and theta_j arrays:
    rsi = np.linspace(rsrange[0], rsrange[1], nregrid[0])
    thetaj = np.linspace(phirange[0], phirange[1] / 2.0, nregrid[1])

    # allocate xij arrays:
    nelements = nregrid[0] * nregrid[1]
    rij = np.empty(nelements)
    zij = np.empty(nelements)

    # create single indexed points:
    for i in range(nregrid[0]):
        for j in range(nregrid[1]):
            zij[j + i * nregrid[1]] = rsi[i] * np.cos(thetaj[j])
            rij[j + i * nregrid[1]] = rsi[i] * np.sin(thetaj[j])

    # griddata to points:
    data = griddata((rr, zz), np.reshape(datarz, -1), (rij, zij), method="linear")
    data = np.ma.masked_array(data, np.isnan(data))

    # Now create the theta average:
    aniso_av = np.zeros(nregrid[0])
    for i in range(nregrid[0]):
        index = np.arange(nregrid[1]) + i * nregrid[1]
        aniso_av[i] = data[index].mean()

    aniso_av = np.ma.masked_array(aniso_av, np.isnan(aniso_av))

    return {
        "aniso_av": aniso_av,
        "nregrid": nregrid,
        "rrange": rrange,
        "phirange": phirange,
        "zrange": zrange,
        "rsph": rsi,
        "offset": offset,
        "filenameout": filenameout,
        "type": type,
    }
Exemple #10
0
def get1D(offset,
          nregrid,
          rrange=[0., 1.5e18],
          phirange=[0., 6.283185307179586],
          zrange=[-1.5e18, 1.5e18],
          filenameout='data',
          type='pvtu'):

    # load the data:
    pointdata = load(offset, filenameout=filenameout, type=type)
    aniso = get(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    # Gathering data:
    datarz = average(aniso,
                     points,
                     nregrid,
                     rrange=rrange,
                     phirange=phirange,
                     zrange=zrange)

    rsrange = [0., np.sqrt(rrange[1]**2 + np.max(zrange)**2)]

    # create r and z arrays:
    r = np.linspace(rrange[0], rrange[1], nregrid[0])
    z = np.linspace(zrange[0], zrange[1], nregrid[2])
    rr, zz = np.meshgrid(r, z)
    rr = np.reshape(rr, -1)
    zz = np.reshape(zz, -1)

    # create rs_i and theta_j arrays:
    rsi = np.linspace(rsrange[0], rsrange[1], nregrid[0])
    thetaj = np.linspace(phirange[0], phirange[1] / 2., nregrid[1])

    # allocate xij arrays:
    nelements = nregrid[0] * nregrid[1]
    rij = np.empty(nelements)
    zij = np.empty(nelements)

    # create single indexed points:
    for i in range(nregrid[0]):
        for j in range(nregrid[1]):
            zij[j + i * nregrid[1]] = rsi[i] * np.cos(thetaj[j])
            rij[j + i * nregrid[1]] = rsi[i] * np.sin(thetaj[j])


# griddata to points:
    data = griddata((rr, zz),
                    np.reshape(datarz, -1), (rij, zij),
                    method='linear')
    data = np.ma.masked_array(data, np.isnan(data))

    # Now create the theta average:
    aniso_av = np.zeros(nregrid[0])
    for i in range(nregrid[0]):
        index = np.arange(nregrid[1]) + i * nregrid[1]
        aniso_av[i] = data[index].mean()

    aniso_av = np.ma.masked_array(aniso_av, np.isnan(aniso_av))

    return {
        'aniso_av': aniso_av,
        'nregrid': nregrid,
        'rrange': rrange,
        'phirange': phirange,
        'zrange': zrange,
        'rsph': rsi,
        'offset': offset,
        'filenameout': filenameout,
        'type': type
    }
Exemple #11
0
def get_correlation(offset,
                    nregrid,
                    rrange=[0., 1.5e18],
                    phirange=[0., 6.283185307179586],
                    zrange=[-1.5e18, 1.5e18],
                    functiona=get,
                    functionb=fieldstrength,
                    filenameout='data',
                    type='pvtu'):
    # load the data:
    pointdata = load(offset, filenameout=filenameout, type=type)
    a = functiona(pointdata)
    b = functionb(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    # Gathering data:
    meanA = averageNumba(a,
                         points,
                         nregrid,
                         rrange=rrange,
                         phirange=phirange,
                         zrange=zrange)
    meanB = averageNumba(b,
                         points,
                         nregrid,
                         rrange=rrange,
                         phirange=phirange,
                         zrange=zrange)

    stddevA = stddevNumba(a,
                          points,
                          nregrid,
                          rrange=rrange,
                          phirange=phirange,
                          zrange=zrange)
    stddevB = stddevNumba(b,
                          points,
                          nregrid,
                          rrange=rrange,
                          phirange=phirange,
                          zrange=zrange)

    data = correlationNumba(a,
                            b,
                            meanA,
                            meanB,
                            stddevA,
                            stddevB,
                            points,
                            nregrid,
                            rrange=rrange,
                            phirange=phirange,
                            zrange=zrange)

    return {
        'data': data,
        'nregrid': nregrid,
        'rrange': rrange,
        'phirange': phirange,
        'zrange': zrange,
        'offset': offset,
        'filenameout': filenameout,
        'type': type
    }
Exemple #12
0
def plot(offset,
         nregrid,
         xrange=[-1.8e18, 1.8e18],
         yrange=[-1.8e18, 1.8e18],
         filenameout='data',
         type='pvtu'):

    nlevels = 256

    path = 'movie'

    timescale = 1.05772480719860e-1
    time_start = 212.16
    time = offset * timescale + time_start

    pointdata = load(offset, filenameout=filenameout, type=type)
    aniso = get(pointdata)
    points = ah.vtk2array(pointdata.GetPoints().GetData())

    x = points[:, 0]
    y = points[:, 1]
    z = points[:, 2]

    # this is needed because griddata freaks out otherwise:
    smalldouble = 1.e-8

    tmp = (xrange[1] - xrange[0]) * smalldouble
    xi = np.linspace(xrange[0] - tmp, xrange[1] + tmp, nregrid[0])
    tmp = (yrange[1] - yrange[0]) * smalldouble
    yi = np.linspace(yrange[0] - tmp, yrange[1] + tmp, nregrid[1])
    data = griddata((x, y),
                    aniso[0], (xi[None, :], yi[:, None]),
                    method='linear')
    mask = griddata((x, y),
                    aniso[1], (xi[None, :], yi[:, None]),
                    method='linear')
    data = np.ma.masked_array(data, mask)

    plt.clf()
    cs = plt.contourf(xi,
                      yi,
                      data,
                      levels=np.arange(nlevels) / float(nlevels - 1))
    cb = plt.colorbar()
    cb.set_ticks(np.arange(11) / 10.)

    ax = plt.gca()
    ax.set_aspect('equal')

    plt.ylabel('z [cm]')
    plt.xlabel('y [cm]')
    plt.title(''.join(
        ['Departure from tor. field,  t=',
         str(time)[0:5], ' yrs']))

    plt.savefig(''.join([path, '/aniso_',
                         str(offset).zfill(4), '.png']),
                format="png",
                transparent=False)

    #    plt.show()
    plt.close()