docs: def write_sorting(sorting, save_path, sampling_frequency):
          '''
          Save sorting extractor to MEArec format.
          Parameters
          ----------
          sorting: SortingExtractor
              Sorting extractor object to be saved
          save_path: str
              .h5 or .hdf5 path
          sampling_frequency: int
              Sampling frequency in Hz
  
          '''
          assert HAVE_MREX, "To use the MEArec extractors, install MEArec: \n\n pip install MEArec\n\n"
          save_path = Path(save_path)
          if save_path.is_dir():
              print("The file will be saved as sorting.h5 in the provided folder")
              save_path = save_path / 'sorting.h5'
          if save_path.suffix == '.h5' or save_path.suffix == '.hdf5':
              # create neo spike trains
              spiketrains = []
              for u in sorting.get_unit_ids():
                  st = neo.SpikeTrain(times=sorting.get_unit_spike_train(u) / float(sampling_frequency) * pq.s,
                                      t_start=np.min(sorting.get_unit_spike_train(u) / float(sampling_frequency)) * pq.s,
                                      t_stop=np.max(sorting.get_unit_spike_train(u) / float(sampling_frequency)) * pq.s)
                  st.annotate(unit_id=u)
                  spiketrains.append(st)
  
              duration = np.max([st.t_stop.magnitude for st in spiketrains])
              info = {'recordings': {'fs': sampling_frequency}, 'spiketrains': {'duration': duration}}
              rec_dict = {'spiketrains': spiketrains}
              recgen = mr.RecordingGenerator(rec_dict=rec_dict, info=info)
              mr.save_recording_generator(recgen, str(save_path), verbose=False)
          else:
              raise Exception("Provide a folder or an .h5/.hdf5 as 'save_path'")