@@ -0,0 +1,2105 @@
+%22%22%22utilty script to take first TRAIN_DUR seconds of song (as determine from .not.mat files)%0Aand move to a sub-directory called 'train_subset'. Execute in the directory where this should happen.%0AUsed for experiments to measure accuracy when just using first TRAIN_DUR seconds of song to label %0Athe next n days of song.%0A%22%22%22%0Aimport argparse%0Afrom glob import glob%0Aimport os%0Afrom pathlib import Path%0Aimport shutil%0A%0Aimport crowsetta%0A%0ATRAIN_DUR = 60%0AVAL_DUR = 80%0A%0AANNOT_EXT = '.not.mat'%0AVOC_FORMAT = 'notmat'%0A%0ASUBSET_DIR = 'train_subset'%0A%0Aparser = argparse.ArgumentParser(description='Move subset of training data to a sub-directory.')%0Aparser.add_argument('--labelset', dest='labelset', action='store', default=None,%0A                    help='set of labels each file in training subset should contain')%0A%0Adef main(train_dur=TRAIN_DUR,%0A         val_dur=VAL_DUR,%0A         annot_ext=ANNOT_EXT,%0A         voc_format=VOC_FORMAT,%0A         subset_dir=SUBSET_DIR,%0A         labelset=None):%0A    %22%22%22%0A    %22%22%22%0A    labelset = list(labelset)  # assumes single string%0A    annot_files = glob(f'*%7Bannot_ext%7D')%0A    annot_files = sorted(annot_files)%0A    scribe = crowsetta.Transcriber(voc_format=voc_format)%0A    seqs = scribe.to_seq(annot_files)%0A%0A    dur = 0%0A    seq_ctr = 0%0A    seqs_to_use = %5B%5D%0A    total_dur = train_dur + val_dur%0A    while dur %3C total_dur:%0A        if seq_ctr %3E len(seqs):%0A            raise ValueError(%0A                f'ran out of annotation files before finding subset of duration %7Btotal_dur%7D'%0A            )%0A%0A        if labelset:%0A            if not set(seqs%5Bseq_ctr%5D.labels).issubset(set(labelset)):%0A                import pdb;pdb.set_trace()%0A                seq_ctr += 1%0A                continue%0A%0A        dur += seqs%5Bseq_ctr%5D.offsets_s%5B-1%5D%0A        seqs_to_use.append(seqs%5Bseq_ctr%5D)%0A        seq_ctr += 1%0A%0A    os.makedirs(subset_dir)%0A%0A    for seq in seqs_to_use:%0A        seq_stem = Path(seq.file).stem%0A        seq_files = glob(f'%7Bseq_stem%7D*')%0A        for seq_file in seq_files:%0A    %09    shutil.move(seq_file, subset_dir)%0A%0A%0Aif __name__ == '__main__':%0A    args = parser.parse_args()%0A    main(labelset=args.labelset)%0A%0A

add scripts/make_train_subset.py