sortedKeys=list(sorted(circles.keys(),key=keyfunc))# sort dict keys !! necessary for itt.groupby
# for k, g in itt.groupby(sortedKeys, keyfunc): # group data with commun keyfunc output (more info : https://docs.python.org/3/library/itertools.html#itertools.groupby)
fork,ginitt.groupby(sortedKeys,keyfunc):# group data with commun keyfunc output (more info : https://docs.python.org/3/library/itertools.html#itertools.groupby)
# if subFilterFunc(k): # apply filter
ifsubFilterFunc(k):# apply filter
# figax = plt.subplots(figsize=(10,7)) # create new plot
figax=plt.subplots(figsize=(10,7))# create new plot
# g = list(g) # convert from grouper type to list (if not the generator will empty itself after the first passage)
g=list(g)# convert from grouper type to list (if not the generator will empty itself after the first passage)
# keyfunc2 = lambda x:x.Initial_State # key for the sub grouping
keyfunc2=lambdax:x.Initial_State# key for the sub grouping
# sortedKeys2 = list(sorted(g,key=keyfunc2)) # sort sub group key !! necessary for itt.groupby
sortedKeys2=list(sorted(g,key=keyfunc2))# sort sub group key !! necessary for itt.groupby
# for k2, g2 in itt.groupby(sortedKeys2, keyfunc2): # sub-group grouped data with commun keyfunc2 output the data will be on the same plot but with different label
fork2,g2initt.groupby(sortedKeys2,keyfunc2):# sub-group grouped data with commun keyfunc2 output the data will be on the same plot but with different label
# g2 = list(g2) # convert from grouper type to list (if not the generator will empty itself after the first passage)
g2=list(g2)# convert from grouper type to list (if not the generator will empty itself after the first passage)
# # plot the sub grouped data point
# plot the sub grouped data point
# plotDictListValue(mapDictList(lambda prop,x:x[radiusSelect], circles), # create a sub dictionary of circle only selecting one of the circles
plotDictListValue(mapDictList(lambdaprop,x:x[radiusSelect],circles),# create a sub dictionary of circle only selecting one of the circles
# Xaxis="Power", # name of the proprety to use as the X axis
Xaxis="Power",# name of the proprety to use as the X axis
# keyFilter=lambda x:x in g2, # only select point of the sub group
keyFilter=lambdax:xing2,# only select point of the sub group
# figax=figax, # figure and axis to use
figax=figax,# figure and axis to use
# logScale=True, # logaritmic Y scaling
logScale=True,# logaritmic Y scaling
# label=k2, # use the sub-grouping key as label
label=k2,# use the sub-grouping key as label
# title='\n'.join([str(a)+" = "+str(b) for a,b in zip(groups,k)]) # format title using the outer group keys
title='\n'.join([str(a)+" = "+str(b)fora,binzip(groups,k)])# format title using the outer group keys
# )
)
# plt.show()
plt.show()
#%% export radius
#%% export radius
...
@@ -595,7 +586,7 @@ for k, g in itt.groupby(sortedKeys, keyfunc): # group data with commun keyfunc o
...
@@ -595,7 +586,7 @@ for k, g in itt.groupby(sortedKeys, keyfunc): # group data with commun keyfunc o
plt.title(k)# use group key as title
plt.title(k)# use group key as title
plt.show()
plt.show()
fitParam[k]=np.array([popt[0],popt[1]/np.pi/popt[0]**2])# convert to sigma and fluence threshold and store the fit parameters into the fitParam dictonary
fitParam[k]=np.array([np.abs(popt[0]),popt[1]/np.pi/popt[0]**2])# convert to sigma and fluence threshold and store the fit parameters into the fitParam dictonary
np.savetxt(os.path.join(saveDir,'GaussFit.csv'),data,header=paramName+'\n'+units,fmt='%s',delimiter=",")# export to .csv as str array and with the constructed header
np.savetxt(os.path.join(saveDir,'GaussFit.csv'),data,header=paramName+'\n'+units,fmt='%s',delimiter=",")# export to .csv as str array and with the constructed header
#%% get sigmoid threshold
fitTanhFunc=lambdax,offset,w:0.5*(1+np.tanh((x-offset)/w))# function to fit
domainDetectionCount={}
sigmoidFit={}
radiusSelect=OUTERCERCLE# select circle radius to plot can be INNERCERCLE or OUTERCERCLE
groups=[paramforparaminpropDef.keys()ifparam!="Power"]# group data based on the propreties except Power
subParams=namedtuple('subParams',groups)# create a subparameter nametuple class to store selected propreties
keyfunc=lambdax:subParams(**{key:getattr(x,key)forkeyingroups})# get keys of the grouped data
sortedKeys=list(sorted(circles.keys(),key=keyfunc))# sort dict keys !! necessary for itt.groupby
fork,ginitt.groupby(sortedKeys,keyfunc):# group data with commun keyfunc output (more info : https://docs.python.org/3/library/itertools.html#itertools.groupby)
g=list(sorted(g,key=lambdax:x.Power))# convert and sort from grouper type to list (if not the generator will empty itself after the first passage)
fork2ing:# for each key
domainDetectionCount[k2]=np.sum(list(map(lambdax:x[radiusSelect]>0,circles[k2])))# count the number of non zero selected radius
data=np.array([[k2.Power/1E3/repRate,domainDetectionCount[k2]/len(circles[k2])]fork2ing])# calculate data to fit Energy pulse [J] ; number of count
try:
popt,pcov=curve_fit(fitTanhFunc,data[:,0],data[:,1],p0=(np.min(data[:,0]),1),maxfev=1000000)# fit with the previously defined function fitTanhFunc
perr=np.sqrt(np.diag(pcov))# calculate fit standard deviation
plt.plot(data[:,0],data[:,1],".")# plot to be fitted data
newEp=np.linspace(min(data[:,0]),max(data[:,0]),500)# X for ploting of the the fited function calculated from the min and max of the data
newN=[fitTanhFunc(p,*popt)forpinnewEp]# Y for ploting of the the fited function calculaded at every X
plt.plot(newEp,newN)# plot fited function
plt.title(k)# use group key as title
plt.show()
sigmoidFit[k]=[*popt,*perr]# store fit parameters and standard deviation
exceptRuntimeErroraserr:# if fit fails
print(err,k)# print error
plt.plot(data[:,0],data[:,1],".")# plot data without fit
plt.title(k)# use group key as title
plt.show()
#%% export domain detection count
sortKey=lambdax:[getattr(x[0],p)forpinx[0]._fieldsifp!="Power"]+[x[0].Power]# function to sort parameters with power as last sort element
dataMapper=lambdax:list(x[0])+[x[0].Power/1E3/repRate,x[1]]# function to extract parameters and data from the domainDetectionCount dictonary
# map domainDetectionCount dictonary to export data
np.savetxt(os.path.join(saveDir,'DetectionCount.csv'),data,header=paramName+'\n'+units,fmt='%s',delimiter=",")# export to .csv as str array and with the constructed header
#%% export sigmoid fit parameters
parameters=[paramforparaminpropDef.keys()ifparam!="Power"]# list of propreties to use as column to discribe the output
# retrive propreties to fill the columns and append the fit parameters
np.savetxt(os.path.join(saveDir,'sigmoidFit.csv'),data,header=paramName+'\n'+units,fmt='%s',delimiter=",")# export to .csv as str array and with the constructed header