so_source module

class martini.sources.so_source.SOSource(distance=<Quantity 3. Mpc>, vpeculiar=<Quantity 0. km / s>, rotation={'rotmat': array([[1., 0., 0.],        [0., 1., 0.],        [0., 0., 1.]])}, ra=<Quantity 0. deg>, dec=<Quantity 0. deg>, SO_args=None, SO_instance=None, rescale_hsm_g=1)[source]

Bases: SPHSource

Class abstracting HI sources using the simobj package for interface to simulation data.

This class accesses simulation data via the simobj package (https://github.com/kyleaoman/simobj); see the documentation of that package for further configuration instructions.

Parameters:
  • distance (Quantity, optional) – Quantity, with dimensions of length. Source distance, also used to set the velocity offset via Hubble’s law. (Default: 3 * U.Mpc)

  • vpeculiar (Quantity, optional) – Quantity, with dimensions of velocity. Source peculiar velocity, added to the velocity from Hubble’s law. (Default: 0 * U.km * U.s**-1)

  • rotation (dict, optional) –

    Must have a single key, which must be one of axis_angle, rotmat or L_coords. Note that the ‘y-z’ plane will be the one eventually placed in the plane of the “sky”. The corresponding value must be:

    • axis_angle : 2-tuple, first element one of ‘x’, ‘y’, ‘z’ for the axis to rotate about, second element a Quantity with dimensions of angle, indicating the angle to rotate through.

    • rotmat : A (3, 3) ndarray specifying a rotation.

    • L_coords : A 2-tuple containing an inclination and an azimuthal angle (both Quantity instances with dimensions of angle). The routine will first attempt to identify a preferred plane based on the angular momenta of the central 1/3 of particles in the source. This plane will then be rotated to lie in the plane of the “sky” (‘y-z’), rotated by the azimuthal angle about its angular momentum pole (rotation about ‘x’), and inclined (rotation about ‘y’). A 3-tuple may be provided instead, in which case the third value specifies the position angle on the sky (second rotation about ‘x’). The default position angle is 270 degrees.

    (Default: np.eye(3))

  • ra (Quantity, optional) – Quantity, with dimensions of angle. Right ascension for the source centroid. (Default: 0 * U.deg)

  • dec (Quantity, optional) – Quantity, with dimensions of angle. Declination for the source centroid. (Default: 0 * U.deg)

  • SO_args (dict, optional) – Dictionary of keyword arguments to pass to a call to simobj.simobj.SimObj. Arguments are: obj_id, snap_id, mask_type, mask_args, mask_kwargs, configfile, simfiles_configfile, ncpu. See simobj package documentation for details. Provide SO_args or SO_instance, not both.

  • SO_instance (simobj.simobj.SimObj, optional) – An initialized simobj.simobj.SimObj object. Provide SO_instance or SO_args, not both.

apply_mask(mask)

Remove particles from source arrays according to a mask.

Parameters:

mask (ArrayLike) – Boolean mask. Remove particles with indices corresponding to False values from the source arrays.

boost(boost_vector)

Apply an offset to the source velocity.

Note that the “line of sight” is along the ‘x’ axis.

Parameters:

translation_vector (Quantity) – Quantity with shape (3, ), with dimensions of velocity. Vector by which to offset the source particle velocities.

preview(max_points=5000, fig=1, lim=None, vlim=None, point_scaling='auto', title='', save=None)

Produce a figure showing the source particle coordinates and velocities.

Makes a 3-panel figure showing the projection of the source as it will appear in the mock observation. The first panel shows the particles in the y-z plane, coloured by the x-component of velocity (MARTINI projects the source along the x-axis). The second and third panels are position-velocity diagrams showing the x-component of velocity against the y and z coordinates, respectively.

Parameters:
  • max_points (int, optional) – Maximum number of points to draw per panel, the particles will be randomly subsampled if the source has more. (Default: 1000)

  • fig (int, optional) – Number of the figure in matplotlib, it will be created as plt.figure(fig). (Default: 1)

  • lim (Quantity, optional) – Quantity, with dimensions of length. The coordinate axes extend from -lim to lim. If unspecified, the maximum absolute coordinate of particles in the source is used. (Default: None)

  • vlim (Quantity, optional) – Quantity, with dimensions of speed. The velocity axes and colour bar extend from -vlim to vlim. If unspecified, the maximum absolute velocity of particles in the source is used. (Default: None)

  • point_scaling (str, optional) – By default points are scaled in size and transparency according to their HI mass and the smoothing length (loosely proportional to their surface densities, but with different scaling to achieve a visually useful plot). For some sources the automatic scaling may not give useful results, using point_scaling="fixed" will plot points of constant size without opacity. (Default: "auto")

  • title (str, optional) – A title for the figure can be provided. (Default: "")

  • save (str, optional) – If provided, the figure is saved using plt.savefig(save). A .png or .pdf suffix is recommended. (Default: None)

Returns:

out – The preview figure.

Return type:

Figure

rotate(axis_angle=None, rotmat=None, L_coords=None)

Rotate the source.

The arguments correspond to different rotation types. Multiple types cannot be given in a single function call.

Parameters:
  • axis_angle (tuple) – First element one of {"x", "y", "z"} for the axis to rotate about, second element a Quantity with dimensions of angle, indicating the angle to rotate through (right-handed rotation).

  • rotmat (ArrayLike) – Rotation matrix with shape (3, 3).

  • L_coords (tuple) – First element containing an inclination, second element an azimuthal angle (both Quantity instances with dimensions of angle). The routine will first attempt to identify a preferred plane based on the angular momenta of the central 1/3 of particles in the source. This plane will then be rotated to lie in the ‘y-z’ plane, followed by a rotation by the azimuthal angle about its angular momentum pole (rotation about ‘x’), and then inclined (rotation about ‘y’). By default the position angle on the sky is 270 degrees, but if a third element is provided it sets the position angle (second rotation about ‘x’).

save_current_rotation(fname)

Output current rotation matrix to file.

This includes the rotations applied for RA and Dec. The rotation matrix can be applied to astropy coordinates (e.g. a CartesianRepresentation) as coordinates.transform(np.loadtxt(fname)).

Parameters:

fname (str) – File in which to save rotation matrix. A file handle can also be passed.

translate(translation_vector)

Translate the source.

Note that the “line of sight” is along the ‘x’ axis.

Parameters:

translation_vector (Quantity) – Quantity with shape (3, ), with dimensions of length. Vector by which to offset the source particle coordinates.