|
22 | 22 | from scipy.spatial.transform import Rotation |
23 | 23 |
|
24 | 24 | from pyneuroml.pynml import read_neuroml2_file |
25 | | -from pyneuroml.utils import extract_position_info, rotate_cell, translate_cell_to_coords |
| 25 | +from pyneuroml.utils import extract_position_info, make_cell_upright |
26 | 26 | from pyneuroml.utils.plot import ( |
27 | 27 | DEFAULTS, |
28 | 28 | get_cell_bound_box, |
@@ -782,65 +782,6 @@ def plot_interactive_3D( |
782 | 782 | app.run() |
783 | 783 |
|
784 | 784 |
|
785 | | -def make_cell_upright( |
786 | | - cell: Cell = None, |
787 | | - inplace: bool = False, |
788 | | -) -> Cell: |
789 | | - """Use cell's PCA to make it upright |
790 | | -
|
791 | | - .. versionadded:: 1.2.13 |
792 | | -
|
793 | | - :param cell: cell object to translate |
794 | | - :type cell: neuroml.Cell |
795 | | - :param inplace: toggle whether the cell object should be modified inplace |
796 | | - or a copy created (creates and returns a copy by default) |
797 | | - :type inplace: bool |
798 | | - :returns: new neuroml.Cell object |
799 | | - :rtype: neuroml.Cell |
800 | | - """ |
801 | | - |
802 | | - # Get all segments' distal points |
803 | | - segment_points = [] |
804 | | - segments_all = cell.morphology.segments |
805 | | - for segment in segments_all: |
806 | | - segment_points.append([segment.distal.x, segment.distal.y, segment.distal.z]) |
807 | | - |
808 | | - coords = numpy.array(segment_points) |
809 | | - from sklearn.decomposition import PCA |
810 | | - |
811 | | - # Get the PCA components |
812 | | - pca = PCA() |
813 | | - pca.fit(coords) |
814 | | - |
815 | | - # Get the principal component axes |
816 | | - principal_axes = pca.components_ |
817 | | - # Get the first principal component axis |
818 | | - first_pca = principal_axes[0] |
819 | | - # y angle needed to eliminate z component |
820 | | - y_angle = math.atan(first_pca[2] / first_pca[0]) |
821 | | - rotation_y = numpy.array( |
822 | | - [ |
823 | | - [math.cos(y_angle), 0, math.sin(y_angle)], |
824 | | - [0, 1, 0], |
825 | | - [-math.sin(y_angle), 0, math.cos(y_angle)], |
826 | | - ] |
827 | | - ) |
828 | | - rotated_pca = numpy.dot(rotation_y, first_pca) |
829 | | - |
830 | | - # z angle needed to eliminate x component |
831 | | - z_angle = -math.atan(rotated_pca[0] / rotated_pca[1]) |
832 | | - |
833 | | - if z_angle < 0: |
834 | | - z_angle += numpy.pi |
835 | | - |
836 | | - logger.debug("Making cell upright for visualization") |
837 | | - cell = translate_cell_to_coords(cell, inplace=inplace, dest=[0, 0, 0]) |
838 | | - cell = rotate_cell( |
839 | | - cell, 0, y_angle, z_angle, "yzx", relative_to_soma=False, inplace=inplace |
840 | | - ) |
841 | | - return cell |
842 | | - |
843 | | - |
844 | 785 | def plot_3D_cell_morphology( |
845 | 786 | offset: typing.List[float] = [0, 0, 0], |
846 | 787 | cell: Optional[Cell] = None, |
|
0 commit comments