original_docstring: 
              Find peaks in the experiment spectrum, with a specified threshold value or automatic threshold.
              The method calls the peak_find function from the analysis module, which in itself wraps peakutils.
  
              The function works by finding regions of the intensity where the first derivative goes to zero
              and changes sign. This gives peak frequency/intensities from the digitized spectrum, which is
              then "refined" by interpolating over each peak and fitting a Gaussian to determine the peak.
  
              The peaks are then returned as a pandas DataFrame, which can also be accessed in the peaks_df
              attribute of AssignmentSession.
              
              When a value of threshold is not provided, the function will turn to use automated methods for
              noise detection, either by taking a single value as the baseline (not ALS), or by using the
              asymmetric least-squares method for fitting the baseline. In both instances, the primary intensity
              column to be used for analysis will be changed to "SNR", which is the recommended approach.
  
              To use the ALS algorithm there may be some tweaking involved for the parameters.
              These are typically found empirically, but for reference here are some "optimal" values
              that have been tested.
              
              For millimeter-wave spectra, larger values of lambda are favored:
              
              lambda = 1e5
              p = 0.1
              
              This should get rid of periodic (fringe) baselines, and leave the "real" signal behind.
  
              Parameters
              ----------
              threshold : float or None, optional
                  Peak detection threshold. If None, will take 1.5 times the noise RMS.
              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.
              sigma : float, optional
                  Defines the number of sigma (noise RMS) above the baseline to use as the peak detection threshold.
              min_dist : int, optional
                  Number of channels between peaks to be detected.
              als : bool, optional
                  If True, uses ALS fitting to determine a baseline.
              kwargs
                  Additional keyword arguments are passed to the ALS fitting routine.
  
              Returns
              -------
              peaks_df : dataframe
                  Pandas dataframe with Frequency/Intensity columns, corresponding to peaks
          
docstring: Find peaks in the experiment spectrum, with a specified threshold value or automatic threshold.
  The method calls the peak_find function from the analysis module, which in itself wraps peakutils.
  
  The function works by finding regions of the intensity where the first derivative goes to zero
  and changes sign. This gives peak frequency/intensities from the digitized spectrum, which is
  then "refined" by interpolating over each peak and fitting a Gaussian to determine the peak.
  
  The peaks are then returned as a pandas DataFrame, which can also be accessed in the peaks_df
  attribute of AssignmentSession.
  
  When a value of threshold is not provided, the function will turn to use automated methods for
  noise detection, either by taking a single value as the baseline (not ALS), or by using the
  asymmetric least-squares method for fitting the baseline. In both instances, the primary intensity
  column to be used for analysis will be changed to "SNR", which is the recommended approach.
  
  To use the ALS algorithm there may be some tweaking involved for the parameters.
  These are typically found empirically, but for reference here are some "optimal" values
  that have been tested.
  
  For millimeter-wave spectra, larger values of lambda are favored.
  
  
  
  This should get rid of periodic (fringe) baselines, and leave the "real" signal behind.
  
  Parameters
  
  threshold : float or None, optional
  Peak detection threshold. If None, will take 1.5 times the noise RMS.
  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.
  sigma : float, optional
  Defines the number of sigma (noise RMS) above the baseline to use as the peak detection threshold.
  min_dist : int, optional
  Number of channels between peaks to be detected.
  als : bool, optional
  If True, uses ALS fitting to determine a baseline.
  kwargs
  Additional keyword arguments are passed to the ALS fitting routine.
  
  Returns
  
  peaks_df : dataframe
  Pandas dataframe with Frequency/Intensity columns, corresponding to peaks
