docs: def rectwv_coeff_to_ds9(rectwv_coeff,
                          limits=None,
                          rectified=False,
                          numpix=100):
      """Generate ds9 region output with requested slitlet limits
  
      Parameters
      ----------
      rectwv_coeff : RectWaveCoeff instance
          Rectification and wavelength calibration coefficients for the
          particular CSU configuration.
      limits : str
          Region to be saved: the only two possibilities are 'boundaries'
          and 'frontiers'.
      rectified : bool
          If True, the regions correspond to the rectified image.
      numpix : int
          Number of points in which the X-range interval is subdivided
          in order to save each boundary as a connected set of line
          segments. This option is only relevant when rectified=False.
  
      Returns
      -------
      output : str
          String containing the full output to be exported as a ds9 region
          file.
      """
  
      # protections
      if limits not in ['boundaries', 'frontiers']:
          raise ValueError('Unexpect limits=' + str(limits))
  
      # retrieve relevant wavelength calibration parameters
      grism_name = rectwv_coeff.tags['grism']
      filter_name = rectwv_coeff.tags['filter']
      wv_parameters = set_wv_parameters(filter_name, grism_name)
      naxis1_enlarged = wv_parameters['naxis1_enlarged']
      crpix1_enlarged = wv_parameters['crpix1_enlarged']
      crval1_enlarged = wv_parameters['crval1_enlarged']
      cdelt1_enlarged = wv_parameters['cdelt1_enlarged']
  
      ds9_output = '# Region file format: DS9 version 4.1\n' \
                   'global color=green dashlist=2 4 width=2 ' \
                   'font="helvetica 10 normal roman" select=1 ' \
                   'highlite=1 dash=1 fixed=0 edit=1 ' \
                   'move=1 delete=1 include=1 source=1\nphysical\n#\n'
  
      ds9_output += '#\n# uuid (rectwv_coeff): {0}\n'.format(rectwv_coeff.uuid)
      ds9_output += \
          '# grism...............: {0}\n'.format(rectwv_coeff.tags['grism'])
      ds9_output += \
          '# filter..............: {0}\n'.format(rectwv_coeff.tags['filter'])
  
      for islitlet in range(1, EMIR_NBARS + 1):
          if islitlet not in rectwv_coeff.missing_slitlets:
              dumdict = rectwv_coeff.contents[islitlet - 1]
              if islitlet % 2 == 0:
                  if limits == 'frontiers':
                      colorbox = '#0000ff'  # '#ff77ff'
                  else:
                      colorbox = '#ff00ff'  # '#ff77ff'
              else:
                  if limits == 'frontiers':
                      colorbox = '#0000ff'  # '#4444ff'
                  else:
                      colorbox = '#00ffff'  # '#4444ff'
  
              ds9_output += '#\n# islitlet...........: {0}\n'.format(islitlet)
              ds9_output += '# csu_bar_slit_center: {0}\n'.format(
                  dumdict['csu_bar_slit_center']
              )
              if rectified:
                  crpix1_linear = 1.0
                  crval1_linear = dumdict['crval1_linear']
                  cdelt1_linear = dumdict['cdelt1_linear']
                  if limits == 'frontiers':
                      ydum_lower = dumdict['y0_frontier_lower_expected']
                      ydum_upper = dumdict['y0_frontier_upper_expected']
                  else:
                      ydum_lower = dumdict['y0_reference_lower_expected']
                      ydum_upper = dumdict['y0_reference_upper_expected']
                  wave_ini = crval1_linear + \
                             (0.5 - crpix1_linear) * cdelt1_linear
                  xdum_ini = (wave_ini - crval1_enlarged) / cdelt1_enlarged
                  xdum_ini += crpix1_enlarged
                  wave_end = crval1_linear + \
                             (EMIR_NAXIS1 + 0.5 - crpix1_linear) * cdelt1_linear
                  xdum_end = (wave_end - crval1_enlarged) / cdelt1_enlarged
                  xdum_end += crpix1_enlarged
                  for ydum in [ydum_lower, ydum_upper]:
                      ds9_output += \
                          'line {0} {1} {2} {3}'.format(
                              xdum_ini, ydum,
                              xdum_end, ydum
                          )
                      ds9_output += ' # color={0}\n'.format(colorbox)
                  # slitlet label
                  ydum_label = (ydum_lower + ydum_upper) / 2.0
                  xdum_label = EMIR_NAXIS1 / 2 + 0.5
                  wave_center = crval1_linear + \
                                (xdum_label - crpix1_linear) * cdelt1_linear
                  xdum_label = (wave_center - crval1_enlarged) / cdelt1_enlarged
                  xdum_label += crpix1_enlarged
                  ds9_output += 'text {0} {1} {{{2}}} # color={3} ' \
                                'font="helvetica 10 bold ' \
                                'roman"\n'.format(xdum_label, ydum_label,
                                                  islitlet, colorbox)
              else:
                  if limits == 'frontiers':
                      pol_lower = Polynomial(
                          dumdict['frontier']['poly_coef_lower']
                      )
                      pol_upper = Polynomial(
                          dumdict['frontier']['poly_coef_upper']
                      )
                  else:
                      pol_lower = Polynomial(
                          dumdict['spectrail']['poly_coef_lower']
                      )
                      pol_upper = Polynomial(
                          dumdict['spectrail']['poly_coef_upper']
                      )
                  xdum = np.linspace(1, EMIR_NAXIS1, num=numpix)
                  ydum = pol_lower(xdum)
                  for i in range(len(xdum) - 1):
                      ds9_output += \
                          'line {0} {1} {2} {3}'.format(
                              xdum[i], ydum[i],
                              xdum[i + 1], ydum[i + 1]
                          )
                      ds9_output += ' # color={0}\n'.format(colorbox)
                  ydum = pol_upper(xdum)
                  for i in range(len(xdum) - 1):
                      ds9_output += \
                          'line {0} {1} {2} {3}'.format(
                              xdum[i], ydum[i],
                              xdum[i + 1], ydum[i + 1]
                          )
                      ds9_output += ' # color={0}\n'.format(colorbox)
                  # slitlet label
                  xdum_label = EMIR_NAXIS1 / 2 + 0.5
                  ydum_lower = pol_lower(xdum_label)
                  ydum_upper = pol_upper(xdum_label)
                  ydum_label = (ydum_lower + ydum_upper) / 2.0
                  ds9_output += 'text {0} {1} {{{2}}} # color={3} ' \
                                'font="helvetica 10 bold ' \
                                'roman"\n'.format(xdum_label, ydum_label,
                                                  islitlet, colorbox)
  
      return ds9_output