original_docstring: 
          Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes.
  
          Parameters
          ----------
          Q - float
              Partition function at temperature T
          T - float
              Temperature in Kelvin
          name - str, optional
              Name of the molecule to perform the analysis on. Can be used as a selector.
          formula - str, optional
              Chemical formula of the molecule to perform the analysis on. Can be used as a selector.
          smiles - str, optional
              SMILES code of the molecule to perform the analysis on. Can be used as a selector,
          chi_thres - float
              Threshold for the Chi Squared value to consider fits for statistics. Any instances of fits with Chi
              squared values above this value will not be used to calculate line profile statistics.
  
          Returns
          -------
          return_data - list
              First element is the profile dataframe, and second element is the fitted velocity.
              If a rotational temperature analysis is also performed, the third element will be the least-squares
              regression.
  
          
docstring: Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes.
  Parameters
  
  float
  Partition function at temperature T
  T - float
  Temperature in Kelvin
  name - str, optional
  Name of the molecule to perform the analysis on. Can be used as a selector.
  formula - str, optional
  Chemical formula of the molecule to perform the analysis on. Can be used as a selector.
  smiles - str, optional
  SMILES code of the molecule to perform the analysis on. Can be used as a selector,
  chi_thres - float
  Threshold for the Chi Squared value to consider fits for statistics. Any instances of fits with Chi
  squared values above this value will not be used to calculate line profile statistics.
  
  Returns
  
  list
  First element is the profile dataframe, and second element is the fitted velocity.
  If a rotational temperature analysis is also performed, the third element will be the least-squares
  regression.
docstring_tokens: Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes . Parameters float Partition function at temperature T T - float Temperature in Kelvin name - str optional Name of the molecule to perform the analysis on . Can be used as a selector . formula - str optional Chemical formula of the molecule to perform the analysis on . Can be used as a selector . smiles - str optional SMILES code of the molecule to perform the analysis on . Can be used as a selector chi_thres - float Threshold for the Chi Squared value to consider fits for statistics . Any instances of fits with Chi squared values above this value will not be used to calculate line profile statistics . Returns list First element is the profile dataframe and second element is the fitted velocity . If a rotational temperature analysis is also performed the third element will be the least - squares regression .
code: def analyze_molecule(
          self, Q=None, T=None, name=None, formula=None, smiles=None, chi_thres=10.0
      ):
          """
          Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes.
  
          Parameters
          ----------
          Q - float
              Partition function at temperature T
          T - float
              Temperature in Kelvin
          name - str, optional
              Name of the molecule to perform the analysis on. Can be used as a selector.
          formula - str, optional
              Chemical formula of the molecule to perform the analysis on. Can be used as a selector.
          smiles - str, optional
              SMILES code of the molecule to perform the analysis on. Can be used as a selector,
          chi_thres - float
              Threshold for the Chi Squared value to consider fits for statistics. Any instances of fits with Chi
              squared values above this value will not be used to calculate line profile statistics.
  
          Returns
          -------
          return_data - list
              First element is the profile dataframe, and second element is the fitted velocity.
              If a rotational temperature analysis is also performed, the third element will be the least-squares
              regression.
  
          """
          if name:
              selector = "name"
              value = name
          elif formula:
              selector = "formula"
              value = formula
          elif smiles:
              selector = "smiles"
              value = smiles
          else:
              raise Exception(
                  "No valid selector specified! Please give a name, formula, or SMILES code."
              )
          # Loop over all of the assignments
          mol_data = list()
          for index, ass_obj in enumerate(self.assignments):
              # If the assignment matches the criteria
              # we perform the analysis
              if ass_obj.__dict__[selector] == value:
                  self.logger.info(
                      f"Performing line profile analysis on assignment index {index}."
                  )
                  # Perform a Gaussian fit whilst supplying as much information as we can
                  # The width is excluded because it changes significantly between line profiles
                  fit_result, summary = analysis.fit_line_profile(
                      self.data,
                      center=ass_obj.frequency,
                      intensity=ass_obj.intensity,
                      freq_col=self.freq_col,
                      int_col=self.int_col,
                      logger=self.logger,
                  )
                  # If the fit actually converged and worked
                  if fit_result:
                      # Calculate what the lab frame frequency would be in order to calculate the frequency offset
                      lab_freq = fit_result.best_values["center"] + units.dop2freq(
                          self.session.velocity, fit_result.best_values["center"]
                      )
                      summary["Frequency offset"] = lab_freq - ass_obj.catalog_frequency
                      summary["Doppler velocity"] = units.freq2vel(
                          ass_obj.catalog_frequency, summary["Frequency offset"]
                      )
                      if Q is not None and T is not None:
                          # Add the profile parameters to list
                          profile_dict = aa.lineprofile_analysis(
                              fit_result, ass_obj.I, Q, T, ass_obj.ustate_energy
                          )
                          ass_obj.N = profile_dict["N cm$^{-2}$"]
                          summary.update(profile_dict)
                      ass_obj.fit = fit_result
                      mol_data.append(summary)
          # If there are successful analyses performed, format the results
          if len(mol_data) > 0:
              profile_df = pd.DataFrame(data=mol_data)
              # Sort the dataframe by ascending order of chi square - better fits are at the top
              profile_df.sort_values(["Chi squared"], inplace=True)
              # Threshold the dataframe to ensure good statistics
              profile_df = profile_df.loc[profile_df["Chi squared"] <= chi_thres]
              # Calculate the weighted average VLSR based on the goodness-of-fit
              profile_df.loc[:, "Weight"] = (
                  profile_df["Chi squared"].max() / profile_df["Chi squared"].values
              )
              weighted_avg = np.sum(
                  profile_df["Weight"] * profile_df["Doppler velocity"]
              ) / np.sum(profile_df["Weight"])
              # Calculate the weighted standard deviation
              stdev = np.sum(
                  profile_df["Weight"]
                  * (profile_df["Doppler velocity"] - weighted_avg) ** 2
              ) / np.sum(profile_df["Weight"])
              self.logger.info(
                  f"Calculated VLSR: {weighted_avg:.3f}+/-{stdev:.3f}"
                  f" based on {len(profile_df)} samples."
              )
              return_data = [profile_df, ufloat(weighted_avg, stdev)]
              # If there's data to perform a rotational temperature analysis, then do it!
              if "L" in profile_df.columns:
                  self.logger.info("Performing rotational temperature analysis.")
                  rot_temp = aa.rotational_temperature_analysis(
                      profile_df["L"], profile_df["E upper"]
                  )
                  self.logger.info(rot_temp.fit_report())
                  return_data.append(rot_temp)
              return return_data
          else:
              self.logger.info("No molecules found, or fits were unsuccessful!")
              return None