docstring_tokens: Find peaks in the experiment spectrum with a specified threshold value or automatic threshold . The method calls the peak_find function from the analysis module which in itself wraps peakutils . The function works by finding regions of the intensity where the first derivative goes to zero and changes sign . This gives peak frequency / intensities from the digitized spectrum which is then " refined " by interpolating over each peak and fitting a Gaussian to determine the peak . The peaks are then returned as a pandas DataFrame which can also be accessed in the peaks_df attribute of AssignmentSession . When a value of threshold is not provided the function will turn to use automated methods for noise detection either by taking a single value as the baseline ( not ALS ) or by using the asymmetric least - squares method for fitting the baseline . In both instances the primary intensity column to be used for analysis will be changed to " SNR " which is the recommended approach . To use the ALS algorithm there may be some tweaking involved for the parameters . These are typically found empirically but for reference here are some " optimal " values that have been tested . For millimeter - wave spectra larger values of lambda are favored . This should get rid of periodic ( fringe ) baselines and leave the " real " signal behind . Parameters threshold : float or None optional Peak detection threshold . If None will take 1 . 5 times the noise RMS . 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 . sigma : float optional Defines the number of sigma ( noise RMS ) above the baseline to use as the peak detection threshold . min_dist : int optional Number of channels between peaks to be detected . als : bool optional If True uses ALS fitting to determine a baseline . kwargs Additional keyword arguments are passed to the ALS fitting routine . Returns peaks_df : dataframe Pandas dataframe with Frequency / Intensity columns corresponding to peaks
code: def find_peaks(
          self, threshold=None, region=None, sigma=6, min_dist=10, als=True, **kwargs
      ):
          """
              Find peaks in the experiment spectrum, with a specified threshold value or automatic threshold.
              The method calls the peak_find function from the analysis module, which in itself wraps peakutils.
  
              The function works by finding regions of the intensity where the first derivative goes to zero
              and changes sign. This gives peak frequency/intensities from the digitized spectrum, which is
              then "refined" by interpolating over each peak and fitting a Gaussian to determine the peak.
  
              The peaks are then returned as a pandas DataFrame, which can also be accessed in the peaks_df
              attribute of AssignmentSession.
              
              When a value of threshold is not provided, the function will turn to use automated methods for
              noise detection, either by taking a single value as the baseline (not ALS), or by using the
              asymmetric least-squares method for fitting the baseline. In both instances, the primary intensity
              column to be used for analysis will be changed to "SNR", which is the recommended approach.
  
              To use the ALS algorithm there may be some tweaking involved for the parameters.
              These are typically found empirically, but for reference here are some "optimal" values
              that have been tested.
              
              For millimeter-wave spectra, larger values of lambda are favored:
              
              lambda = 1e5
              p = 0.1
              
              This should get rid of periodic (fringe) baselines, and leave the "real" signal behind.
  
              Parameters
              ----------
              threshold : float or None, optional
                  Peak detection threshold. If None, will take 1.5 times the noise RMS.
              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.
              sigma : float, optional
                  Defines the number of sigma (noise RMS) above the baseline to use as the peak detection threshold.
              min_dist : int, optional
                  Number of channels between peaks to be detected.
              als : bool, optional
                  If True, uses ALS fitting to determine a baseline.
              kwargs
                  Additional keyword arguments are passed to the ALS fitting routine.
  
              Returns
              -------
              peaks_df : dataframe
                  Pandas dataframe with Frequency/Intensity columns, corresponding to peaks
          """
          if self.int_col == "SNR":
              # if we run peak find again, the int_col is incorrectly
              # going to be set to SNR giving us bad results. Use the
              # last column instead.
              columns = self.data.columns.to_list()
              columns = [col for col in columns if col != "SNR"]
              self.int_col = columns[-1]
              self.logger.info(f"SNR set as int_col and is invalid for peak finding. Using {self.int_col} instead.")
          if threshold is None and als is False:
              # Use a quasi-intelligent method of determining the noise floor
              # and ultimately using noise + 1 sigma
              baseline, rms = self.detect_noise_floor(region)
              threshold = baseline + (rms * sigma)
              # Convert threshold into SNR units
              threshold /= baseline
              self.data["SNR"] = self.data[self.int_col] / np.abs(baseline)
              self.int_col = "SNR"
              self.logger.info("Now using SNR as primary intensity unit.")
          elif threshold is None and als is True:
              baseline, _ = self.detect_noise_floor(als=True, **kwargs)
              # Convert to SNR, and start using this instead
              self.data["SNR"] = self.data[self.int_col] / np.abs(baseline)
              self.int_col = "SNR"
              self.logger.info("Now using SNR as primary intensity unit.")
              # If using ALS, the sigma argument becomes the threshold value in SNR units
              threshold = sigma
          self.threshold = threshold
          self.logger.info(f"Peak detection threshold is: {threshold}")
          peaks_df = analysis.peak_find(
              self.data,
              freq_col=self.freq_col,
              int_col=self.int_col,
              thres=threshold,
              min_dist=min_dist,
          )
          # Shift the peak intensities down by the noise baseline
          if als is False:
              baseline = getattr(self.session, "baseline", 0.0)
              peaks_df.loc[:, self.int_col] = peaks_df[self.int_col] - baseline
          self.logger.info(f"Found {len(peaks_df)} peaks in total.")
          # Reindex the peaks
          peaks_df.reset_index(drop=True, inplace=True)
          if len(peaks_df) != 0:
              # Generate U-lines
              self.df2ulines(peaks_df, self.freq_col, self.int_col)
              # Assign attribute
              self.peaks = peaks_df
              self.peaks.to_csv(
                  f"./outputs/{self.session.experiment}-peaks.csv", index=False
              )
              return peaks_df
          else:
              return None
