def test_int_indexer_short_14(self): expected = [[(0.0, interval.Interval(note.Note('G3'), note.Note('G4')).name), (0.0625, interval.Interval(note.Note('G3'), note.Note('G4')).name), (0.125, u'Rest'), (0.1875, u'Rest'), (0.25, interval.Interval(note.Note('A3'), note.Note('G4')).name), (0.3125, interval.Interval(note.Note('A3'), note.Note('G4')).name), (0.375, u'Rest'), (0.4375, u'Rest'), (0.5, interval.Interval(note.Note('G3'), note.Note('G4')).name)]] expected = {'0,1': pandas_maker(expected)[0]} not_processed = [[(0.0, u'G4', 0.0625), (0.0625, u'G4', 0.0625), (0.125, u'G4', 0.0625), (0.1875, u'G4', 0.0625), (0.25, u'G4', 0.0625), (0.3125, u'G4', 0.0625), (0.375, u'G4', 0.0625), (0.4375, u'G4', 0.0625), (0.5, u'G4')], [(0.0, u'G3', 0.125), (0.125, u'Rest', 0.125), (0.25, u'A3', 0.125), (0.375, u'Rest', 0.0625), (0.4375, u'Rest', 0.0625), (0.5, u'G3')]] test_in = pandas_maker(not_processed) int_indexer = IntervalIndexer(test_in, {u'quality': True, u'simple or compound': u'compound'}) actual = int_indexer.run()[u'interval.IntervalIndexer'] self.assertEqual(len(expected), len(actual.columns)) for key in expected.iterkeys(): self.assertTrue(key in actual) self.assertSequenceEqual(list(expected[key].index), list(actual[key].index)) self.assertSequenceEqual(list(expected[key]), list(actual[key]))
def test_interval_indexer_1(self): # BWV7.7: full soprano and bass parts test_parts = pandas.concat([self.bwv77_soprano, self.bwv77_bass], axis=1) test_parts.columns = pandas.MultiIndex.from_product([('A', ), ('a', 'b')]) expected = make_series(TestIntervalIndexerLong.bwv77_S_B_basis) setts = {'simple or compound': 'compound', 'quality': True} actual = IntervalIndexer(test_parts, setts).run().iloc[:, 0] self.assertTrue(actual.equals(expected))
def test_int_indexer_short_1(self): expected = [(0.0, interval.Interval(note.Note('G3'), note.Note('G4')).name)] expected = TestIntervalIndexerShort.pandas_maker([expected])[0] not_processed = [[(0.0, u'G4')], [(0.0, u'G3')]] test_in = TestIntervalIndexerShort.pandas_maker(not_processed) int_indexer = IntervalIndexer(test_in, {u'quality': True, u'simple or compound': u'compound'}) actual = int_indexer.run()[u'0,1'] self.assertSequenceEqual(list(expected.index), list(actual.index)) self.assertSequenceEqual(list(expected.values), list(actual.values))
def test_interval_indexer_4(self): # BWV7.7: small soprano and bass parts; "simple" in settings, "quality" not test_parts = pandas.concat([self.bwv77_s_small, self.bwv77_b_small], axis=1) test_parts.columns = pandas.MultiIndex.from_product([('A', ), ('a', 'b')]) expected = make_series( TestIntervalIndexerLong.bwv77_S_B_small_simple_noqual) setts = {'simple or compound': 'simple'} actual = IntervalIndexer(test_parts, setts).run().iloc[:, 0] self.assertTrue(actual.equals(expected))
def test_interval_indexer_4(self): # BWV7.7: small soprano and bass parts; "simple" in settings, "quality" not test_parts = [self.bwv77_s_small, self.bwv77_b_small] expected = TestIntervalIndexerLong.bwv77_S_B_small_simple_noqual setts = {u'simple or compound': u'simple'} int_indexer = IntervalIndexer(test_parts, setts) actual = int_indexer.run()[u'0,1'] self.assertEqual(len(expected), len(actual)) for i, ind in enumerate(list(actual.index)): self.assertEqual(expected[i][0], ind) self.assertEqual(expected[i][1], actual[ind])
def test_interval_indexer_1(self): # BWV7.7: full soprano and bass parts test_parts = [self.bwv77_soprano, self.bwv77_bass] expected = TestIntervalIndexerLong.bwv77_S_B_basis setts = {u'simple or compound': u'compound', u'quality': True} int_indexer = IntervalIndexer(test_parts, setts) actual = int_indexer.run()[u'0,1'] self.assertEqual(len(expected), len(actual)) for i, ind in enumerate(list(actual.index)): self.assertEqual(expected[i][0], ind) self.assertEqual(expected[i][1], actual[ind])
def test_interval_indexer_1(self): # BWV7.7: full soprano and bass parts test_parts = [self.bwv77_soprano, self.bwv77_bass] expected = {'0,1': make_series(TestIntervalIndexerLong.bwv77_S_B_basis)} setts = {u'simple or compound': u'compound', u'quality': True} int_indexer = IntervalIndexer(test_parts, setts) actual = int_indexer.run()[u'interval.IntervalIndexer'] self.assertEqual(len(expected), len(actual.columns)) for key in expected.iterkeys(): self.assertTrue(key in actual) self.assertSequenceEqual(list(expected[key].index), list(actual[key].index)) self.assertSequenceEqual(list(expected[key]), list(actual[key]))
def test_interval_indexer_3(self): # BWV7.7: small soprano and bass parts; "simple" and "quality" not in settings, and the # settings are in fact not specified test_parts = pandas.concat([self.bwv77_s_small, self.bwv77_b_small], axis=1) test_parts.columns = pandas.MultiIndex.from_product([('A', ), ('a', 'b')]) expected = make_series( TestIntervalIndexerLong.bwv77_S_B_small_compound_noqual) # setts = {} actual = IntervalIndexer(test_parts).run().iloc[:, 0] self.assertTrue(actual.equals(expected))
def test_interval_indexer_4(self): # BWV7.7: small soprano and bass parts; "simple" in settings, "quality" not test_parts = [self.bwv77_s_small, self.bwv77_b_small] expected = {'0,1': make_series(TestIntervalIndexerLong.bwv77_S_B_small_simple_noqual)} setts = {u'simple or compound': u'simple'} int_indexer = IntervalIndexer(test_parts, setts) actual = int_indexer.run()[u'interval.IntervalIndexer'] self.assertEqual(len(expected), len(actual.columns)) for key in expected.iterkeys(): self.assertTrue(key in actual) self.assertSequenceEqual(list(expected[key].index), list(actual[key].index)) self.assertSequenceEqual(list(expected[key]), list(actual[key]))
def test_interval_indexer_3(self): # BWV7.7: small soprano and bass parts; "simple" and "quality" not in settings, and the # settings are in fact not specified test_parts = [self.bwv77_s_small, self.bwv77_b_small] expected = TestIntervalIndexerLong.bwv77_S_B_small_compound_noqual #setts = {} int_indexer = IntervalIndexer(test_parts) actual = int_indexer.run()[u'0,1'] self.assertEqual(len(expected), len(actual)) for i, ind in enumerate(list(actual.index)): self.assertEqual(expected[i][0], ind) self.assertEqual(expected[i][1], actual[ind])
def test_interval_indexer_2(self): # BWV7.7: small soprano and bass parts; "simple" in settings test_parts = pandas.concat([self.bwv77_s_small, self.bwv77_b_small], axis=1) expected = {'0,1': make_series(TestIntervalIndexerLong.bwv77_S_B_small_simple_qual)} setts = {'simple or compound': 'simple', 'quality': True} int_indexer = IntervalIndexer(test_parts, setts) actual = int_indexer.run()['interval.IntervalIndexer'] self.assertEqual(len(expected), len(actual.columns)) for key in six.iterkeys(expected): self.assertTrue(key in actual) self.assertSequenceEqual(list(expected[key].index), list(actual[key].index)) self.assertSequenceEqual(list(expected[key]), list(actual[key]))
def test_int_indexer_short_3(self): expected = pandas.Series(['P8', 'Rest'], index=[0.0, 0.25], name='0,1') not_processed = [[(0.0, 'G4')], [(0.0, 'G3'), (0.25, 'Rest')]] test_in = pandas_maker(not_processed) test_in.columns = pandas.MultiIndex.from_product([('notes', ), ('0', '1')]) setts = { 'quality': True, 'simple or compound': 'compound', 'directed': True } actual = IntervalIndexer(test_in, settings=setts).run().iloc[:, 0] self.assertTrue(actual.equals(expected))
def test_int_indexer_short_1(self): expected = pandas.Series('P8', name='0,1') test_in = pandas.concat( [pandas.Series('G4'), pandas.Series('G3')], axis=1) test_in.columns = pandas.MultiIndex.from_product([('notes', ), ('0', '1')]) setts = { 'quality': True, 'simple or compound': 'compound', 'directed': True } actual = IntervalIndexer(test_in, settings=setts).run().iloc[:, 0] self.assertTrue(actual.equals(expected))
def test_interval_indexer_3(self): # BWV7.7: small soprano and bass parts; "simple" and "quality" not in settings, and the # settings are in fact not specified test_parts = [self.bwv77_s_small, self.bwv77_b_small] expected = {'0,1': make_series(TestIntervalIndexerLong.bwv77_S_B_small_compound_noqual)} # setts = {} int_indexer = IntervalIndexer(test_parts) actual = int_indexer.run()[u'interval.IntervalIndexer'] self.assertEqual(len(expected), len(actual.columns)) for key in expected.iterkeys(): self.assertTrue(key in actual) self.assertSequenceEqual(list(expected[key].index), list(actual[key].index)) self.assertSequenceEqual(list(expected[key]), list(actual[key]))
def test_int_indexer_short_1(self): expected = [[(0.0, interval.Interval(note.Note('G3'), note.Note('G4')).name)]] expected = {'0,1': pandas_maker(expected)[0]} not_processed = [[(0.0, 'G4')], [(0.0, 'G3')]] test_in = pandas_maker(not_processed) int_indexer = IntervalIndexer(test_in, {'quality': True, 'simple or compound': 'compound', 'directed': True}) actual = int_indexer.run()['interval.IntervalIndexer'] self.assertEqual(len(expected), len(actual.columns)) for key in six.iterkeys(expected): self.assertTrue(key in actual) self.assertSequenceEqual(list(expected[key].index), list(actual[key].index)) self.assertSequenceEqual(list(expected[key]), list(actual[key]))
def test_int_ind_indexer_init_13(self): int_indexer_1 = IntervalIndexer([], { 'quality': True, 'simple or compound': 'compound', 'directed': False }) int_indexer_2 = IntervalIndexer( [], { 'quality': 'diatonic with quality', 'simple or compound': 'compound', 'directed': False }) self.assertEqual(int_indexer_1._indexer_func.__name__, 'indexer_dwq_und_com') self.assertEqual(int_indexer_2._indexer_func.__name__, 'indexer_dwq_und_com')
def test_int_ind_indexer_init_4(self): int_indexer_1 = IntervalIndexer([], { 'quality': False, 'simple or compound': 'simple', 'directed': False }) int_indexer_2 = IntervalIndexer( [], { 'quality': 'diatonic no quality', 'simple or compound': 'simple', 'directed': False }) self.assertEqual(int_indexer_1._indexer_func.__name__, 'indexer_dnq_und_sim') self.assertEqual(int_indexer_2._indexer_func.__name__, 'indexer_dnq_und_sim')
def test_int_ind_indexer_init_7(self): int_indexer = IntervalIndexer( [], { 'quality': 'interval class', 'simple or compound': 'simple', 'directed': False }) self.assertEqual(int_indexer._indexer_func.__name__, 'indexer_icl_und_sim')
def test_int_ind_indexer_init_14(self): int_indexer = IntervalIndexer( [], { 'quality': 'chromatic', 'simple or compound': 'compound', 'directed': False }) self.assertEqual(int_indexer._indexer_func.__name__, 'indexer_chr_und_com')
def test_int_indexer_short_17(self): expected = pandas.Series( ['P8', 'P8', 'M10', 'Rest', 'Rest', 'm7', 'M6'], index=[.0, .5, .75, 1.125, 1.25, 1.375, 2.0], name='0,1') not_processed = [[(0.0, 'G4'), (0.5, 'A4', 0.75), (1.25, 'F4', 0.75), (2.0, 'E4')], [(0.0, 'G3'), (0.5, 'A3'), (0.75, 'F3', 0.375), (1.125, 'Rest'), (1.375, 'G3', 0.625), (2.0, 'G3')]] test_in = pandas_maker(not_processed) test_in.columns = pandas.MultiIndex.from_product([('notes', ), ('0', '1')]) setts = { 'quality': True, 'simple or compound': 'compound', 'directed': True } actual = IntervalIndexer(test_in, settings=setts).run().iloc[:, 0] self.assertTrue(actual.equals(expected))
def run_my_task(self, inputs, settings, outputs): # Set execution settings. wrapper_settings = dict( [(k, settings[k]) for k in ('Simple or Compound Intervals', 'Interval Quality')] ) execution_settings = dict() if wrapper_settings['Simple or Compound Intervals'] == 0: execution_settings['simple or compound'] = 'simple' else: execution_settings['simple or compound'] = 'compound' execution_settings['quality'] = wrapper_settings['Interval Quality'] execution_settings['mp'] = False execution_settings['directed'] = True # Run. infile = inputs['NoteRest Interval Indexer Result'][0]['resource_path'] outfile = outputs['Vertical Interval Indexer Result'][0]['resource_path'] data = DataFrame.from_csv(infile, header = [0, 1]) # We know the first two rows constitute a MultiIndex vertical_intervals = IntervalIndexer(data, execution_settings).run() vertical_intervals.to_csv(outfile) return True