code_tokens: def analyze_molecule ( self , Q = None , T = None , name = None , formula = None , smiles = None , chi_thres = 10.0 ) : if name : selector = "name" value = name elif formula : selector = "formula" value = formula elif smiles : selector = "smiles" value = smiles else : raise Exception ( "No valid selector specified! Please give a name, formula, or SMILES code." ) mol_data = list ( ) for index , ass_obj in enumerate ( self . assignments ) : if ass_obj . __dict__ [ selector ] == value : self . logger . info ( f"Performing line profile analysis on assignment index {index}." ) fit_result , summary = analysis . fit_line_profile ( self . data , center = ass_obj . frequency , intensity = ass_obj . intensity , freq_col = self . freq_col , int_col = self . int_col , logger = self . logger , ) if fit_result : lab_freq = fit_result . best_values [ "center" ] + units . dop2freq ( self . session . velocity , fit_result . best_values [ "center" ] ) summary [ "Frequency offset" ] = lab_freq - ass_obj . catalog_frequency summary [ "Doppler velocity" ] = units . freq2vel ( ass_obj . catalog_frequency , summary [ "Frequency offset" ] ) if Q is not None and T is not None : profile_dict = aa . lineprofile_analysis ( fit_result , ass_obj . I , Q , T , ass_obj . ustate_energy ) ass_obj . N = profile_dict [ "N cm$^{-2}$" ] summary . update ( profile_dict ) ass_obj . fit = fit_result mol_data . append ( summary ) if len ( mol_data ) > 0 : profile_df = pd . DataFrame ( data = mol_data ) profile_df . sort_values ( [ "Chi squared" ] , inplace = True ) profile_df = profile_df . loc [ profile_df [ "Chi squared" ] <= chi_thres ] profile_df . loc [ : , "Weight" ] = ( profile_df [ "Chi squared" ] . max ( ) / profile_df [ "Chi squared" ] . values ) weighted_avg = np . sum ( profile_df [ "Weight" ] * profile_df [ "Doppler velocity" ] ) / np . sum ( profile_df [ "Weight" ] ) stdev = np . sum ( profile_df [ "Weight" ] * ( profile_df [ "Doppler velocity" ] - weighted_avg ) ** 2 ) / np . sum ( profile_df [ "Weight" ] ) self . logger . info ( f"Calculated VLSR: {weighted_avg:.3f}+/-{stdev:.3f}" f" based on {len(profile_df)} samples." ) return_data = [ profile_df , ufloat ( weighted_avg , stdev ) ] if "L" in profile_df . columns : self . logger . info ( "Performing rotational temperature analysis." ) rot_temp = aa . rotational_temperature_analysis ( profile_df [ "L" ] , profile_df [ "E upper" ] ) self . logger . info ( rot_temp . fit_report ( ) ) return_data . append ( rot_temp ) return return_data else : self . logger . info ( "No molecules found, or fits were unsuccessful!" ) return None
short_docstring: Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes.
short_docstring_tokens: Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes .
comment: """
          Function for providing some astronomically relevant parameters by analyzing Gaussian line shapes.
  
          Parameters
          ----------
          Q - float
              Partition function at temperature T
          T - float
              Temperature in Kelvin
          name - str, optional
              Name of the molecule to perform the analysis on. Can be used as a selector.
          formula - str, optional
              Chemical formula of the molecule to perform the analysis on. Can be used as a selector.
          smiles - str, optional
              SMILES code of the molecule to perform the analysis on. Can be used as a selector,
          chi_thres - float
              Threshold for the Chi Squared value to consider fits for statistics. Any instances of fits with Chi
              squared values above this value will not be used to calculate line profile statistics.
  
          Returns
          -------
          return_data - list
              First element is the profile dataframe, and second element is the fitted velocity.
              If a rotational temperature analysis is also performed, the third element will be the least-squares
              regression.
  
          """$SEP$# Loop over all of the assignments$SEP$# If the assignment matches the criteria$SEP$# we perform the analysis$SEP$# Perform a Gaussian fit whilst supplying as much information as we can$SEP$# The width is excluded because it changes significantly between line profiles$SEP$# If the fit actually converged and worked$SEP$# Calculate what the lab frame frequency would be in order to calculate the frequency offset$SEP$# Add the profile parameters to list$SEP$# If there are successful analyses performed, format the results$SEP$# Sort the dataframe by ascending order of chi square - better fits are at the top$SEP$# Threshold the dataframe to ensure good statistics$SEP$# Calculate the weighted average VLSR based on the goodness-of-fit$SEP$# Calculate the weighted standard deviation$SEP$# If there's data to perform a rotational temperature analysis, then do it!