{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Re-center Particles\n", "\n", "How to update particle location centers from alignments in 2D Classification data. \n", "\n", "Before proceeding, [install the `cryosparc-tools` module](../intro.md) in your Python environment. Also ensure CryoSPARC base ports +2 and +3 (`40002` and `40003` in this example) are available on this machine.\n", "\n", "The following python dependencies are also required to render results and may be installed with `conda` or `pip`:\n", "\n", "* `pandas`\n", "* `matplotlib`\n", "* `numpy` (included with `cryosparc-tools`)\n", "\n", "First initialize the `CryoSPARC` client:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connection succeeded to CryoSPARC command_core at http://cryoem5:40002\n", "Connection succeeded to CryoSPARC command_vis at http://cryoem5:40003\n" ] } ], "source": [ "from cryosparc.tools import CryoSPARC\n", "\n", "cs = CryoSPARC(host=\"cryoem5\", base_port=40000)\n", "assert cs.test_connection()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This instance has a 2D Classification and Select 2D Classes job at `P251-J15` and `P251-J16`, respectively. Re-extract those selected particles with updated centers computed by the 2D Classification job.\n", "\n", "First retrieve the job handle and its particles output with the `load_output` method." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "project = cs.find_project(\"P251\")\n", "job = cs.find_job(\"P251\", \"J16\")\n", "particles = job.load_output(\"particles_selected\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get a subset of relevant columns and display the first 10 rows as a `pandas` dataframe:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | alignments2D/psize_A | \n", "alignments2D/shift | \n", "blob/psize_A | \n", "location/center_x_frac | \n", "location/center_y_frac | \n", "location/micrograph_shape | \n", "uid | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "2.30125 | \n", "[-5.2, -2.6] | \n", "0.6575 | \n", "0.934483 | \n", "0.753333 | \n", "[7676, 7420] | \n", "12660056651751289214 | \n", "
1 | \n", "2.30125 | \n", "[-5.2, 7.8] | \n", "0.6575 | \n", "0.627586 | \n", "0.163333 | \n", "[7676, 7420] | \n", "17971771557537199412 | \n", "
2 | \n", "2.30125 | \n", "[-5.2, 0.0] | \n", "0.6575 | \n", "0.413793 | \n", "0.448333 | \n", "[7676, 7420] | \n", "17954957875627625872 | \n", "
3 | \n", "2.30125 | \n", "[-5.2, 7.8] | \n", "0.6575 | \n", "0.441379 | \n", "0.311667 | \n", "[7676, 7420] | \n", "5996321661655483102 | \n", "
4 | \n", "2.30125 | \n", "[2.6, 10.4] | \n", "0.6575 | \n", "0.603448 | \n", "0.088333 | \n", "[7676, 7420] | \n", "9631994642463500771 | \n", "
5 | \n", "2.30125 | \n", "[-13.0, 0.0] | \n", "0.6575 | \n", "0.860345 | \n", "0.720000 | \n", "[7676, 7420] | \n", "16429739213182044957 | \n", "
6 | \n", "2.30125 | \n", "[0.0, 7.8] | \n", "0.6575 | \n", "0.924138 | \n", "0.563333 | \n", "[7676, 7420] | \n", "15428131659279662499 | \n", "
7 | \n", "2.30125 | \n", "[-2.6, 0.0] | \n", "0.6575 | \n", "0.925862 | \n", "0.926667 | \n", "[7676, 7420] | \n", "10124600487485993501 | \n", "
8 | \n", "2.30125 | \n", "[2.6, -5.2] | \n", "0.6575 | \n", "0.482759 | \n", "0.445000 | \n", "[7676, 7420] | \n", "644635160388285141 | \n", "
9 | \n", "2.30125 | \n", "[2.6, 2.6] | \n", "0.6575 | \n", "0.039655 | \n", "0.228333 | \n", "[7676, 7420] | \n", "2866600664684787659 | \n", "