Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Convert RAMSES file `output` to tipsy format readable by pkdgrav
and Amiga Halo Finder. Does all unit conversions etc. into the
pkdgrav unit system. Creates a file called `output_fullbox.tipsy`.
**Input**:
*output*: name of RAMSES output
**Optional Keywords**:
*write_param*: whether or not to write the parameter file (default = True)
"""
s = pynbody.load(output)
lenunit, massunit, timeunit = get_tipsy_units(s)
# l_unit = Unit('%f kpc'%lenunit)
# t_unit = Unit('%f Gyr'%timeunit)
velunit = lenunit / timeunit
tipsyfile = "%s_fullbox.tipsy" % (output)
s['mass'].convert_units(massunit)
s.g['temp']
# get the appropriate tform
get_tform(s)
s.g['metals'] = s.g['metal']
s['pos'].convert_units(lenunit)
import pynbody
import pynbody.plot.sph as sph
import matplotlib.pylab as plt
# load the snapshot and set to physical units
s = pynbody.load('testdata/g15784.lr.01024.gz')
s.physical_units()
# load the halos
h = s.halos()
# center on the largest halo and align the disk
pynbody.analysis.angmom.sideon(h[1])
# create the subplots
f, axs = plt.subplots(1,2,figsize=(14,6))
#create a simple slice showing the gas temperature, with velocity vectors overlaid
sph.velocity_image(h[1].g, vector_color="cyan", qty="temp",width=50,cmap="YlOrRd",
denoise=True,approximate_fast=False, subplot=axs[0], show_cbar = False)
#you can also make a stream visualization instead of a quiver plot
import pynbody
import pynbody.plot.sph as sph
import matplotlib.pylab as plt
# load the snapshot and set to physical units
s = pynbody.load('testdata/g15784.lr.01024.gz')
s.physical_units()
# load the halos
h = s.halos()
# center on the largest halo and align the disk
pynbody.analysis.angmom.faceon(h[1])
#create an image of gas density integrated down the line of site (z axis)
sph.image(h[1].g,qty="rho",units="g cm^-2",width=100,cmap="Greys")
import pynbody
import pynbody.plot.sph as sph
import matplotlib.pylab as plt
# load the snapshot and set to physical units
s = pynbody.load('testdata/g15784.lr.01024.gz')
s.physical_units()
# load the halos
h = s.halos()
# center on the largest halo and align the disk
pynbody.analysis.angmom.sideon(h[1])
# create the subplots
f, axs = plt.subplots(1,2,figsize=(14,6))
#create a simple slice showing the gas temperature, with velocity vectors overlaid
sph.velocity_image(h[1].g, vector_color="cyan", qty="temp",width=50,cmap="YlOrRd",
denoise=True,approximate_fast=False, subplot=axs[0], show_cbar = False)
#you can also make a stream visualization instead of a quiver plot
import pynbody
import pynbody.plot.sph as sph
import matplotlib.pylab as plt
# load the snapshot and set to physical units
s = pynbody.load('testdata/g15784.lr.01024.gz')
s.physical_units()
# load the halos
h = s.halos()
# center on the largest halo and align the disk
pynbody.analysis.angmom.faceon(h[1])
#create a simple slice of gas density
sph.image(h[1].g,qty="rho",units="g cm^-3",width=100,cmap="Greys")
def load_copy(self, i):
"""Load the a fresh SimSnap with only the particle in halo i"""
from .. import load
return load(self.base.filename, take=self._get_halo_indices(i))
def load_copy(self, i):
"""Load a fresh SimSnap with only the particles in halo i"""
if i>=len(self):
raise KeyError, "No such halo"
from . import load
halo = load(self.base.filename, take=self._get_particles_for_halo(i))
self._add_halo_id(halo, i)
return halo
import pynbody
import pynbody.plot.sph as sph
import matplotlib.pylab as plt
# load the snapshot and set to physical units
s = pynbody.load('testdata/g15784.lr.01024.gz')
s.physical_units()
# load the halos
h = s.halos()
# center on the largest halo and align the disk
pynbody.analysis.angmom.faceon(h[1])
#create a simple slice of gas density
sph.image(h[1].g,qty="rho",units="g cm^-3",width=100,cmap="Greys")
import pynbody
import pynbody.plot.sph as sph
import matplotlib.pylab as plt
# load the snapshot and set to physical units
s = pynbody.load('testdata/g15784.lr.01024.gz')
s.physical_units()
# load the halos
h = s.halos()
# center on the largest halo and align the disk
pynbody.analysis.angmom.sideon(h[1])
#create a simple slice showing the gas temperature
sph.image(h[1].g,qty="temp",width=50,cmap="YlOrRd", denoise=True,approximate_fast=False)
"""Load the a fresh SimSnap with only the particle in halo i"""
from .. import load
if self._dosort is not None:
i = self._sorted_indices[i-1]
f = util.open_(self._ahfBasename + 'particles')
fpos = self._halos[i].properties['fstart']
f.seek(fpos,0)
ids = self._load_ahf_particle_block(f, nparts=self._halos[i].properties['npart'])
f.close()
return load(self.base.filename, take=ids)