def transform_scalars(dataset):
from tomviz import utils
import numpy as np
# Get the current volume as a NumPy array.
array = utils.get_array(dataset)
# Operate on your data, here we square root it.
result = np.sqrt(array)
# Set the transformed data, displayed in Tomviz.
utils.set_array(dataset, result)
import tomviz.operators
class SquareRootOperator(tomviz.operators.CancelableOperator):
def transform_scalars(self, dataset):
from tomviz import utils
import numpy as np
self.progress.maximum = 10
scalars = utils.get_scalars(dataset)
# Process dataset in chunks, user can cancel.
result = np.float32(scalars)
step = 0
# Processing loop goes here...
utils.set_scalars(dataset, result)
def transform_scalars(self, dataset):
# ...other stuff from previous slide
scalars = utils.get_scalars(dataset)
# Process dataset in chunks, user can cancel.
result = np.float32(scalars)
for chunk in np.array_split(result, 10):
if self.canceled:
return
np.sqrt(chunk, chunk)
step += 1
self.progress.value = step
utils.set_scalars(dataset, result)
import tomviz.operators
CHUNKS = 10
class SquareRootOperator(tomviz.operators.CancelableOperator):
def transform_scalars(self, dataset):
from tomviz import utils
import numpy as np
self.progress.maximum = CHUNKS
scalars = utils.get_scalars(dataset)
# Process dataset in chunks, user can cancel.
result = np.float32(scalars)
step = 0
for chunk in np.array_split(result, CHUNKS):
if self.canceled:
return
np.sqrt(chunk, chunk)
step += 1
self.progress.value = step
utils.set_scalars(dataset, result)
{
"name": "Fancy Square Root",
"label": "Classy Square Root",
"description": "This is the fanciest square root operator, it does it all...",
"parameters": [
{
"name": "number_of_chunks",
"label": "Number of Chunks",
"type": "int",
"default": 10,
"minimum": 1,
"maximum": 1000
}
]
}
import tomviz.operators
class SquareRootOperator(tomviz.operators.CancelableOperator):
def transform_scalars(self, dataset, number_of_chunks = 10):
from tomviz import utils
import numpy as np
self.progress.maximum = number_of_chunks
scalars = utils.get_scalars(dataset)
# Process dataset in chunks, user can cancel.
result = np.float32(scalars)
step = 0
for chunk in np.array_split(result, number_of_chunks):
if self.canceled:
return
np.sqrt(chunk, chunk)
step += 1
self.progress.value = step
utils.set_scalars(dataset, result)
$ git clone --recursive git://github.com/openchemistry/tomviz
$ cd tomviz/tomviz/python
$ mkvirtualenv tomviz
$ pip install -e .
$ tomviz-pipeline -s state.tvsm -d data.emd -o output.emd
[2019-07-23 14:14:59,647] INFO: Executing 'Invert Data' operator
[2019-07-23 14:14:59,963] INFO: Writing transformed data.