Writer functions

These functions are used to write the elements of the visualisations; both the HTML and the X3D parts.

Created on Fri Mar 22 16:45:23 2024

@author: ixakalabadie

class visl3d.writers.WriteHTML(filename, cube, description=None, pagetitle=None)[source]

Bases: object

Create an HTML file with an embbeded X3D figure and functions to interact with it.

Parameters:
  • filename (str) – Name of the HTML file including the extension (.html).

  • cube (Cube) – Object of the Cube class.

  • description (str, optional) – A description for the web page.

  • pagetitle (str, optional) – The title of the web page.

Methods

buttons([viewpoint, tube, sphere, box, ...])

Makes the buttons to apply different functions in the web page.

close_html()

Must be used to finish and close the HTML file.

close_x3d(filename)

Insert the X3D file and close the X3D part of the HTML.

func_animation()

Make JS function to start/stop the animation of the X3D models.

func_axes()

Make JS function to hide/show axes labels.

func_background()

Make JS function to change the background color of the X3D figure.

func_colormaps()

Make JS function to change the colormap of the layers.

func_galaxies()

Make JS function to hide/show galaxies and their labels.

func_galsize()

Make JS function to change the size of the galaxy markers and their labels.

func_grids()

Make JS function to hide/show grids.

func_image2d()

Make JS function to show/hide the 2D image.

func_layers()

Make JS funcion to hide/show layers.

func_markers()

Create buttons to create markers for the X3D model interactively in the web page.

func_move2dimage()

Make JS function to move the 2D image along the spectral axis.

func_pick()

Allows picking the coordinates by clicking in the figure.

func_pymarkers([tube, sphere, box, cone])

JS function to hide/show markers created with make_markers() directly to the X3D model.

func_scalev([sphere, box, cone, tube, trans])

Make JS funtion to change the scale of the spectral axis.

func_setCenterOfRotation(centers)

Make JS function to change the center of rotation from given options.

start_x3d()

Start the X3D part of the HTML.

viewpoints([point])

Define viewpoints for the X3D figure.

buttons(viewpoint=None, tube=None, sphere=None, box=None, cone=None, centrot=False)[source]

Makes the buttons to apply different functions in the web page.

Parameters:
  • viewpoint (list) – List of names for the viewpoints. Viewpoints must be created in “viewpoints()”.

  • tube (list) – List with the points parameter included in make_markers() for tubes.

  • sphere (list) – List with the points parameter included in make_markers() for spheres.

  • box (list) – List with the points parameter included in make_markers() for boxes.

  • cone (list) – List with the points parameter included in make_markers() for cones.

  • centrot (bool) – Create button to change the center of rotation.

close_html()[source]

Must be used to finish and close the HTML file. Not using this function results in an error.

close_x3d(filename)[source]

Insert the X3D file and close the X3D part of the HTML. Must go after viewpoints() and start_x3d().

Parameters:

filename (string) – Name of the X3D file to be inserted.

func_animation()[source]

Make JS function to start/stop the animation of the X3D models.

func_axes()[source]

Make JS function to hide/show axes labels.

func_background()[source]

Make JS function to change the background color of the X3D figure. Must be after buttons()

func_colormaps()[source]

Make JS function to change the colormap of the layers. Must be after buttons()

func_galaxies()[source]

Make JS function to hide/show galaxies and their labels. The X3D file must have galaxies for this to work. Must be after buttons()

func_galsize()[source]

Make JS function to change the size of the galaxy markers and their labels. The X3D file must have galaxies for this to work. Must be after buttons()

func_grids()[source]

Make JS function to hide/show grids.

func_image2d()[source]

Make JS function to show/hide the 2D image. The X3D file must have a 2D image for this to work. Must be after buttons().

func_layers()[source]

Make JS funcion to hide/show layers.

func_markers()[source]

Create buttons to create markers for the X3D model interactively in the web page. Must be after buttons(). It is assumed that scalev is used. It will fail otherwise. The JS functions are included by default in ‘markers.js’.

func_move2dimage()[source]

Make JS function to move the 2D image along the spectral axis. The X3D file must have a 2D image for this to work. Must be after buttons()

func_pick()[source]

Allows picking the coordinates by clicking in the figure. WORKS WITH VIEWPOINT NOT WITH ORTHOVIEWPOINT. NOT FINISHED, DON’T USE.

func_pymarkers(tube=None, sphere=None, box=None, cone=None)[source]

JS function to hide/show markers created with make_markers() directly to the X3D model.

