4d — Export images for cryoSPARC

Export scripts · 4d User Manual

← Back to Export, Stats & Notifications

Export 4D-STEM images for cryoSPARC processing

This script (export/standard/10_ExportImages.script) collects the reconstructed images from every dataset in the project and writes them, together with their metadata, into a folder structure compatible with cryoSPARC's Import Movies function. Images are exported as MRC files and the per-image metadata is written into a STAR file, so 4D-STEM reconstructions can be taken straight into cryoSPARC for further single-particle processing. It is the Export section's main hand-off step.

Purpose

For each image directory in the project it copies the chosen reconstruction outputs (bright-field, dark-field, parallax, shadow, ptychography) into a tidy, per-type folder layout under one export directory, renaming each file after its original micrograph, and builds a metadata STAR file listing every exported image with its voltage, aberration, defocus and dose.

Parameters

ParameterRole
export_doitMaster switch. y actually performs the export; n only simulates it (a dry run that reports what would be copied).
export_basedirThe directory the export is written into (created if missing).
export_h5file_doitAlso copy the raw HDF5 stack of each dataset into an HDF5_Stacks/ subdirectory.
export_reconstruction_brightfieldExport the bright-field image (fd_BF_image.mrc).
export_reconstruction_darkfieldExport the dark-field image (fd_DF_image.mrc).
export_reconstruction_parallax_py4dstemExport the py4DSTEM parallax reconstruction (parallax_output_upsampled.mrc).
export_reconstruction_parallax_torchsliceExport the Torchslice parallax reconstruction (parallax.mrc).
export_reconstruction_shadowExport the shadow image (shadow_image.mrc).
export_reconstruction_ptycho_py4dstemExport the py4DSTEM ptychography result.
export_reconstruction_ptycho_ptychobonesExport the PtychoBones ptychography result.
export_reconstruction_ptycho_torchsliceExport the Torchslice ptychography result.
export_metadata_doitWrite the micrographs_4d.star metadata file (voltage, Cs, defocus, doses per image).
Each reconstruction toggle is a y/n switch — turn on only the reconstruction types you actually produced. With export_doit = n the whole run is a simulation, handy for checking the file mapping before copying anything.

Algorithm

  1. Ensures export_basedir exists and creates the HDF5_Stacks/ subdirectory; if metadata export is on, removes any previous micrographs_4d.star.
  2. Reads the project's list of image directories (4d_merge_dirfile.dat) and loops over each. For every dataset it fetches the per-image parameters from the central project database (merge/4d_project.db): the raw-stack name, KV, CS, the parallax defocus, and the frame/total dose (missing values default to 0). The output file names are derived from the original micrograph name.
  3. For each enabled reconstruction type it calls the helper 4d_export_files.com, which copies that dataset's MRC file into a per-type subfolder of the export directory, renamed with a short prefix:
    TypeSourceExported as
    Bright-fieldfd_BF_image.mrcbrightfield/BF_<name>.mrc
    Dark-fieldfd_DF_image.mrcdarkfield/DF_<name>.mrc
    Parallax (py4DSTEM)parallax_output_upsampled.mrcparallax/ParPy_<name>.mrc
    Parallax (Torchslice)parallax.mrcparallax/ParTo_<name>.mrc
    Shadowshadow_image.mrcshadow/Shad_<name>.mrc
    Ptychography (py4DSTEM)ptycho_py4dstem.mrcptycho_py4dstem/PtyPy_<name>.mrc
    Ptychography (PtychoBones)ptycho_ptychobones.mrcptycho_ptychobones/PtyBo_<name>.mrc
    Ptychography (Torchslice)ptycho_torchslice.mrcptycho_torchslice/PtyTo_<name>.mrc
    The raw HDF5 stack is likewise copied into HDF5_Stacks/ when that toggle is on.
  4. If metadata export is on, it appends one row per image to micrographs_4d.star — columns _rln4dscanName, _rlnImage, _rlnVoltage, _rlnSphericalAberration, _rlnDefocus, _rlnFrameDose, _rlnTotalDose — writing the header first if the file is new.
  5. Reports progress and prints the full export path when finished.

Results

Data written — a cryoSPARC-ready folder under export_basedir:

The export directory and the STAR file are registered as important results, so they show in the Manual Processing Results / Images panel. In cryoSPARC, use Import Movies (or Import Micrographs) pointing at the exported MRC folder and micrographs_4d.star to continue processing.