Пример #1
0
def test_radial_profiles():
    arr = random_periodic_upsample(128, 16, seed=0)
    mask = np.zeros(arr.shape, dtype=np.bool_)
    arr_x = vcalc.cderivative(arr, 'X_DIR')
    arr_y = vcalc.cderivative(arr, 'Y_DIR')
    arr_div = np.sqrt(arr_x**2 + arr_y**2)
    surf = _cp.TopoSurface(arr)
    rprofs = radial_profiles(surf, threshold=25, expand_regions=1, other_arr=arr_div, mask=mask)
    arr[mask] = 2 * arr.max()
    pl.imshow(arr, interpolation='nearest')
    pl.figure()
    pl.imshow(arr_div)
    pl.figure()
    pl.hold(True)
    linreg_xy = ([], [])
    for minmax, (rprof, region) in rprofs.items():
        # minmax_flux = arr_div[minmax]
        pts, fluxes, avg_fluxes, avg_fluxes_errs, avg_dists, avg_dists_errs = \
                zip(*rprof)
        linreg_xy[0].extend(fluxes)
        linreg_xy[1].extend(avg_fluxes)
        # fluxes = np.abs(np.array(fluxes) - minmax_flux)
        # avg_fluxes = np.abs(np.array(avg_fluxes) - minmax_flux)
        # pl.plot(avg_dists, avg_fluxes, 'd-')
        pl.plot(avg_dists, avg_fluxes, 'd-')
    pl.grid()
    slope, intercept, rval, pval, stderr = stats.linregress(*linreg_xy)
    print
    print "slope: %f" % slope
    print "intercept: %f" % intercept
    print "rval: %f" % rval
    print "pval: %f" % pval
    print "stderr: %f" % stderr
    import pdb; pdb.set_trace()
Пример #2
0
def test_ti():

    # number of gridpoints.
    nn = 256
    # wavenumbers in X & Y dimensions, resp.
    n, m = 20, 13 
    x1max = x0max =  256.0
    Y = np.linspace(0, x1max, nn, endpoint=False)
    X = Y[:,np.newaxis]
    arr = np.sin(2. * np.pi * n * X / x0max) + np.sin(2. * np.pi * m * Y / x1max)

    d_x = vcalc.cderivative(arr, 'X_DIR')
    d_y = vcalc.cderivative(arr, 'Y_DIR')
    deriv_norm = 10.0 * 1.0 / np.sqrt((d_x**2 + d_y**2).max())

    d_x *= deriv_norm
    d_y *= deriv_norm

    interp1 = Interp2DPeriodic(x0max, x0max, -d_y)
    interp2 = Interp2DPeriodic(x0max, x0max, d_x)

    ntracers = 10
    scale = 1.0
    ti = TraceIntegrator(ntracers, scale, x0max, x1max, interp1, interp2, 1.e-6, 0.0)

    positions = np.empty(2*ntracers, dtype=np.double)
    positions[::2] = np.linspace(0.0, nn, ntracers)
    positions[1::2] = np.linspace(0.0, nn, ntracers)

    times = np.linspace(0.0, 50.0, 10)

    positions_vs_t = []

    t_init = times[0]
    for time in times[1:]:
        positions_vs_t.append(list(positions.copy()))
        ti.evolve(t=t_init, t1=time, h=1.0e-6, y=positions)
        t_init = time

    if 0:
        pl.ion()
        dta = np.array(positions_vs_t)
        pl.imshow(arr)
        for i in range(0, 2*ntracers, 2):
            x0 = dta[:,i]
            y0 = dta[:,i+1]
            pl.scatter(y0, x0)
        raw_input("enter to quit")
Пример #3
0
    def __init__(self, scalar_arr):
        self.arr = scalar_arr
        len1 = self.len1 = float(self.arr.shape[0])
        len2 = self.len2 = float(self.arr.shape[1])

        self.arr_interp = Interp2DPeriodic(len1, len2, self.arr)

        self.deriv1 = vcalc.cderivative(self.arr, 'X_DIR')
        self.deriv2 = vcalc.cderivative(self.arr, 'Y_DIR')

        self.perp_deriv1 =  self.deriv2
        self.perp_deriv2 = -self.deriv1

        self.perp_deriv1_interp = Interp2DPeriodic(len1, len2, self.perp_deriv1)
        self.perp_deriv2_interp = Interp2DPeriodic(len1, len2, self.perp_deriv2)

        self.deriv12 = vcalc.cderivative(self.deriv1, 'Y_DIR')
        self.deriv11 = vcalc.cderivative(self.arr, 'X_DIR', order=2)
        self.deriv22 = vcalc.cderivative(self.arr, 'Y_DIR', order=2)

        self.deriv12_interp = Interp2DPeriodic(len1, len2, self.deriv12)
        self.deriv11_interp = Interp2DPeriodic(len1, len2, self.deriv11)
        self.deriv22_interp = Interp2DPeriodic(len1, len2, self.deriv22)
Пример #4
0
def test_derivator():
    N = global_N
    n, m = 10, 3
    test_data = tv.sin_cos_arr(N, n, m)
    dd = field_trace.Derivator(test_data)

    psi_1 = vcalc.cderivative(test_data, 'X_DIR')
    psi_2 = vcalc.cderivative(test_data, 'Y_DIR')

    ok_(np.allclose(dd.deriv1, psi_1))
    ok_(np.allclose(dd.deriv2, psi_2))

    ok_(np.allclose(dd.perp_deriv1, psi_2))
    ok_(np.allclose(dd.perp_deriv2, -psi_1))

    psi_11 = vcalc.cderivative(test_data, 'X_DIR', order=2)
    psi_22 = vcalc.cderivative(test_data, 'Y_DIR', order=2)
    psi_12 = vcalc.cderivative(test_data, 'X_DIR')
    psi_12 = vcalc.cderivative(psi_12,    'Y_DIR')

    Xlen = float(N)

    psi_11_interp = Interp2DPeriodic(Xlen, Xlen, psi_11)
    psi_22_interp = Interp2DPeriodic(Xlen, Xlen, psi_22)
    psi_12_interp = Interp2DPeriodic(Xlen, Xlen, psi_12)

    num_pts = 100
    rand_Xs = np.random.uniform(0.0, float(N), num_pts)
    rand_Ys = np.random.uniform(0.0, float(N), num_pts)

    def compare_interps(dd_interp, interp, xys):
        dd_interps = [dd_interp.eval(x, y) for (x, y) in zip(*xys)]
        interps    =    [interp.eval(x, y) for (x, y) in zip(*xys)]
        ok_(np.allclose(dd_interps, interps))

    compare_interps(dd.deriv12_interp, psi_12_interp, [rand_Xs, rand_Ys])
    compare_interps(dd.deriv11_interp, psi_11_interp, [rand_Xs, rand_Ys])
    compare_interps(dd.deriv22_interp, psi_22_interp, [rand_Xs, rand_Ys])