Parameters:
  • tube (list) – List with the points parameter included in make_markers() for tubes.

  • sphere (list) – List with the points parameter included in make_markers() for spheres.

  • box (list) – List with the points parameter included in make_markers() for boxes.

  • cone (list) – List with the points parameter included in make_markers() for cones.

func_scalev(sphere=None, box=None, cone=None, tube=None, trans=None)[source]

Make JS funtion to change the scale of the spectral axis. Must be after buttons().

Parameters:
  • tube (list) – List with the points parameter included in make_markers() for tubes.

  • sphere (list) – List with the points parameter included in make_markers() for spheres.

  • box (list) – List with the points parameter included in make_markers() for boxes.

  • cone (list) – List with the points parameter included in make_markers() for cones.

  • delta (list) – List with the delta of the cube (header[CDELT]).

  • trans (list) – Transformation factor to the cube. It is calculated with (2000/nx, 2000/ny, 2000/nz).

func_setCenterOfRotation(centers)[source]

Make JS function to change the center of rotation from given options. Must be after buttons()

Parameters:

centers (list) – List of strings with the coordinates (as different from the centre) of the centers of rotation to be added. E.g. [“0 10 0”, “10 0 10”]

start_x3d()[source]

Start the X3D part of the HTML. Must go before viewpoints() and close_x3d().

viewpoints(point=None)[source]

Define viewpoints for the X3D figure. Must go after start_x3d() and before close_x3d().

Parameters:

point (list, optional) – List of points to define viewpoints. The point will be used to create a vector from the origin. For example, [1,0,0] will create a viewpoint looking at the positive x-axis. The y axis is inverted.

class visl3d.writers.WriteVis(filename, cube, description=None, pagetitle=None)[source]

Bases: object

Create an HTML file to visualise a 3D model of spectral line data (without an X3D file).

Parameters:
  • filename (str) – Name of the HTML file to be created (without extension).

  • cube (Cube) – Cube object with the data to be visualised.

  • pagetitle (str, optional) – The title of the web page.

  • description (str) – A description for the web page.

Methods

buttons([viewpoint, tube, sphere, box, ...])

Makes the buttons to apply different functions in the web page.

close()

Closes the X3D file.

close_html()

Must be used to finish and close the HTML file.

close_x3d()

Close the X3D section of the HTML.

func_animation()

Make JS function to start/stop the animation of the X3D models.

func_axes()

Make JS function to hide/show axes labels.

func_background()

Make JS function to change the background color of the X3D figure.

func_colormaps()

Make JS function to change the colormap of the layers.

func_galaxies()

Make JS function to hide/show galaxies and their labels.

func_galsize()

Make JS function to change the size of the galaxy markers and their labels.

func_grids()

Make JS function to hide/show grids.

func_image2d()

Make JS function to show/hide the 2D image.

func_layers()

Make JS funcion to hide/show layers.

func_markers()

Create buttons to create markers for the X3D model interactively in the web page.

func_move2dimage()

Make JS function to move the 2D image along the spectral axis.

func_pick()

Allows picking the coordinates by clicking in the figure.

func_pymarkers([tube, sphere, box, cone])

JS function to hide/show markers created with make_markers() directly to the X3D model.

func_scalev([sphere, box, cone, tube, trans])

Make JS funtion to change the scale of the spectral axis.

func_setCenterOfRotation(centers)

Make JS function to change the center of rotation from given options.

make_animation([cycleinterval, axis])

Create an animation to rotate the X3D model along one axis.

make_galaxies()

Creates spheres and labels in the model at the location of galaxies given as input.

make_image2d()

Create a 2D image object in the X3D model.

make_labels()

Create the labels of different elements in the figure.

make_layers([shifts, add_normals])

Calculate iso-surfaces from the data and write the objects in the X3D file.

make_markers(geom, points, shape, trans, color)

Create markers in the X3D model.

make_outline()

Creates an object for an outline in the X3D file.

make_ticklines()

Create tickline objects in the X3D model.

start_x3d([point])

Start the X3D section of the HTML.

buttons(viewpoint=None, tube=None, sphere=None, box=None, cone=None, centrot=False)[source]

Makes the buttons to apply different functions in the web page.

Parameters:
  • viewpoint (list) – List of names for the viewpoints. Viewpoints must be created in “viewpoints()”.

  • tube (list) – List with the points parameter included in make_markers() for tubes.

  • sphere (list) – List with the points parameter included in make_markers() for spheres.

  • box (list) – List with the points parameter included in make_markers() for boxes.

  • cone (list) – List with the points parameter included in make_markers() for cones.

  • centrot (bool) – Create button to change the center of rotation.

