gadget package¶
gadget.Loader¶
-
class
gadget.loader.Loader(filename, snapshot=None, filenum=None, format=None, fields=None, parttype=None, combineFiles=False, toDouble=False, onlyHeader=False, verbose=False, **param)¶ Bases:
object-
addField(name, pres=None, dtype=None, unit=None)¶ Adds a field to the snapshot
Parameters: - name – name of the fields
- pres – array conating the number of elements per particle for each particle type (ex. for a 3 comp. for gas only [3,0,0,0,0,0])
- dtype – data type of the new field (default is used floating point precision)
-
close()¶ This closes the snapshot
-
iterFiles()¶ Provides an iterator over all files of the snapshot
-
nextFile(num=None)¶ Changes to the next file within the same snapshot (only if combineFiles=flase)
Parameters: num – (optional) number of the fiule to load . If not given, the next file is loaded.
-
nextSnapshot(snapshot=None)¶ Changes to the next snapshot
Parameters: snapshot – (optional) number of the snapshot to load. If not given, the next snapshot is loaded
-
to_comoving()¶
-
to_physical()¶
-
to_unit_system(system)¶
-
write(filename=None, format=None)¶ Writes the snapshot or subfind object to a file
Parameters: - filename – (optional) name of the file
- format – (otional) file format to use (Currently only format 3 is supported)
-
gadget.Snapshot¶
-
class
gadget.Snapshot(filename, snapshot=None, filenum=None, format=None, fields=None, parttype=None, combineFiles=False, toDouble=False, onlyHeader=False, verbose=False, filter=None, sortID=False, physicalUnits=False, **param)¶ Bases:
gadget.loader.LoaderThis class loads Gadget snapshots. Currently reading of file format 1, 2 and 3 (hdf5) is supported. Writing is only supported for format 3.
- The snapshot can be selected through:
by providing the path of the snapshot as filename, i.e.
sn = gadget.Snapshot(“snap_001.hdf5”)
by providing the output folder and the snapshot number (and file number if needed), i.e.
sn = gadget.Snapshot(“output”, 1) would load snapshot 1 in folder output
sn = gadget.Snapshot(“output”, 1, 10) would load file number 10 of snapshot 1 of a multifile snapshot (if combineFiles=False; default file number is 0, if none is provided)
The file format is autodetected. If autodetection failes, try specifying the file format through the
formatoption. If the file name or snapshot folder name is not detected (i.e. for subboxes), it can be provided using the optional parameterssnapprefixanddirprefix.Parameters: - filename – The name of the snapshot file
- snapshot – snapshot number to load
- filenum – file of snapshot to load (if combineFiles = false)
- format – (optional) file format of the snapshot, otherwise this is guessed from the file name
- fields – (optional) list of fields to load, if None, all fields available in the snapshot are loaded
- parttype – (optional) array with particle type numbers to load, if None, all particles are loaded
- combineFiles – (optinal) if False only on part of the snapshot is loaded at a time, use nextFile() to go the next file.
- toDouble – (optinal) converts all values of type float to double precision
- onlyHeader – (optinal) load only the snapshot header
- verbose – (optional) enable debug output
- filter – Only load a filtered subset of the snapshot, specified by the filter object.
- sortID – sort all loaded data in each group by particle id
- physical – where possible comoving units are converted to physical units and h factors are added
-
newFilter(filter)¶ Reloads the snapshot using a new filter
Parameters: filter – Only load a filtered subset of the snapshot, specified by the filter object.
gadget.Subfind¶
-
class
gadget.Subfind(filename, snapshot=None, filenum=None, format=None, fields=None, parttype=None, combineFiles=False, toDouble=False, onlyHeader=False, verbose=False, **param)¶ Bases:
gadget.loader.LoaderThis class loads subfind cataloges.
- The subfind catalog can be selected through:
by providing the path of the subfind cataloge as filename, i.e.
sn = gadget.Subfind(“snap_001.hdf5”)
by providing the output folder and the cataloge number (and file number if needed), i.e.
sn = gadget.Subfind(“output”, 1) would load catalog 1 in folder output
sn = gadget.Subfind(“output”, 1, 10) would load file number 10 of catalog 1 of a multifile cataloge (if combineFiles=False; default file number is 0, if none is provided)
The file format is autodetected. If autodetection failes, try specifying the file format through the
formatoption. If the file name or cataloge folder name is not detected (i.e. for subboxes), it can be provided using the optional parameterssnapprefixanddirprefix.Parameters: - filename – The name of the cataloge file
- snapshot – snapshot number to load
- filenum – file of cataloge to load (if combineFiles = false)
- format – (optional) file format of the cataloge, otherwise this is guessed from the file name
- fields – (optional) list of fields to load, if None, all fields available in the cataloge are loaded
- parttype – (optional) array with particle type numbers to load, (groups : 0, subhalos : 1) if None, all particles are loaded
- combineFiles – (optinal) if False only on part of the cataloge is loaded at a time, use nextFile() to go the next file.
- toDouble – (optinal) converts all values of type float to double precision
- onlyHeader – (optinal) load only the cataloge header
- verbose – (optional) enable debug output
gadget.ICs¶
-
class
gadget.ICs(filename, num_part, format=None, masses=None, precision=<Mock name='mock.float32' id='139641611369296'>, longids=False, verbose=False, **param)¶ Bases:
gadget.loader.LoaderProvides an empty snapshot object used for initial condictions generation
Parameters: - filename – The name of the snapshot file
- num_part – num_part must be an array with NTYPES integers, giving the number in each particle species
- format – (optional) file format of the snapshot, otherwise this is guessed from the file name
- masses – (optinal) array with masses of each particle species, (0 if specified in the mass array)
- precision – (optional) precision used for floating point fields (default is np.float32)
- longids – (optional) wheter particle IDs are 32 bit or 64 bit integers (default is 32 bit)
- verbose – (optional) enable debug output
gadget.Simulation¶
-
class
gadget.Simulation(filename, snapshot=None, filenum=None, format=None, fields=None, parttype=None, combineFiles=True, toDouble=False, onlyHeader=False, verbose=False, filter=None, sortID=False, physicalUnits=False, **param)¶ Bases:
gadget.loader.SnapshotLoades a snapshot with additional analysis and plotting routines available
The parameters are the same as for the Snapshot object.
-
centerat(center, group=None)¶ Recenters all particles to
centerIn consecutive calls, center ios always relative to the original center of the snapshot.
Parameters: - center – new center
- group – particle group used, if
Noneall particles are affected
-
coordtransform(zaxis, center=None, xaxis=None, fields=['pos', 'vel'])¶
-
get_AMRgrid(value, gradient=None, res=1024, center=None, box=None, group=None)¶
-
get_AMRline(value, gradient=None, res=1024, center=None, axis=0, box=None, group=None)¶
-
get_AMRslice(value, gradient=None, res=None, center=None, axis=[0, 1], box=None, group=None)¶
-
get_Agrid(value, gradient=None, res=None, center=None, box=None, group=None)¶
-
get_Aslice(value, gradient=None, res=None, center=None, axis=[0, 1], box=None, group=None)¶
-
get_SPHgrid(value, hsml='hsml', weights=None, normalized=True, res=1024, center=None, box=None, group=None)¶
-
get_SPHproj(value, hsml='hsml', weights=None, normalized=True, res=None, center=None, axis=[0, 1], box=None, group=None)¶
-
get_raddens(value='mass', center=None, bins=100, range=None, log=False, periodic=True, group=None)¶ Computes a radial density profile
The values are added to a binned profile and divided by the volume of each bin. The i-th bin for data \(d_j\) is computed as \(b_i = 1/V_i \sum_j d_j\), where the sum goes over all cells/particles in bin i and \(V_i\) is the volume of the i-th bin.
- Examples:
- Density profile: sn.get_raddens(sn.Masses)
Parameters: - value – quantity for which the density profile is computed
- center – center, if None the default center is used
- bins – number of bins used
- range – lower and upper end of the profile
- log – whether to generate a log scaled profile
- periodic – whether the boundaries are periodic or not
- group – particle group used, if
Noneall particles are considered
-
get_radprof(value, weights=None, center=None, bins=100, range=None, log=False, periodic=True, group=None)¶ Computes a radial profile
The binned profile is normalized by the weights, or if non given by the number of particles in the bins. The i-th bin for data \(d_j\) and corresponding weights \(w_j\) is computed as \(b_i = \sum_j w_j * d_j / \sum_j\) \(w_j\), where the sum goes over all cells/particles in bin i.
- Examples:
Density profile (Volume weighted): sn.get_radprof(sn.Density, weights=sn.Volume)
Temperature profile: sn.get_radprof(sn.Temperature, weights=sn.Masses)
Parameters: - value – quantity for which the density profile is computed
- weights – weights of each cell/particle
- center – center, if None the default center is used
- bins – number of bins used
- range – lower and upper end of the profile
- log – whether to generate a log scaled profile
- periodic – whether the boundaries are periodic or not
- group – particle group used, if
Noneall particles are considered
-
plot_AMRline(value, gradient=None, log=False, res=1024, center=None, axis=0, box=None, group=None, newlabels=False, newfig=True, axes=None, **params)¶
-
plot_AMRmesh(res=None, center=None, axis=[0, 1], box=None, group=None, newfig=False, axes=None, **params)¶
-
plot_AMRslice(value, gradient=None, log=False, res=None, center=None, axis=[0, 1], box=None, group=None, vmin=None, vmax=None, dvalue=None, dgradient=None, colorbar=True, cblabel=None, contour=False, newlabels=False, newfig=True, axes=None, **params)¶
-
plot_Agrid(value, gradient=None, log=False, weights=None, res=1024, center=None, axis=[0, 1], box=None, group=None, vmin=None, vmax=None, dvalue=None, dgradient=None, colorbar=True, cblabel=None, contour=False, newlabels=False, newfig=True, axes=None, mode='mean', **params)¶
-
plot_Aslice(value, gradient=None, log=False, res=None, center=None, axis=[0, 1], box=None, group=None, vmin=None, vmax=None, dvalue=None, dgradient=None, colorbar=True, cblabel=None, contour=False, contouralpha=1.0, newlabels=False, newfig=True, axes=None, **params)¶
-
plot_SPHproj(value, hsml='hsml', weights=None, normalized=True, log=False, res=None, center=None, axis=[0, 1], box=None, group=None, vmin=None, vmax=None, dvalue=None, dweights=None, colorbar=True, cblabel=None, contour=False, newlabels=False, newfig=True, axes=None, **params)¶
-
plot_pos(center=None, axis=[0, 1], box=None, periodic=True, group=None, newfig=True, axes=None, **params)¶
-
plot_raddens(value='mass', center=None, bins=100, range=None, log=False, periodic=True, group=None, **params)¶ Plots a radial density profile
The values are added to a binned profile and divided by the volume of each bin. The i-th bin for data \(d_j\) is computed as \(b_i = 1/V_i \sum_j d_j\), where the sum goes over all cells/particles in bin i and \(V_i\) is the volume of the i-th bin. No new figure is created, additional parameters are passed to the matplotlib pollting command.
- Examples:
- Density profile: sn.plot_raddens(sn.Masses)
Parameters: - value – quantity for which the density profile is computed
- center – center, if None the default center is used
- bins – number of bins used
- range – lower and upper end of the profile
- log – whether to generate a log scaled profile
- periodic – whether the boundaries are periodic or not
- group – particle group used, if
Noneall particles are considered
-
plot_radprof(value, weights=None, center=None, bins=100, range=None, log=False, periodic=True, group=None, **params)¶ Plots a radial profile
The binned profile is normalized by the weights, or if non given by the number of particles in the bins. The i-th bin for data d_j and corresponding weights \(w_j\) is computed as \(b_i = \sum_j w_j * d_j / \sum_j w_j\), where the sum goes over all cells/particles in bin i. No new figure is created, additional parameters are passed to the matplotlib pollting command.
- Examples:
Density profile (Volume weighted): sn.plot_radprof(sn.Density, weights=sn.Volume)
Temperature profile: sn.plot_radprof(sn.Temperature, weights=sn.Masses)
Parameters: - value – quantity for which the density profile is computed
- weights – weights of each cell/particle
- center – center, if None the default center is used
- bins – number of bins used
- range – lower and upper end of the profile
- log – whether to generate a log scaled profile
- periodic – whether the boundaries are periodic or not
- group – particle group used, if
Noneall particles are considered
-
r(center=None, periodic=True, group=None)¶ Computes the radial distance of particles.
Parameters: - center – center, if None the dault center is used
- periodic – whether the boundaries are periodic or not
- group – particle group used, if
Noneall particles are considered
-
set_box(box)¶ Sets the default region showen in plotting routines
Parameters: box – array containing the side length of the box.
-
set_center(center)¶ Sets the default center used in plotting routines
Parameters: center – array containing the coordinates of the plotting center.
-
gadget.Filters¶
-
class
gadget.filter.Halo(catalog, halo=None, subhalo=None)¶ Bases:
gadget.filter.Filter-
getIndices(data)¶
-
reset()¶
-
setHalo(halo=None, subhalo=None)¶
-
-
class
gadget.filter.Rectangle(center, boxsize, periodic_wrap_length=None)¶ Bases:
gadget.filter.Filter-
getIndices(data)¶
-
-
class
gadget.filter.Sphere(center, radius)¶ Bases:
gadget.filter.Filter-
getIndices(data)¶
-
-
class
gadget.filter.Stars¶ Bases:
gadget.filter.Filter-
getIndices(data)¶
-