tools#
Main module exporting the CryoSPARC class for interfacing with a CryoSPARC
instance from Python
Examples
>>> from cryosparc.tools import CryoSPARC
>>> cs = CryoSPARC("http://localhost:61000")
>>> project = cs.find_project("P3")
Classes:
High-level object for interfacing with CryoSPARC. |
Data:
Supported micrograph file formats. |
Functions:
|
Downsample a micrograph or movie. |
|
Get the |
|
Get list of import signatures for a path or list of paths. |
|
Apply butterworth lowpass filter to the 2D array data with the given pixel size ( |
- class CryoSPARC#
High-level object for interfacing with CryoSPARC. Initialize with the URL of a local or remote CryoSPARC instance.
- Parameters:
base_url (str, optional) – CryoSPARC instance URL, e.g., “localhost:61000” or “https://cryosparc.example.com”. Same URL used to access CryoSPARC from a web browser. Defaults to
os.getenv("CRYOSPARC_BASE_URL").host (str, optional) – Hostname or IP address running CryoSPARC master. Cannot be specified with
base_url. Defaults toos.getenv("CRYOSPARC_MASTER_HOSTNAME").base_port (int, optional) – CryoSPARC services base port number. Cannot be specified with
base_url. Defaults toos.getenv("CRYOSPARC_BASE_PORT").email (str, optional) – CryoSPARC user account email address. Defaults to
os.getenv("CRYOSPARC_EMAIL").password (str, optional) – CryoSPARC user account password address. Defaults to
os.getenv("CRYOSPARC_PASSWORD").license (str, optional) – (Deprecated) CryoSPARC license key. Defaults to
os.getenv("CRYOSPARC_LICENSE_ID").timeout (int, optional) – Timeout error for HTTP requests to CryoSPARC command services. Defaults to 300.
Examples
Load project job and micrographs
>>> from cryosparc.tools import CryoSPARC >>> cs = CryoSPARC("localhost:61000", email="ali@example.com", password="password123") >>> job = cs.find_job("P3", "J42") >>> micrographs = job.load_output('exposures')
Remove corrupt exposures (assumes
is_mic_corruptfunction)>>> filtered_micrographs = micrographs.query( ... lambda mic: is_mic_corrupt(mic["micrograph_blob/path"]) ... ) >>> cs.save_external_result( ... project_uid="P3", ... workspace_uid="W1", ... dataset=filtered_micrographs, ... type="exposure", ... name="filtered_exposures", ... passthrough=("J42", "exposures") ... ) "J43"
Attributes:
HTTP REST API client for
apiservice.URL used for communication CryoSPARC instance REST API.
Information and metadata about job types available in this instance.
User account currently logged into CryoSPARC.
Methods:
__init__([base_url, host, base_port, email, ...])attach_project(path, *[, wait])Attach an existing project directory to this instance.
cp(project_uid, source_path[, target_path])Copy a file or folder to a project directory.
create_external_job(project_uid, workspace_uid)Add a new External job to this project to save computed outputs to.
create_job(project_uid, workspace_uid, type)Add a new job with the given type to a project workspace.
create_project(parent_path, title[, desc])Start a new empty project.
create_workspace(project_uid, title[, desc])Create a new empty workspace in a project.
download(project_uid, path)Open a file in a project for reading.
Download the asset with the given ID from the database.
download_dataset(project_uid, path)Download a .cs dataset file from a project directory.
Download a file from a project directory to a target path or writeable file handle.
download_mrc(project_uid, path)Download a .mrc file from a project directory.
find_external_job(project_uid, job_uid)Get an External job by its unique project and job ID.
find_job(project_uid, job_uid)Get a job by its unique project and job ID.
find_jobs([project_uid, workspace_uid, order])Search for jobs.
find_project(project_uid)Get a project by its unique ID.
find_projects(*[, order])Search for projects available to the current user.
find_workspace(project_uid, workspace_uid)Find a workspace in a project by its unique ID.
find_workspaces([project_uid, order])Search for workspaces.
(Deprecated) Get a summary of job types available for this instance, organized by category.
Find registered scheduled lanes that jobs may be queued to.
get_targets([lane])Find a list of connected worker node or cluster targets that jobs may be queued to.
import_job(project_uid, workspace_uid, path, *)Import a job into a project workspace from a location on disk.
list_assets(project_uid, job_uid)Find files available in the database for a job.
list_files(project_uid[, prefix, recursive])List files in a project directory.
mkdir(project_uid, target_path[, parents, ...])Create a subfolder in a project directory.
print_job_types([category, show_legacy])Print a table of job types and their titles, organized by category.
refresh()Reset cache and refresh instance details.
save_external_result(project_uid, ...[, ...])Save a result dataset to a project, via External Job.
symlink(project_uid, source_path[, target_path])Create a symbolic link in a project directory.
Verify connection to CryoSPARC.
upload(project_uid, target_path, source, *)Upload a file to a project directory.
upload_dataset(project_uid, target_path, dset, *)Upload a dataset as a .cs file into a project directory.
upload_mrc(project_uid, target_path, data, ...)Upload a numpy 2D or 3D array to a project directory as an MRC file.
- __init__(base_url: str | None = None, *, host: str | None = None, base_port: int | str | None = None, email: str | None = None, password: str | None = None, license: str | None = None, timeout: int = 300)#
- attach_project(path: str | PurePosixPath, *, wait: bool = False) ProjectController#
Attach an existing project directory to this instance.
The directory may not already be attached to any other CryoSPARC instance. A lock file will be created in the project directory to prevent it from being attached to multiple instances at the same time.
Project will not be available to modify until the attach process completes, which may take some time depending on the size of the project. Set
wait=Trueto block until the project is fully attached and available.Once attach completes, the project will be visible and modifiable in the web UI. The project is assigned a new unique ID upon attach.
- Parameters:
path (str | Path) – Absolute path to project directory, e.g.
/home/user/cryosparc-projects/CS-t20s. If the CryoSPARC instance is hosted remotely, this should be a path available on the server file system.wait (bool, optional) – If True, wait and poll until project is attached and available. Defaults to False.
- Returns:
attached project accessor object
- Return type:
- Raises:
APIError – Project cannot be attached, e.g., if path does not exist or is already attached to another instance.
ProjectError – If attachment successfully starts but does fully complete due to invalid or corrupted data.
- base_url: str#
URL used for communication CryoSPARC instance REST API.
- cp(project_uid: str, source_path: str | PurePosixPath, target_path: str | PurePosixPath = '') None#
Copy a file or folder to a project directory. May only copy files within the project directory or from paths the user is authorized to access by an administrator.
If copying to a remote CryoSPARC instance, the source path must be accessible on the server file system. If the source path is only available locally, use
upload()instead.- Parameters:
project_uid (str) – Target project UID, e.g., “P3”.
source_path (str | Path) – Relative or absolute path of source file or folder to copy. If relative, assumed to be within the project directory.
target_path (str | Path, optional) – Name or path in the project directory to copy into. If not specified, uses the same file name as the source. Defaults to “”.
- create_external_job(project_uid: str, workspace_uid: str, title: str = '', desc: str = '') ExternalJobController#
Add a new External job to this project to save computed outputs to.
- Parameters:
project_uid (str) – Project UID to create in, e.g., “P3”
workspace_uid (str) – Workspace UID to create job in, e.g., “W1”
title (str, optional) – Title for external job (recommended). Defaults to “”.
desc (str, optional) – Markdown description for external job. Defaults to “”.
- Returns:
created external job accessor object
- Return type:
- create_job(project_uid: str, workspace_uid: str, type: str, connections: Dict[str, Tuple[str | JobController, str] | List[Tuple[str | JobController, str]]] = {}, params: Dict[str, Any] = {}, title: str = '', desc: str = '') JobController#
Add a new job with the given type to a project workspace.
All available job types and associated metadata are available from
job_register.- Parameters:
project_uid (str) – Project UID to create job in, e.g., “P3”
workspace_uid (str) – Workspace UID to create job in, e.g., “W1”
type (str) – Job type identifier, e.g., “homo_abinit”
connections (dict[str, tuple[str | JobController, str] | list[tuple[str | JobController, str]]]) – Initial input connections. Each key is an input name and each value is a (job, output name) tuple. Defaults to {}
params (dict[str, Any], optional) – Specify parameter values. Defaults to {}.
title (str, optional) – Job title. Defaults to “”.
desc (str, optional) –
Job Markdown description. Defaults to “”.
- Returns:
created job accessor object.
- Return type:
- Raises:
APIError – Job cannot be created or connected.
Examples
Create an Import Movies job.
>>> from cryosparc.tools import CryoSPARC >>> cs = CryoSPARC("http://localhost:61000") >>> import_job = cs.create_job("P3", "W1", "import_movies") >>> import_job.set_param("blob_paths", "/bulk/data/t20s/*.tif") True
Create a 3-class ab-initio job connected to existing particles.
>>> abinit_job = cs.create_job("P3", "W1", "homo_abinit" ... connections={"particles": ("J20", "particles_selected")} ... params={"abinit_K": 3} ... )
- create_project(parent_path: str | PurePosixPath, title: str, desc: str | None = None) ProjectController#
Start a new empty project. Creates new subfolder in the parent directory with a generated name based on the provided title.
- Parameters:
parent_path (str | Path) – Absolute path to create project in, e.g.
/home/user/cryosparc-projects. If the CryoSPARC instance is hosted remotely, this should be a path available on the server file system.title (str) – Title of new project.
desc (str, optional) –
Markdown text description. Defaults to None.
- Returns:
created project accessor object
- Return type:
- Raises:
APIError – Project cannot be created.
- create_workspace(project_uid: str, title: str, desc: str | None = None) WorkspaceController#
Create a new empty workspace in a project.
- download(project_uid: str, path: str | PurePosixPath)#
Open a file in a project for reading. Use to get files from a remote CryoSPARC instance whose project directories are not available on the file system where this script runs.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
path (str | Path) – Name or path of file in project directory.
- Yields:
BinaryIteratorIO –
- Use a context manager to read the file from the
request body.
Examples
Download a job’s metadata
>>> cs = CryoSPARC("http://localhost:61000") >>> with cs.download('P3', 'J42/job.json') as res: >>> job_data = json.loads(res.read())
- download_asset(fileid: str, target: str | PurePath) Path#
- download_asset(fileid: str, target: IO[bytes]) IO[bytes]
Download the asset with the given ID from the database.
- Parameters:
fileid (str) – GridFS file object ID
target (str | Path | IO) – Local file path or writeable file handle to write response data.
- Returns:
resulting target path or file handle.
- Return type:
Path | IO
- download_dataset(project_uid: str, path: str | PurePosixPath) Dataset#
Download a .cs dataset file from a project directory.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”.
path (str | Path) – Path to .cs file in project directory.
- Returns:
Loaded dataset instance
- Return type:
- download_file(project_uid: str, path: str | PurePosixPath) Path#
- download_file(project_uid: str, path: str | PurePosixPath, target: str | PurePath) Path
- download_file(project_uid: str, path: str | PurePosixPath, target: IO[bytes]) IO[bytes]
Download a file from a project directory to a target path or writeable file handle.
Use to get files from a remote CryoSPARC instance whose project directories are not available on the file system where this script runs.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”.
path (str | Path) – Name or path of file in project directory.
target (str | Path | IO, optional) – Local file path, directory path or writeable file handle to write response data. If not specified, downloads to current working directory with a similar file name. Defaults to “”.
- Returns:
resulting target path or file handle.
- Return type:
Path | IO
- download_mrc(project_uid: str, path: str | PurePosixPath) Tuple[mrc.Header, NDArray]#
Download a .mrc file from a project directory.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
path (str | Path) – Name or path to .mrc file in project directory.
- Returns:
MRC file header and data as a numpy array
- Return type:
tuple[Header, NDArray]
- find_external_job(project_uid: str, job_uid: str) ExternalJobController#
Get an External job by its unique project and job ID. External jobs may be used to save custom results from external tools or scripts to a CryoSPARC project.
- Parameters:
project_uid (str) – Project unique ID, e.g,. “P3”
job_uid (str) – Job unique ID, e.g,. “J42”
- Raises:
APIError – External job does not exist or cannot be accessed.
TypeError – If job is not an external job
- Returns:
external job accessor object
- Return type:
- find_job(project_uid: str, job_uid: str) JobController#
Get a job by its unique project and job ID.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
job_uid (str) – job unique ID, e.g., “J42”
- Returns:
job accessor object
- Return type:
- find_jobs(project_uid: str | List[str] | None = None, workspace_uid: str | List[str] | None = None, *, order: Literal[1, -1] = 1, **search: Unpack[JobSearch]) Iterable[JobController]#
Search for jobs.
Example
>>> jobs = cs.find_jobs("P3", "W3") >>> jobs = cs.find_jobs(["P42", "P43"]) >>> jobs = cs.find_jobs( ... type="homo_reconstruct", ... completed_at=(datetime(2025, 3, 1), datetime(2025, 3, 31)), ... order=-1, ... ) >>> for job in jobs: ... print(job.uid)
- Parameters:
project_uid (str | list[str] | None) – Project unique ID, e.g., “P3”. If not specified, returns jobs from all projects. Defaults to None.
workspace_uid (str | list[str] | None) – Workspace unique ID, e.g., “W1”. If not specified, returns jobs from all workspaces. Defaults to None.
order (int, optional) – Sort order for resulting jobs, 1 for ascending, -1 for descending. Defaults to 1.
**search (JobSearch) – Additional search parameters to filter jobs, specified as keyword arguments.
- Returns:
job accessor objects
- Return type:
Iterable[JobController]
- find_project(project_uid: str) ProjectController#
Get a project by its unique ID.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
- Returns:
project accessor object
- Return type:
- Raises:
APIError – project not found or cannot be accessed.
- find_projects(*, order: Literal[1, -1] = 1) Iterable[ProjectController]#
Search for projects available to the current user.
- Parameters:
order (int, optional) – Sort order for resulting projects, 1 for ascending, -1 for descending. Defaults to 1.
- Returns:
project accessor objects
- Return type:
Iterable[ProjectController]
- find_workspace(project_uid: str, workspace_uid: str) WorkspaceController#
Find a workspace in a project by its unique ID.
- Parameters:
project_uid (str) – Project unique ID, e.g,. “P3”
workspace_uid (str) – Workspace unique ID, e.g., “W1”
- Returns:
workspace accessor object
- Return type:
- Raises:
APIError – Workspace does not exist or cannot be accessed.
- find_workspaces(project_uid: str | List[str] | None = None, *, order: Literal[1, -1] = 1) Iterable[WorkspaceController]#
Search for workspaces.
- Parameters:
project_uid (str | list[str] | None) – Project unique ID, e.g., “P3”. If not specified, returns workspaces from all projects.
order (int, optional) – Sort order for resulting workspaces, 1 for ascending, -1 for descending. Defaults to 1.
- Returns:
workspace accessor objects
- Return type:
Iterable[WorkspaceController]
- get_job_sections() List[JobSection]#
(Deprecated) Get a summary of job types available for this instance, organized by category.
- Returns:
- List of job section dictionaries. Job types
are listed in the
"contains"key in each dictionary.
- Return type:
list[JobSection]
- get_lanes() List[SchedulerLane]#
Find registered scheduled lanes that jobs may be queued to.
- Returns:
Details about available lanes.
- Return type:
list[SchedulerLane]
- get_targets(lane: str | None = None) List[SchedulerTarget]#
Find a list of connected worker node or cluster targets that jobs may be queued to.
- Parameters:
lane (str, optional) – Only get targets in the lane with this name. Returns all targets if not specified. Defaults to None.
- Returns:
Details about available targets.
- Return type:
list[SchedulerTarget]
- import_job(project_uid: str, workspace_uid: str, path: str | PurePosixPath, *, wait: bool = False) JobController#
Import a job into a project workspace from a location on disk.
The exported job directory must be copied into the target project directory with all its symbolic links resolved. By convention, the exported job directory should be located in the project directory →
importssubfolder.The resulting job will be in an “importing” state until CryoSPARC verifies its contents and outputs. Set
wait=Trueto block until the job is ready to use.- Parameters:
project_uid (str) – Project UID to import in, e.g., “P3”
workspace_uid (str) – Workspace UID to import job in, e.g., “W1”
path (str | Path) – Path to job directory, must be in the project directory. If the CryoSPARC instance is hosted remotely, this should be a path available on the server file system. e.g.,
"/projects/CS-project/imports/jobs/J134_homo_abinit"or"imports/jobs/J134_homo_abinit"wait (bool, optional) – If True, wait until job import is complete before returning. Defaults to False.
- Returns:
importing or imported job accessor object
- Return type:
- Raises:
- property job_register: JobRegister#
Information and metadata about job types available in this instance.
- list_assets(project_uid: str, job_uid: str) List[GridFSFile]#
Find files available in the database for a job.
Each entry is the resulting list an object with an
idkey. Useidto download the file withdownload_asset().- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
job_uid (str) – job unique ID, e.g., “J42”
- Returns:
Asset details
- Return type:
list[GridFSFile]
- list_files(project_uid: str, prefix: str | PurePosixPath = '', recursive: bool = False) List[str]#
List files in a project directory.
Note that enabling
recursiveincludes both subdirectories and their files in the list.- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”.
prefix (str | Path, optional) – Subfolder inside project to list. Defaults to “”.
recursive (bool, optional) – If True, include files in all subfolders. Defaults to False.
- Returns:
List of file paths relative to the project directory.
- Return type:
list[str]
- mkdir(project_uid: str, target_path: str | PurePosixPath, parents: bool = False, exist_ok: bool = False) None#
Create a subfolder in a project directory.
- Parameters:
project_uid (str) – Target project unique ID
target_path (str | Path) – Name or path of folder to create inside the project directory.
parents (bool, optional) – If True, any missing parents are created as needed. Defaults to False.
exist_ok (bool, optional) – If True, does not raise an error for existing directories. Still raises if the target path is not a directory. Defaults to False.
- print_job_types(category: Literal['import', 'motion_correction', 'ctf_estimation', 'exposure_curation', 'particle_picking', 'extraction', 'deep_picker', 'particle_curation', 'reconstruction', 'refinement', 'ctf_refinement', 'variability', 'flexibility', 'postprocessing', 'local_refinement', 'helix', 'utilities', 'simulations', 'live', 'instance_testing', 'workflows'] | Container[Literal['import', 'motion_correction', 'ctf_estimation', 'exposure_curation', 'particle_picking', 'extraction', 'deep_picker', 'particle_curation', 'reconstruction', 'refinement', 'ctf_refinement', 'variability', 'flexibility', 'postprocessing', 'local_refinement', 'helix', 'utilities', 'simulations', 'live', 'instance_testing', 'workflows']] | None = None, *, show_legacy: bool = False)#
Print a table of job types and their titles, organized by category.
- Parameters:
category (Category | list[Category], optional) – Only show jobs from this category or list of categories. Defaults to None.
show_legacy (bool, optional) – If True, also show legacy jobs. Defaults to False.
- save_external_result(project_uid: str, workspace_uid: str | None, dataset: Dataset[R], type: Literal['exposure', 'particle', 'template', 'volume', 'volume_multi', 'mask', 'live', 'ml_model', 'symmetry_candidate', 'flex_mesh', 'flex_model', 'hyperparameter', 'denoise_model', 'annotation_model'], name: str | None = None, slots: List[str | Slot | Datafield] | None = None, passthrough: Tuple[str, str] | None = None, title: str = '', desc: str = '', image: str | PurePath | IO[bytes] | Any | None = None, savefig_kw: dict = {'bbox_inches': 'tight', 'pad_inches': 0}) str#
Save a result dataset to a project, via External Job. Specify at least the dataset to save and the type of data.
If neither
workspace_uidnorpassthroughare specified, saves result to the project’s newest workspace. Ifpassthroughis specified butworkspace_uidis not, saves to the passthrough job’s newest workspace.Examples
Save all particle data
>>> particles = Dataset() >>> cs.save_external_result("P1", "W1", particles, 'particle') "J43"
Save new particle locations that inherit passthrough slots from a parent job.
>>> particles = Dataset() >>> cs.save_external_result( ... project_uid="P1", ... workspace_uid="W1", ... dataset=particles, ... type='particle', ... name='particles', ... slots=['location'], ... passthrough=('J42', 'selected_particles'), ... title='Re-centered particles' ... ) "J44"
Save a result with multiple slots of the same type.
>>> cs.save_external_result( ... project_uid="P1", ... workspace_uid="P1", ... dataset=particles, ... type="particle", ... name="particle_alignments", ... slots=[ ... {"dtype": "alignments3D", "name": "alignments_class_0"}, ... {"dtype": "alignments3D", "name": "alignments_class_1"}, ... {"dtype": "alignments3D", "name": "alignments_class_2"}, ... ] ... ) "J45"
- Parameters:
project_uid (str) – Project UID to save results into.
workspace_uid (str | None) – Workspace UID to save results into. Specify
Noneto auto-select a workspace.dataset (Dataset) – Result dataset.
type (Datatype) – Type of output dataset.
name (str, optional) – Name of output on created External job. Same as type if unspecified. Defaults to None.
slots (list[SlotSpec], optional) – List of slots expected to be created for this output such as
locationorblob. Do not specify any slots that were passed through from an input unless those slots are modified in the output. Defaults to None.passthrough (tuple[str, str], optional) – Indicates that this output inherits slots from the specified output. e.g.,
("J1", "particles"). Defaults to None.title (str, optional) – Human-readable title for this output. Defaults to “”.
desc (str, optional) –
Markdown description for this output. Defaults to “”.
image (str | Path | IO | Figure, optional) – Optional image file or matplotlib Figure to set as the image for this output. Defaults to None.
savefig_kw (dict, optional) – Additional keyword arguments to pass to
figure.savefig()when saving matplotlib Figures. Defaults todict(bbox_inches="tight", pad_inches=0).
- Raises:
APIError – Output could not be created.
- Returns:
UID of External job where output was saved
- Return type:
str
- symlink(project_uid: str, source_path: str | PurePosixPath, target_path: str | PurePosixPath = '') None#
Create a symbolic link in a project directory. May only create links to files or folders the user is authorized to access by an administrator.
- Parameters:
project_uid (str) – Target project UID, e.g., “P3”.
source_path (str | Path) – Relative or absolute path of source file or folder to create a link to. If relative, assumed to be within the project directory.
target_path (str | Path) – Name or path of new symlink in the project directory. If not specified, creates link with the same file name as the source. Defaults to “”.
- test_connection()#
Verify connection to CryoSPARC.
- Returns:
True if connection succeeded, False otherwise
- Return type:
bool
- upload(project_uid: str, target_path: str | PurePosixPath, source: str | PurePath | IO | Buffer | Stream, *, overwrite: bool = False) None#
Upload a file to a project directory.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
target_path (str | Path) – Name or path of file to write in the project directory.
source (str | Path | IO | Buffer | Stream) – Local path or file handle to upload. May also specified as raw bytes.
overwrite (bool, optional) – If True, overwrite existing files. If False, raises error on existing files. Defaults to False.
- upload_dataset(project_uid: str, target_path: str | PurePosixPath, dset: Dataset, *, format: int = 1, overwrite: bool = False) None#
Upload a dataset as a .cs file into a project directory.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
target_path (str | Path) – Name or path of dataset to save in the project directory. Should have a
.csextension.dset (Dataset) – dataset to save.
format (int) – Format to save in from
cryosparc.dataset.*_FORMAT, defaults to NUMPY_FORMAT)overwrite (bool, optional) – If True, overwrite existing files. If False, raises error on existing files. Defaults to False.
- upload_mrc(project_uid: str, target_path: str | PurePosixPath, data: NDArray, psize: float, *, overwrite: bool = False) None#
Upload a numpy 2D or 3D array to a project directory as an MRC file.
- Parameters:
project_uid (str) – Project unique ID, e.g., “P3”
target_path (str | Path) – Name or path of MRC file to save in the project directory. Should have a
.mrcextension.data (NDArray) – Numpy array with MRC file data.
psize (float) – Pixel size to include in MRC header.
overwrite (bool, optional) – If True, overwrite existing files. If False, raises error on existing files. Defaults to False.
- LICENSE_REGEX = re.compile('[a-f\\d]{8}-[a-f\\d]{4}-[a-f\\d]{4}-[a-f\\d]{4}-[a-f\\d]{12}')#
Regular expression for matching CryoSPARC license IDs.
- SUPPORTED_EXPOSURE_FORMATS = {'CMRCBZ2', 'EER', 'MRC', 'MRCBZ2', 'MRCS', 'TIFF'}#
Supported micrograph file formats.
- VERSION_REGEX = re.compile('^v\\d+\\.\\d+\\.\\d+')#
Regular expression for CryoSPARC minor version, e.g., ‘v4.1.0’
- downsample(arr: NDArray, factor: int = 2)#
Downsample a micrograph or movie.
- Parameters:
arr (NDArray) – 2D or 3D numpy array factor (int, optional): How much to reduce size by. e.g., a factor of 2 would reduce a 1024px MRC to 512px, and a factor of 3 would reduce it to 256px. Defaults to 2.
- Returns:
Downsampled MRC file
- Return type:
NDArray
- get_exposure_format(data_format: str, voxel_type: str | None = None) str#
Get the
movie_blob/formatormicrograph_blobformat value for an exposure type, wheredata_formatis one of“MRC”
“MRCS”
“TIFF”
“CMRCBZ2”
“MRCBZ2”
“EER”
And
voxel_type(if specified) is one of“16 BIT FLOAT”:
“32 BIT FLOAT”
“SIGNED 16 BIT INTEGER”
“UNSIGNED 8 BIT INTEGER”
“UNSIGNED 16 BIT INTEGER”
- Parameters:
data_format (str) – One of
SUPPORTED_EXPOSURE_FORMATSsuch as"TIFF"or"MRC". The value of the<dataFormat>tag in an EPU XML file.voxel_type (str, optional) – The value of the
<voxelType>tag in an EPU file such as"32 BIT FLOAT". Required whendata_formatisMRCorMRCS. Defaults to None.
- Returns:
- The format string to save into the
{prefix}/formatfield of a CryoSPARC exposure dataset. e.g.,
"TIFF"or"MRC/2"
- The format string to save into the
- Return type:
str
- get_import_signatures(abs_paths: str | Iterable[str] | NDArray) List[int]#
Get list of import signatures for a path or list of paths.
- Parameters:
abs_paths (str | Iterable[str] | NDArray) – Absolute path or list of file paths.
- Returns:
Import signatures as 64-bit numpy integers
- Return type:
list[int]
- lowpass2(arr: NDArray, psize_A: float, cutoff_resolution_A: float = 0.0, order: float = 1.0)#
Apply butterworth lowpass filter to the 2D array data with the given pixel size (
psize_A).cutoff_resolution_Ashould be a non-negative number specified in Angstroms.- Parameters:
arr (NDArray) – 2D numpy array to apply lowpass to.
psize_A (float) – Pixel size of array data.
cutoff_resolution_A (float, optional) – Cutoff resolution, in Angstroms. Defaults to 0.0.
order (float, optional) – Filter order. Defaults to 1.0.
- Returns:
Lowpass-filtered copy of given numpy array
- Return type:
NDArray
- Raises:
ValueError – Not a 2D array or cutoff resolution is not positive.