code_tokens: def find_peaks ( self , threshold = None , region = None , sigma = 6 , min_dist = 10 , als = True , ** kwargs ) : if self . int_col == "SNR" : columns = self . data . columns . to_list ( ) columns = [ col for col in columns if col != "SNR" ] self . int_col = columns [ - 1 ] self . logger . info ( f"SNR set as int_col and is invalid for peak finding. Using {self.int_col} instead." ) if threshold is None and als is False : baseline , rms = self . detect_noise_floor ( region ) threshold = baseline + ( rms * sigma ) threshold /= baseline self . data [ "SNR" ] = self . data [ self . int_col ] / np . abs ( baseline ) self . int_col = "SNR" self . logger . info ( "Now using SNR as primary intensity unit." ) elif threshold is None and als is True : baseline , _ = self . detect_noise_floor ( als = True , ** kwargs ) self . data [ "SNR" ] = self . data [ self . int_col ] / np . abs ( baseline ) self . int_col = "SNR" self . logger . info ( "Now using SNR as primary intensity unit." ) threshold = sigma self . threshold = threshold self . logger . info ( f"Peak detection threshold is: {threshold}" ) peaks_df = analysis . peak_find ( self . data , freq_col = self . freq_col , int_col = self . int_col , thres = threshold , min_dist = min_dist , ) if als is False : baseline = getattr ( self . session , "baseline" , 0.0 ) peaks_df . loc [ : , self . int_col ] = peaks_df [ self . int_col ] - baseline self . logger . info ( f"Found {len(peaks_df)} peaks in total." ) peaks_df . reset_index ( drop = True , inplace = True ) if len ( peaks_df ) != 0 : self . df2ulines ( peaks_df , self . freq_col , self . int_col ) self . peaks = peaks_df self . peaks . to_csv ( f"./outputs/{self.session.experiment}-peaks.csv" , index = False ) return peaks_df else : return None
short_docstring: Find peaks in the experiment spectrum, with a specified threshold value or automatic threshold.
short_docstring_tokens: Find peaks in the experiment spectrum with a specified threshold value or automatic threshold .
comment: """
              Find peaks in the experiment spectrum, with a specified threshold value or automatic threshold.
              The method calls the peak_find function from the analysis module, which in itself wraps peakutils.
  
              The function works by finding regions of the intensity where the first derivative goes to zero
              and changes sign. This gives peak frequency/intensities from the digitized spectrum, which is
              then "refined" by interpolating over each peak and fitting a Gaussian to determine the peak.
  
              The peaks are then returned as a pandas DataFrame, which can also be accessed in the peaks_df
              attribute of AssignmentSession.
              
              When a value of threshold is not provided, the function will turn to use automated methods for
              noise detection, either by taking a single value as the baseline (not ALS), or by using the
              asymmetric least-squares method for fitting the baseline. In both instances, the primary intensity
              column to be used for analysis will be changed to "SNR", which is the recommended approach.
  
              To use the ALS algorithm there may be some tweaking involved for the parameters.
              These are typically found empirically, but for reference here are some "optimal" values
              that have been tested.
              
              For millimeter-wave spectra, larger values of lambda are favored:
              
              lambda = 1e5
              p = 0.1
              
              This should get rid of periodic (fringe) baselines, and leave the "real" signal behind.
  
              Parameters
              ----------
              threshold : float or None, optional
                  Peak detection threshold. If None, will take 1.5 times the noise RMS.
              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.
              sigma : float, optional
                  Defines the number of sigma (noise RMS) above the baseline to use as the peak detection threshold.
              min_dist : int, optional
                  Number of channels between peaks to be detected.
              als : bool, optional
                  If True, uses ALS fitting to determine a baseline.
              kwargs
                  Additional keyword arguments are passed to the ALS fitting routine.
  
              Returns
              -------
              peaks_df : dataframe
                  Pandas dataframe with Frequency/Intensity columns, corresponding to peaks
          """$SEP$# if we run peak find again, the int_col is incorrectly$SEP$# going to be set to SNR giving us bad results. Use the$SEP$# last column instead.$SEP$# Use a quasi-intelligent method of determining the noise floor$SEP$# and ultimately using noise + 1 sigma$SEP$# Convert threshold into SNR units$SEP$# Convert to SNR, and start using this instead$SEP$# If using ALS, the sigma argument becomes the threshold value in SNR units$SEP$# Shift the peak intensities down by the noise baseline$SEP$# Reindex the peaks$SEP$# Generate U-lines$SEP$# Assign attribute