# dataset is the main module required to interact with cryoSPARC .cs files
from cryosparc_compute import dataset
# instatiate a new Dataset object
particle_dataset = dataset.Dataset()
# load the dataset into memory from file
dataset_path = '/bulk6/data/devv2stephan_projects_bulk6/P28/exports/groups/P28_J283_particles_selected/P28_J283_particles_selected_exported.cs'
particle_dataset.from_file(dataset_path)
# organize information about the original micrographs these particles were extracted from
micrograph_pixel_size = 0.6575 # also can be obtained from mscope_params/psize_A
micrograph_ny = particle_dataset.data['location/micrograph_shape'][0][0]
micrograph_nx = particle_dataset.data['location/micrograph_shape'][0][1]
# get the shift values obtained from 2D classification in angstroms (Ã…)
pixel_size = particle_dataset.data['alignments2D/psize_A'].reshape(-1,1)
shifts = particle_dataset.data['alignments2D/shift'] * pixel_size
# calulate the current locations of the particles in angstroms (Ã…)
location_xs = (particle_dataset.data['location/center_x_frac'].reshape(-1,1) * # fraction relative to micrograph
location_ys = (particle_dataset.data['location/center_y_frac'].reshape(-1,1) * # fraction relative to micrograph
# calculate the new locations of the particles, after applying the shifts
recentered_locations = n.concatenate((location_xs, location_ys), 1) - shifts
# convert the new locations back to fractions relative to the micrograph
recentered_fraction_xs = (recentered_locations[:,0] /
recentered_fraction_ys = (recentered_locations[:,1] /
# save the new fractions back to the dataset
particle_dataset.data['location/center_x_frac'] = recentered_fraction_xs
particle_dataset.data['location/center_y_frac'] = recentered_fraction_ys
# reset the shifts now that they've already been applied to the particle locations
particle_dataset.data['alignments2D/shift'] = 0
# save the dataset back to disk
# Note: this will overwrite the currently exported dataset
particle_dataset.to_file(dataset_path)