nodes: 0, module; 1, function_definition; 2, function_name:trunk_angles; 3, parameters; 4, block; 5, identifier:nrn; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, comment:# In order to avoid the failure of the process in case the neurite_type does not exist; 10, if_statement; 11, function_definition; 12, comment:# Sorting angles according to x-y plane; 13, expression_statement; 14, expression_statement; 15, return_statement; 16, identifier:neurite_type; 17, attribute; 18, string; 19, assignment; 20, not_operator; 21, block; 22, function_name:_sort_angle; 23, parameters; 24, block; 25, assignment; 26, assignment; 27, list_comprehension; 28, identifier:NeuriteType; 29, identifier:all; 30, string_content:Calculates the angles between all the trunks of the neuron.
      The angles are defined on the x-y plane and the trees
      are sorted from the y axis and anticlock-wise.; 31, identifier:vectors; 32, call; 33, attribute; 34, return_statement; 35, identifier:p1; 36, identifier:p2; 37, expression_statement; 38, expression_statement; 39, expression_statement; 40, return_statement; 41, identifier:order; 42, call; 43, identifier:ordered_vectors; 44, subscript; 45, call; 46, for_in_clause; 47, identifier:trunk_vectors; 48, argument_list; 49, identifier:vectors; 50, identifier:size; 51, list; 52, comment:"""Angle between p1-p2 to sort vectors"""; 53, assignment; 54, assignment; 55, parenthesized_expression; 56, attribute; 57, argument_list; 58, subscript; 59, slice; 60, list; 61, attribute; 62, argument_list; 63, pattern_list; 64, call; 65, identifier:nrn; 66, keyword_argument; 67, identifier:ang1; 68, call; 69, identifier:ang2; 70, call; 71, binary_operator:ang1 - ang2; 72, identifier:np; 73, identifier:argsort; 74, call; 75, identifier:vectors; 76, identifier:order; 77, attribute; 78, attribute; 79, identifier:morphmath; 80, identifier:angle_between_vectors; 81, subscript; 82, subscript; 83, identifier:i; 84, identifier:_; 85, identifier:enumerate; 86, argument_list; 87, identifier:neurite_type; 88, identifier:neurite_type; 89, attribute; 90, argument_list; 91, attribute; 92, argument_list; 93, identifier:ang1; 94, identifier:ang2; 95, attribute; 96, argument_list; 97, identifier:COLS; 98, identifier:X; 99, identifier:COLS; 100, identifier:Y; 101, identifier:ordered_vectors; 102, identifier:i; 103, identifier:ordered_vectors; 104, binary_operator:i - 1; 105, identifier:ordered_vectors; 106, identifier:np; 107, identifier:arctan2; 108, list_splat; 109, identifier:np; 110, identifier:arctan2; 111, list_splat; 112, identifier:np; 113, identifier:array; 114, list_comprehension; 115, identifier:i; 116, integer:1; 117, subscript; 118, subscript; 119, call; 120, for_in_clause; 121, identifier:p1; 122, slice; 123, identifier:p2; 124, slice; 125, identifier:_sort_angle; 126, argument_list; 127, identifier:i; 128, subscript; 129, unary_operator; 130, unary_operator; 131, binary_operator:i / np.linalg.norm(i); 132, list; 133, identifier:vectors; 134, slice; 135, slice; 136, integer:1; 137, integer:1; 138, identifier:i; 139, call; 140, integer:0; 141, integer:1; 142, integer:0; 143, integer:2; 144, attribute; 145, argument_list; 146, attribute; 147, identifier:norm; 148, identifier:i; 149, identifier:np; 150, identifier:linalg
code: def trunk_angles(nrn, neurite_type=NeuriteType.all):
      '''Calculates the angles between all the trunks of the neuron.
      The angles are defined on the x-y plane and the trees
      are sorted from the y axis and anticlock-wise.
      '''
      vectors = trunk_vectors(nrn, neurite_type=neurite_type)
      # In order to avoid the failure of the process in case the neurite_type does not exist
      if not vectors.size:
          return []
  
      def _sort_angle(p1, p2):
          """Angle between p1-p2 to sort vectors"""
          ang1 = np.arctan2(*p1[::-1])
          ang2 = np.arctan2(*p2[::-1])
          return (ang1 - ang2)
  
      # Sorting angles according to x-y plane
      order = np.argsort(np.array([_sort_angle(i / np.linalg.norm(i), [0, 1])
                                   for i in vectors[:, 0:2]]))
  
      ordered_vectors = vectors[order][:, [COLS.X, COLS.Y]]
  
      return [morphmath.angle_between_vectors(ordered_vectors[i], ordered_vectors[i - 1])
              for i, _ in enumerate(ordered_vectors)]