picadae calibration programs
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

plot_calibrate.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import sys,os,json,types
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import matplotlib._color_data as mcd
  5. from matplotlib.pyplot import figure
  6. from rms_analysis import calibrate_recording_analysis
  7. from rms_analysis import key_info_dictionary
  8. def plot_by_pitch( inDir, keyInfoD, pitch=None ):
  9. anlD = calibrate_recording_analysis( inDir )
  10. jsonFn = os.path.join(inDir, "meas.json" )
  11. audioFn = os.path.join(inDir, "audio.wav" )
  12. with open(jsonFn,"r") as f:
  13. r = json.load(f)
  14. measD = r['measD']
  15. cfg = types.SimpleNamespace(**r['cfg'])
  16. axN = len(measD) if pitch is None else 1
  17. fig,axL = plt.subplots(axN,1)
  18. fig.set_size_inches(18.5, 10.5*axN)
  19. # for each pitch
  20. for axi,(midi_pitch,measL)in enumerate(measD.items()):
  21. midi_pitch = int(midi_pitch)
  22. if pitch is not None and pitch != midi_pitch:
  23. continue
  24. if pitch is not None:
  25. axi = 0
  26. axL = [ axL ]
  27. targetDbS = set()
  28. hmPulseDbL = []
  29. tdPulseDbL = []
  30. anPulseDbL = []
  31. # for each measurement on this pitch
  32. for mi,d in enumerate(measL):
  33. m = types.SimpleNamespace(**d)
  34. # form a list of pulse/db measurements associated with this pitch
  35. hmPulseDbL.append( (m.pulse_us,m.hm['db'],m.matchFl,m.hm['durMs'],m.skipMeasFl) )
  36. tdPulseDbL.append( (m.pulse_us,m.td['db'],m.matchFl,m.td['durMs'],m.skipMeasFl) )
  37. ar = next(ad for ad in anlD[midi_pitch] if ad['meas_idx']==mi )
  38. anPulseDbL.append( (m.pulse_us,ar['db'],m.matchFl,m.hm['durMs'],m.skipMeasFl))
  39. # get the unique set of targets
  40. targetDbS.add(m.targetDb)
  41. # sort measurements on pulse length
  42. hmPulseDbL = sorted(hmPulseDbL,key=lambda x: x[0])
  43. tdPulseDbL = sorted(tdPulseDbL,key=lambda x: x[0])
  44. anPulseDbL = sorted(anPulseDbL,key=lambda x: x[0])
  45. # plot the re-analysis
  46. pulseL,dbL,matchFlL,_,_ = zip(*anPulseDbL)
  47. axL[axi].plot( pulseL, dbL, label="post", marker='.' )
  48. # plot harmonic measurements
  49. pulseL,dbL,matchFlL,durMsL,skipFlL = zip(*hmPulseDbL)
  50. axL[axi].plot( pulseL, dbL, label="harm", marker='.' )
  51. # plot time-domain based measuremented
  52. pulseL,dbL,matchFlL,_,_ = zip(*tdPulseDbL)
  53. axL[axi].plot( pulseL, dbL, label="td", marker='.' )
  54. # plot target boundaries
  55. for targetDb in targetDbS:
  56. lwr = targetDb * ((100.0 - cfg.tolDbPct)/100.0)
  57. upr = targetDb * ((100.0 + cfg.tolDbPct)/100.0 )
  58. axL[axi].axhline(targetDb)
  59. axL[axi].axhline(lwr,color='lightgray')
  60. axL[axi].axhline(upr,color='gray')
  61. # plot match and 'too-short' markers
  62. for i,matchFl in enumerate(matchFlL):
  63. if durMsL[i] < cfg.minMeasDurMs:
  64. axL[axi].plot( pulseL[i], dbL[i], marker='x', color='black', linestyle='None')
  65. if skipFlL[i]:
  66. axL[axi].plot( pulseL[i], dbL[i], marker='+', color='blue', linestyle='None')
  67. if matchFl:
  68. axL[axi].plot( pulseL[i], dbL[i], marker='.', color='red', linestyle='None')
  69. axL[axi].set_title("pitch:%i %s" % (midi_pitch,keyInfoD[midi_pitch].type))
  70. plt.legend()
  71. plt.show()
  72. def plot_all_notes( inDir ):
  73. jsonFn = os.path.join(inDir, "meas.json" )
  74. audioFn = os.path.join(inDir, "audio.wav" )
  75. with open(jsonFn,"r") as f:
  76. r = json.load(f)
  77. measD = r['measD']
  78. axN = 0
  79. for midi_pitch,measL in measD.items():
  80. axN += len(measL)
  81. print(axN)
  82. fig,axL = plt.subplots(axN,1)
  83. fig.set_size_inches(18.5, 10.5*axN)
  84. i = 0
  85. for midi_pitch,measL in measD.items():
  86. for d in measL:
  87. axL[i].plot(d['td']['rmsDbV'])
  88. axL[i].plot(d['hm']['rmsDbV'])
  89. axL[i].axvline(d['td']['pk_idx'],color='red')
  90. axL[i].axvline(d['hm']['pk_idx'],color='green')
  91. i += 1
  92. plt.show()
  93. if __name__ == "__main__":
  94. pitch = None
  95. inDir = sys.argv[1]
  96. yamlFn = sys.argv[2]
  97. if len(sys.argv) > 3:
  98. pitch = int(sys.argv[3])
  99. keyInfoD = key_info_dictionary( yamlCfgFn=yamlFn)
  100. #plot_all_notes( inDir )
  101. plot_by_pitch(inDir,keyInfoD,pitch)
  102. #calibrate_recording_analysis( inDir )