Acquisition Formats
The copick.ops.acquisition module imports tilt series, alignments and CTF fits from the files of AreTomo3, Warp,
RELION 5, IMOD, CTFFIND4 and SerialEM, and exports them to these formats. copick.util.acquisition_formats reads the
files, maps their rows to tilt-series sections and converts alignments between the tools' frames and copick's CETS
frame (see Geometry).
Import
copick.ops.acquisition.add_tilt_series_from_file
add_tilt_series_from_file(root: CopickRoot, run_name: str, ts_type: str, path: PathLike, file_type: Optional[str] = None, pixel_size: Optional[float] = None, angles: Optional[PathLike] = None, angles_format: Optional[str] = None, mdoc: Union[PathLike, str, None] = 'auto', ctf: Optional[PathLike] = None, ctf_format: Optional[str] = None, dose_per_tilt: Optional[float] = None, voltage: Optional[float] = None, spherical_aberration: Optional[float] = None, amplitude_contrast: Optional[float] = None, tilt_axis_angle: Optional[float] = None, handedness: Optional[str] = None, section_map: str = 'auto', angle_tolerance: float = DEFAULT_ANGLE_TOLERANCE, sort_by_angle: bool = False, is_aligned: bool = False, levels: int = TILT_SERIES_LEVELS, chunks: Tuple[int, int, int] = TILT_SERIES_CHUNKS, dtype: Optional[str] = 'float32', create: bool = True, overwrite: bool = False) -> CopickTiltSeries
Add a tilt series from a stack file and its acquisition metadata.
Parameters:
-
root(CopickRoot) –The copick project.
-
run_name(str) –The run.
-
ts_type(str) –Type of the tilt series (e.g.
raw). -
path(PathLike) –The stack (MRC
.mrc/.st/.mrcs/.ali, TIFF, or Zarr). -
file_type(Optional[str], default:None) –Format of the stack (
mrc,tiff,zarr). Default: from the extension. -
pixel_size(Optional[float], default:None) –Pixel size in Angstrom. Default: from the stack's header or the mdoc.
-
angles(Optional[PathLike], default:None) –Tilt-angle file in stack order (
.rawtlt,.tlt, AreTomo3_TLT.txt). -
angles_format(Optional[str], default:None) –Its format. Default: from its name.
-
mdoc(Union[PathLike, str, None], default:'auto') –SerialEM mdoc;
"auto"uses one next to the stack,Nonenone. -
ctf(Optional[PathLike], default:None) –CTF fits (AreTomo3
_CTF.txt, CTFFIND4, Warp XML, RELIONtomograms.star). -
ctf_format(Optional[str], default:None) –Their format. Default: from the file name.
-
dose_per_tilt(Optional[float], default:None) –Dose of every image in e/Ų, overriding the files.
-
voltage(Optional[float], default:None) –Acceleration voltage in kV.
-
spherical_aberration(Optional[float], default:None) –Spherical aberration in mm.
-
amplitude_contrast(Optional[float], default:None) –Amplitude contrast.
-
tilt_axis_angle(Optional[float], default:None) –Tilt-axis angle in degrees, overriding the mdoc.
-
handedness(Optional[str], default:None) –right_handedorleft_handed, if known. -
section_map(str, default:'auto') –How the mdoc's and CTF file's rows map to sections (see
copick.util.acquisition_formats). -
angle_tolerance(float, default:DEFAULT_ANGLE_TOLERANCE) –Largest difference in degrees between a row's angle and its section's nominal angle.
-
sort_by_angle(bool, default:False) –Store the sections in ascending nominal tilt angle.
-
is_aligned(bool, default:False) –Whether the images are already aligned.
-
levels(int, default:TILT_SERIES_LEVELS) –Number of pyramid levels.
-
chunks(Tuple[int, int, int], default:TILT_SERIES_CHUNKS) –Chunk shape.
-
dtype(Optional[str], default:'float32') –Data type of the stored images (
None: that of the stack). -
create(bool, default:True) –Create the run if it does not exist.
-
overwrite(bool, default:False) –Replace the images of an existing tilt series.
Returns:
-
CopickTiltSeries(CopickTiltSeries) –The tilt series.
copick.ops.acquisition.add_alignment_from_file
add_alignment_from_file(root: CopickRoot, run_name: str, path: PathLike, fmt: str, ts_type: str, name: Optional[str] = None, tomo_name: Optional[str] = None, native_pixel_size: Optional[float] = None, volume_size: Optional[Sequence[int]] = None, thickness: Optional[int] = None, reference_tomogram: Optional[str] = None, link_tomograms: Sequence[str] = (), preferred: bool = False, ctf: Optional[PathLike] = None, ctf_format: Optional[str] = None, tlt: Optional[PathLike] = None, update_tilt_series: bool = True, section_map: str = 'auto', angle_tolerance: float = DEFAULT_ANGLE_TOLERANCE, assume_frame: Optional[str] = None, rigid_only: bool = False, allow_varying_grids: bool = False, overwrite: bool = False) -> CopickAlignment
Add an alignment of a tilt series from a tool's files.
Parameters:
-
root(CopickRoot) –The copick project.
-
run_name(str) –The run.
-
path(PathLike) –The alignment: AreTomo3
.aln, Warp tilt-series XML, RELIONtomograms.staror IMOD basename. -
fmt(str) –aretomo3,warp,relionorimod. -
ts_type(str) –The tilt series it aligns.
-
name(Optional[str], default:None) –Name of the alignment. Default: the format.
-
tomo_name(Optional[str], default:None) –The tomogram of a RELION file listing several. Default: the run name, if the file lists several.
-
native_pixel_size(Optional[float], default:None) –Pixel size of the stack the tool aligned, if not that of the tilt series.
-
volume_size(Optional[Sequence[int]], default:None) –Size
(x, y, z)of the tool's reconstruction in pixels, overriding the files. -
thickness(Optional[int], default:None) –Thickness of the tool's reconstruction in pixels, overriding the files.
-
reference_tomogram(Optional[str], default:None) –URI (
tomo_type@voxel_size) of the tomogram the tool reconstructed with this alignment; it becomes the reference volume and is linked. -
link_tomograms(Sequence[str], default:()) –URIs of further tomograms reconstructed with this alignment.
-
preferred(bool, default:False) –Prefer this alignment over the tilt series' others.
-
ctf(Optional[PathLike], default:None) –CTF fits to store on the tilt series (AreTomo3
_CTF.txt, ...). -
ctf_format(Optional[str], default:None) –Their format. Default: from the file name.
-
tlt(Optional[PathLike], default:None) –AreTomo3
_TLT.txtwhose acquisition order and dose to store on the tilt series. -
update_tilt_series(bool, default:True) –Whether
ctfandtltare stored on the tilt series. -
section_map(str, default:'auto') –How the tool's rows map to sections.
-
angle_tolerance(float, default:DEFAULT_ANGLE_TOLERANCE) –Largest difference in degrees between a row's angle and its section's nominal angle.
-
assume_frame(Optional[str], default:None) –Centre convention (
halforfloor) of an IMOD alignment of odd-sized images. -
rigid_only(bool, default:False) –Import the rigid part of a local AreTomo3 alignment.
-
allow_varying_grids(bool, default:False) –Drop the spatially varying deformation of a Warp alignment.
-
overwrite(bool, default:False) –Replace an existing alignment of this name (its tomogram links are kept).
Returns:
-
CopickAlignment(CopickAlignment) –The alignment.
copick.ops.acquisition.add_ctf_from_file
add_ctf_from_file(root: CopickRoot, run_name: str, ts_type: str, path: PathLike, ctf_format: Optional[str] = None, section_map: str = 'auto', angle_tolerance: float = DEFAULT_ANGLE_TOLERANCE, tomo_name: Optional[str] = None) -> CopickTiltSeries
Set the CTF fits of a tilt series from a file.
Raises:
-
PermissionError–If the tilt series is read-only (changing static metadata is not supported yet).
Export
copick.ops.acquisition.export_tilt_series
export_tilt_series(tilt_series: CopickTiltSeries, output_dir: PathLike, output_format: str = 'mrc', level: int = 0, angles: Optional[str] = 'rawtlt', ctf_format: Optional[str] = None, basename: Optional[str] = None) -> List[Path]
Export a tilt series as a stack, with its tilt angles and CTF fits.
Parameters:
-
tilt_series(CopickTiltSeries) –The tilt series.
-
output_dir(PathLike) –Directory to write to.
-
output_format(str, default:'mrc') –mrc,tifforzarr. -
level(int, default:0) –Pyramid level of the stack (
mrc,tiff). -
angles(Optional[str], default:'rawtlt') –Angle file to write:
rawtlt,tlt,aretomo3-tltorNone. -
ctf_format(Optional[str], default:None) –CTF file to write:
aretomo3,ctffind4orNone. -
basename(Optional[str], default:None) –Base name of the files. Default: the run name.
Returns:
-
List[Path]–The written paths.
copick.ops.acquisition.export_alignment
export_alignment(alignment: CopickAlignment, output_dir: PathLike, output_format: str, reference_tomogram: Optional[CopickTomogram] = None, include_ctf: bool = False, drop_x_tilt: bool = False, hand: float = -1.0, relion_tomo_name: Optional[str] = None, assume_frame: Optional[str] = None, basename: Optional[str] = None, amplitude_contrast: Optional[float] = None) -> Union[List[Path], Any]
Export an alignment in a tool's format.
Parameters:
-
alignment(CopickAlignment) –The alignment.
-
output_dir(PathLike) –Directory to write to.
-
output_format(str) –aretomo3(.aln+_TLT.txt),warp(tilt-series XML),relion,imod(.xf,.tlt,.xtilt,tilt.com,newst.comin<output_dir>/<basename>/) orcdp(CryoET Data Portal alignment JSON). -
reference_tomogram(Optional[CopickTomogram], default:None) –Tomogram the tool should reconstruct; default: the alignment's reference volume.
-
include_ctf(bool, default:False) –Also write the CTF fits (AreTomo3
_CTF.txt, Warp grids, RELION columns). -
drop_x_tilt(bool, default:False) –Drop the tilt about x, which AreTomo3 cannot represent.
-
hand(float, default:-1.0) –RELION
rlnTomoHand. -
relion_tomo_name(Optional[str], default:None) –RELION
rlnTomoName. Default: the run name. -
assume_frame(Optional[str], default:None) –Centre convention for IMOD with odd sizes.
-
basename(Optional[str], default:None) –Base name of the files. Default: the run name.
-
amplitude_contrast(Optional[float], default:None) –RELION amplitude contrast if the tilt series has none (default 0.07).
Returns:
-
Union[List[Path], Any]–The written paths, or for
reliontheRelionAlignmentto write (seewrite_relion_alignments).
copick.ops.acquisition.export_alignments
export_alignments(root: CopickRoot, alignment_uri: str, output_dir: PathLike, output_format: str, run_names: Optional[Sequence[str]] = None, reference_tomogram: Optional[str] = None, **kwargs) -> List[Path]
Export the alignments a URI selects, from all or some runs.
RELION alignments are written to one tomograms.star in output_dir, each run's under its own name.
Parameters:
-
root(CopickRoot) –The copick project.
-
alignment_uri(str) –Alignments to export (e.g.
aretomo3or*@raw?default=true). -
output_dir(PathLike) –Directory to write to.
-
output_format(str) –aretomo3,warp,relion,imodorcdp. -
run_names(Optional[Sequence[str]], default:None) –Runs to export. Default: all.
-
reference_tomogram(Optional[str], default:None) –URI of each run's tomogram the tool should reconstruct.
-
**kwargs–Passed to
export_alignment.
Returns:
-
List[Path]–The written paths.
copick.ops.acquisition.export_ctf
export_ctf(tilt_series: CopickTiltSeries, output_dir: PathLike, fmt: str = 'aretomo3', basename: Optional[str] = None) -> Path
Export the CTF fits of a tilt series as an AreTomo3 _CTF.txt or a CTFFIND4 file.
copick.ops.acquisition.write_relion_alignments
Write RELION alignments of several tomograms as one tomograms.star and tilt_series/<name>.star each.
Formats
copick.util.acquisition_formats.open_stack
Open a stack of tilt images for reading.
MRC files (.mrc, .st, .mrcs, .ali) are memory-mapped, so sections are read as they are used. TIFF
files are read whole. A Zarr store is read at its first OME-Zarr level, or as a plain array.
Yields:
-
Stack(Stack) –The images
(section, y, x)and the header pixel size in Angstrom (Noneif unknown).
copick.util.acquisition_formats.read_angles
Read a tilt-angle file: IMOD .rawtlt/.tlt or AreTomo3 _TLT.txt (with acquisition order and dose).
copick.util.acquisition_formats.read_mdoc
Read a SerialEM tilt-series mdoc.
Parameters:
-
path(str) –The mdoc.
-
dose_per_tilt(Optional[float], default:None) –Dose of every image in e/Ų, overriding the file's.
Returns:
-
AcquisitionTable(AcquisitionTable) –One row per
[ZValue]section, keyed byZValue.
copick.util.acquisition_formats.read_ctf
read_ctf(path: str, fmt: str, pixel_size: Optional[float] = None, tomo_name: Optional[str] = None) -> CtfTable
Read per-image CTF fits.
Parameters:
-
path(str) –The file: an AreTomo3
_CTF.txt, a CTFFIND4 output.txt, a Warp tilt-series XML or a RELIONtomograms.star. -
fmt(str) –aretomo3,ctffind4,warporrelion. -
pixel_size(Optional[float], default:None) –Pixel size of a Warp tilt series, if its XML does not record one.
-
tomo_name(Optional[str], default:None) –The tomogram of a RELION file listing several.
Returns:
-
CtfTable(CtfTable) –The fits in canonical form (
u >= vin Angstrom, angle in [0, 180) degrees, phase in degrees).
copick.util.acquisition_formats.read_native_alignment
read_native_alignment(path: str, fmt: str, pixel_size: Optional[float] = None, tomo_name: Optional[str] = None, image_size: Optional[Tuple[int, int]] = None, rigid_only: bool = False, allow_varying_grids: bool = False) -> NativeAlignment
Read an alignment in a tool's format.
Parameters:
-
path(str) –The
.aln(AreTomo3), tilt-series XML (Warp),tomograms.star(RELION) or basename /.xf(IMOD, with.tlt, optional.xtiltandtilt.comnext to it). -
fmt(str) –aretomo3,warp,relionorimod. -
pixel_size(Optional[float], default:None) –Pixel size of the stack the tool aligned, if not that of the tilt series (Warp: overrides its XML).
-
tomo_name(Optional[str], default:None) –The tomogram of a RELION file listing several.
-
image_size(Optional[Tuple[int, int]], default:None) –Image size
(width, height), needed for RELION files with projection matrices. -
rigid_only(bool, default:False) –Keep the rigid part of a local (patch) AreTomo3 alignment.
-
allow_varying_grids(bool, default:False) –Drop the spatially varying deformation of a Warp alignment.
Raises:
-
ValueError–If the alignment is local and its loss is not allowed, or the files are inconsistent.
copick.util.acquisition_formats.map_rows
map_rows(n_sections: int, angles: Optional[Sequence[float]], mode: str, nominal: Optional[Sequence[Optional[float]]] = None, tolerance: float = DEFAULT_ANGLE_TOLERANCE, keys: Optional[Sequence[int]] = None, what: str = 'rows', refined: bool = False, n_rows: Optional[int] = None) -> List[int]
The tilt-series section of each row of a file.
Parameters:
-
n_sections(int) –Number of sections of the tilt series.
-
angles(Optional[Sequence[float]]) –Tilt angle of each row, if the file has them; rows without are taken to be in ascending angle.
-
mode(str) –index,sortedorangle(see the module documentation). -
nominal(Optional[Sequence[Optional[float]]], default:None) –Nominal tilt angle of each section, if known.
-
tolerance(float, default:DEFAULT_ANGLE_TOLERANCE) –Largest difference in degrees between a row's angle and the nominal tilt angle of its section.
-
keys(Optional[Sequence[int]], default:None) –Section each row names (
indexmode). -
what(str, default:'rows') –Name of the rows in messages.
-
refined(bool, default:False) –Whether the rows' angles may be refined; a mismatch is then only reported.
-
n_rows(Optional[int], default:None) –Number of rows, for files with neither angles nor keys.
Returns:
-
List[int]–The section of each row.
Raises:
-
ValueError–If the rows cannot be mapped, or the mapping contradicts the nominal tilt angles.
copick.util.acquisition_formats.native_to_copick
native_to_copick(native: NativeAlignment, metadata: CopickTiltSeriesMetadata, reference: CopickReferenceVolume, section_map: str = 'auto', tolerance: float = DEFAULT_ANGLE_TOLERANCE, assume_frame: Optional[CenterKind] = None, n_sections: Optional[int] = None) -> ImportedAlignment
Map an alignment to the sections of a tilt series and convert it to copick's CETS frame.
Parameters:
-
native(NativeAlignment) –The alignment.
-
metadata(CopickTiltSeriesMetadata) –Metadata of the tilt series.
-
reference(CopickReferenceVolume) –Its reference volume (see
native_reference). -
section_map(str, default:'auto') –How the tool's rows map to sections (see the module documentation).
-
tolerance(float, default:DEFAULT_ANGLE_TOLERANCE) –Largest difference in degrees between a row's angle and the nominal angle of its section.
-
assume_frame(Optional[CenterKind], default:None) –Centre convention of an IMOD alignment of odd-sized images or volumes.
-
n_sections(Optional[int], default:None) –Number of sections of the tilt series (default: that of the metadata).
copick.util.acquisition_formats.copick_to_native
copick_to_native(file: CopickAlignmentFile, metadata: CopickTiltSeriesMetadata, source_format: str, n_sections: int, reference: Optional[CopickReferenceVolume] = None, reference_offset: Optional[Sequence[float]] = None, sort_by_angle: bool = True, drop_x_tilt: bool = False, assume_frame: Optional[CenterKind] = None) -> ExportedAlignment
Convert a copick alignment to a tool's frame and row order.
Parameters:
-
file(CopickAlignmentFile) –The alignment.
-
metadata(CopickTiltSeriesMetadata) –Metadata of its tilt series.
-
source_format(str) –The tool:
ARETOMO3,WARP,RELION,IMODorPORTAL. -
n_sections(int) –Number of sections of the tilt series.
-
reference(Optional[CopickReferenceVolume], default:None) –The volume the tool should reconstruct (default: the alignment's reference volume).
-
reference_offset(Optional[Sequence[float]], default:None) –Offset of
referencefrom the alignment's reference volume (seerebase_sections). -
sort_by_angle(bool, default:True) –Order the rows by ascending nominal tilt angle (else by section).
-
drop_x_tilt(bool, default:False) –Set the tilt about x to zero, for tools that cannot represent it.
-
assume_frame(Optional[CenterKind], default:None) –Centre convention for IMOD with odd sizes.
Raises:
-
ValueError–If the alignment has no reference volume or its tilt series no images.
copick.util.acquisition_formats.rebase_sections
rebase_sections(file: CopickAlignmentFile, reference: CopickReferenceVolume, reference_offset: Optional[Sequence[float]] = None) -> List[CopickSectionAlignment]
The sections of an alignment with another reference volume.
Positions p of the new reference relate to those of the old one as p_old = p + o, so the shifts become
t + (R @ o)[:2]. Without reference_offset, the two volumes share their centre in the alignment's native
convention, as copick assumes for tomograms reconstructed with an alignment (see CopickAlignment.project).
Parameters:
-
file(CopickAlignmentFile) –The alignment.
-
reference(CopickReferenceVolume) –The new reference volume.
-
reference_offset(Optional[Sequence[float]], default:None) –oin Angstrom, from the new reference's CETS centre to the old one's.