Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2023 19:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PlethoraChutney/269c75ceebf632d028a5e8734545b513 to your computer and use it in GitHub Desktop.
Un-downsample a symmetry-expanded particle stack
from import CryoSPARC
import numpy as np
cs = CryoSPARC(
# you'll need env variables here, or just set stuff directly
# we will filter fullsize_particles so that only the intersection with
# downsampled particles are retained. ctf, alignments, etc. will all
# still come from fullsize_particles
# if you want alignments from the downsampled job, you have to change
# pixel size and scale the shifts, which we don't do here. It's not as
# simple as just changing the passthrough!
select_project = "P294"
select_workspace = "W2"
job_fullsize_particles = "J31"
job_downsampled_particles = "J34"
ds_particles = cs.find_job(select_project, job_downsampled_particles).load_output(
full_particles = cs.find_job(select_project, job_fullsize_particles).load_output(
# pseudoparticles are uniquely identified by the combination
# of their source UID and symmetry expansion index
full_particles.add_fields(["intersect_field"], ["str"])
full_particles["intersect_field"] = [
f"{r['sym_expand/src_uid']}.{r['sym_expand/idx']}" for r in full_particles.rows()
ds_particles.add_fields(["intersect_field"], ["str"])
ds_particles["intersect_field"] = [
f"{r['sym_expand/src_uid']}.{r['sym_expand/idx']}" for r in ds_particles.rows()
# this is a little slow --- lots of string comparisons
intersection = full_particles.query(
{"intersect_field": ds_particles["intersect_field"]}
passthrough=(job_fullsize_particles, "particles"),
title="Filtered Subset",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment