code: def add_jitter(psr, ecorr ,flagid=None, flags=None, coarsegrain=0.1,
                 seed=None):
      
      
      if seed is not None:
          N.random.seed(seed)
      
      if flags is None:
          t, U = quantize_fast(N.array(psr.toas(),'d'), dt=coarsegrain)
      elif flags is not None and flagid is not None:
          t, f, U = quantize_fast(N.array(psr.toas(),'d'),
                                  N.array(psr.flagvals(flagid)),
                                  dt=coarsegrain)
  
      # default jitter value
      ecorrvec = N.zeros(len(t))
      
      # check that jitter is scalar if flags is None
      if flags is None:
          if not N.isscalar(ecorr):
              raise ValueError('ERROR: If flags is None, jitter must be a scalar')
          else:
              ecorrvec = N.ones(len(t)) * ecorr
  
      if flags is not None and flagid is not None and not N.isscalar(ecorr):
          if len(ecorr) == len(flags):
              for ct, flag in enumerate(flags):
                  ind = flag == N.array(f)
                  ecorrvec[ind] = ecorr[ct]
  
      psr.stoas[:] += (1 / day) * N.dot(U*ecorrvec, N.random.randn(U.shape[1]))
docs: Add correlated quadrature noise of rms `ecorr` [s],
      with coarse-graining time `coarsegrain` [days].
      Optionally take a pseudorandom-number-generator seed.