original_docstring: 
          Set the noise parameters for the current spectrum. Control over what "defines" the noise floor
          is specified with the parameter region. By default, if region is None then the function will
          perform an initial peak find using 1% of the maximum intensity as the threshold. The noise region
          will be established based on the largest gap between peaks, i.e. hopefully capturing as little
          features in the statistics as possible.
          
          The alternative method is invoked when the `als` argument is set to True, which will use the
          asymmetric least-squares method to determine the baseline. Afterwards, the baseline is decimated
          by an extremely heavy Gaussian blur, and one ends up with a smoothly varying baseline. In this
          case, there is no `noise_rms` attribute to be returned as it is not required to determine the
          minimum peak threshold.
  
          Parameters
          ----------
          region : 2-tuple or None, optional
              If None, use the automatic algorithm. Otherwise, a 2-tuple specifies the region of the spectrum
              in frequency to use for noise statistics.
          als : bool, optional
              If True, will use the asymmetric least squares method to determine the baseline.
          kwargs
              Additional kwargs are passed into the ALS function.
  
          Returns
          -------
          baseline - float
              Value of the noise floor
          rms - float
              Noise RMS/standard deviation
          
docstring: Set the noise parameters for the current spectrum. Control over what "defines" the noise floor
  is specified with the parameter region. By default, if region is None then the function will
  perform an initial peak find using 1% of the maximum intensity as the threshold. The noise region
  will be established based on the largest gap between peaks, i.e. hopefully capturing as little
  features in the statistics as possible.
  
  The alternative method is invoked when the `als` argument is set to True, which will use the
  asymmetric least-squares method to determine the baseline. Afterwards, the baseline is decimated
  by an extremely heavy Gaussian blur, and one ends up with a smoothly varying baseline. In this
  case, there is no `noise_rms` attribute to be returned as it is not required to determine the
  minimum peak threshold.
  
  Parameters
  
  region : 2-tuple or None, optional
  If None, use the automatic algorithm. Otherwise, a 2-tuple specifies the region of the spectrum
  in frequency to use for noise statistics.
  als : bool, optional
  If True, will use the asymmetric least squares method to determine the baseline.
  kwargs
  Additional kwargs are passed into the ALS function.
  
  Returns
  
  float
  Value of the noise floor
  rms - float
  Noise RMS/standard deviation
