code: def gen_triplets_master(wv_master, geometry=None, debugplot=0):
      nlines_master = wv_master.size
      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]
      iter_comb_triplets = itertools.combinations(range(nlines_master), 3)
      triplets_master_list = [val for val in iter_comb_triplets]
      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')
      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
      isort_ratios_master = np.argsort(ratios_master)
      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]:
          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(geometry)
          pause_debugplot(debugplot, pltshow=True, tight_layout=True)
      return ntriplets_master, ratios_master_sorted, triplets_master_sorted_list