code: def wls_iter(
      design_matrix,
      sig,
      S0,
      Diso=3e-3,
      mdreg=2.7e-3,
      min_signal=1.0e-6,
      piterations=3,
  ):
      """Applies weighted linear least squares fit of the water free elimination
      model to single voxel signals.
  
      Parameters
      ----------
      design_matrix : array (g, 7)
          Design matrix holding the covariants used to solve for the regression
          coefficients.
      sig : array (g, )
          Diffusion-weighted signal for a single voxel data.
      S0 : float
          Non diffusion weighted signal (i.e. signal for b-value=0).
      Diso : float, optional
          Value of the free water isotropic diffusion. Default is set to 3e-3
          $mm^{2}.s^{-1}$. Please adjust this value if you are assuming different
          units of diffusion.
       mdreg : float, optimal
          DTI's mean diffusivity regularization threshold. If standard DTI
          diffusion tensor's mean diffusivity is almost near the free water
          diffusion value, the diffusion signal is assumed to be only free water
          diffusion (i.e. volume fraction will be set to 1 and tissue's diffusion
          parameters are set to zero). Default md_reg is 2.7e-3 $mm^{2}.s^{-1}$
          (corresponding to 90% of the free water diffusion value).
      min_signal : float
          The minimum signal value. Needs to be a strictly positive
          number. Default: minimal signal in the data provided to `fit`.
      piterations : inter, optional
          Number of iterations used to refine the precision of f. Default is set
          to 3 corresponding to a precision of 0.01.
  
      Returns
      -------
      All parameters estimated from the free water tensor model.
      Parameters are ordered as follows:
          1) Three diffusion tensor's eigenvalues
          2) Three lines of the eigenvector matrix each containing the
             first, second and third coordinates of the eigenvector
          3) The volume fraction of the free water compartment
      """
      W = design_matrix
  
      # DTI ordinary linear least square solution
      log_s = np.log(np.maximum(sig, min_signal))
  
      # Define weights
      S2 = np.diag(sig**2)
  
      # DTI weighted linear least square solution
      WTS2 = np.dot(W.T, S2)
      inv_WT_S2_W = np.linalg.pinv(np.dot(WTS2, W))
      invWTS2W_WTS2 = np.dot(inv_WT_S2_W, WTS2)
      params = np.dot(invWTS2W_WTS2, log_s)
  
      md = (params[0] + params[2] + params[5]) / 3
      # Process voxel if it has significant signal from tissue
      if md < mdreg and np.mean(sig) > min_signal and S0 > min_signal:
          # General free-water signal contribution
          fwsig = np.exp(
              np.dot(
                  design_matrix,
                  np.array([Diso, 0, Diso, 0, 0, Diso, 0]),
              )
          )
  
          df = 1  # initialize precision
          flow = 0  # lower f evaluated
          fhig = 1  # higher f evaluated
          ns = 9  # initial number of samples per iteration
          for p in range(piterations):
              df = df * 0.1
              fs = np.linspace(
                  flow + df, fhig - df, num=ns
              )  # sampling f
              SFW = np.array(
                  [
                      fwsig,
                  ]
                  * ns
              )  # repeat contributions for all values
              FS, SI = np.meshgrid(fs, sig)
              SA = SI - FS * S0 * SFW.T
              # SA < 0 means that the signal components from the free water
              # component is larger than the total fiber. This cases are present
              # for inappropriate large volume fractions (given the current S0
              # value estimated). To overcome this issue negative SA are replaced
              # by data's min positive signal.
              SA[SA <= 0] = min_signal
              y = np.log(SA / (1 - FS))
              all_new_params = np.dot(invWTS2W_WTS2, y)
              # Select params for lower F2
              SIpred = (1 - FS) * np.exp(
                  np.dot(W, all_new_params)
              ) + FS * S0 * SFW.T
              F2 = np.sum(np.square(SI - SIpred), axis=0)
              Mind = np.argmin(F2)
              params = all_new_params[:, Mind]
              f = fs[Mind]  # Updated f
              flow = f - df  # refining precision
              fhig = f + df
              ns = 19
  
          evals, evecs = decompose_tensor(from_lower_triangular(params))
          fw_params = np.concatenate(
              (evals, evecs[0], evecs[1], evecs[2], np.array([f])),
              axis=0,
          )
      else:
          fw_params = np.zeros(13)
          if md > mdreg:
              fw_params[12] = 1.0
  
      return fw_params
  
imports: import warnings
  import numpy
  import scipy.optimize
  from dipy.reconst.base import ReconstModel
  from dipy.reconst.dti import TensorFit, design_matrix, decompose_tensor, _decompose_tensor_nan, from_lower_triangular, lower_triangular
  from dipy.reconst.dki import _positive_evals
  from dipy.reconst.vec_val_sum import vec_val_vect
  from dipy.core.ndindex import ndindex
  from dipy.core.gradients import check_multi_b
  from dipy.reconst.multi_voxel import multi_voxel_fit
label_desc: Use image node_id 2 for calling a global function with example usage: wls_iter(design_matrix, sig, S0, Diso, mdreg, min_signal, piterations) and returns: fw_params