docstring_tokens: Set the noise parameters for the current spectrum . Control over what " defines " the noise floor is specified with the parameter region . By default if region is None then the function will perform an initial peak find using 1% of the maximum intensity as the threshold . The noise region will be established based on the largest gap between peaks i . e . hopefully capturing as little features in the statistics as possible . The alternative method is invoked when the ` als ` argument is set to True which will use the asymmetric least - squares method to determine the baseline . Afterwards the baseline is decimated by an extremely heavy Gaussian blur and one ends up with a smoothly varying baseline . In this case there is no ` noise_rms ` attribute to be returned as it is not required to determine the minimum peak threshold . Parameters region : 2 - tuple or None optional If None use the automatic algorithm . Otherwise a 2 - tuple specifies the region of the spectrum in frequency to use for noise statistics . als : bool optional If True will use the asymmetric least squares method to determine the baseline . kwargs Additional kwargs are passed into the ALS function . Returns float Value of the noise floor rms - float Noise RMS / standard deviation
code: def detect_noise_floor(self, region=None, als=True, **kwargs):
          """
          Set the noise parameters for the current spectrum. Control over what "defines" the noise floor
          is specified with the parameter region. By default, if region is None then the function will
          perform an initial peak find using 1% of the maximum intensity as the threshold. The noise region
          will be established based on the largest gap between peaks, i.e. hopefully capturing as little
          features in the statistics as possible.
          
          The alternative method is invoked when the `als` argument is set to True, which will use the
          asymmetric least-squares method to determine the baseline. Afterwards, the baseline is decimated
          by an extremely heavy Gaussian blur, and one ends up with a smoothly varying baseline. In this
          case, there is no `noise_rms` attribute to be returned as it is not required to determine the
          minimum peak threshold.
  
          Parameters
          ----------
          region : 2-tuple or None, optional
              If None, use the automatic algorithm. Otherwise, a 2-tuple specifies the region of the spectrum
              in frequency to use for noise statistics.
          als : bool, optional
              If True, will use the asymmetric least squares method to determine the baseline.
          kwargs
              Additional kwargs are passed into the ALS function.
  
          Returns
          -------
          baseline - float
              Value of the noise floor
          rms - float
              Noise RMS/standard deviation
          """
          if als is False:
              if region is None:
                  # Perform rudimentary peak detection
                  threshold = 0.2 * self.data[self.int_col].max()
                  peaks_df = analysis.peak_find(
                      self.data,
                      freq_col=self.freq_col,
                      int_col=self.int_col,
                      thres=threshold,
                  )
                  if len(peaks_df) >= 2:
                      # find largest gap in data, including the edges of the spectrum
                      freq_values = list(peaks_df["Frequency"].values)
                      freq_values.extend(
                          [self.data[self.freq_col].min(), self.data[self.freq_col].max()]
                      )
                      # sort the values
                      freq_values = sorted(freq_values)
                      self.logger.info("Possible noise region:")
                      self.logger.info(freq_values)
                      index = np.argmax(np.diff(freq_values))
                      # Define region as the largest gap
                      region = freq_values[index : index + 2]
                      # Add a 30 MHz offset to either end of the spectrum
                      region[0] = region[0] + 30.0
                      region[1] = region[1] - 30.0
                      # Make sure the frequencies are in ascending order
                      region = np.sort(region)
                      self.logger.info(
                          "Noise region defined as {} to {}.".format(*region)
                      )
                      noise_df = self.data.loc[self.data[self.freq_col].between(*region)]
                      if len(noise_df) < 50:
                          noise_df = self.data.sample(int(len(self.data) * 0.1))
                          self.logger.warning(
                              "Noise region too small; taking a statistical sample."
                          )
                  else:
                      # If we haven't found any peaks, sample 10% of random channels and determine the
                      # baseline from those values
                      noise_df = self.data.sample(int(len(self.data) * 0.1))
                      self.logger.warning(
                          "No obvious peaks detected; taking a statistical sample."
                      )
              else:
                  # If we haven't found any peaks, sample 10% of random channels and determine the
                  # baseline from those values
                  noise_df = self.data.sample(int(len(self.data) * 0.1))
                  self.logger.warning(
                      "No obvious peaks detected; taking a statistical sample."
                  )
                  # Calculate statistics
              baseline = np.average(noise_df[self.int_col])
              rms = np.std(noise_df[self.int_col])
              self.session.noise_region = region
              self.session.noise_rms = rms
              self.session.baseline = baseline
              self.logger.info(f"Baseline signal set to {baseline}.")
              self.logger.info(f"Noise RMS set to {rms}.")
          elif als is True:
              # Use the asymmetric least-squares method to determine the baseline
              self.logger.info(
                  "Using asymmetric least squares method for baseline determination."
              )
              als_params = {"lam": 1e2, "p": 0.05, "niter": 10}
              als_params.update(**kwargs)
              baseline = fitting.baseline_als(self.data[self.int_col], **als_params)
              # Decimate the noise with a huge Gaussian blur
              baseline = gaussian_filter(baseline, 200.0)
              rms = np.std(baseline)
              self.session.baseline = baseline
              self.session.noise_region = "als"
              self.session.noise_rms = rms
          return baseline, rms
