### Install tomviz-pipeline package Source: https://tomviz.readthedocs.io/en/latest/pipelines.html Install the pipeline runner from the local repository source. ```bash git clone --recursive https://github.com/openchemistry/tomviz cd tomviz/tomviz/python pip install . ``` -------------------------------- ### Install the Acquisition Server Source: https://tomviz.readthedocs.io/en/latest/acquisition.html Commands to clone the repository and set up the Python virtual environment with necessary dependencies. ```bash git clone --recursive git://github.com/openchemistry/tomviz.git cd tomviz/acquisition python -m venv tomviz-acq source tomviz-acq/bin/activate pip install -e . pip install -e .[tiff] pip install -e .[test] ``` -------------------------------- ### Start the Acquisition Server Source: https://tomviz.readthedocs.io/en/latest/acquisition.html Command to launch the passive acquisition server process. ```bash source tomviz-acq/bin/activate tomviz-acquisition -a tomviz.acquisition.vendors.passive.PassiveWatchSource ``` -------------------------------- ### Setup External Python Environment Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Commands to create a Conda environment and install the required tomviz-pipeline package. ```bash conda create -n my_transform_env python=3.10 conda activate my_transform_env conda install -c conda-forge tomviz-pipeline pip install torch # or any other packages your transform needs ``` -------------------------------- ### Start a Test Sequence Source: https://tomviz.readthedocs.io/en/latest/acquisition.html Command to simulate data acquisition by writing images from a stack to a directory at a specified interval. ```bash tomviz-tiltseries-writer -p /tmp/test -d 5 -t tiff ``` -------------------------------- ### Install tomviz-pipeline via conda Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Installs the pipeline execution package from the conda-forge channel. ```bash conda install -c conda-forge tomviz-pipeline ``` -------------------------------- ### Accessing Dataset in Operator Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/dataset.html Example of how the Dataset object is provided as the first argument to the transform function in a tomviz operator. ```python def transform(dataset, rotation_angle=90.0, rotation_axis=0): # ... array = dataset.active_scalars # ... ``` -------------------------------- ### Create a data source Source: https://tomviz.readthedocs.io/en/latest/interactive.html Initialize a new data source from a file and append it to the application's pipelines. ```python >>> from tomviz import state >>> ds = state.DataSource( fileNames=['SMALL_PtCu_NanoParticle.tif'] ) >>> p = state.Pipeline(ds) >>> state.pipelines.append(p) ``` -------------------------------- ### Taking a screenshot Source: https://tomviz.readthedocs.io/en/latest/interactive.html Load a state file, execute the pipeline, and save the active view as an image file. ```python >>> from tomviz import state >>> state.load('test.tvsm') >>> state.pipelines[0].execute() >>> view = state.active_view >>> view.save_screenshot('screen.png') ``` -------------------------------- ### Download SAM 2 Model Checkpoint Source: https://tomviz.readthedocs.io/en/latest/ml_segmentation.html Commands to create the checkpoint directory and download the base plus model weights. ```bash mkdir -p ~/.tomviz/sam2/checkpoints && cd ~/.tomviz/sam2/checkpoints curl -O https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt ``` -------------------------------- ### Create a Spreadsheet with tomviz.utils Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/utils.html Demonstrates the usage of make_spreadsheet to format data into a dictionary containing a vtkTable object. ```python spreadsheet = utils.make_spreadsheet(column_names, table) return { 'table_data': spreadsheet, } ``` -------------------------------- ### Configure output format Source: https://tomviz.readthedocs.io/en/latest/pipelines.html Specify the output format to bundle pipeline state or generate individual port files. ```bash tomviz-pipeline -s pipeline.tvsm -o results/ --output-format state ``` ```python run("pipeline.tvsm", "results/", output_format="state") ``` -------------------------------- ### Execute a pipeline Source: https://tomviz.readthedocs.io/en/latest/interactive.html Load a state file and trigger the execution of the first pipeline in the state. ```python >>> from tomviz import state >>> state.load('test.tvsm') >>> state.pipelines[0].execute() ``` -------------------------------- ### Create SAM 3 Conda Environment Source: https://tomviz.readthedocs.io/en/latest/ml_segmentation.html Initializes the required environment using the provided YAML configuration file. ```bash conda env create -f sam3-tomviz-cuda.yml ``` -------------------------------- ### Execute a pipeline Source: https://tomviz.readthedocs.io/en/latest/pipelines.html Run a saved pipeline state file against pinned inputs. ```bash tomviz-pipeline -s pipeline.tvsm -o results/ ``` ```python from tomviz.pipeline import run run("pipeline.tvsm", "results/") ``` -------------------------------- ### Create Conda Environment Source: https://tomviz.readthedocs.io/en/latest/ml_segmentation.html Command to initialize the required conda environment for SAM 2 operations. ```bash conda env create -f sam2-tomviz-cpu.yml ``` -------------------------------- ### tomviz.state.DataSource Source: https://tomviz.readthedocs.io/en/latest/interactive.html Creates a new data source from specified files. ```APIDOC ## tomviz.state.DataSource(fileNames) ### Description Initializes a data source object using a list of file paths. ### Usage ```python from tomviz import state ds = state.DataSource(fileNames=['SMALL_PtCu_NanoParticle.tif']) p = state.Pipeline(ds) state.pipelines.append(p) ``` ``` -------------------------------- ### Batch process datasets via command line Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Iterates through multiple files to process them using a saved pipeline state. ```bash for f in dataset_*.emd; do tomviz-pipeline -s my_pipeline.tvh5 -d "$f" -o "output_${f}" done ``` -------------------------------- ### Load a state file Source: https://tomviz.readthedocs.io/en/latest/interactive.html Use the state module to load an existing .tvsm state file into the application. ```python >>> from tomviz import state >>> state.load('test.tvsm') ``` -------------------------------- ### tomviz.utils.make_spreadsheet(column_names, table) Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/utils.html Creates a vtkTable object from a 2D numpy array and a list of column names. ```APIDOC ## tomviz.utils.make_spreadsheet(column_names, table) ### Description Converts a 2D numpy array into a vtkTable object, optionally including axes labels and log scale settings. ### Parameters - **column_names** (list of strings) - Required - A list of names for the columns in the table. - **table** (numpy.ndarray) - Required - A 2D numpy array containing the table data. - **axes_labels** (list, optional) - Optional - A list of two strings for axes labels. - **axes_log_scale** (list, optional) - Optional - A list of two booleans indicating log scale for axes. ### Returns - **vtkTable** - A vtkTable object containing the formatted data. ``` -------------------------------- ### make_spreadsheet(column_names, table, axes_labels, axes_log_scale) Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/utils.html Creates a vtkTable object that can be used within the Tomviz pipeline and saved to a JSON file. ```APIDOC ## make_spreadsheet(column_names, table, axes_labels, axes_log_scale) ### Description Constructs a spreadsheet object (vtkTable) for use within Tomviz. If returned from an operator, it will appear in the pipeline. ### Parameters - **column_names** (list[str]) - List of names for the table columns. - **table** (np.ndarray) - The data to populate the table. - **axes_labels** (tuple[str, str], optional) - Labels for the axes. - **axes_log_scale** (tuple[bool, bool], optional) - Log scale settings for the axes. ### Returns - **vtkTable** - The created spreadsheet object. ``` -------------------------------- ### Add a visualization Source: https://tomviz.readthedocs.io/en/latest/interactive.html Attach a Volume visualization module to a data source within a pipeline. ```python >>> from tomviz import state >>> ds = state.DataSource( fileNames=['SMALL_PtCu_NanoParticle.tif'] ) >>> p = state.Pipeline(ds) >>> state.pipelines.append(p) >>> from tomviz.modules import Volume >>> m = Volume() >>> p.dataSource.modules.append(m) ``` -------------------------------- ### Implement a SourceNode Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Subclass tomviz.nodes.SourceNode and implement the produce method to generate data without inputs. ```python import tomviz.nodes import numpy as np class MySphere(tomviz.nodes.SourceNode): def produce(self, radius=10.0, shape_x=100, shape_y=100, shape_z=100): ds = self.create_dataset() # Generate a sphere x, y, z = np.mgrid[:shape_x, :shape_y, :shape_z] center = np.array([shape_x, shape_y, shape_z]) / 2 dist = np.sqrt((x - center[0])**2 + (y - center[1])**2 + (z - center[2])**2) volume = (dist <= radius).astype(np.float32) ds.active_scalars = volume ds.spacing = (1.0, 1.0, 1.0) return {'output': ds} ``` -------------------------------- ### transform(dataset, threshold=127, radius_spacing=1, save_to_file=False, output_folder='') Source: https://tomviz.readthedocs.io/en/latest/operators/utilities.html Calculates the pore size distribution of a dataset. ```APIDOC ## transform(dataset, threshold=127, radius_spacing=1, save_to_file=False, output_folder='') ### Description Calculates the pore size distribution of a dataset. ### Parameters - **threshold** (int) - Optional - Default: 127, Minimum: 0 - **radius_spacing** (int) - Optional - Default: 1, Minimum: 1 - **save_to_file** (bool) - Optional - Default: False - **output_folder** (directory) - Optional - Default: '' ### Results - **pore_size_distribution** (table) - Pore Size Distribution ``` -------------------------------- ### tomviz.state.load Source: https://tomviz.readthedocs.io/en/latest/interactive.html Loads a Tomviz state file (.tvsm) into the application. ```APIDOC ## tomviz.state.load(filename) ### Description Loads a state file into the current Tomviz session. ### Usage ```python from tomviz import state state.load('test.tvsm') ``` ``` -------------------------------- ### Ptycho Source Configuration Defaults Source: https://tomviz.readthedocs.io/en/latest/operators/utilities.html Default values for Ptycho Source parameters including directory paths, file info, and dataset rotation settings. ```text - default: '' ``` ```text - default: True ``` ```text - default: '[]' ``` ```text - default: '{}' ``` -------------------------------- ### PyStackRegImageAlignment.transform Source: https://tomviz.readthedocs.io/en/latest/operators/alignment.html Perform image alignment using PyStackReg. ```APIDOC ## PyStackRegImageAlignment.transform ### Description Perform image alignment using PyStackReg. ### Parameters - **dataset** (object) - The dataset to process. - **transform_source** (enumeration) - The source of the transformation matrices. Options: 'generate', 'from_file'. Default: 'generate'. - **transform_type** (enumeration) - Transformation type for the registration. Options: 'translation', 'rigid body', 'scaled rotation', 'affine', 'bilinear'. Default: 'translation'. - **transform_file** (file) - Transformation file (npz format) to apply. Visible if transform_source is 'from_file'. - **padding** (int) - Array padding along non-tilt axes before registration. Default: 10. - **reference** (enumeration) - The reference slice to use. Options: 'previous', 'first', 'mean', 'slice_index'. Default: 'slice_index'. - **ref_slice_index** (int) - Slice index to use for the reference. Default: 0. - **apply_to_all_arrays** (bool) - Apply the registration transformation to all arrays within this data source. Default: True. - **transforms_save_file** (save_file) - Save transformations file to apply to other datasets later. ``` -------------------------------- ### Handle Progress and Cancellation Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Use the progress and canceled attributes within a node to report status and handle user cancellation. ```python class MyNode(tomviz.nodes.TransformNode): def transform(self, inputs, **params): self.progress.maximum = 100 for i in range(100): if self.canceled: return None # Do work self.progress.value = i + 1 return {'volume': inputs['volume']} ``` -------------------------------- ### Constant Dataset Configuration Source: https://tomviz.readthedocs.io/en/latest/operators/utilities.html Configuration parameters for generating a 3D dataset filled with a constant value. ```text - default: `[100, 100, 100]` - minimum: `[1, 1, 1]` ``` ```text - default: `0.0` ``` -------------------------------- ### view.save_screenshot(filename, palette=None, resolution=None) Source: https://tomviz.readthedocs.io/en/latest/interactive.html Saves the current view to an image file with optional palette and resolution settings. ```APIDOC ## view.save_screenshot(filename, palette=None, resolution=None) ### Description Captures the active view and saves it to the specified filename. ### Parameters - **filename** (str) - Required - The path to save the screenshot. - **palette** (Palette) - Optional - The background palette to use (e.g., TransparentBackground, BlackBackground). - **resolution** (tuple) - Optional - The resolution of the output image. ``` -------------------------------- ### OtsuMultipleThreshold Source: https://tomviz.readthedocs.io/en/latest/operators/segmentation.html Uses the Otsu multiple threshold algorithm to automatically determine thresholds. ```APIDOC ## OtsuMultipleThreshold.transform(dataset, number_of_thresholds=1, enable_valley_emphasis=False) ### Description Use Otsu multiple threshold algorithm to automatically determine thresholds separating voxels into different classes based on image intensity. ### Parameters - **dataset** (dataset) - Required - The input dataset. - **number_of_thresholds** (int) - Optional - Number of thresholds (default: 1, minimum: 1). - **enable_valley_emphasis** (bool) - Optional - Enable valley emphasis (default: False). ### Returns - **label_map** (label_map) - Label Map ``` -------------------------------- ### tomviz.state.pipelines.execute Source: https://tomviz.readthedocs.io/en/latest/interactive.html Executes a pipeline associated with the current state. ```APIDOC ## pipeline.execute() ### Description Triggers the execution of a pipeline object. ### Usage ```python from tomviz import state state.load('test.tvsm') state.pipelines[0].execute() ``` ``` -------------------------------- ### Random Particles Configuration Defaults Source: https://tomviz.readthedocs.io/en/latest/operators/utilities.html Default values for generating random 3D particles, including shape dimensions and sparsity settings. ```text - default: [128, 128, 128] - minimum: [1, 1, 1] - maximum: [512, 512, 512] ``` ```text - default: 30.0 - minimum: 1.0 - maximum: 100.0 - step: 5.0 ``` ```text - default: 60.0 - minimum: 1.0 - maximum: 100.0 - step: 5.0 ``` ```text - default: 0.2 - minimum: 0.0 - maximum: 1.0 - step: 0.05 ``` -------------------------------- ### Custom Transform Configuration JSON Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Define the display name, label, and description for a custom transform by creating a JSON file with the same base name as the Python script. ```json { "name" : "Custom Thing", "label" : "Operate on data", "description" : "Apply my special operation to the data..." } ``` -------------------------------- ### PyXRF Source Configuration Defaults Source: https://tomviz.readthedocs.io/en/latest/operators/utilities.html Default values for PyXRF Source parameters including command strings, directory paths, and processing flags. ```text - default: 'pyxrf-utils' ``` ```text - default: '' ``` ```text - default: '[]' ``` ```text - default: False ``` ```text - default: 'sclr1_ch4' ``` ```text - default: True ``` ```text - default: '{}' ``` -------------------------------- ### Override inputs for single-source pipelines Source: https://tomviz.readthedocs.io/en/latest/pipelines.html Provide new input files or globs to replace the source defined in the state file. ```bash # One file → one run. tomviz-pipeline -s pipeline.tvsm -o results/ --input data.emd # Glob → one run per matched file. tomviz-pipeline -s pipeline.tvsm -o results/ --input 'data/*.emd' # Explicit list (comma-separated, no spaces). tomviz-pipeline -s pipeline.tvsm -o results/ --input a.emd,b.emd,c.emd ``` ```python from tomviz.pipeline import run run("pipeline.tvsm", "results/", inputs="data.emd") run("pipeline.tvsm", "results/", inputs="data/*.emd") run("pipeline.tvsm", "results/", inputs=["a.emd", "b.emd", "c.emd"]) ``` -------------------------------- ### Saving a screenshot with a transparent background Source: https://tomviz.readthedocs.io/en/latest/interactive.html Use the palette argument to specify a background style when saving a screenshot. ```python >>> from tomviz import views >>> view = views.active_view >>> view.save_screenshot('screen.png', palette=views.Palette.TransparentBackground) ``` -------------------------------- ### Accessing Tomviz views Source: https://tomviz.readthedocs.io/en/latest/interactive.html Retrieve the currently active view or a list of all available views from the state module. ```python >>> from tomviz import state >>> active = state.active_view ``` ```python >>> from tomviz import state >>> views = state.views ``` -------------------------------- ### Create Spreadsheet Object Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/utils.html Creates a vtkTable object for use within Tomviz, which can be displayed in the pipeline and exported to JSON. ```python def make_spreadsheet(column_names: list[str], table: np.ndarray, axes_labels: tuple[str, str] = None, axes_log_scale: tuple[bool, bool] = None) -> 'vtkTable': """Make a spreadsheet object to use within Tomviz If returned from an operator, this will ultimately appear within the pipeline, and will be save-able to a JSON file. ``` -------------------------------- ### Execute a saved pipeline state Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Runs a saved pipeline file and writes the output to a specified file. ```bash tomviz-pipeline -s -o ``` -------------------------------- ### Configure External Subprocess Execution Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Specify a tomviz_pipeline_env path in the JSON metadata to run the transform in an isolated Python environment. ```json { "name": "MyAITransform", "label": "AI Denoise", "tomviz_pipeline_env": "/path/to/conda/envs/ai_env" } ``` -------------------------------- ### Create a simple Python transform Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Defines a basic transform function that operates on dataset scalars using NumPy. ```python def transform(dataset): """Python transform that operates on the input array""" import numpy as np # Get the current volume as a numpy array. array = dataset.active_scalars # This is where you operate on your data, here we square root it. result = np.sqrt(array) # This is where the transformed data is set, it will display in tomviz. dataset.active_scalars = result # Optionally set the voxel sizes (in physical units) dataset.spacing = [5, 10, 7] ``` -------------------------------- ### Recon_TV_minimization.transform Source: https://tomviz.readthedocs.io/en/latest/operators/reconstruction.html Reconstruct a tilt series using TV Minimization. ```APIDOC ## Recon_TV_minimization.transform(dataset, Niter=10, Nupdates=0) ### Description Reconstruct a tilt series using TV Minimization. ### Parameters - **dataset** (dataset) - Required - The input tilt series dataset. - **Niter** (int) - Optional - Number of iterations (default: 1, min: 0). - **Nupdates** (int) - Optional - Number of updates (default: 0, min: 0, max: 100). ``` -------------------------------- ### Electron Beam Shape Parameters Source: https://tomviz.readthedocs.io/en/latest/operators/utilities.html Configuration parameters for generating a convergent electron beam in 3D for STEM imaging. ```text - default: `300.0` - minimum: `1.0` - maximum: `1000000.0` - step: `50.0` ``` ```text - default: `30.0` - minimum: `0.0` - maximum: `500.0` - step: `0.5` ``` ```text - default: `256` - minimum: `64` - maximum: `2048` ``` ```text - default: `0.1` - minimum: `0.0001` - precision: 4 decimal places - step: `0.1` ``` ```text - default: `512` - minimum: `1` - maximum: `2048` ``` ```text - default: `-50.0` - minimum: `-1000000.0` - maximum: `1000000.0` - step: `5.0` ``` ```text - default: `100.0` - minimum: `-1000000.0` - maximum: `1000000.0` - step: `5.0` ``` ```text - default: `0.2` - minimum: `-1000000.0` - maximum: `1000000.0` - step: `0.1` ``` -------------------------------- ### Recon_tomopy.transform Source: https://tomviz.readthedocs.io/en/latest/operators/reconstruction.html Runs TomoPy reconstruction on a dataset using various algorithms. ```APIDOC ## Recon_tomopy.transform ### Description Run TomoPy reconstruction on a dataset. ### Parameters - **dataset** (dataset) - The input dataset to reconstruct. - **algorithm** (enumeration) - Reconstruction algorithm to use (default: 'gridrec'). Options: 'gridrec', 'fbp', 'sirt', 'art', 'tv', 'mlem', 'ospml_hybrid'. - **num_iter** (int) - Number of iterations for iterative methods (default: 5, range: 1-1000). - **reg_par** (double) - Regularization parameter for TV (default: 0.1, range: 0.0001-10.0). - **use_gpu** (bool) - Use GPU acceleration via CUDA (default: False). ``` -------------------------------- ### Dataset Methods Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/dataset.html Methods for managing scalar arrays within the dataset. ```APIDOC ## Dataset Methods ### scalars(name: str | None = None) -> numpy.ndarray - Retrieves a scalar array by name. If name is None, returns the active scalar array. - Raises KeyError if the name does not exist. ### set_scalars(name: str, array: numpy.ndarray) - Adds or updates a scalar array. If the name exists, it is overwritten. ### remove_scalars(name: str) - Removes a scalar array by name. - Raises KeyError if the name does not exist. ``` -------------------------------- ### tomviz.modules.Volume Source: https://tomviz.readthedocs.io/en/latest/interactive.html Adds a Volume visualization module to a pipeline. ```APIDOC ## tomviz.modules.Volume() ### Description Appends a Volume visualization module to the data source modules list. ### Usage ```python from tomviz.modules import Volume m = Volume() p.dataSource.modules.append(m) ``` ``` -------------------------------- ### Define an integer parameter Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Defines a numeric parameter with a minimum bound. ```json { "name" : "iterations", "label" : "Number of Iterations", "type" : "int", "default" : 100, "minimum" : 0 } ``` -------------------------------- ### Define Custom Transform Metadata Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Use JSON to define transform names, labels, and user-configurable parameters. ```json { "name": "Fancy Square Root", "label": "Classy Square Root", "description": "A configurable square root operator.", "parameters": [ { "name": "number_of_chunks", "label": "Number of Chunks", "type": "int", "default": 10, "minimum": 1, "maximum": 1000 } ] } ``` -------------------------------- ### tomviz.nodes.SourceNode Source: https://tomviz.readthedocs.io/en/latest/operators_development.html A base class for nodes that produce output data without inputs. Users must implement the produce method. ```APIDOC ## tomviz.nodes.SourceNode ### Description Base class for creating data sources. Implement the `produce` method to generate and return a dictionary of output datasets. ### Method `produce(self, **kwargs)` ### Parameters - **kwargs** (dict) - Keyword arguments passed from the JSON description file. ### Returns - **dict** - A dictionary mapping output port names to Dataset objects. ``` -------------------------------- ### Apply a transformation to each scalar array Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/dataset.html Demonstrates using apply_to_each_scalar_array within a TransformNode to apply a constant addition to all scalar arrays in a dataset. ```python class AddConstant(tomviz.nodes.TransformNode): def transform(self, inputs, constant=0.0): ds = inputs["volume"] return { "volume": ds.apply_to_each_scalar_array( lambda a: a + constant) } ``` -------------------------------- ### Dataset Interface Methods Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/dataset.html Methods and properties available on the Dataset object for data manipulation and metadata access. ```APIDOC ## Dataset.apply_to_each_scalar_array(fn) ### Description Returns a new Dataset with each scalar array transformed by the provided function. The original dataset remains unmodified. ### Parameters - **fn** (Callable[[np.ndarray], np.ndarray | None]) - Required - A function that takes a numpy array and returns a transformed array or None to exclude it. ### Returns - **Dataset** - A new Dataset instance containing the transformed scalar arrays. ## Dataset.empty_copy() ### Description Creates a new Dataset of the same type, preserving metadata (spacing, tilt angles, dimensions, file_name) but excluding scalar arrays. ### Returns - **Dataset** - A new empty Dataset instance. ## Dataset Properties - **scan_ids** (np.ndarray | None): Get or set the scan IDs for projections in a tilt series. - **dark** (np.ndarray | None): Read-only access to dark field calibration data. - **white** (np.ndarray | None): Read-only access to white field (flat field) calibration data. - **file_name** (str | None): Read-only access to the original filename of the dataset. - **metadata** (dict): Read-only access to the dictionary of arbitrary metadata associated with the dataset. ``` -------------------------------- ### Implement a TransformNode Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Subclass tomviz.nodes.TransformNode and implement the transform method to process input data. ```python import tomviz.nodes class AddConstant(tomviz.nodes.TransformNode): def transform(self, inputs, constant=0.0): ds = inputs['volume'] ds.active_scalars = ds.active_scalars + constant return {'volume': ds} ``` -------------------------------- ### Define a multi-element integer parameter Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Defines an integer parameter that accepts an array of values. ```json { "name" : "shift", "label" : "Shift", "type" : "int", "default" : [0, 0, 0] } ``` -------------------------------- ### Dataset.apply_to_each_scalar_array(fn) Source: https://tomviz.readthedocs.io/en/latest/api/index.html Returns a new Dataset with each scalar array replaced by the result of the provided function. The original dataset remains unmodified. ```APIDOC ## Dataset.apply_to_each_scalar_array(fn) ### Description Returns a new Dataset with each scalar array replaced by `fn(array)`. The original dataset is not modified. ### Parameters - **fn** (Callable[[ndarray], ndarray | None]) - Required - A function that takes a numpy array and returns a new array or None to filter it out. ### Return Type - **Dataset** ``` -------------------------------- ### BinaryOpen.transform Source: https://tomviz.readthedocs.io/en/latest/operators/transformation.html Perform morphological opening on segmented objects with a given label by a spherically symmetric structuring element of a given radius. ```APIDOC ## BinaryOpen.transform ### Description Perform morphological opening on segmented objects with a given label by a spherically symmetric structuring element of a given radius. ### Parameters - **dataset** (object) - The dataset to transform. - **structuring_element_id** (enumeration) - Optional. 0: Box, 1: Ball, 2: Cross. Default: 0. - **radius** (int) - Optional. Minimum: 1. Default: 1. - **object_label** (int) - Optional. Default: 1. - **background_label** (int) - Optional. Default: 0. ``` -------------------------------- ### Recon_WBP.transform Source: https://tomviz.readthedocs.io/en/latest/operators/reconstruction.html Reconstructs a tilt series using the Weighted Back Projection (WBP) method. ```APIDOC ## Recon_WBP.transform ### Description Reconstruct a tilt series using Weighted Back Projection (WBP) method. The tilt series data should be aligned prior to reconstruction. ### Parameters - **dataset** (dataset) - The input dataset. - **Nrecon** (int) - Size of reconstruction (range: 1-4096). - **filter** (enumeration) - Filter type (default: 1). Options: 0 (None), 1 (Ramp), 2 (Shepp-Logan), 3 (Cosine), 4 (Hamming), 5 (Hann). - **interp** (enumeration) - Interpolation method (default: 0). Options: 0 (Linear), 1 (Nearest), 2 (Spline), 3 (Cubic). - **Nupdates** (int) - Number of updates (default: 0, minimum: 0). ``` -------------------------------- ### Define a boolean parameter Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Defines a toggle parameter for the UI. ```json { "name" : "enable_feature", "label" : "Enable Feature", "type" : "bool", "default" : false } ``` -------------------------------- ### Shift3D.transform Source: https://tomviz.readthedocs.io/en/latest/operators/alignment.html Shift a dataset in 3D space. ```APIDOC ## Shift3D.transform ### Description Shift a dataset. ### Parameters - **dataset** (object) - The dataset to process. - **SHIFT** (double) - Amount to shift by. Range: [-999, -999, -999] to [999, 999, 999]. Default: [0.0, 0.0, 0.0]. ``` -------------------------------- ### tomviz.utils.pad_array(array, padding, tilt_axis) Source: https://tomviz.readthedocs.io/en/latest/api/index.html Adds padding to an array while ignoring the tilt axis. ```APIDOC ## tomviz.utils.pad_array(array, padding, tilt_axis) ### Description Add padding to an array. Ignore the tilt axis. ### Parameters - **array** (ndarray) - Required - The input array. - **padding** (int) - Required - The amount of padding. - **tilt_axis** (int) - Required - The axis to ignore. ### Return Type - **ndarray** ``` -------------------------------- ### Recon_ART.transform Source: https://tomviz.readthedocs.io/en/latest/operators/reconstruction.html Reconstruct a tilt series using Algebraic Reconstruction Technique (ART) with a positivity constraint. ```APIDOC ## Recon_ART.transform(dataset, Niter=1, Nupdates=0, beta=1.0) ### Description Reconstruct a tilt series using Algebraic Reconstruction Technique (ART) with a positivity constraint. ### Parameters - **dataset** (dataset) - Required - The input tilt series dataset. - **Niter** (int) - Optional - Number of iterations (default: 1, min: 1). - **Nupdates** (int) - Optional - Number of updates (default: 0, min: 0, max: 100). - **beta** (double) - Optional - Relaxation parameter (default: 1.0, min: 0.01, max: 2.0). ``` -------------------------------- ### Iterate Through All Dataset Channels Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Loop through all available scalar names to perform operations across multiple channels. ```python def transform(dataset): import numpy as np channel_sum = None for name in dataset.scalars_names: channel = dataset.scalars(name) if channel_sum is None: channel_sum = channel else: channel_sum += channel dataset.active_scalars = channel_sum ``` -------------------------------- ### Define a double parameter Source: https://tomviz.readthedocs.io/en/latest/operators_development.html Defines a floating-point parameter with bounds and precision settings. ```json { "name" : "rotation_angle", "label" : "Angle", "type" : "double", "default" : 90.0, "minimum" : -360.0, "maximum" : 360.0, "precision" : 1 } ``` -------------------------------- ### tomviz.Dataset Source: https://tomviz.readthedocs.io/en/latest/operators_development.html The Dataset object provides properties and methods for managing scalar arrays, metadata, and geometry. ```APIDOC ## tomviz.Dataset ### Properties - **active_scalars** (ndarray) - Get/set the active scalar array. - **active_name** (str) - Get/set the name of the active scalar. - **num_scalars** (int) - Number of scalar arrays. - **scalars_names** (list) - List of all scalar array names. - **spacing** (tuple) - Voxel spacing (x, y, z). - **tilt_angles** (ndarray) - NumPy array of tilt angles. - **tilt_axis** (int/None) - Axis index for tilting. - **scan_ids** (ndarray) - NumPy array of scan IDs. - **dark/white** (data) - Dark/white field calibration data. - **file_name** (str) - Original filename. - **metadata** (dict) - Arbitrary metadata dictionary. ### Methods - **scalars(name)** - Get a scalar array by name. - **set_scalars(name, array)** - Add or update a scalar array. - **remove_scalars(name)** - Remove a scalar array. - **empty_copy()** - Create a new dataset with same geometry but no arrays. ``` -------------------------------- ### Defining screenshot palette options Source: https://tomviz.readthedocs.io/en/latest/interactive.html The Palette enum defines available background styles for saved screenshots. ```python class Palette(Enum): Current = "" TransparentBackground = "TransparentBackground" BlackBackground = "BlackBackground" DefaultBackground = "DefaultBackground" GradientBackground = "GradientBackground" GrayBackground = "GrayBackground" PrintBackground = "PrintBackground" WhiteBackground = "WhiteBackground" ``` -------------------------------- ### Implement a CompletableOperator in Python Source: https://tomviz.readthedocs.io/en/latest/_modules/tomviz/operators.html Use the completed property to break out of iterative loops early while still returning the current dataset. ```python import tomviz.operators class MyCompletableOperator(tomviz.operators.CompletableOperator): def transform(self, dataset, ...): while True: if self.completed: # Break out of the iterative loop and return the current # results. ``` -------------------------------- ### SAM2Segment3D Source: https://tomviz.readthedocs.io/en/latest/operators/segmentation.html Segments a 3D volume with Meta’s Segment Anything Model 2 (SAM 2). ```APIDOC ## SAM2Segment3D.transform(dataset, seed=(-1, -1, -1), prompt_mode=0, invert_contrast=False, z_axis=0, propagate=0, model_size=2, device=0, checkpoint_dir='', trim_fraction=0.1, keep_seed_component=True) ### Description Segment a 3D volume with Meta’s Segment Anything Model 2 (SAM 2). The Z-axis is treated as the video time axis. ### Parameters - **dataset** (dataset) - Required - The input dataset. - **seed** (int) - Optional - Seed point (default: [-1, -1, -1]). - **prompt_mode** (enumeration) - Optional - Prompt mode (0: Point, 1: Auto Mask) (default: 0). - **invert_contrast** (bool) - Optional - Invert contrast (default: False). - **z_axis** (enumeration) - Optional - Z-axis (0: First, 1: Middle, 2: Last) (default: 0). - **propagate** (enumeration) - Optional - Propagation direction (0: Both, 1: Forward, 2: Backward) (default: 0). ```