Add Operations
The copick.ops.add
module provides functions for adding data to Copick projects, including runs, voxel spacings, tomograms, and features. These functions handle the creation and storage of data entities with proper validation and metadata management.
Functions
copick.ops.add.add_run
Import a run into copick.
Parameters:
-
root
(CopickRoot
) –The copick root object.
-
name
(str
) –The name of the run.
-
exist_ok
(bool
, default:False
) –If True, do not raise an error if the run already exists. Defaults to False.
-
log
(bool
, default:False
) –Log the operation. Defaults to False.
copick.ops.add.get_or_create_run
copick.ops.add.add_voxelspacing
add_voxelspacing(root: CopickRoot, run: str, voxel_spacing: float, create: bool = True, exist_ok: bool = False, log: bool = False) -> CopickVoxelSpacing
Import a voxel spacing into copick.
Parameters:
-
root
(CopickRoot
) –The copick root object.
-
run
(str
) –The name of the run.
-
voxel_spacing
(float
) –The voxel spacing of the run.
-
create
(bool
, default:True
) –Create the object if it does not exist. Defaults to True.
-
exist_ok
(bool
, default:False
) –If True, do not raise an error if the voxel spacing already exists. Defaults to False.
-
log
(bool
, default:False
) –Log the operation. Defaults to False.
copick.ops.add.get_or_create_voxelspacing
get_or_create_voxelspacing(run: CopickRun, voxel_size: float, create: bool = True, log: bool = False) -> CopickVoxelSpacing
Get or create a voxel spacing object.
Parameters:
-
run
(CopickRun
) –The run object.
-
voxel_size
(float
) –The voxel size.
-
create
(bool
, default:True
) –Create the object if it does not exist. Defaults to True.
-
log
(bool
, default:False
) –Log the operation. Defaults to False.
copick.ops.add.add_tomogram
add_tomogram(root: CopickRoot, run: str, tomo_type: str, volume: Union[ndarray, Dict[float, ndarray]], voxel_spacing: float = None, create: bool = True, exist_ok: bool = False, overwrite: bool = False, create_pyramid: bool = False, pyramid_levels: int = 3, chunks: Tuple[int, ...] = (256, 256, 256), meta: Dict[str, Any] = None, log: bool = False) -> CopickTomogram
Add a tomogram to a copick run.
Parameters:
-
root
(CopickRoot
) –The copick root object.
-
volume
(Dict[float, ndarray]
) –Multi-scale pyramid of the tomogram. Keys are the voxel size in Angstroms.
-
create
(bool
, default:True
) –Create the object if it does not exist. Defaults to True.
-
exist_ok
(bool
, default:False
) –If True, do not raise an error if the volume already exists. Defaults to False.
-
overwrite
(bool
, default:False
) –Overwrite the object if it exists. Defaults to False.
-
run
(str
) –The run the tomogram is part of. Default: Name of the input file.
copick.ops.add.add_features
add_features(root: CopickRoot, run: str, voxel_spacing: float, tomo_type: str, feature_type: str, features_vol: ndarray, exist_ok: bool = False, overwrite: bool = False, chunks: Tuple[int, int, int] = (256, 256, 256), meta: Dict[str, Any] = None, log: bool = False) -> CopickFeatures
Add features to a copick run.
Parameters:
-
root
(CopickRoot
) –The copick root object.
-
features
(Dict[str, Any]
) –The features to add.
-
run
(str
) –The run the features are part of.
-
exist_ok
(bool
, default:False
) –If True, do not raise an error if the features already exist. Defaults to False.
-
overwrite
(bool
, default:False
) –Overwrite the object if it exists. Defaults to False.
-
log
(bool
, default:False
) –Log the operation. Defaults to False.
Usage Examples
Adding a Run
from copick.ops.add import add_run
from copick.impl.filesystem import CopickRootFSSpec
# Open a project
root = CopickRootFSSpec.from_file("config.json")
# Add a new run
run = add_run(root, "experiment_001", exist_ok=True, log=True)
Adding a Tomogram
import numpy as np
from copick.ops.add import add_tomogram
# Create sample volume data
volume = np.random.rand(512, 512, 512).astype(np.float32)
# Add tomogram with pyramid generation
tomogram = add_tomogram(
root=root,
run="experiment_001",
tomo_type="wbp",
volume=volume,
voxel_spacing=10.0,
create_pyramid=True,
pyramid_levels=4,
log=True
)