Exemple #1
0
 def zoom(self, center=None, size=None):
     if center is None:
         center = self.cut.center
     if size is None:
         size = self.cut.size
     self.cut.take(Cut(center=center, size=size))
     self.invalidate()
Exemple #2
0
 def unfold(self, M):
     self.gas.unfold(M, self.boxsize)
     self.star.unfold(M, self.boxsize)
     self.boxsize = self.bh.unfold(M, self.boxsize)
     self.cut.take(
         Cut(xcut=[0, self.boxsize[0]],
             ycut=[0, self.boxsize[1]],
             zcut=[0, self.boxsize[2]]))
Exemple #3
0
 def __init__(self, shape=(600, 600)):
     self.format = None
     self.shape = shape
     self.cache1 = {}
     self.cache2 = {}
     self.F = {}
     self.cut = Cut()
     self.periodic = False
Exemple #4
0
def crop_snapshot(center, size, map, format, snapname, output):
    cut = Cut(center=center, size=size)
    mesh = Meshmap(map)

    gas = Field(
        components={
            'mass': 'f4',
            'rho': 'f4',
            'ie': 'f4',
            'xHI': 'f4',
            'ye': 'f4',
            'id': 'u8',
            'sfr': 'f4',
            'met': 'f4',
            'sml': 'f4'
        })
    bh = Field(components={
        'mass': 'f4',
        'bhmdot': 'f4',
        'bhmass': 'f4',
        'id': 'u8'
    })
    star = Field(components={
        'mass': 'f4',
        'sft': 'f4',
        'met': 'f4',
        'id': 'u8'
    })

    fids = mesh.cut2fid(cut)
    print fids
    snapshots = [Snapshot(snapname % fid, format) for fid in fids]

    gas.take_snapshots(snapshots, 0, cut=cut)
    star.take_snapshots(snapshots, 4, cut=cut)
    bh.take_snapshots(snapshots, 5, cut=cut)
    left = center - size * 0.5
    gas['locations'][:, :] -= left[newaxis, :]
    star['locations'][:, :] -= left[newaxis, :]
    bh['locations'][:, :] -= left[newaxis, :]
    print bh['id']
    out = Snapshot(output, format, create=True)
    for f in snapshots[0].header.dtype.names:
        out.header[f] = snapshots[0].header[f]

    out.header['unused'][0:3] = center
    out.header['boxsize'] = size[0]
    gas.dump_snapshots([out], 0)
    star.dump_snapshots([out], 4)
    bh.dump_snapshots([out], 5)
Exemple #5
0
    def use(self,
            snapname,
            format,
            components={},
            bhcomponents={
                'bhmass': 'f4',
                'bhmdot': 'f4',
                'id': 'u8'
            },
            starcomponents={
                'sft': 'f4',
                'mass': 'f4'
            },
            gas=0,
            halo=1,
            disk=2,
            bulge=3,
            star=4,
            bh=5,
            cut=None,
            gascomponents=None,
            periodic=True):
        if gascomponents is not None:
            self.components = gascomponents
        else:
            self.components = components
            self.components['mass'] = 'f4'
            self.components['sml'] = 'f4'

        self.snapname = snapname
        self.format = format
        self.F['gas'] = Field(components=self.components)
        self.F['bh'] = Field(components=bhcomponents)
        self.F['star'] = Field(components=starcomponents)
        self.F['halo'] = Field(components=self.components)
        self.F['disk'] = Field(components=self.components)
        self.F['bulge'] = Field(components=self.components)

        self.ptype = {
            "gas": gas,
            "halo": halo,
            "disk": disk,
            "bulge": bulge,
            "star": star,
            "bh": bh,
        }
        try:
            snapname = self.snapname % 0
        except TypeError:
            snapname = self.snapname
        snap = Snapshot(snapname, self.format)
        self.gas.init_from_snapshot(snap)
        self.bh.init_from_snapshot(snap)
        self.star.init_from_snapshot(snap)
        self.halo.init_from_snapshot(snap)
        self.disk.init_from_snapshot(snap)
        self.bulge.init_from_snapshot(snap)

        self.C = snap.C
        if cut is not None:
            self.cut.take(cut)
        else:
            try:
                boxsize = snap.C['boxsize']
                self.cut.take(
                    Cut(xcut=[0, boxsize],
                        ycut=[0, boxsize],
                        zcut=[0, boxsize]))
            except:
                pass

        self.boxsize = ones(3) * snap.C['boxsize']
        self.redshift = snap.C['redshift']
        self.invalidate()
        self.periodic = periodic
Exemple #6
0
 def slice(self, z, thickness):
     cut = Cut(center=self.cut.center, size=self.cut.size)
     cut['z'] = [z - thickness / 2.0, z + thickness / 2.0]
     self.cut.take(cut)
     self.invalidate()