code_tokens: def detect_noise_floor ( self , region = None , als = True , ** kwargs ) : if als is False : if region is None : threshold = 0.2 * self . data [ self . int_col ] . max ( ) peaks_df = analysis . peak_find ( self . data , freq_col = self . freq_col , int_col = self . int_col , thres = threshold , ) if len ( peaks_df ) >= 2 : freq_values = list ( peaks_df [ "Frequency" ] . values ) freq_values . extend ( [ self . data [ self . freq_col ] . min ( ) , self . data [ self . freq_col ] . max ( ) ] ) freq_values = sorted ( freq_values ) self . logger . info ( "Possible noise region:" ) self . logger . info ( freq_values ) index = np . argmax ( np . diff ( freq_values ) ) region = freq_values [ index : index + 2 ] region [ 0 ] = region [ 0 ] + 30.0 region [ 1 ] = region [ 1 ] - 30.0 region = np . sort ( region ) self . logger . info ( "Noise region defined as {} to {}." . format ( * region ) ) noise_df = self . data . loc [ self . data [ self . freq_col ] . between ( * region ) ] if len ( noise_df ) < 50 : noise_df = self . data . sample ( int ( len ( self . data ) * 0.1 ) ) self . logger . warning ( "Noise region too small; taking a statistical sample." ) else : noise_df = self . data . sample ( int ( len ( self . data ) * 0.1 ) ) self . logger . warning ( "No obvious peaks detected; taking a statistical sample." ) else : noise_df = self . data . sample ( int ( len ( self . data ) * 0.1 ) ) self . logger . warning ( "No obvious peaks detected; taking a statistical sample." ) baseline = np . average ( noise_df [ self . int_col ] ) rms = np . std ( noise_df [ self . int_col ] ) self . session . noise_region = region self . session . noise_rms = rms self . session . baseline = baseline self . logger . info ( f"Baseline signal set to {baseline}." ) self . logger . info ( f"Noise RMS set to {rms}." ) elif als is True : self . logger . info ( "Using asymmetric least squares method for baseline determination." ) als_params = { "lam" : 1e2 , "p" : 0.05 , "niter" : 10 } als_params . update ( ** kwargs ) baseline = fitting . baseline_als ( self . data [ self . int_col ] , ** als_params ) baseline = gaussian_filter ( baseline , 200.0 ) rms = np . std ( baseline ) self . session . baseline = baseline self . session . noise_region = "als" self . session . noise_rms = rms return baseline , rms
short_docstring: Set the noise parameters for the current spectrum.
short_docstring_tokens: Set the noise parameters for the current spectrum .
comment: """
          Set the noise parameters for the current spectrum. Control over what "defines" the noise floor
          is specified with the parameter region. By default, if region is None then the function will
          perform an initial peak find using 1% of the maximum intensity as the threshold. The noise region
          will be established based on the largest gap between peaks, i.e. hopefully capturing as little
          features in the statistics as possible.
          
          The alternative method is invoked when the `als` argument is set to True, which will use the
          asymmetric least-squares method to determine the baseline. Afterwards, the baseline is decimated
          by an extremely heavy Gaussian blur, and one ends up with a smoothly varying baseline. In this
          case, there is no `noise_rms` attribute to be returned as it is not required to determine the
          minimum peak threshold.
  
          Parameters
          ----------
          region : 2-tuple or None, optional
              If None, use the automatic algorithm. Otherwise, a 2-tuple specifies the region of the spectrum
              in frequency to use for noise statistics.
          als : bool, optional
              If True, will use the asymmetric least squares method to determine the baseline.
          kwargs
              Additional kwargs are passed into the ALS function.
  
          Returns
          -------
          baseline - float
              Value of the noise floor
          rms - float
              Noise RMS/standard deviation
          """$SEP$# Perform rudimentary peak detection$SEP$# find largest gap in data, including the edges of the spectrum$SEP$# sort the values$SEP$# Define region as the largest gap$SEP$# Add a 30 MHz offset to either end of the spectrum$SEP$# Make sure the frequencies are in ascending order$SEP$# If we haven't found any peaks, sample 10% of random channels and determine the$SEP$# baseline from those values$SEP$# If we haven't found any peaks, sample 10% of random channels and determine the$SEP$# baseline from those values$SEP$# Calculate statistics$SEP$# Use the asymmetric least-squares method to determine the baseline$SEP$# Decimate the noise with a huge Gaussian blur