paicos.image_creators package

Submodules

paicos.image_creators.gpu_ray_projector module

paicos.image_creators.gpu_sph_projector module

paicos.image_creators.image_creator module

This defines a base class for image creators (such as Projector and Slicer)

class paicos.image_creators.image_creator.ImageCreator(snap, center, widths, direction, npix=512, parttype=0)

Bases: object

This is a base class for creating images from a snapshot.

__init__(snap, center, widths, direction, npix=512, parttype=0)

Initialize the ImageCreator class. This method will be called by subclasses such as Projector or Slicer.

Parameters:
  • snap (object) – Snapshot object from which the image is created.

  • center – Center of the image (3D coordinates).

  • widths – Width of the image in each direction (3D coordinates)

  • direction (str, Orientation) – Direction of the image (‘x’, ‘y’, ‘z’) or an Orientation instance.

  • npix (int) – Number of pixels in the image (default is 512).

property area

The area of the image plane.

property area_per_pixel

The area per pixel of the image plane.

property center

Center of the image (3D coordinates).

property centered_extent

Same as ‘extent’ but centered on the center of the image.

property depth

The depth of the image.

do_unit_consistency_check()

This function is called inside image creators to ensure that length units are consistent.

double_resolution()

Calling this method doubles the pixel resolution of the image creator.

property extent

The extent of the image in the horizontal-vertical plane. The idea with this property is that it corresponds to the matplotlib imshow keyword argument ‘extent’. When using units, one has to remember to pass image_creator.extent.value rather than image_creator.extent.

half_resolution()

Calling this method halves the pixel resolution of the image creator.

property height

The vertical height of the image.

info()

Prints some information about the image creator instance. TODO: Add things like the number of cells/particles in the current instance.

move_center_along_normal_vector(shift)

Moves the center of the image along its depth direction. Value can be positive or negative and must have same units as the center.

(TODO: In principle we could just convert the distance to same units).

move_center_along_perp_vector1(shift)

Moves the center of the image along its horizontal direction. Value can be positive or negative and must have same units as the center.

(TODO: In principle we could just convert the distance to same units).

move_center_along_perp_vector2(shift)

Moves the center of the image along its vertical direction. Value can be positive or negative and must have same units as the center.

(TODO: In principle we could just convert the distance to same units).

property npix

The number of pixels along the horizontal direction of the image.

property npix_height

The number of pixels of an image in the vertical direction.

property npix_width

The number of pixels along the horizontal direction of the image.

property parttype

The parttype being imaged, e.g. parttype=0 are the Voronoi gas cells.

reset_center()

Resets the center of the image creator to the value it had at initialization.

property volume

The volume of the projection region (0 for slices).

property volume_per_pixel

The volume per pixel in the image.

property width

The horizontal width of the image.

property width_x

The x-component of .widths

property width_y

The y-component of .widths

property width_z

The z-component of .widths

property widths

Width of the image in each direction (3D coordinates).

property x_c

The x-component of .center

property y_c

The y-component of .center

property z_c

The z-component of .center

zoom(factor)

Calling this method zooms the view by the input factor, that is, the horizontal width and vertical height of the image creator is changed like this:

width = width / factor

height = height / factor

A factor less than one zooms out the view.

paicos.image_creators.image_creator_actions module

class paicos.image_creators.image_creator_actions.Actions(snapnum=None, image_creator=None, dry_run=True)

Bases: object

The purpose of this class is to simplify the steps that are usually involved in creating animations and/or interactive widgets.

This is very much work in progress and subject to change. Send Thomas an email if you would like a working example.

change_snapnum(snapnum)
create_log(outfolder='.', basename='image')
depth(arg)
double_resolution()
expand_log(zoom_max=1.02, max_angle=1, verbose=False, outfolder=None, basename=None)
half_resolution()
height(arg)
make_image_creator(snapnum)

TODO: Add example implementation in the docstring of of this method.

