def METHOD_NAME(imzml_reader: FSImzMLReader, spectra_per_chunk_n, ds_segments, ds_segments_path):
    logger.info(f'Segmenting dataset into {len(ds_segments)} segments')
    rmtree(ds_segments_path, ignore_errors=True)
    ds_segments_path.mkdir(parents=True)
    mz_segments = extend_ds_segment_bounds(ds_segments)
    sp_id_chunks = chunk_list(xs=range(imzml_reader.n_spectra), size=spectra_per_chunk_n)
    for chunk_i, sp_ids in enumerate(sp_id_chunks, 1):
        logger.debug(f'Segmenting spectra chunk {chunk_i}')
        sp_chunk_df = fetch_chunk_spectra_data(sp_ids, imzml_reader)
        segment_spectra_chunk(sp_chunk_df, mz_segments, ds_segments_path)