Miscellaneous functions

This module includes functions to be used by other modules or that can be useful in the preparation of data before creating visualisations

Created on Fri Mar 22 13:57:23 2024

@author: ixakalabadie

visl3d.misc.calc_axis_angle(point)[source]
visl3d.misc.calc_camera_position(vector)[source]
visl3d.misc.calc_isolevels(cube, unit=None)[source]

Function to calculate isolevels if not given by the user.

Parameters:

cube (3D array) – Datacube.

visl3d.misc.calc_step(cube, isolevels)[source]

To automatically calculate best step size (marching cubes algorithm) to obtain light models.

visl3d.misc.create_colormap(colormap, isolevels, start=0, end=255, lightdark=False)[source]

Function to create a colormap for the iso-surfaces.

Parameters:
  • colormap (string) – Name of a matplotlib colormap.

  • isolevels (list) – List of values of the iso-surfaces.

  • start (int, optional) – Starting element of the colormap array. Default is 0.

  • end (int, optional) – Ending element of the colormap array. Default is 255.

  • lightdark (bool, optional) – Wheter to reverse the colormap if the darkest side is at the beggining

Returns:

cmap – List of strings with the colors of the colormap in the format ‘r g b’.

Return type:

list

visl3d.misc.cube_info(cube)[source]
visl3d.misc.find_nearest(array, value)[source]

Find the nearest value in an array to a given value

Parameters:
  • array (array-like) – 1D array

  • value (float) – Value to compare with.

Returns:

The nearest value in the array and its index.

Return type:

tuple

visl3d.misc.get_axlabnames(mags)[source]
Parameters:
  • mags (array) – Array with the names of the magnitudes. Must be of length 3.

  • units (array) – Array with the names of the units. Must be length 4, the units of the corresponding magnitudes being the last 3 elements.

visl3d.misc.get_galaxies(galaxies, cubecoords, cubeunits, delta, trans)[source]

Obtain a dictionary with galaxy names, coordinates and colors to introduce in a Cube object to use in writers.make_galaxies().

Parameters:
  • galaxies (list or string) – List with the names of galaxies to include in the model. If ‘query’ a NED query is made within the limits of the cube. If None no galaxies are included.

  • cubecoords (array-like) – 3x2 array with the coordinates of the cube in the format [[ramin, ramax], [decmin, decmax], [zmin, zmax]] and in the same units as cubeunits.

  • cubeunits (array-like) – len 4 array with the units of the cube as strings.

  • obj (string) – Name of the object to query in NED.

  • delta (array-like) – len 3 array with the delta values of the cube.

  • trans (array-like) – len 3 array with the scale of each coordinate axis. It is calculated like [2000/nx, 2000/ny, 2000/nz].

Returns:

galdict – Dictionary with the names of the galaxies as keys and two dictionaries with the coordinates and color of the galaxy as values.

Return type:

dict

visl3d.misc.get_imcol(image=None, position=None, survey=None, cmap='Greys', **kwargs)[source]

Downloads an image from astroquery and returns the colors of the pixels using a certain colormap, in hexadecimal format, as required by ‘write_x3d().make_image2d’. See astroquery.skyview.SkyView.get_images() for more information.

Having a large field of view (verts) might disalign the image with the cube. This issue will be fixed in the future.

Parameters:
  • image (2D or 3D array, optional) – Image data in RGB format between 0 and 1 (3D). The RGB column must be last. If 2D, the image will be converted automatically. The image will cover the full FoV of the created cube model (after applying limits). Example for 3D array: - image = np.array([img1, img2, img3]) - image = np.transpose(img, axes=(1,2,0)) # shape=(3,ny,nx)->(ny,nx,3)

  • position (string or SkyCoord, optional) – Name of an object or it position coordinates.

  • survey (string, optional) – Survey from which to make the query. See astroquery.skyview.SkyView.list_surveys().

  • **kwargs – Other parameters for astroquery.skyview.SkyView.get_images(). Useful parameters are ‘unit’, ‘pixels’ and ‘coordinates’.

Returns:

  • imcol (array) – Array with the colors of each pixel in hexadecimal format.

  • shape (tuple) – Shape of the image.

  • img (array) – Image data.

visl3d.misc.get_rms(cube)[source]

Calculate the RMS of a data cube from negative noise. This method assumes that there is no absoption.

Parameters:

cube (3D array) – Data cube.

visl3d.misc.get_rms2(cube)[source]

Calculate the RMS of a data cube from negative noise. This method assumes that there is no absoption.

Parameters:

cube (3D array) – Data cube.

visl3d.misc.insert_3darray(big, small)[source]

Insert values of smaller 3D array into the middle of the zero array.

visl3d.misc.marching_cubes(cube, level, shift=(0, 0, 0), step_size=1)[source]

Implementation of marching cubes algorithm to a datacube.

Parameters:
  • cube (3D array) – Datacube.

  • level (float) – Value of the isosurface.

  • shift (tuple, optional) – Shift in RA, DEC and V in pixels. The default is (0,0,0).

  • step_size (int, optional) – Step size for the marching_cubes algorithm. Sets the resolution. High step sizes produce low resolution models. Default is 1.

Returns:

  • Tuple with (1) Array with the coordinates of the vertices of the created triangular faces

  • and (2) the indices for those faces and (3) normal vectors for each face.

visl3d.misc.objquery(result, coords, otype)[source]

Constrain query table to certain coordinates and object type

visl3d.misc.preview2d(cube, v1=None, v2=None, norm='asinh', figsize=(10, 8))[source]

TO DO

Parameters:
  • cube (3d array) – The data cube. Must be unitless.

  • v1 (array, optional) – Minimum and maximum values for the colormap. If None the minimum and maximum of image 1 are taken. Default is None.

  • v2 (float, optional) – Minimum and maximum values for the colormap. If None the minimum and maximum of image 2 are taken. Default is None.

  • norm (string) – A scale name, one of ‘asinh’, ‘function’, ‘functionlog’, ‘linear’, ‘log’, ‘logit’ or ‘symlog’. Default is ‘asinh’. For more information see ~matplotlib.colors.Normalize.

  • figsize (tuple, optional) – Figure size. Default is (10,8).

Return type:

None.

visl3d.misc.tabs(n)[source]

Create a string with n tabs.

visl3d.misc.transpose(array, delta)[source]

Transpose data array taking the direction of delta into account.