Repository: spikeinterface/spikeinterface
Issue: Unable to save waveforms and post-processed data for curated units

I'm going through this spikeinteface tutorial: https://github.com/SpikeInterface/spiketutorials/blob/master/Official_Tutorial_SI_0.96_Oct22/SpikeInterface_Tutorial.ipynb

The line of code below gives me the associated stack trace below:
`we_curated = we.select_units(keep_unit_ids, new_folder="waveforms_curated")`

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [106], line 1
----> 1 we_curated = we.select_units(keep_unit_ids, new_folder="waveforms_curated")

File /opt/anaconda/anaconda3/envs/si_env/lib/python3.9/site-packages/spikeinterface/core/waveform_extractor.py:529, in WaveformExtractor.select_units(self, unit_ids, new_folder, use_relative_path)
    527 for ext_name in self.get_available_extension_names():
    528     ext = self.load_extension(ext_name)
--> 529     ext.select_units(unit_ids, new_waveform_extractor=we)
    531 return we

File /opt/anaconda/anaconda3/envs/si_env/lib/python3.9/site-packages/spikeinterface/core/waveform_extractor.py:1124, in BaseWaveformExtractorExtension.select_units(self, unit_ids, new_waveform_extractor)
   1122 new_extension = self.__class__(new_waveform_extractor)
   1123 new_extension.set_params(**self._params)
-> 1124 new_extension_data = self._select_extension_data(unit_ids=unit_ids)
   1125 new_extension._extension_data = new_extension_data
   1126 new_extension._save()

File /opt/anaconda/anaconda3/envs/si_env/lib/python3.9/site-packages/spikeinterface/postprocessing/template_metrics.py:53, in TemplateMetricsCalculator._select_extension_data(self, unit_ids)
     51 def _select_extension_data(self, unit_ids):
     52     # filter metrics dataframe
---> 53     new_metrics = self.template_metrics.loc[np.array(unit_ids)]
     54     return dict(metrics=new_metrics)

AttributeError: 'TemplateMetricsCalculator' object has no attribute 'template_metrics'

Changed files:
spikeinterface/postprocessing/template_metrics.py, spikeinterface/postprocessing/tests/common_extension_tests.py

diff --git a/spikeinterface/postprocessing/template_metrics.py b/spikeinterface/postprocessing/template_metrics.py
index ffefe048..fb27a7f8 100644
--- a/spikeinterface/postprocessing/template_metrics.py
+++ b/spikeinterface/postprocessing/template_metrics.py
@@ -50,7 +50,7 @@ class TemplateMetricsCalculator(BaseWaveformExtractorExtension):
 
     def _select_extension_data(self, unit_ids):
         # filter metrics dataframe
-        new_metrics = self.template_metrics.loc[np.array(unit_ids)]
+        new_metrics = self._extension_data['metrics'].loc[np.array(unit_ids)]
         return dict(metrics=new_metrics)
         
     def _run(self):
diff --git a/spikeinterface/postprocessing/tests/common_extension_tests.py b/spikeinterface/postprocessing/tests/common_extension_tests.py
index e72b3d77..d4a7f745 100644
--- a/spikeinterface/postprocessing/tests/common_extension_tests.py
+++ b/spikeinterface/postprocessing/tests/common_extension_tests.py
@@ -1,4 +1,5 @@
 import pytest
+import shutil
 from spikeinterface import extract_waveforms, load_extractor
 from spikeinterface.extractors import toy_example
 from spikeinterface.postprocessing import get_template_channel_sparsity
@@ -75,15 +76,25 @@ class WaveformExtensionCommonTestSuite:
             _ = self.extension_class.get_extension_function()(we, **ext_kwargs)
             # reload as an extension from we
             assert self.extension_class.extension_name in we.get_available_extension_names()
-            assert self.we1.is_extension(self.extension_class.extension_name)
-            ext = self.we1.load_extension(self.extension_class.extension_name)
+            assert we.is_extension(self.extension_class.extension_name)
+            ext = we.load_extension(self.extension_class.extension_name)
             assert isinstance(ext, self.extension_class)
             for ext_name in self.extension_data_names:
                 assert ext_name in ext._extension_data
             if not in_memory:
+                # test select units
+                new_folder = cache_folder / f"{we.folder.stem}_{self.extension_class.extension_name}_selected"
+                if new_folder.is_dir():
+                    shutil.rmtree(new_folder)
+                we_new = we.select_units(unit_ids=we.sorting.unit_ids[::2], 
+                                         new_folder=cache_folder / \\
+                                             f"{we.folder.stem}_{self.extension_class.extension_name}_selected")
                 ext_loaded = self.extension_class.load_from_folder(we.folder)
                 for ext_name in self.extension_data_names:
                     assert ext_name in ext_loaded._extension_data
+            else:
+                # test select units
+                we_new = we.select_units(unit_ids=we.sorting.unit_ids[::2])
     
     def test_extension(self):
         print("Test extension", self.extension_class)