コード例 #1
0
    def orient_box(self, **kwargs):
        """
        Center and rotate box coordinates AND velocities according to 
        received kwargs 'center' and 'view'. If 'center' unspecified,
        looks for 'centering' kwargs and attempts to auto-center the box.
        """
        center = kwargs.get('center', None)
        vcenter = kwargs.get('vcenter', None)
        centering = kwargs.get('centering', None)
        view = kwargs.get('view', None)
        dlim = kwargs.pop('dens_lim', 1e9)
        xyz = ['x', 'y', 'z']
        uvw = ['u', 'v', 'w']
        try:
            pos_vel = self[xyz + uvw]
        except KeyError:
            self.load_coords()
            self.load_velocities()
            pos_vel = self[xyz + uvw]

        if center:
            if vcenter is None:
                print "Warning: Not Re-centering particle Velocities!"
            pos_vel = analyze.center_box(pos_vel, center, vcenter)
        else:
            if centering in ['avg','max']:
                try:
                    dens = self.get_number_density()
                except AttributeError:
                    raise KeyError("Cannot density-center dark matter!")
                pos_vel = analyze.center_box(pos_vel, density=dens, **kwargs)
            elif centering == 'box':
                pos_vel = analyze.center_box(pos_vel, **kwargs)
        self[pos_vel.keys()] = pos_vel

        if view:
            print 'Rotating Box...'
            if view == 'face':
                try:
                    dens = self.get_number_density()
                except AttributeError:
                    raise KeyError("Cannot density-center dark matter!")
                xyz, uvw = visualize.set_view(view, self[xyz], velocity=self[uvw],
                                               density=dens, dens_lim=dlim)
            else:
                xyz, uvw = visualize.set_view(view, self[xyz], velocity=self[uvw])
            print 'Rotation complete.'
            self[['x', 'y', 'z']] = xyz
            self[['u', 'v', 'w']] = uvw
コード例 #2
0
def project(snapshot, scale, view, **kwargs):
    pps = kwargs.pop('pps', 500)
    sm = kwargs.pop('sm', 1.7)
    shiftx = kwargs.pop('shiftx', None)
    shifty = kwargs.pop('shifty', None)
    shiftz = kwargs.pop('shiftz', None)
    dens_lim = kwargs.pop('dens_lim', None)
    boxsize = float("".join(ch if ch.isdigit() else "" for ch in scale))
    unit = "".join(ch if not ch.isdigit() else "" for ch in scale)
    dens = snapshot.gas.get_number_density()
    xyz = snapshot.gas.get_coords(unit)
    uvw = snapshot.gas.get_velocities()
    hsml = snapshot.gas.get_smoothing_length(unit)

    print 'Calculating...'
    xyz = analyze.center_box(xyz, velocity=uvw, density=dens, **kwargs)
    xyz = set_view(view, xyz)
    x = xyz.x
    y = xyz.y
    z = xyz.z
    if shiftx:
        x += shiftx
    if shifty:
        y += shifty
    if shiftz:
        z += shiftz
    snapshot.update_sink_coordinates(x, y, z)
    # Artificially shrink sink smoothing lengths.
    for s in snapshot.sinks:
        hsml[s.index] *= .5
    data = snap.gas['x', 'y', 'z', 'ndensity',
                    'smoothing_length'].copy(deep=True)
    data = trim_view(boxsize, data, **kwargs)
    if dens_lim:
        arrs = [scalar, x, y, z, hsml]
        scalar, x, y, z, hsml = analyze.data_slice(scalar > dens_lim, *arrs)
    hsml = numpy.fmax(sm * hsml, boxsize / pps / 2)
    xi, yi = build_grid(boxsize, pps)
    zi = scalar_map(x, y, scalar, hsml, boxsize, pps, xi.shape)
    print '%s:: min: %.3e max: %.3e' % (loadable, zi.min(), zi.max())
    imscale = kwargs.pop('imscale', 'log')
    if imscale == 'log':
        zi = numpy.log10(zi)
        print 'log(%s):: min: %.3e max: %.3e' % (loadable, zi.min(), zi.max())
    else:
        print 'Returning raw (non-log) values!'
    return xi, yi, zi
コード例 #3
0
ファイル: visualize.py プロジェクト: astrosmith/pyGadget
def project(snapshot, scale, view, **kwargs):
    pps = kwargs.pop('pps',500)
    sm = kwargs.pop('sm',1.7)
    shiftx = kwargs.pop('shiftx',None)
    shifty = kwargs.pop('shifty',None)
    shiftz = kwargs.pop('shiftz',None)
    dens_lim = kwargs.pop('dens_lim', None)
    boxsize = float("".join(ch if ch.isdigit() else "" for ch in scale))
    unit = "".join(ch if not ch.isdigit() else "" for ch in scale)
    dens = snapshot.gas.get_number_density()
    xyz = snapshot.gas.get_coords(unit)
    uvw = snapshot.gas.get_velocities()
    hsml = snapshot.gas.get_smoothing_length(unit)

    print 'Calculating...'
    xyz = analyze.center_box(xyz, velocity=uvw, density=dens, **kwargs)
    xyz = set_view(view, xyz)
    x = xyz.x
    y = xyz.y
    z = xyz.z
    if shiftx:
        x += shiftx
    if shifty:
        y += shifty
    if shiftz:
        z += shiftz
    snapshot.update_sink_coordinates(x,y,z)
    # Artificially shrink sink smoothing lengths.
    for s in snapshot.sinks:
        hsml[s.index] *= .5
    data = snap.gas['x', 'y', 'z', 'ndensity', 'smoothing_length'].copy(deep=True)
    data = trim_view(boxsize, data, **kwargs)
    if dens_lim:
        arrs = [scalar,x,y,z,hsml]
        scalar,x,y,z,hsml = analyze.data_slice(scalar > dens_lim, *arrs)
    hsml = numpy.fmax(sm * hsml, boxsize/pps/2)
    xi,yi = build_grid(boxsize,pps)
    zi = scalar_map(x,y,scalar,hsml,boxsize,pps,xi.shape)
    print '%s:: min: %.3e max: %.3e' %(loadable, zi.min(),zi.max())
    imscale = kwargs.pop('imscale','log')
    if imscale == 'log':
        zi = numpy.log10(zi)
        print 'log(%s):: min: %.3e max: %.3e' %(loadable, zi.min(),zi.max())
    else:
        print 'Returning raw (non-log) values!'
    return xi,yi,zi