plot_seq.py,plot_seq_1.py : Add new plots.
This commit is contained in:
parent
846f1d5aa8
commit
b4b0973e9a
@ -296,7 +296,7 @@ def plot_resample_pulse_times( inDir, analysisArgsD, midi_pitch, printDir="" ):
|
|||||||
|
|
||||||
fig,axL = plt.subplots(2,1,gridspec_kw={'height_ratios': [2, 1]})
|
fig,axL = plt.subplots(2,1,gridspec_kw={'height_ratios': [2, 1]})
|
||||||
|
|
||||||
axL[0].plot(pulseUsL,rmsDbV,marker='.' )
|
axL[0].plot(pulseUsL,rmsDbV,marker='.',color="red" )
|
||||||
|
|
||||||
#plot_curve( ax, velTblUsL,velTblDbL)
|
#plot_curve( ax, velTblUsL,velTblDbL)
|
||||||
|
|
||||||
|
160
plot_seq_1.py
160
plot_seq_1.py
@ -39,12 +39,21 @@ def fit_to_reference( pkL, refTakeId ):
|
|||||||
return zip(db_outL,us_outL,dur_outL,tid_outL)
|
return zip(db_outL,us_outL,dur_outL,tid_outL)
|
||||||
|
|
||||||
|
|
||||||
def get_merged_pulse_db_measurements( inDir, midi_pitch, analysisArgsD ):
|
def get_merged_pulse_db_measurements( inDir, midi_pitch, analysisArgsD, takeId=None ):
|
||||||
|
|
||||||
inDir = os.path.join(inDir,"%i" % (midi_pitch))
|
inDir = os.path.join(inDir,"%i" % (midi_pitch))
|
||||||
|
|
||||||
|
takeIdL = []
|
||||||
|
if takeId is not None:
|
||||||
|
takeIdL.append(takeId)
|
||||||
|
else:
|
||||||
takeDirL = os.listdir(inDir)
|
takeDirL = os.listdir(inDir)
|
||||||
|
|
||||||
|
# for each take in this directory
|
||||||
|
for take_folder in takeDirL:
|
||||||
|
takeIdL.append(int(take_folder))
|
||||||
|
|
||||||
|
|
||||||
pkL = []
|
pkL = []
|
||||||
|
|
||||||
refTakeId = None
|
refTakeId = None
|
||||||
@ -52,9 +61,7 @@ def get_merged_pulse_db_measurements( inDir, midi_pitch, analysisArgsD ):
|
|||||||
dbRefL = None
|
dbRefL = None
|
||||||
|
|
||||||
# for each take in this directory
|
# for each take in this directory
|
||||||
for take_folder in takeDirL:
|
for take_number in takeIdL:
|
||||||
|
|
||||||
take_number = int(take_folder)
|
|
||||||
|
|
||||||
if refTakeId is None:
|
if refTakeId is None:
|
||||||
refTakeId = take_number
|
refTakeId = take_number
|
||||||
@ -324,8 +331,98 @@ def plot_us_db_curves( ax, inDir, keyMapD, midi_pitch, analysisArgsD, plotResamp
|
|||||||
|
|
||||||
ax.set_ylabel( "%i %s %s" % (midi_pitch, keyMapD[midi_pitch]['type'],keyMapD[midi_pitch]['class']))
|
ax.set_ylabel( "%i %s %s" % (midi_pitch, keyMapD[midi_pitch]['type'],keyMapD[midi_pitch]['class']))
|
||||||
|
|
||||||
|
|
||||||
|
def plot_us_db_take_curve( ax, inDir, keyMapD, midi_pitch, takeId, analysisArgsD ):
|
||||||
|
|
||||||
|
usL, dbL, durMsL, takeIdL, holdDutyPctL = get_merged_pulse_db_measurements( inDir, midi_pitch, analysisArgsD['rmsAnalysisArgs'] )
|
||||||
|
|
||||||
|
reUsL, reDbL, noiseL, resampleL, skipL, firstAudibleIdx, firstNonSkipIdx = get_resample_points( usL, dbL, durMsL, takeIdL, analysisArgsD['resampleMinDurMs'], analysisArgsD['resampleMinDb'], analysisArgsD['resampleNoiseLimitPct'] )
|
||||||
|
|
||||||
|
# plot first audible and non-skip position
|
||||||
|
if False:
|
||||||
|
|
||||||
|
if firstNonSkipIdx is not None:
|
||||||
|
ax.plot( usL[firstNonSkipIdx], dbL[firstNonSkipIdx], markersize=15, marker='+', linestyle='None', color='red')
|
||||||
|
|
||||||
|
if firstAudibleIdx is not None:
|
||||||
|
ax.plot( usL[firstAudibleIdx], dbL[firstAudibleIdx], markersize=15, marker='*', linestyle='None', color='red')
|
||||||
|
|
||||||
|
# plot the resample points
|
||||||
|
if plotResamplePointsFl:
|
||||||
|
ax.plot( reUsL, reDbL, markersize=13, marker='x', linestyle='None', color='green')
|
||||||
|
|
||||||
|
# plot the noisy sample positions
|
||||||
|
if noiseL:
|
||||||
|
nUsL,nDbL = zip(*noiseL)
|
||||||
|
ax.plot( nUsL, nDbL, marker='o', markersize=9, linestyle='None', color='black')
|
||||||
|
|
||||||
|
# plot the noisy sample positions and the neighbors included in the noisy region
|
||||||
|
if resampleL:
|
||||||
|
nUsL,nDbL = zip(*resampleL)
|
||||||
|
ax.plot( nUsL, nDbL, marker='+', markersize=8, linestyle='None', color='red')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# plot actual sample points
|
||||||
|
|
||||||
|
elbow_us = None
|
||||||
|
elbow_db = None
|
||||||
|
elbow_len = None
|
||||||
|
|
||||||
|
usL,dbL,takeIdL = zip(*[(us,dbL[i],takeIdL[i]) for i,us in enumerate(usL) if usMax is None or us <= usMax])
|
||||||
|
|
||||||
|
if plotTakesFl:
|
||||||
|
for takeId in list(set(takeIdL)):
|
||||||
|
|
||||||
|
# get the us,db points included in this take
|
||||||
|
xL,yL = zip(*[(usL[i],dbL[i]) for i in range(len(usL)) if takeIdL[i]==takeId ])
|
||||||
|
|
||||||
|
ax.plot(xL,yL, marker='.',label=takeId)
|
||||||
|
|
||||||
|
for i,(x,y) in enumerate(zip(xL,yL)):
|
||||||
|
ax.text(x,y,str(i))
|
||||||
|
|
||||||
|
|
||||||
|
#if elbow_len is None or len(xL) > elbow_len:
|
||||||
|
if takeId+1 == len(set(takeIdL)):
|
||||||
|
elbow_us,elbow_db = elbow.find_elbow(xL,yL)
|
||||||
|
elbow_len = len(xL)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
ax.plot(usL, dbL, marker='.')
|
||||||
|
|
||||||
|
ax.plot([elbow_us],[elbow_db],marker='*',markersize=12,color='red',linestyle='None')
|
||||||
|
|
||||||
|
# plot the skip points in yellow
|
||||||
|
if False:
|
||||||
|
if skipL:
|
||||||
|
nUsL,nDbL = zip(*skipL)
|
||||||
|
ax.plot( nUsL, nDbL, marker='.', linestyle='None', color='yellow')
|
||||||
|
|
||||||
|
# plot the locations where the hold duty cycle changes with vertical black lines
|
||||||
|
for us_duty in holdDutyPctL:
|
||||||
|
us,duty = tuple(us_duty)
|
||||||
|
if us > 0:
|
||||||
|
ax.axvline(us,color='black')
|
||||||
|
|
||||||
|
# plot the 'minDb' reference line
|
||||||
|
ax.axhline(analysisArgsD['resampleMinDb'] ,color='black')
|
||||||
|
|
||||||
|
if os.path.isfile("minInterpDb.json"):
|
||||||
|
with open("minInterpDb.json","r") as f:
|
||||||
|
r = json.load(f)
|
||||||
|
if midi_pitch in r['pitchL']:
|
||||||
|
ax.axhline( r['minDbL'][ r['pitchL'].index(midi_pitch) ], color='blue' )
|
||||||
|
ax.axhline( r['maxDbL'][ r['pitchL'].index(midi_pitch) ], color='blue' )
|
||||||
|
|
||||||
|
ax.set_ylabel( "%i %s %s" % (midi_pitch, keyMapD[midi_pitch]['type'],keyMapD[midi_pitch]['class']))
|
||||||
|
|
||||||
|
|
||||||
def plot_us_db_curves_main( inDir, cfg, pitchL, plotTakesFl=True, usMax=None, printDir="" ):
|
def plot_us_db_curves_main( inDir, cfg, pitchL, plotTakesFl=True, usMax=None, printDir="" ):
|
||||||
|
|
||||||
|
|
||||||
analysisArgsD = cfg.analysisArgs
|
analysisArgsD = cfg.analysisArgs
|
||||||
keyMapD = { d['midi']:d for d in cfg.key_mapL }
|
keyMapD = { d['midi']:d for d in cfg.key_mapL }
|
||||||
axN = len(pitchL)
|
axN = len(pitchL)
|
||||||
@ -336,6 +433,7 @@ def plot_us_db_curves_main( inDir, cfg, pitchL, plotTakesFl=True, usMax=None, pr
|
|||||||
fig.set_size_inches(18.5, 10.5*axN)
|
fig.set_size_inches(18.5, 10.5*axN)
|
||||||
|
|
||||||
for ax,midi_pitch in zip(axL,pitchL):
|
for ax,midi_pitch in zip(axL,pitchL):
|
||||||
|
|
||||||
plot_us_db_curves( ax,inDir, keyMapD, midi_pitch, analysisArgsD, plotTakesFl=plotTakesFl, usMax=usMax )
|
plot_us_db_curves( ax,inDir, keyMapD, midi_pitch, analysisArgsD, plotTakesFl=plotTakesFl, usMax=usMax )
|
||||||
|
|
||||||
if plotTakesFl:
|
if plotTakesFl:
|
||||||
@ -346,6 +444,54 @@ def plot_us_db_curves_main( inDir, cfg, pitchL, plotTakesFl=True, usMax=None, pr
|
|||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
def _plot_us_db_takes( inDir, cfg, pitchL, takeIdL, printDir="", printFn="" ):
|
||||||
|
|
||||||
|
assert( len(pitchL) == len(takeIdL) )
|
||||||
|
|
||||||
|
analysisArgsD = cfg.analysisArgs
|
||||||
|
keyMapD = { d['midi']:d for d in cfg.key_mapL }
|
||||||
|
fig,ax = plt.subplots(1,1)
|
||||||
|
|
||||||
|
fig.set_size_inches(18.5, 10.5)
|
||||||
|
|
||||||
|
for midi_pitch,takeId in zip(pitchL,takeIdL):
|
||||||
|
|
||||||
|
usL, dbL, durMsL, _, holdDutyPctL = get_merged_pulse_db_measurements( inDir, midi_pitch, analysisArgsD['rmsAnalysisArgs'], takeId=takeId )
|
||||||
|
|
||||||
|
ax.plot(usL,dbL, marker='.',label="%i:%i %s %s" % (midi_pitch,takeId,keyMapD[midi_pitch]['class'],keyMapD[midi_pitch]['type']))
|
||||||
|
|
||||||
|
# for i,(x,y) in enumerate(zip(usL,dbL)):
|
||||||
|
# ax.text(x,y,str(i))
|
||||||
|
|
||||||
|
|
||||||
|
if printDir:
|
||||||
|
plt.savefig(os.path.join(printDir,printFn),format="png")
|
||||||
|
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
def plot_us_db_takes( inDir, cfg, pitchL, printDir=""):
|
||||||
|
|
||||||
|
takeIdL = None
|
||||||
|
takeIdL = [ pitchL[i] for i in range(1,len(pitchL),2) ]
|
||||||
|
pitchL = [ pitchL[i] for i in range(0,len(pitchL),2) ]
|
||||||
|
|
||||||
|
return _plot_us_db_takes( inDir, cfg, pitchL, takeIdL, printDir, "us_db_takes.png")
|
||||||
|
|
||||||
|
def plot_us_db_takes_last( inDir, cfg, pitchL, printDir ):
|
||||||
|
|
||||||
|
takeIdL = []
|
||||||
|
for pitch in pitchL:
|
||||||
|
|
||||||
|
inDirL = os.listdir( os.path.join(inDir,str(pitch)))
|
||||||
|
|
||||||
|
inDirL = sorted(inDirL)
|
||||||
|
|
||||||
|
takeIdL.append( int(inDirL[-1]) )
|
||||||
|
|
||||||
|
return _plot_us_db_takes( inDir, cfg, pitchL, takeIdL, printDir, "us_db_takes_last.png")
|
||||||
|
|
||||||
|
|
||||||
def plot_all_noise_curves( inDir, cfg, pitchL=None ):
|
def plot_all_noise_curves( inDir, cfg, pitchL=None ):
|
||||||
|
|
||||||
pitchFolderL = os.listdir(inDir)
|
pitchFolderL = os.listdir(inDir)
|
||||||
@ -800,7 +946,7 @@ def gen_vel_map( inDir, cfg, minMaxDbFn, dynLevelN, cacheFn ):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
printDir =os.path.expanduser( "~/src/picadae_ac_3/doc")
|
printDir = None #os.path.expanduser( "~/src/picadae_ac_3/doc")
|
||||||
cfgFn = sys.argv[1]
|
cfgFn = sys.argv[1]
|
||||||
inDir = sys.argv[2]
|
inDir = sys.argv[2]
|
||||||
mode = sys.argv[3]
|
mode = sys.argv[3]
|
||||||
@ -814,6 +960,10 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
if mode == 'us_db':
|
if mode == 'us_db':
|
||||||
plot_us_db_curves_main( inDir, cfg, pitchL, plotTakesFl=True,usMax=None, printDir=printDir )
|
plot_us_db_curves_main( inDir, cfg, pitchL, plotTakesFl=True,usMax=None, printDir=printDir )
|
||||||
|
elif mode == 'us_db_pitch_take':
|
||||||
|
plot_us_db_takes( inDir, cfg, pitchL, printDir=printDir)
|
||||||
|
elif mode == 'us_db_pitch_last':
|
||||||
|
plot_us_db_takes_last( inDir, cfg, pitchL, printDir=printDir)
|
||||||
elif mode == 'noise':
|
elif mode == 'noise':
|
||||||
plot_all_noise_curves( inDir, cfg, pitchL )
|
plot_all_noise_curves( inDir, cfg, pitchL )
|
||||||
elif mode == 'min_max':
|
elif mode == 'min_max':
|
||||||
|
Loading…
Reference in New Issue
Block a user