diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-11-22 12:10:01 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-11-22 12:10:01 -0500 |
commit | b46c2b6db6088d90c6f84d29e431283ac54ab175 (patch) | |
tree | 57ac4f4b58d71b3e92690ee3718c3bfc138a9056 | |
parent | df393b378983cf925ab9145d6eb3e773a8aee50c (diff) |
Handle short files.
-rwxr-xr-x | shuffle_truncate.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/shuffle_truncate.py b/shuffle_truncate.py index c936ece..a7219a5 100755 --- a/shuffle_truncate.py +++ b/shuffle_truncate.py | |||
@@ -43,6 +43,9 @@ def shuffle_truncate(arrays, fnames, target_length=None): | |||
43 | # Gotta be uniformly shuffled. | 43 | # Gotta be uniformly shuffled. |
44 | print "Shuffling %s ..." % n | 44 | print "Shuffling %s ..." % n |
45 | numpy.random.shuffle(a) | 45 | numpy.random.shuffle(a) |
46 | else: | ||
47 | # not enough samples | ||
48 | print "Not shuffling %s (too few samples)." % n | ||
46 | 49 | ||
47 | # Now select the same number of samples from each file. | 50 | # Now select the same number of samples from each file. |
48 | truncated = [a[:shortest] for a in arrays] | 51 | truncated = [a[:shortest] for a in arrays] |
@@ -77,8 +80,11 @@ def shuffle_truncate_store_individually(files, cutoff): | |||
77 | os.path.basename(f)) | 80 | os.path.basename(f)) |
78 | sys.stdout.flush() | 81 | sys.stdout.flush() |
79 | name = target_file(f, 'sbn') | 82 | name = target_file(f, 'sbn') |
83 | fs = os.stat(f) | ||
80 | if os.path.exists(name): | 84 | if os.path.exists(name): |
81 | print "Skipping since %s exists." % name | 85 | print "Skipping since %s exists." % name |
86 | elif fs.st_size == 0: | ||
87 | print "Skipping since trace is empty." | ||
82 | else: | 88 | else: |
83 | shuffle_truncate_store([f], cutoff=cutoff) | 89 | shuffle_truncate_store([f], cutoff=cutoff) |
84 | 90 | ||