cryosparc.workspace#

Classes:

Workspace(cs, project_uid, uid)

Accessor class to a workspace in CryoSPARC with ability create jobs and save results.

class cryosparc.workspace.Workspace(cs: CryoSPARC, project_uid: str, uid: str)#

Accessor class to a workspace in CryoSPARC with ability create jobs and save results. Should be instantiated through CryoSPARC.find_workspace or Project.find_workspace.

uid#

Workspace unique ID, e.g., “W42”

Type:

str

project_uid#

Project unique ID, e.g., “P3”

Type:

str

doc#

All workspace data from the CryoSPARC database. Database contents may change over time, use the refresh method to update.

Type:

WorkspaceDocument

Methods:

create_external_job([title, desc])

Add a new External job to this workspace to save generated outputs to.

create_job(type[, connections, params, ...])

Create a new job with the given type.

refresh()

Reload this workspace from the CryoSPARC database.

save_external_result(dataset, type[, name, ...])

Save the given result dataset to a workspace.

create_external_job(title: str | None = None, desc: str | None = None) ExternalJob#

Add a new External job to this workspace to save generated outputs to.

Parameters:
  • workspace_uid (str) – Workspace UID to create job in, e.g., “W1”

  • title (str, optional) – Title for external job (recommended). Defaults to None.

  • desc (str, optional) – Markdown description for external job. Defaults to None.

Returns:

created external job instance

Return type:

ExternalJob

create_job(type: str, connections: Dict[str, Tuple[str, str] | List[Tuple[str, str]]] = {}, params: Dict[str, Any] = {}, title: str | None = None, desc: str | None = None) Job#

Create a new job with the given type. Use the CryoSPARC.get_job_sections method to query available job types on the connected CryoSPARC instance.

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, str] | list[tuple[str, str]]]) – Initial input connections. Each key is an input name and each value is a (job uid, output name) tuple. Defaults to {}

  • params (dict[str, any], optional) – Specify parameter values. Defaults to {}.

  • title (str, optional) – Job title. Defaults to None.

  • desc (str, optional) – Job markdown description. Defaults to None.

Returns:

created job instance. Raises error if job cannot be created.

Return type:

Job

Examples

Create an Import Movies job.

>>> from cryosparc.tools import CryoSPARC
>>> cs = CryoSPARC()
>>> workspace = cs.find_workspace("P3", "W3")
>>> import_job = workspace.create_job("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 = workspace.create_job("homo_abinit"
...     connections={"particles": ("J20", "particles_selected")}
...     params={"abinit_K": 3}
... )
refresh()#

Reload this workspace from the CryoSPARC database.

Returns:

self

Return type:

Workspace

save_external_result(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 | Datafield] | None = None, passthrough: Tuple[str, str] | None = None, title: str | None = None, desc: str | None = None) str#

Save the given result dataset to a workspace.

Parameters:
  • 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 location or blob. 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 None.

  • desc (str, optional) – Markdown description for this output. Defaults to None.

Returns:

UID of created job where this output was saved.

Return type:

str

Examples

Save all particle data

>>> particles = Dataset()
>>> workspace.save_external_result(particles, 'particle')
"J43"

Save new particle locations that inherit passthrough slots from a parent job

>>> particles = Dataset()
>>> workspace.save_external_result(
...     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.

>>> workspace.save_external_result(
...     dataset=particles,
...     type="particle",
...     name="particle_alignments",
...     slots=[
...         {"dtype": "alignments3D", "prefix": "alignments_class_0", "required": True},
...         {"dtype": "alignments3D", "prefix": "alignments_class_1", "required": True},
...         {"dtype": "alignments3D", "prefix": "alignments_class_2", "required": True},
...     ]
... )
"J45"