code: def apply_sfr_reach_obs():
      
      assert os.path.exists("sfr_reach_obs.config")
      df_key = pd.read_csv("sfr_reach_obs.config", index_col=0)
  
      assert df_key.iloc[0, 0] == "sfr_out_file", df_key.iloc[0, :]
      sfr_out_file = df_key.iloc[0].reach
      df_key = df_key.iloc[1:, :].copy()
      df_key.loc[:, "segment"] = df_key.segment.apply(np.int)
      df_key.loc[:, "reach"] = df_key.reach.apply(np.int)
      df_key = df_key.set_index('obs_base')
  
      sfr_kper = load_sfr_out(sfr_out_file, df_key)
      kpers = list(sfr_kper.keys())
      kpers.sort()
  
      results = []
      for kper in kpers:
          df = sfr_kper[kper]
          for sr in df_key.itertuples():
              ob = df.loc["{0:03d}_{1:03d}".format(sr.segment, sr.reach), :]
              results.append([kper, sr.Index, ob["flaqx"], ob["flout"]])
      df = pd.DataFrame(data=results, columns=["kper", "obs_base", "flaqx", "flout"])
      df.sort_values(by=["kper", "obs_base"], inplace=True)
      df.to_csv(sfr_out_file+".reach_processed", sep=' ', index=False)
      return df
docs: apply the sfr reach observation process - pairs with setup_sfr_reach_obs().
      requires sfr_reach_obs.config.  Writes <sfr_out_file>.processed, where
      <sfr_out_file> is defined in "sfr_reach_obs.config"
  
  
      Parameters
      ----------
      None
  
      Returns
      -------
      df : pd.DataFrame
          a dataframe of sfr aquifer and outflow ad segment,reach locations