scivianna.data package

Scivianna Data Module

The data module provides core data structures and workers for managing simulation data in Scivianna, including 1D plots, 2D geometries, and data containers.

Files

File

Description

__init__.py

Package initialization file

data_container.py

Container class for holding and managing visualization data

data1d.py

Data structures for 1D plot data (line charts, time series)

data2d.py

Data structures for 2D geometry data (meshes, fields, polygons)

data_2d_worker.py

Worker process for handling 2D data operations asynchronously

Data Types

Data1D

Handles one-dimensional data for line plots:

  • Time series data

  • Line charts with multiple variables

Data2D

Handles two-dimensional geometry data:

  • Mesh cells with associated values

  • Color maps (RGBA per cell)

  • Alpha/transparency values

  • Polygon-based or grid-based geometries

DataContainer

Unified container that manages both 1D and 2D data:

  • Stores current field values

  • Manages color bar properties

  • Tracks data metadata and labels

Key Features

  • Color Management: Built-in support for RGBA color arrays (0-255 range)

  • Field Labels: Automatic tracking of available fields for selection widgets

  • Data Validation: Methods to verify data integrity before visualization

Integration

The data module integrates with:

  • Interfaces: Data is loaded via interface modules (MED, VTK, CSV)

  • Plotters: Data is rendered by 1D and 2D plotter backends

  • Agents: AI agent can manipulate Data2D properties programmatically

Submodules

scivianna.data.data1d module

class scivianna.data.data1d.Data1D

Bases: DataContainer

Data class containing the 2D geometry data

check_valid()

Checks if this Data1D is valid, raises an AssertionError otherwise

copy() Data1D

Returns a copy of self

Returns:

Identical copy of self

Return type:

Data1D

classmethod from_dataframe(df: DataFrame)

Build a Data1D object from a list of PolygonElement

Parameters:

df (pd.DataFrame) – Pandas dataframe to build the Data1D from

Returns:

Requested Data1D

Return type:

Data1D

classmethod from_serie_dict(series: Dict[str, Series])

Build a Data1D object from a list of PolygonElement

Parameters:

series (Dict[str, pd.Series]) – Dict of pandas Series to build the Data1D with

Returns:

Requested Data1D

Return type:

Data1D

line_colors: List[Tuple[int, int, int]]

List of contained line colors

line_ids: List[int | str]

List of contained line ids

line_styles: List[str]

List of contained line edge colors

line_values: List[Series]

List of contained line values

scivianna.data.data2d module

class scivianna.data.data2d.Data2D

Bases: DataContainer

Data class containing the 2D geometry data

cell_colors: ndarray

Numpy array containing a list of contained cell colors

cell_edge_colors: ndarray

Numpy array containing a list of contained cell edge colors

cell_ids: ndarray

Numpy array containing a list of contained cell ids

cell_values: ndarray

Numpy array containing a list of contained cell values

check_valid()

Checks if this Data2D is valid, raises an AssertionError otherwise

convert_to_polygons()

Convert the geometry to polygons

copy() Data2D

Returns a copy of self

Returns:

Identical copy of self

Return type:

Data2D

data_type: DataType

Whether the data are provided from a polygon list or a grid

classmethod from_grid(grid: ndarray, u_values: ndarray, v_values: ndarray, simplify: bool = False)

Build a Data2D object from a list of PolygonElement

Parameters:
  • grid (np.ndarray) – Numpy 2D array defining the 2D geometry

  • u_values (np.ndarray) – Coordinates of the grid points on the horizontal axis

  • v_values (np.ndarray) – Coordinates of the grid points on the vertical axis

  • simplify (bool) – Simplify the polygons when converted to polygon list

Returns:

Requested Data2D

Return type:

Data2D

classmethod from_polygon_list(polygon_list: List[PolygonElement])

Build a Data2D object from a list of PolygonElement

Parameters:

polygon_list (List[PolygonElement]) – Polygons contained in the Data2D

Returns:

Requested Data2D

Return type:

Data2D

get_grid() ndarray

Returns the grid associated to the current geometry

Returns:

Geometry as a 2D grid

Return type:

np.ndarray

Raises:

NotImplementedError – Grid extraction from polygon list not implemented yet.

get_polygons() List[PolygonElement]

Returns the polygon list of the geometry. If defined as grid, the grid is rasterized and self is converted to polygon data.

Returns:

Polygon list

Return type:

List[PolygonElement]

grid: ndarray

2D grid defining the geometry

polygons: List[PolygonElement]

List of polygons defining the geometry

simplify: bool

Simplify the polygons when converting from grid to polygon list

u_values: ndarray

Coordinates of the grid points on the horizontal axis

v_values: ndarray

Coordinates of the grid points on the vertical axis

scivianna.data.data_2d_worker module

class scivianna.data.data_2d_worker.Data2DWorker(data2d: Data2D)

Bases: object

Worker that receives a Data2D object and works with it.

check_valid()

Check if the Data2D is valid

Raises:

AssertionError – Current Data2D is not valid

get_colors() ndarray

Returns the color per 2D cell of the geometry. The returned object is a np.ndarray of shape (cell_count, 4), with values ranging from 0 to 255.

Returns:

Numpy array with the value per cell

Return type:

np.ndarray

get_numpy()

Returns the numpy module

get_values() ndarray

Returns the value per 2D cell of the geometry

Returns:

Numpy array with the value per cell

Return type:

np.ndarray

has_changed() bool

Tells if the data_2d was changed by the agent

Returns:

data_2d changed

Return type:

bool

reset()

Returns to the data2d provided in the initialization

set_alphas(alphas: ndarray) bool

Sets the cells opacity values, expects a numpy array of integers between 0 and 255. return True if it’s ok.

Parameters:

alphas (np.ndarray) – Opacity values

Returns:

True if the given array is ok

Return type:

bool

set_colors(colors: ndarray) bool

Sets the cells color values, expects a numpy array of integers between 0 and 255 of shape (cell_count, 4). return True if it’s ok.

Parameters:

colors (np.ndarray) – np array containing the new per cell colors. expects a numpy array of integers between 0 and 255 of shape (cell_count, 4).

Returns:

True if the given array is ok

Return type:

bool

scivianna.data.data_container module

class scivianna.data.data_container.DataContainer

Bases: object

Module contents