original_docstring: 
      Calculate average position per phase and subtract it in order to estimate noise levels.
      Leaves input unchanged, returns dataframe with extra columns 'mean*' and 'noise*' contains the averages.
      
docstring: Calculate average position per phase and subtract it in order to estimate noise levels.
  Leaves input unchanged, returns dataframe with extra columns 'mean*' and 'noise*' contains the averages.
docstring_tokens: Calculate average position per phase and subtract it in order to estimate noise levels . Leaves input unchanged returns dataframe with extra columns ' mean * ' and ' noise * ' contains the averages .
code: def split_mean_noise_per_phase(df):
      """
      Calculate average position per phase and subtract it in order to estimate noise levels.
      Leaves input unchanged, returns dataframe with extra columns 'mean*' and 'noise*' contains the averages.
      """
      # which phases to keep
      phases = set(df['phase'].values)
      phases.remove(0)
      # iterate over phases
      result = df.copy()
      for phase in phases:
          # filter dataframe for this phase
          mask = (df['phase'] == phase)
          maskn = (df['phase'] == phase) & ~np.isnan(df['pos_Rz'])
          # if one coordinate is missing (NaN), then all are
          dfp = df[maskn]
          # subtract average and store it
          for dof in ['x', 'y', 'Rz']:
              avg = np.mean(dfp['pos_'+dof])
              result.loc[mask, 'noise_'+dof] = result.loc[mask, 'pos_'+dof] - avg
              result.loc[mask, 'mean_'+dof] = avg
              if dof == 'Rz':
                  # numpy.unwrap was used to make angle continuous, but from now on (presentation purposes) we want a standardized value in [0,2pi)
                  result.loc[mask, 'mean_'+dof] %= (2 * np.pi)
      return result
code_tokens: def split_mean_noise_per_phase ( df ) : phases = set ( df [ 'phase' ] . values ) phases . remove ( 0 ) result = df . copy ( ) for phase in phases : mask = ( df [ 'phase' ] == phase ) maskn = ( df [ 'phase' ] == phase ) & ~ np . isnan ( df [ 'pos_Rz' ] ) dfp = df [ maskn ] for dof in [ 'x' , 'y' , 'Rz' ] : avg = np . mean ( dfp [ 'pos_' + dof ] ) result . loc [ mask , 'noise_' + dof ] = result . loc [ mask , 'pos_' + dof ] - avg result . loc [ mask , 'mean_' + dof ] = avg if dof == 'Rz' : result . loc [ mask , 'mean_' + dof ] %= ( 2 * np . pi ) return result
short_docstring: Calculate average position per phase and subtract it in order to estimate noise levels.
short_docstring_tokens: Calculate average position per phase and subtract it in order to estimate noise levels .
comment: """
      Calculate average position per phase and subtract it in order to estimate noise levels.
      Leaves input unchanged, returns dataframe with extra columns 'mean*' and 'noise*' contains the averages.
      """$SEP$# which phases to keep$SEP$# iterate over phases$SEP$# filter dataframe for this phase$SEP$# if one coordinate is missing (NaN), then all are$SEP$# subtract average and store it$SEP$# numpy.unwrap was used to make angle continuous, but from now on (presentation purposes) we want a standardized value in [0,2pi)