nodes: 0, module; 1, function_definition; 2, function_name:gen_triplets_master; 3, parameters; 4, block; 5, identifier:wv_master; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, comment:# Check that the wavelengths in the master table are sorted; 11, expression_statement; 12, for_statement; 13, comment:# Generate all the possible triplets with the numbers of the lines; 14, comment:# in the master table. Each triplet is defined as a tuple of three; 15, comment:# numbers corresponding to the three line indices in the master; 16, comment:# table. The collection of tuples is stored in an ordinary python; 17, comment:# list.; 18, expression_statement; 19, expression_statement; 20, comment:# Verify that the number of triplets coincides with the expected; 21, comment:# value.; 22, expression_statement; 23, if_statement; 24, comment:# For each triplet, compute the relative position of the central; 25, comment:# line.; 26, expression_statement; 27, for_statement; 28, comment:# Compute the array of indices that index the above ratios in; 29, comment:# sorted order.; 30, expression_statement; 31, comment:# Simultaneous sort of position ratios and triplets.; 32, expression_statement; 33, expression_statement; 34, if_statement; 35, return_statement; 36, identifier:geometry; 37, None; 38, identifier:debugplot; 39, integer:0; 40, comment:"""Compute information associated to triplets in master table.
  
      Determine all the possible triplets that can be generated from the
      array `wv_master`. In addition, the relative position of the
      central line of each triplet is also computed.
  
      Parameters
      ----------
      wv_master : 1d numpy array, float
          Array with wavelengths corresponding to the master table
          (Angstroms).
      geometry : tuple (4 integers) or None
          x, y, dx, dy values employed to set the window geometry.
      debugplot : int
          Determines whether intermediate computations and/or plots
          are displayed. The valid codes are defined in
          numina.array.display.pause_debugplot.
  
      Returns
      -------
      ntriplets_master : int
          Number of triplets built from master table.
      ratios_master_sorted : 1d numpy array, float
          Array with values of the relative position of the central line
          of each triplet, sorted in ascending order.
      triplets_master_sorted_list : list of tuples
          List with tuples of three numbers, corresponding to the three
          line indices in the master table. The list is sorted to be in
          correspondence with `ratios_master_sorted`.
  
      """; 41, assignment; 42, assignment; 43, identifier:i; 44, call; 45, block; 46, assignment; 47, assignment; 48, assignment; 49, comparison_operator:ntriplets_master == comb(nlines_master, 3, exact=True); 50, block; 51, else_clause; 52, assignment; 53, pattern_list; 54, call; 55, block; 56, assignment; 57, assignment; 58, assignment; 59, comparison_operator:abs(debugplot) in [21, 22]; 60, comment:# compute and plot histogram with position ratios; 61, block; 62, expression_list; 63, identifier:nlines_master; 64, attribute; 65, identifier:wv_previous; 66, subscript; 67, identifier:range; 68, argument_list; 69, if_statement; 70, expression_statement; 71, identifier:iter_comb_triplets; 72, call; 73, identifier:triplets_master_list; 74, list_comprehension; 75, identifier:ntriplets_master; 76, call; 77, identifier:ntriplets_master; 78, call; 79, if_statement; 80, block; 81, identifier:ratios_master; 82, call; 83, identifier:index; 84, identifier:value; 85, identifier:enumerate; 86, argument_list; 87, expression_statement; 88, expression_statement; 89, expression_statement; 90, expression_statement; 91, identifier:isort_ratios_master; 92, call; 93, identifier:ratios_master_sorted; 94, subscript; 95, identifier:triplets_master_sorted_list; 96, list_comprehension; 97, call; 98, list; 99, expression_statement; 100, expression_statement; 101, comment:#; 102, import_from_statement; 103, expression_statement; 104, expression_statement; 105, expression_statement; 106, expression_statement; 107, expression_statement; 108, expression_statement; 109, expression_statement; 110, expression_statement; 111, comment:# set window geometry; 112, expression_statement; 113, expression_statement; 114, identifier:ntriplets_master; 115, identifier:ratios_master_sorted; 116, identifier:triplets_master_sorted_list; 117, identifier:wv_master; 118, identifier:size; 119, identifier:wv_master; 120, integer:0; 121, integer:1; 122, identifier:nlines_master; 123, comparison_operator:wv_previous >= wv_master[i]; 124, block; 125, assignment; 126, attribute; 127, argument_list; 128, identifier:val; 129, for_in_clause; 130, identifier:len; 131, argument_list; 132, identifier:comb; 133, argument_list; 134, comparison_operator:abs(debugplot) >= 10; 135, block; 136, raise_statement; 137, attribute; 138, argument_list; 139, identifier:triplets_master_list; 140, assignment; 141, assignment; 142, assignment; 143, assignment; 144, attribute; 145, argument_list; 146, identifier:ratios_master; 147, identifier:isort_ratios_master; 148, subscript; 149, for_in_clause; 150, identifier:abs; 151, argument_list; 152, integer:21; 153, integer:22; 154, assignment; 155, assignment; 156, dotted_name; 157, dotted_name; 158, assignment; 159, assignment; 160, assignment; 161, assignment; 162, call; 163, call; 164, call; 165, call; 166, call; 167, call; 168, identifier:wv_previous; 169, subscript; 170, raise_statement; 171, identifier:wv_previous; 172, subscript; 173, identifier:itertools; 174, identifier:combinations; 175, call; 176, integer:3; 177, identifier:val; 178, identifier:iter_comb_triplets; 179, identifier:triplets_master_list; 180, identifier:nlines_master; 181, integer:3; 182, keyword_argument; 183, call; 184, integer:10; 185, expression_statement; 186, expression_statement; 187, call; 188, identifier:np; 189, identifier:zeros; 190, identifier:ntriplets_master; 191, pattern_list; 192, identifier:value; 193, identifier:delta1; 194, binary_operator:wv_master[i2] - wv_master[i1]; 195, identifier:delta2; 196, binary_operator:wv_master[i3] - wv_master[i1]; 197, subscript; 198, binary_operator:delta1 / delta2; 199, identifier:np; 200, identifier:argsort; 201, identifier:ratios_master; 202, identifier:triplets_master_list; 203, identifier:i; 204, identifier:i; 205, identifier:isort_ratios_master; 206, identifier:debugplot; 207, identifier:bins_in; 208, call; 209, pattern_list; 210, call; 211, identifier:numina; 212, identifier:array; 213, identifier:display; 214, identifier:matplotlib_qt; 215, identifier:plt; 216, identifier:fig; 217, call; 218, identifier:ax; 219, call; 220, identifier:width_hist; 221, binary_operator:0.8*(bins_out[1]-bins_out[0]); 222, identifier:center; 223, binary_operator:(bins_out[:-1]+bins_out[1:])/2; 224, attribute; 225, argument_list; 226, attribute; 227, argument_list; 228, attribute; 229, argument_list; 230, attribute; 231, argument_list; 232, identifier:set_window_geometry; 233, argument_list; 234, identifier:pause_debugplot; 235, argument_list; 236, identifier:wv_master; 237, identifier:i; 238, call; 239, identifier:wv_master; 240, identifier:i; 241, identifier:range; 242, argument_list; 243, identifier:exact; 244, True; 245, identifier:abs; 246, argument_list; 247, call; 248, call; 249, identifier:ValueError; 250, argument_list; 251, identifier:i1; 252, identifier:i2; 253, identifier:i3; 254, subscript; 255, subscript; 256, subscript; 257, subscript; 258, identifier:ratios_master; 259, identifier:index; 260, identifier:delta1; 261, identifier:delta2; 262, attribute; 263, argument_list; 264, identifier:hist; 265, identifier:bins_out; 266, attribute; 267, argument_list; 268, attribute; 269, argument_list; 270, attribute; 271, argument_list; 272, float:0.8; 273, parenthesized_expression; 274, parenthesized_expression; 275, integer:2; 276, identifier:ax; 277, identifier:bar; 278, identifier:center; 279, identifier:hist; 280, keyword_argument; 281, keyword_argument; 282, identifier:ax; 283, identifier:set_xlabel; 284, string; 285, identifier:ax; 286, identifier:set_ylabel; 287, string; 288, identifier:ax; 289, identifier:set_title; 290, binary_operator:"Number of lines/triplets: " +
                       str(nlines_master) + "/" + str(ntriplets_master); 291, identifier:geometry; 292, identifier:debugplot; 293, keyword_argument; 294, keyword_argument; 295, identifier:ValueError; 296, argument_list; 297, identifier:nlines_master; 298, identifier:debugplot; 299, identifier:print; 300, argument_list; 301, identifier:print; 302, argument_list; 303, string; 304, identifier:wv_master; 305, identifier:i2; 306, identifier:wv_master; 307, identifier:i1; 308, identifier:wv_master; 309, identifier:i3; 310, identifier:wv_master; 311, identifier:i1; 312, identifier:np; 313, identifier:linspace; 314, float:0.0; 315, float:1.0; 316, integer:41; 317, identifier:np; 318, identifier:histogram; 319, identifier:ratios_master; 320, keyword_argument; 321, identifier:plt; 322, identifier:figure; 323, identifier:fig; 324, identifier:add_subplot; 325, integer:111; 326, binary_operator:bins_out[1]-bins_out[0]; 327, binary_operator:bins_out[:-1]+bins_out[1:]; 328, identifier:align; 329, string; 330, identifier:width; 331, identifier:width_hist; 332, string_content:distance ratio in each triplet; 333, string_content:Number of triplets; 334, binary_operator:"Number of lines/triplets: " +
                       str(nlines_master) + "/"; 335, call; 336, identifier:pltshow; 337, True; 338, identifier:tight_layout; 339, True; 340, binary_operator:'Wavelengths:\n--> ' +
                               str(wv_previous) + '\n--> ' + str(wv_master[i]) +
                               '\nin master table are duplicated or not sorted'; 341, string; 342, identifier:nlines_master; 343, string; 344, identifier:ntriplets_master; 345, string_content:Invalid number of combinations; 346, identifier:bins; 347, identifier:bins_in; 348, subscript; 349, subscript; 350, subscript; 351, subscript; 352, string_content:center; 353, binary_operator:"Number of lines/triplets: " +
                       str(nlines_master); 354, string:"/"; 355, identifier:str; 356, argument_list; 357, binary_operator:'Wavelengths:\n--> ' +
                               str(wv_previous) + '\n--> ' + str(wv_master[i]); 358, string; 359, string_content:>>> Total number of lines in master table:; 360, string_content:>>> Number of triplets in master table...:; 361, identifier:bins_out; 362, integer:1; 363, identifier:bins_out; 364, integer:0; 365, identifier:bins_out; 366, slice; 367, identifier:bins_out; 368, slice; 369, string:"Number of lines/triplets: "; 370, call; 371, identifier:ntriplets_master; 372, binary_operator:'Wavelengths:\n--> ' +
                               str(wv_previous) + '\n--> '; 373, call; 374, string_content; 375, unary_operator; 376, integer:1; 377, identifier:str; 378, argument_list; 379, binary_operator:'Wavelengths:\n--> ' +
                               str(wv_previous); 380, string; 381, identifier:str; 382, argument_list; 383, escape_sequence:\n; 384, integer:1; 385, identifier:nlines_master; 386, string; 387, call; 388, string_content; 389, subscript; 390, string_content; 391, identifier:str; 392, argument_list; 393, escape_sequence:\n; 394, identifier:wv_master; 395, identifier:i; 396, escape_sequence:\n; 397, identifier:wv_previous
code: def gen_triplets_master(wv_master, geometry=None, debugplot=0):
      """Compute information associated to triplets in master table.
  
      Determine all the possible triplets that can be generated from the
      array `wv_master`. In addition, the relative position of the
      central line of each triplet is also computed.
  
      Parameters
      ----------
      wv_master : 1d numpy array, float
          Array with wavelengths corresponding to the master table
          (Angstroms).
      geometry : tuple (4 integers) or None
          x, y, dx, dy values employed to set the window geometry.
      debugplot : int
          Determines whether intermediate computations and/or plots
          are displayed. The valid codes are defined in
          numina.array.display.pause_debugplot.
  
      Returns
      -------
      ntriplets_master : int
          Number of triplets built from master table.
      ratios_master_sorted : 1d numpy array, float
          Array with values of the relative position of the central line
          of each triplet, sorted in ascending order.
      triplets_master_sorted_list : list of tuples
          List with tuples of three numbers, corresponding to the three
          line indices in the master table. The list is sorted to be in
          correspondence with `ratios_master_sorted`.
  
      """
  
      nlines_master = wv_master.size
  
      # Check that the wavelengths in the master table are sorted
      wv_previous = wv_master[0]
      for i in range(1, nlines_master):
          if wv_previous >= wv_master[i]:
              raise ValueError('Wavelengths:\n--> ' +
                               str(wv_previous) + '\n--> ' + str(wv_master[i]) +
                               '\nin master table are duplicated or not sorted')
          wv_previous = wv_master[i]
  
      # Generate all the possible triplets with the numbers of the lines
      # in the master table. Each triplet is defined as a tuple of three
      # numbers corresponding to the three line indices in the master
      # table. The collection of tuples is stored in an ordinary python
      # list.
      iter_comb_triplets = itertools.combinations(range(nlines_master), 3)
      triplets_master_list = [val for val in iter_comb_triplets]
  
      # Verify that the number of triplets coincides with the expected
      # value.
      ntriplets_master = len(triplets_master_list)
      if ntriplets_master == comb(nlines_master, 3, exact=True):
          if abs(debugplot) >= 10:
              print('>>> Total number of lines in master table:', 
                    nlines_master)
              print('>>> Number of triplets in master table...:', 
                    ntriplets_master)
      else:
          raise ValueError('Invalid number of combinations')
  
      # For each triplet, compute the relative position of the central
      # line.
      ratios_master = np.zeros(ntriplets_master)
      for index, value in enumerate(triplets_master_list):
          i1, i2, i3 = value
          delta1 = wv_master[i2] - wv_master[i1]
          delta2 = wv_master[i3] - wv_master[i1]
          ratios_master[index] = delta1 / delta2
  
      # Compute the array of indices that index the above ratios in
      # sorted order.
      isort_ratios_master = np.argsort(ratios_master)
  
      # Simultaneous sort of position ratios and triplets.
      ratios_master_sorted = ratios_master[isort_ratios_master]
      triplets_master_sorted_list = [triplets_master_list[i]
                                     for i in isort_ratios_master]
  
      if abs(debugplot) in [21, 22]:
          # compute and plot histogram with position ratios
          bins_in = np.linspace(0.0, 1.0, 41)
          hist, bins_out = np.histogram(ratios_master, bins=bins_in)
          #
          from numina.array.display.matplotlib_qt import plt
          fig = plt.figure()
          ax = fig.add_subplot(111)
          width_hist = 0.8*(bins_out[1]-bins_out[0])
          center = (bins_out[:-1]+bins_out[1:])/2
          ax.bar(center, hist, align='center', width=width_hist)
          ax.set_xlabel('distance ratio in each triplet')
          ax.set_ylabel('Number of triplets')
          ax.set_title("Number of lines/triplets: " +
                       str(nlines_master) + "/" + str(ntriplets_master))
          # set window geometry
          set_window_geometry(geometry)
          pause_debugplot(debugplot, pltshow=True, tight_layout=True)
  
      return ntriplets_master, ratios_master_sorted, triplets_master_sorted_list