<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Kampff lab - Ultra dense survey
Here a description of the dataset
Step1:  create a DataIO (and remove if already exists)
Step2:  CatalogueConstructor
Run all chain in one shot.
Step3:  Noise measurement
Step4:  Inspect waveform quality at catalogue level
Step5:  construct catalogue
Step6:  apply peeler
This is the real spike sorting
Step7:  final inspection of cells
<ASSISTANT_TASK:>
Python Code:
# suposing the datset is downloaded here
workdir = '/media/samuel/dataspikesorting/DataSpikeSortingHD2/kampff/ultra dense/'
filename = workdir + 'T2/amplifier2017-02-08T21_38_55.bin'
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import tridesclous as tdc
from tridesclous import DataIO, CatalogueConstructor, Peeler
import os, shutil
Explanation: Kampff lab - Ultra dense survey
Here a description of the dataset:
http://www.kampff-lab.org/ultra-dense-survey/
Here the official publication of this open dataset:
https://crcns.org/data-sets/methods/hdr-1/about-hdr-1
And a paper is being preparing here:
https://doi.org/10.1101/275818
Introduction
This dataset explore optimal size and density of electrodes.
Here 255 extracellular electrodes (5 x 5 μm and spacing of 1 μm) 
Download
Dataset must downloaded locally and manually from crcns or from the google drive in "workdir" path.
The PRB file
tridesclous need a PRB file that describe the geometry of probe.
Create it by copy/paste or download it via github.
End of explanation
dirname = workdir + 'tdc_amplifier2017-02-02T17_18_46'
if os.path.exists(dirname):
    #remove is already exists
    shutil.rmtree(dirname)
    
dataio = DataIO(dirname=dirname)
# feed DataIO with one file
dataio.set_data_source(type='RawData', filenames=[filename], 
                    sample_rate=20000., dtype='int16', total_channel=256,
                    bit_to_microVolt=0.195)
print(dataio)
# set the probe file
dataio.set_probe_file('kampff_ultra_dense_256.prb')
Explanation: create a DataIO (and remove if already exists)
End of explanation
cc = CatalogueConstructor(dataio=dataio, chan_grp=0)
fullchain_kargs = {
    'duration' : 300.,
    'preprocessor' : {
        'highpass_freq' : 400.,
        'lowpass_freq' : 5000.,
        'smooth_size' : 0,
        'chunksize' : 1024,
        'lostfront_chunksize' : 128,
        'signalpreprocessor_engine' : 'numpy',
    },
    'peak_detector' : {
        'peakdetector_engine' : 'numpy',
        'peak_sign' : '-',
        'relative_threshold' : 5.,
        'peak_span' : 0.0002,
    },
    'noise_snippet' : {
        'nb_snippet' : 300,
    },
    'extract_waveforms' : {
        'n_left' : -20,
        'n_right' : 30,
        'mode' : 'rand',
        'nb_max' : 20000,
        'align_waveform' : False,
    },
    'clean_waveforms' : {
        'alien_value_threshold' : 100.,
    },
  }
feat_method = 'peak_max'
feat_kargs = {}
clust_method = 'sawchaincut'
clust_kargs = {}
       
tdc.apply_all_catalogue_steps(cc, fullchain_kargs, 
        feat_method, feat_kargs,clust_method, clust_kargs)
print(cc)
Explanation: CatalogueConstructor
Run all chain in one shot.
End of explanation
dataio = DataIO(dirname=dirname)
tdc.summary_noise(dataio=dataio, chan_grp=0)
Explanation: Noise measurement
End of explanation
tdc.summary_catalogue_clusters(dataio=dataio, chan_grp=0, label=0)
Explanation: Inspect waveform quality at catalogue level
End of explanation
cc.make_catalogue_for_peeler()
Explanation: construct catalogue
End of explanation
initial_catalogue = dataio.load_catalogue(chan_grp=0)
peeler = Peeler(dataio)
peeler.change_params(catalogue=initial_catalogue,
            use_sparse_template=True,
            sparse_threshold_mad=1.5,
            use_opencl_with_sparse=True,
             cl_platform_index=1,
            cl_device_index=0)
peeler.run(duration=300.,
            progressbar=True)
Explanation: apply peeler
This is the real spike sorting: find spike that correcpond to catalogue templates.
End of explanation
tdc.summary_after_peeler_clusters(dataio, chan_grp=0,  label=0, neighborhood_radius=None, show_channels=False)
tdc.summary_after_peeler_clusters(dataio, chan_grp=0,  label=1, neighborhood_radius=None, show_channels=False)
Explanation: final inspection of cells
End of explanation
<END_TASK>