예제 #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 mag_shear_rad_profs(psi_arr):
    psi_x, psi_y = gradient(psi_arr)
    bmag = np.sqrt(psi_x**2 + psi_y**2)
    psi_arr = gaussian_filter(psi_arr, sigma=2.0, mode='wrap')
    mshear = mag_shear(psi_arr)
    surf = _cp.TopoSurface(psi_arr)
    regions = surf.get_minmax_regions()
    for (minmax, pss, type), region in regions:
        pass
    rprofs = radial_profiles(surf, threshold=25, other_arr=bmag)
    pl.ion()
    pl.figure()
    for minmax, (rprof, region) in rprofs.items():
        # minmax_flux = arr_div[minmax]
        pts, extremum_val, avg_bmags, avg_bmags_errs, avg_dists, avg_dists_errs = \
                zip(*rprof)
        # fluxes = np.abs(np.array(fluxes) - minmax_flux)
        # avg_fluxes = np.abs(np.array(avg_fluxes) - minmax_flux)
        pl.subplot(211)
        pl.plot(avg_dists, avg_bmags, 'd-')
        pl.subplot(212)
        pl.imshow(bmag)
        # pl.plot(avg_dists, avg_shear, 'd-')
        raw_input('enter to continue')
        pl.clf()
    import pdb; pdb.set_trace()
    pl.close('all')
예제 #3
0
def test_radial_profiles():
    psi_arr = nth_timeslice('data.h5', 'psi', -1)
    bx_arr = nth_timeslice('data.h5', 'bx', -1)
    by_arr = nth_timeslice('data.h5', 'by', -1)
    # for bx_arr, by_arr, psi_arr in h5_gen('data.h5', ('bx', 'by', 'psi')):
    psi_arr = psi_arr.astype(np.double)
    mask = np.zeros(psi_arr.shape, dtype=np.bool_)
    bmag = np.sqrt(bx_arr**2 + by_arr**2).astype(np.double)
    surf = _cp.TopoSurface(psi_arr)
    rprofs = radial_profiles(surf, threshold=50, expand_regions=10,
            other_arr=bmag, mask=mask)
    # psi_arr[mask] = 2 * psi_arr.max()
    # pl.figure()
    # pl.imshow(psi_arr, interpolation='nearest')
    # pl.figure()
    # pl.imshow(bmag)
    bmag_fig = pl.figure()
    fluxes_vs_dists = pl.figure()
    fluxes_vs_flux = pl.figure()
    pl.hold(False)
    for minmax, (rprof, region) in rprofs.items():
        # minmax_flux = arr_div[minmax]
        rprof.sort(key=lambda x: x[1])
        import pdb; pdb.set_trace()
        pts, fluxes, avg_b, avg_b_errs, avg_dists, avg_dists_errs = zip(*rprof)
        region_xs, region_ys = zip(*region)
        mask = np.ones(bmag.shape, dtype=np.bool_)
        mask[region_xs, region_ys] = False
        masked_bmag = bmag.copy()
        masked_bmag[mask] = 0.0
        pl.figure(bmag_fig.number)
        pl.imshow(masked_bmag)
        avg_b = np.array(avg_b)
        avg_b -= avg_b[0]
        avg_dists = np.array(avg_dists)
        fluxes = np.array(fluxes)
        fluxes -= fluxes.min()
        # 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-')
        b_over_flux = (avg_b-(avg_b.min())) / fluxes
        pl.figure(fluxes_vs_dists.number)
        pl.plot(fluxes, avg_b, 'd-')
        # pl.errorbar(avg_dists, b_over_flux, yerr=avg_fluxes_errs,
                # hold=True)
        pl.figure(fluxes_vs_flux.number)
        # delta_r = np.diff(avg_dists)
        delta_flux = np.diff(fluxes)
        # dr_b_over_r = np.diff(b_over_r) / delta_r
        dr_b_over_flux = np.diff(b_over_flux) / delta_flux
        # pl.plot(avg_dists, (avg_fluxes-avg_fluxes.min()) / avg_dists, 'x-')
        pl.plot(fluxes[:-1], dr_b_over_flux, 'x-')
        # pl.errorbar(avg_dists[:-1], dr_b_over_r, 
                # xerr=avg_dists_errs[:-1],
                # yerr=avg_fluxes_errs[:-1],
                # hold=True)
        raw_input("enter to continue")
    pl.figure(fluxes_vs_dists.number)
    pl.grid()
    pl.figure(fluxes_vs_flux.number)
    pl.grid()
    import pdb; pdb.set_trace()
    pl.close('all')