close()[source]

Closes the X3D file. Not using this function at the end results in an error.

close_html()[source]

Must be used to finish and close the HTML file. Not using this function results in an error.

close_x3d()[source]

Close the X3D section of the HTML. Must go after start_x3d().

func_animation()[source]

Make JS function to start/stop the animation of the X3D models.

func_axes()[source]

Make JS function to hide/show axes labels.

func_background()[source]

Make JS function to change the background color of the X3D figure. Must be after buttons()

func_colormaps()[source]

Make JS function to change the colormap of the layers. Must be after buttons()

func_galaxies()[source]

Make JS function to hide/show galaxies and their labels. The X3D file must have galaxies for this to work. Must be after buttons()

func_galsize()[source]

Make JS function to change the size of the galaxy markers and their labels. The X3D file must have galaxies for this to work. Must be after buttons()

func_grids()[source]

Make JS function to hide/show grids.

func_image2d()[source]

Make JS function to show/hide the 2D image. The X3D file must have a 2D image for this to work. Must be after buttons().

func_layers()[source]

Make JS funcion to hide/show layers.

func_markers()[source]

Create buttons to create markers for the X3D model interactively in the web page. Must be after buttons(). It is assumed that scalev is used. It will fail otherwise. The JS functions are included by default in ‘markers.js’.

func_move2dimage()[source]

Make JS function to move the 2D image along the spectral axis. The X3D file must have a 2D image for this to work. Must be after buttons()

func_pick()[source]

Allows picking the coordinates by clicking in the figure. WORKS WITH VIEWPOINT NOT WITH ORTHOVIEWPOINT. NOT FINISHED, DON’T USE.

func_pymarkers(tube=None, sphere=None, box=None, cone=None)[source]

JS function to hide/show markers created with make_markers() directly to the X3D model.

Parameters:
  • tube (list) – List with the points parameter included in make_markers() for tubes.

  • sphere (list) – List with the points parameter included in make_markers() for spheres.

  • box (list) – List with the points parameter included in make_markers() for boxes.

  • cone (list) – List with the points parameter included in make_markers() for cones.

func_scalev(sphere=None, box=None, cone=None, tube=None, trans=None)[source]

Make JS funtion to change the scale of the spectral axis. Must be after buttons().

Parameters:
  • tube (list) – List with the points parameter included in make_markers() for tubes.

  • sphere (list) – List with the points parameter included in make_markers() for spheres.

  • box (list) – List with the points parameter included in make_markers() for boxes.

  • cone (list) – List with the points parameter included in make_markers() for cones.

  • delta (list) – List with the delta of the cube (header[CDELT]).

  • trans (list) – Transformation factor to the cube. It is calculated with (2000/nx, 2000/ny, 2000/nz).

func_setCenterOfRotation(centers)[source]

Make JS function to change the center of rotation from given options. Must be after buttons()

Parameters:

centers (list) – List of strings with the coordinates (as different from the centre) of the centers of rotation to be added. E.g. [“0 10 0”, “10 0 10”]

make_animation(cycleinterval=10, axis=0)[source]

Create an animation to rotate the X3D model along one axis. Must be outside the Transform “ROOT” element. Should be called after make_ticklines().

make_galaxies()[source]

Creates spheres and labels in the model at the location of galaxies given as input.

make_image2d()[source]

Create a 2D image object in the X3D model.

Parameters:
  • imcol (array, optional) – Array with hexadecimal colors of each pixel for a 2D image. If None, a white image is created. Default is None

  • img_shape (tuple, optional) – Shape of the 2D image. Use None for white image. Default is None.

make_labels()[source]

Create the labels of different elements in the figure.

make_layers(shifts=None, add_normals=False)[source]

Calculate iso-surfaces from the data and write the objects in the X3D file.

Parameters:
  • shift (list, optional) – A list with a arrays of 3D vectors giving the shift in RA, DEC and spectral axis in the same units given to the cube. Similar to l_cube or l_isolevels.

  • add_normals (bool, optional) – Whether to add normal vectors in the X3D model. Default is False.

make_markers(geom, points, shape, trans, color, labels=None)[source]

Create markers in the X3D model. Must be called before make_ticklines().

