code: def apply_threshold(in1, threshold, sigma_level=4):
      
  
      out1 = np.empty_like(in1)
  
      # The conditional here ensures that the function works even when only one scale is considered. Both cases are the
      # same: the MAD estimator is calculated and then the resulting value is used to threshold the input. NOTE: This
      # discards all negative coefficients.
  
      if len(in1.shape)==2:
          out1 = (np.abs(in1)>(sigma_level*threshold))*in1
      else:
          for i in range(in1.shape[0]):
              out1[i,:,:] = (np.abs(in1[i,:,:])>(sigma_level*threshold[i]))*in1[i,:,:]
  
      return out1
docs: This function performs the thresholding of the values in array in1 based on the estimated standard deviation
      given by the MAD (median absolute deviation) estimator about zero.
  
      INPUTS:
      in1             (no default):   The array which is to be thresholded.
      sigma_level     (no default):   The number of estimated deviations at which thresholding is to occur.
  
      OUTPUTS:
      out1                            An thresholded version of in1.