move_center(diff)
move_center_sim_coordinates(diff)
mylogger(string, line_ending='\n', mode='a', command=True)
property next_action
property previous_action
read_log(filename=None, outfolder='.', basename='image')
reset_center()
resume_from_image(filename, frame_num)
resume_from_waypoint(frame_num)
rotate_around_normal_vector(arg)
rotate_around_perp_vector1(arg)
rotate_around_perp_vector2(arg)
step(verbose=False)
width(arg)
zoom(factor)
paicos.image_creators.image_creator_actions.find_angle_subdivisions(angle, max_angle)
paicos.image_creators.image_creator_actions.find_zoom_sub_divisions(zoom, zoom_max)

paicos.image_creators.nested_projector module

Defines a class that creates an image of a given variable by projecting it onto a 2D plane using nested grids.

class paicos.image_creators.nested_projector.NestedProjector(snap, center, widths, direction, npix=512, nvol=8, factor=3, npix_min=128, verbose=False, make_snap_with_selection=True, store_subimages=False)

Bases: Projector

This class implements an SPH-like projection of gas variables using nested grids. It is a subclass of the Projector class, and inherits its properties. It has additional attributes for handling the nested grid projections, and additional methods for dealing with resolution, digitizing particles, and summing up the different resolutions of the images.

Please see also the Projector class.

__init__(snap, center, widths, direction, npix=512, nvol=8, factor=3, npix_min=128, verbose=False, make_snap_with_selection=True, store_subimages=False)

This is the constructor for the NestedProjector class. It initializes the properties inherited from the Projector class, as well as the properties specific to nested projections.

Parameters:
  • snap (Snapshot) – A snapshot object of Snapshot class from paicos package.

  • center (array) – Center of the region on which projection is to be done, e.g. center = [x_c, y_c, z_c].

  • widths (array) – Widths of the region on which projection is to be done, e.g.m widths=[width_x, width_y, width_z].

  • direction (str or Orientation) – Direction of the projection, e.g. ‘x’, ‘y’ or ‘z’, or its orientation (see Orientation class).

  • npix (int, optional) – Number of pixels in the horizontal direction of the image, by default 512.

  • nvol (int, optional) – Integer used to determine the smoothing length, by default 8

  • factor (int, optional) – Multiplicative factor in digitizing, defaults to 3.

  • npix_min (int, optional) – Minimum number of pixels, defaults to 128.

  • verbose (bool, optional) – Flag for verbosity, defaults to False.

  • make_snap_with_selection (bool, optional) – a boolean indicating if a new snapshot object should be made with the selected region, defaults to False.

  • store_subimages (bool, optional) – Flag for storing sub-images, which is useful mainly for testing purposes. Defaults to False.

paicos.image_creators.projector module

Defines a class that creates an image of a given variable by projecting it onto a 2D plane.

class paicos.image_creators.projector.Projector(snap, center, widths, direction, npix=512, parttype=0, nvol=8, make_snap_with_selection=True)

Bases: ImageCreator

A class that allows creating an image of a given variable by projecting it onto a 2D plane.

The Projector class is a subclass of the ImageCreator class. The Projector class creates an image of a given variable by projecting it onto a 2D plane.

It takes in several parameters such as a snapshot object, center and widths of the region, direction of projection, and various optional parameters for number of pixels, smoothing length.

__init__(snap, center, widths, direction, npix=512, parttype=0, nvol=8, make_snap_with_selection=True)

Initialize the Projector class.

Parameters:
  • snap (Snapshot) – A snapshot object of Snapshot class from paicos package.

  • center (numpy array) – Center of the region on which projection is to be done, e.g. center = [x_c, y_c, z_c].

  • widths (numpy array) – Widths of the region on which projection is to be done, e.g.m widths=[width_x, width_y, width_z].

  • direction (str, Orientation) – Direction of the projection, e.g. ‘x’, ‘y’ or ‘z’ or an Orientation instance.

  • npix (int, optional) – Number of pixels in the horizontal direction of the image, by default 512.

  • parttype (int, optional) – Number of the particle type to project, by default gas (PartType 0).

  • nvol (int, optional) – Integer used to determine the smoothing length, by default 8