Parameters:
  • geom (str) – Type of geometry to create. Options are ‘tube’, ‘sphere’, ‘box’, ‘cone’.

  • points (list) – List of points to create the markers. Each element of the list is a len 3 array with the coordinates of the marker (RA,DEC,Z). If geom is ‘tube’, each element of the list is a list of len 3 arrays that define the tubes. Two points define one tube.

  • shape (list) – List of the shape of the markers. If geom is ‘box’, each element of the list is a len 3 array with the size of the box (x,y,z). If geom is ‘cone’, each element of the list is a len 2 array with the radius and height of the cone. Else each element of the list is a float with the radius of the marker.

  • delta (list) – List with the delta of the cube (header[CDELT]).

  • trans (list) – Transformation factor to the cube. It is calculated with (2000/nx, 2000/ny, 2000/nz).

  • color (list) – List with the color of the markers. Each element is a string with RGB values.

make_outline()[source]

Creates an object for an outline in the X3D file.

make_ticklines()[source]

Create tickline objects in the X3D model.

Closes the Transform “ROOT” element. Must be called somewhere after make_layers() and before make_labels().

start_x3d(point=None)[source]

Start the X3D section of the HTML.

Parameters:

point (list, optional) – List of points to define viewpoints. The point will be used to create a vector from the origin. For example, [1,0,0] will create a viewpoint looking at the positive x-axis. The y axis is inverted.

class visl3d.writers.WriteX3D(filename, cube)[source]

Bases: object

Class to create a X3D model of iso-surfaces with 3D spectral line data. Creates an X3D file with the model.

Parameters:
  • filename (str) – Name of the X3D file including the extension (.x3d).

  • cube (Cube) – Object of the Cube class.

Methods

close()

Closes the X3D file.

make_animation([cycleinterval, axis])

Create an animation to rotate the X3D model along one axis.

make_galaxies()

Creates spheres and labels in the model at the location of galaxies given as input.

make_image2d()

Create a 2D image object in the X3D model.

make_labels()

Create the labels of different elements in the figure.

make_layers([shifts, add_normals])

Calculate iso-surfaces from the data and write the objects in the X3D file.

make_markers(geom, points, shape, trans, color)

Create markers in the X3D model.

make_outline()

Creates an object for an outline in the X3D file.

make_ticklines()

Create tickline objects in the X3D model.

close()[source]

Closes the X3D file. Not using this function at the end results in an error.

make_animation(cycleinterval=10, axis=0)[source]

Create an animation to rotate the X3D model along one axis. Must be outside the Transform “ROOT” element. Should be called after make_ticklines().

make_galaxies()[source]

Creates spheres and labels in the model at the location of galaxies given as input.

make_image2d()[source]

Create a 2D image object in the X3D model.

Parameters:
  • imcol (array, optional) – Array with hexadecimal colors of each pixel for a 2D image. If None, a white image is created. Default is None

  • img_shape (tuple, optional) – Shape of the 2D image. Use None for white image. Default is None.

make_labels()[source]

Create the labels of different elements in the figure.

make_layers(shifts=None, add_normals=False)[source]

Calculate iso-surfaces from the data and write the objects in the X3D file.

Parameters:
  • shift (list, optional) – A list with a arrays of 3D vectors giving the shift in RA, DEC and spectral axis in the same units given to the cube. Similar to l_cube or l_isolevels.

  • add_normals (bool, optional) – Whether to add normal vectors in the X3D model. Default is False.

make_markers(geom, points, shape, trans, color, labels=None)[source]

Create markers in the X3D model. Must be called before make_ticklines().

Parameters:
  • geom (str) – Type of geometry to create. Options are ‘tube’, ‘sphere’, ‘box’, ‘cone’.

  • points (list) – List of points to create the markers. Each element of the list is a len 3 array with the coordinates of the marker (RA,DEC,Z). If geom is ‘tube’, each element of the list is a list of len 3 arrays that define the tubes. Two points define one tube.

  • shape (list) – List of the shape of the markers. If geom is ‘box’, each element of the list is a len 3 array with the size of the box (x,y,z). If geom is ‘cone’, each element of the list is a len 2 array with the radius and height of the cone. Else each element of the list is a float with the radius of the marker.

  • delta (list) – List with the delta of the cube (header[CDELT]).

  • trans (list) – Transformation factor to the cube. It is calculated with (2000/nx, 2000/ny, 2000/nz).

  • color (list) – List with the color of the markers. Each element is a string with RGB values.

make_outline()[source]

Creates an object for an outline in the X3D file.

make_ticklines()[source]

Create tickline objects in the X3D model.

Closes the Transform “ROOT” element. Must be called somewhere after make_layers() and before make_labels().