This function removes cosmic peaks from spectral data by computing a specified order derivative to detect spikes. It masks channels around detected peaks that exceed a set threshold and restores them through interpolation, resulting in a clean spectrum.