project_variable(variable)

projects a given variable onto a 2D plane.

Parameters:

variable (str, array) – The variable to be projected, it can be passed as string or a 1d array.

Returns:

The image (2d array) of the projected variable.

Return type:

numpy array

paicos.image_creators.ray_projector module

paicos.image_creators.slicer module

paicos.image_creators.tree_projector module

Defines a class that creates an image of a given variable by projecting the Voronoi cells closest to the line of sight using a KDTree.

class paicos.image_creators.tree_projector.TreeProjector(snap, center, widths, direction, npix=512, npix_depth=None, parttype=0, make_snap_with_selection=False, tol=1, verbose=False, timing=False)

Bases: ImageCreator

This implements projection of gas variables by adding up several slices.

__init__(snap, center, widths, direction, npix=512, npix_depth=None, parttype=0, make_snap_with_selection=False, tol=1, verbose=False, timing=False)

Initialize the Slicer object.

Parameters:
  • snap (Snapshot) – A snapshot object of Snapshot class from paicos package.

  • center – Center of the region on which projection is to be done, e.g. center = [x_c, y_c, z_c].

  • widths – Widths of the region on which projection is to be done, e.g. widths=[width_x, width_y, width_z].

  • direction (str, Orientation) – Direction of the projection, e.g. ‘x’, ‘y’ or ‘z’, or an Orientation instance.

  • npix (int, optional) – Number of pixels in the horizontal direction of the image, by default 512.

  • parttype (int, optional) – The particle type to project, by default gas (PartType 0).

  • npix_depth (int, optional) – Number of pixels in the depth direction, by default set automatically based on the smallest cell sizes in the region and the tolerance parameter, tol (see below).

  • tol (float, optional) – Smaller values of tol adds more slices to the integration. Convergence is expected for tol ≤ 1 but you can experiment with higher values.

  • make_snap_with_selection (bool) – a boolean indicating if a new snapshot object should be made with the selected region, defaults to False.

project_variable(variable, additive=True, extrinsic=None, timing=False)

Project gas variable based on the Voronoi cells closest to each line of sight.

The behavior of this method depends on whether the variable to be projected is additive (extrinsic) or not (intrinsic). (see e.g. https://en.wikipedia.org/wiki/Intensive_and_extensive_properties).

For non-additive (intrinsic) properties, e.g. the density ρ, the returned projection, P, is

P = 1/L ∫ ρ dl ,

where L is the depth of the projection. That is, it is simply the mean of a number of slices.

For additive (extrinsic) properties, e.g. mass M, the returned projection is instead

P = 1 / dA ∫ dM

where dA is the area per pixel and dM is the mass inside a voxel.

Parameters:
  • variable (str, array) – The variable to be projected, it can be passed as string or a 1d array.

  • additive (bool) – A boolean indicating whether the variable to be projected is additive (e.g. Masses, Volumes) or not (e.g. Temperature, density). This parameter was previously named ‘extrinsic’.

  • Returns

    projection2d arr

    A 2d array representing the projected gas variable.

    For non-additive (intrinsic) variables, the unit of the projection is identical to the unit of the input variable. For additive (extrinsic) variables, the projection unit is the input variable unit divided by area.

Examples

We can compute the projected density in two ways, using either additive or non-additive projetions. In both case, we first need to create a TreeProjector object:

tree_projector = pa.TreeProjector(snap, center, widths, 'z')

Method I (divide projected mass by projected volume):

tree_M = tree_projector.project_variable('0_Masses', additive=True)
tree_V = tree_projector.project_variable('0_Volume', additive=True)

tree_rho = tree_M / tree_V

Method II (directly project the density):

rho = tree_projector.project_variable('0_Density', additive=False)

Module contents