Ejemplo n.º 1
0
def pdf_d(iout,
          run='',
          data='../data',
          iv='d',
          i4=0,
          nbin=100,
          xlim=[-4, 3],
          lnd=False):
    """ Plot the PDF of the density """
    s = di.snapshot(iout, run=run, data=data)
    n = nbin
    bins = np.linspace(xlim[0], xlim[1], n + 1)
    htot = 0.0
    i = 0
    for p in s.patches:
        i += 1
        if i % 1000 == 0:
            print('{:.1f}%'.format(i / len(s.patches) * 100.0))
        d = p.var(iv, i4=i4)
        if lnd:
            logd = d / np.log(10.)
        else:
            logd = np.log10(d)
        h, e = np.histogram(logd, bins=bins)
        htot += h
    pl.hist(bins[0:n], bins=bins, weights=htot, log=True, density=True)
    return bins, htot
Ejemplo n.º 2
0
def demo(iout=2, run='.', data='data', dir=0, iv=0):
    s = dispatch.snapshot(iout, run, data)
    #
    print('      yt patches:', len(dispatch.yt.patches(s)))
    print('domain_dimesions:', dispatch.yt.domain_dimensions(s))
    #
    parameters = dispatch.yt.parameters(s)
    yt.load_amr_grids(dispatch.yt.patches(s), **parameters)
Ejemplo n.º 3
0
def open_unigrid(iout=1, run='.', data='../data', verbose=0, copy=True):
    s = dispatch.snapshot(iout, run, data)
    #
    parameters = dispatch.yt.parameters(s)
    #data=dispatch.select.unigrid_volume(s)
    data = dispatch.yt.patches(s, copy=copy)
    ds = yt.load_uniform_grid(data, **parameters)
    return ds
Ejemplo n.º 4
0
def demo(iout=1, run='.', data='../data', dir=0, iv=1):
    snapfile = os.path.join(data, run, 'snapshots.dat')
    assert os.path.isfile(snapfile), 'the file ' + snapfile + ' must exist'
    #
    pl.figure(1)
    pl.clf()
    s = dispatch.snapshot(iout, run, data)
    imshow(dispatch.select.unigrid_plane(s, dir=dir, iv=iv))
    pl.title('dispatch.graphics.imshow')
    #
    pl.figure(2)
    pl.clf()
    pt = [0.5, 0.5, 0.5]
    pp = dispatch.snapshot(iout, run, data).patches
    plot_values_along(pt, pp, dir=dir, iv=iv)
    pl.title('dispatch.graphics.plot_values_along')
    #
    pl.figure(3)
    pl.clf()
    pt = [0.5, 0.5, 0.5]
    plot_patch_values_along(pt,
                            pp,
                            dir=dir,
                            iv=iv,
                            all=True,
                            marker='o',
                            verbose=2)
    pl.title('dispatch.graphics.plot_patch_values_along')
    #
    pl.figure(4)
    pl.clf()
    pt = [0.5, 0.5, 0.5]
    dir = 1
    v = 'd'
    plot_patch_values_along(pt, pp, dir=dir, var=v, all=1, marker='o')
    pl.title('dispatch.graphics.plot_patch_values_along')
    sdir = ['x', 'y', 'z']
    pl.xlabel(sdir[dir])
    pl.ylabel(v)
    pl.tight_layout()
Ejemplo n.º 5
0
def snapshot(iout=1, run='.', data='../data', verbose=0, copy=True):
    """
        Open snapshot iout in directory data/run/, returning a YT data set
    """
    s = dispatch.snapshot(iout, run, data)
    if verbose > 1:
        print('time:', s.time)
    #
    if verbose:
        print('      yt patches:', len(s.patches))
        print('domain_dimesions:', dispatch.yt.domain_dimensions(s))
    #
    parameters = dispatch.yt.parameters(s)
    ds = yt.load_amr_grids(dispatch.yt.patches(s, copy=copy), **parameters)
    return ds
Ejemplo n.º 6
0
def demo(iout=1,run='',data='data'):
    snapfile=os.path.join(data,run,'snapshots.dat')
    assert os.path.isfile(snapfile), 'the file '+snapfile+' must exist'
    #
    s=dispatch.snapshot(iout,run,data)
    print('s.time:',s.time)
Ejemplo n.º 7
0
def demo(iout=1, run='', data='../data'):
    """ Demonstrates the use of packet procedures"""
    snapfile = os.path.join(data, run, 'snapshots.dat')
    assert os.path.isfile(snapfile), 'the file ' + snapfile + ' must exist'
    original = np.get_printoptions()
    np.set_printoptions(formatter={'float': '{:6.3f}'.format})

    #
    def _print(s):
        e = '=================================='
        l1 = len(e) - len(s) / 2
        l2 = len(e) * 2 - len(s) - l1
        print(e[0:l1], s, e[0:l2])

    #
    _print('maxloc:')
    a = np.zeros((2, 3, 4))
    for i in range(a.shape[0]):
        for j in range(a.shape[1]):
            for k in range(a.shape[2]):
                a[i, j, k] = (i - 1)**2 + (j - 2)**3 + (k - 2)**4
    i = ds.maxloc(a)
    print('maxloc(a) =', i, ', value =', a[i[0], i[1], i[2]])
    _print('minloc:')
    i = ds.minloc(a)
    print('minloc(a) =', i, ', value =', a[i[0], i[1], i[2]])
    #
    _print('patch_at:')
    pt = [0.51, 0.52, 0.53]
    pp = dispatch.snapshot(iout, run, data).patches
    p1 = ds.patch_at(pt, pp)
    print('patch_at: id =', p1.id, 'position =', p1.position)
    #
    _print('corners:')
    for a in (True, False):
        print('active =', a)
        c = ds.corners(pp[0], active=a)
        print(' one: {} {}'.format(c[0], c[1]))
        c = ds.corners(pp, active=a)
        print('many: {} {}'.format(c[0], c[1]))
    #
    _print('is_inside')
    for p in (pp[0], p1):
        print('is_inside: id =', p.id, 'position =', p.position, 'result',
              ds.is_inside(pt, p))
    #
    _print('count_inside')
    for p in (pp[0], p1):
        print('count_inside: id =', p.id, 'position =', p.position, 'result',
              ds.count_inside(pt, p))
    #
    _print('indices_and_weights')
    (i, w) = ds.indices_and_weights(pt, p1)
    print(i, w)
    #
    _print('patches_along:')
    ds.patches_along(pt, pp, verbose=2)
    _print('patches_along_x:')
    ds.patches_along_x(pt, pp, verbose=2)
    _print('patches_along_y:')
    ds.patches_along_x(pt, pp, verbose=2)
    _print('patches_along_z:')
    ds.patches_along_x(pt, pp, verbose=2)
    #
    _print('values_along')
    iv = 2
    print('variable index =', iv)
    x, v = ds.values_along(pt, pp, dir=0, iv=iv)
    print('xmin,xmax =', x.min(), x.max())
    print('vmin,vmax =', v.min(), v.max())
    #
    _print('shell_values:')
    shv = ds.shell_values(pp, verbose=1)
    shv.radial_components()
    shv.angles()
    print('variable      min          max       (in shell)')
    for key in shv.var.keys():
        v = np.array(shv.var[key])
        print('{:>8} {:12.3e} {:12.3e} {}'.format(key, v.min(), v.max(),
                                                  v.shape))
    print('average mass flux:', shv.mass_flux())
    #
    np.set_printoptions(**original)