gists/strings.py
2014-10-02 01:26:46 -07:00

78 lines
2.2 KiB
Python
Executable file

#!/usr/bin/python
from data import *
from notes import note2freq
stock = []
stock += daddario_plain_steel
stock += daddario_nickle_wound
#stock += circle_k_plain
#stock += circle_k_hybrid_wound
uw_const = 386.4
def uw2tension(uw, freq, SL):
return (uw*(2*SL*freq)**2)/uw_const
def tension2uw(t, freq, SL):
return (t*uw_const)/(2*SL*freq)**2
outfmt = '{:<8} at {:> 5.2f} lbs ({:>+4.2f})'
finalfmt = 'total: {:>7.2f} lbs ({:>+5.2f})'
def print_ideal_stock(strings, scale_length=25.512):
SL = scale_length
total_tension = 0
total_desired_tension = 0
for note, tension, kind in strings:
freq = note2freq(note)
uw = tension2uw(tension, freq, SL)
closest = ('n/a', 0)
for name, stock_uw in stock:
if kind == 'P' and name[2] != 'P':
continue
if kind == 'W' and name[3] != 'W':
continue
if abs(stock_uw - uw) < abs(closest[1] - uw):
closest = (name, stock_uw)
closest_tension = uw2tension(closest[1], freq, SL)
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))
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)
print()
SL = 25.02
test('NW049' , '0.00043014', 18.97, E2)
test('NW050*', '? ', 19.68, E2)
test('NW052' , '0.00048109', 21.15, E2)