Redundant caching for particles re-imported from "Import result group"

Hi @ScientificWitchery ,

Currently you cannot use any built-in methods to remove particles with large tilt via CryoSPARC. However, this is possible using CryoSPARC Tools. You can obtain a subset of a particle dataset with particles with tilt greater than max_tilt removed by using the following Python script.

import os
import numpy as n
from cryosparc_tools.cryosparc.tools import CryoSPARC
from cryosparc_compute import geometry

cs = CryoSPARC(
    license="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    host="...", # YOUR HOST HERE
    base_port=40000,
    email="example@address.com", # YOUR EMAIL HERE
    password="password" # YOUR PASSWORD HERE
)

assert cs.test_connection()

max_tilt = 5 # desired max tilt here
project = cs.find_project('PX') # desired project id here
job = project.find_job('JY')   # desired job id here
particles_dset = job.load_output('particles') # particles from desired job

poses = particles_dset['alignments3D/pose']

def get_tilts(poses):
    """ Get the tilt angles from 3D particle poses """
    Rs = geometry.expmaps(poses)
    projdirs = Rs[...,2]
    EAs = geometry.projdir_to_EA(projdirs)
    tilts = 90.0 - n.rad2deg(EAs[:,1])
    return tilts

tilts = get_tilts(poses)

# plot tilt histogram
from matplotlib import pyplot as plt
plt.hist(tilts, bins=100)
plt.show()

# subset particles with tilts less than max_tilt
tilt_mask = n.abs(tilts) < max_tilt
particles_dset_subset = particles_dset.mask(tilt_mask)

# Use the project.save_external_result() method with the example specified arguments to save the subset dataset back to
# CryoSPARC for further analysis. The result will be a new “External job” in CryoSPARC in the same workspace as the
# original job.
project.save_external_result('WX', particles_dset_subset, 'particle',  f"tilt_less_than_{str(max_tilt)}" )

Make sure to replace the license ID, host, email, password, with that relevant to your instance, as well as max_tilt, and PX, JY, WZ with the project/job/workspace numbers with the desired project/job/workspace.

We’ve made a note that tilt is a useful attribute for particle-based curation!

Best,
Michael

3 Likes