gists/strings.py

79 lines
2.2 KiB
Python
Raw Normal View History

2014-09-29 21:15:51 -07:00
#!/usr/bin/python
2014-09-30 02:13:14 -07:00
from data import *
2014-10-02 01:21:52 -07:00
from notes import note2freq
2014-09-30 02:13:14 -07:00
stock = []
stock += daddario_plain_steel
stock += daddario_nickle_wound
#stock += circle_k_plain
#stock += circle_k_hybrid_wound
2014-09-29 21:15:51 -07:00
uw_const = 386.4
2014-10-02 01:21:52 -07:00
def uw2tension(uw, freq, SL):
return (uw*(2*SL*freq)**2)/uw_const
2014-09-29 21:15:51 -07:00
2014-10-02 01:21:52 -07:00
def tension2uw(t, freq, SL):
return (t*uw_const)/(2*SL*freq)**2
2014-09-29 21:47:58 -07:00
2014-10-02 01:33:47 -07:00
outfmt = '{:<8} at {:> 5.2f} lb ({:>+4.2f})'
finalfmt = 'total: {:>7.2f} lb ({:>+5.2f})'
2014-10-02 01:21:52 -07:00
def print_ideal_stock(strings, scale_length=25.512):
SL = scale_length
2014-09-29 21:15:51 -07:00
total_tension = 0
total_desired_tension = 0
for note, tension, kind in strings:
freq = note2freq(note)
2014-10-02 01:21:52 -07:00
uw = tension2uw(tension, freq, SL)
2014-09-29 21:15:51 -07:00
closest = ('n/a', 0)
for name, stock_uw in stock:
2014-09-30 02:13:14 -07:00
if kind == 'P' and name[2] != 'P':
continue
if kind == 'W' and name[3] != 'W':
2014-09-29 21:15:51 -07:00
continue
if abs(stock_uw - uw) < abs(closest[1] - uw):
closest = (name, stock_uw)
2014-10-02 01:21:52 -07:00
closest_tension = uw2tension(closest[1], freq, SL)
2014-09-29 21:15:51 -07:00
diff = closest_tension - tension
print(outfmt.format(closest[0], closest_tension, diff))
total_tension += closest_tension
total_desired_tension += tension
error = total_tension - total_desired_tension
print(finalfmt.format(total_tension, error))
2014-10-02 01:21:52 -07:00
if __name__ == '__main__':
# DAd's data is all screwy so we use change scale lengths for a best-fit
SL = 25.4825
D3 = note2freq('D3')
A2 = note2freq('A2')
E2 = note2freq('E2')
test_fmt = '{:8} {:10.8f} == {:10}'
def test(name, unit, tension, note):
print(test_fmt.format(name, tension2uw(tension, note, SL), unit))
test('NW024' , '0.00010857', 15.73, D3)
test('NW025*', '?' , 17.21, D3)
test('NW026' , '0.00012671', 18.38, D3)
print()
test('NW036' , '0.00023964', 19.04, A2)
test('NW037*', '? ', 20.23, A2)
test('NW038' , '0.00026471', 20.96, A2)
print()
SL = 25.18
test('NW039' , '0.00027932', 12.46, E2)
test('NW040*', '? ', 13.18, E2)
test('NW042' , '0.00032279', 14.37, E2)
2014-09-29 21:15:51 -07:00
print()
2014-10-02 01:21:52 -07:00
SL = 25.02
test('NW049' , '0.00043014', 18.97, E2)
test('NW050*', '? ', 19.68, E2)
test('NW052' , '0.00048109', 21.15, E2)