Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def plotIV(coordinate=None, thinning=100, set_region=(0,999,0,999), showPosition=False, figsize=(30,15), savepng=False, dpi=None, annotations=False, data_processing=1, return_only=False):
- start = time.time()
- # voltages
- voltages = [-1000, -500, -200, -100, 0, 100, 200, 500, 600]
- # scans (ordered by voltages)
- scans_ordered = [ 189, 188, 185, 183,181,182, 186, 187, 190]
- current_mean = []
- current_array_list = []
- # plot either with or without negative values and select if the solar cell channel should be selected for the current
- options_dic = {
- 1: (False, False, "Lock in R , ohne Negativwerte"),
- 2: (False, True, "Lock in R, mit Negativwerten"),
- 3: (True, False, "solar cell channel, ohne Negativwerte"),
- 4: (True, True, "solar cell channel, mit Negativwerten")
- }
- if not return_only:
- print(options_dic[data_processing][2])
- A = 2 # plot only from scan_ordered[A] to ...
- B = -2 # ... scan_ordered[B]
- for scan in scans_ordered[A:B]:
- positions = load_h5(scan, "positions")
- y_axis_h5 = positions["/data/encoder_fast/data"]
- z_axis_h5 = positions["/data/encoder_slow/data"]
- y_axis = np.array(y_axis_h5)
- z_axis = np.array(z_axis_h5)
- current = counts2amps(scan,solar_cell_channel_only=options_dic[data_processing][0], negative=options_dic[data_processing][1])
- y_grid, z_grid, current_array = supergrid(y_axis,z_axis,current,1000)
- shape = np.shape(current_array)
- if scan not in [178,181]:
- warp_matrix = ImageRegistrationDic[scan]
- current_array = cv2.warpAffine(current_array, warp_matrix, (shape[1], shape[0]), flags = cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP, borderValue = float("NaN")).astype(np.float32)
- current_mean.append(np.mean(current))
- current_array_list.append(current_array)
- pixelplotting_array = np.stack(current_array_list)
- if return_only:
- return current_array, pixelplotting_array
- for i in range(len(current_mean)):
- print("Mean current for scan", str(scans_ordered[i+A]), "is {} nA.".format(str(round(current_mean[i],2))))
- # the best looking fontsize is about half of the width of the figsize
- fontsize = figsize[0]//2
- fig = plt.figure(figsize=figsize)
- ax1 = fig.add_subplot(121)
- # y and z labels
- ax1.set_xlabel("Bias voltage [mV]", labelpad = 0, style = "italic", fontsize=9/5*fontsize)
- ax1.set_ylabel("Measured current at (y,z) position [nA]", labelpad = 0, style = "italic", fontsize=9/5*fontsize)
- plt.title("IV curve(s) for single pixel(s)", pad = 15, fontsize=round(9/5*fontsize))
- ax1.tick_params(labelsize=fontsize)
- ax1.set_xticks(voltages[A:B])
- # allows to plot only a specific location on the y-z current array (else plot each 'thinning'-squared-th IV curve):
- if coordinate != None:
- ax1.plot(voltages[A:B], pixelplotting_array[:,coordinate[0],coordinate[1]], "-o", markersize=8, linewidth=0.2, color="blue")
- # Create a set of inset Axes: these should fill the bounding box allocated to them.
- ax1_2 = plt.axes([0,0,1,1])
- # Manually set the position and relative size of the inset axes within ax1
- ip = InsetPosition(ax1, [0.2,0.2,0.3,0.3])
- ax1_2.set_axes_locator(ip)
- # ticks and ticklabels need to be shifted according to Image Registration
- scan = scans_ordered[B-1] # show the scan of the last IV curve point as an example
- IRS_y = ImageRegistrationDic[scan][0][2] # IRS = Image Registration Shift (in y or z)
- IRS_z = ImageRegistrationDic[scan][1][2]
- # individual ticks: it's an extrapolated plot from 201x201 to 1000x1000 pixels, but this corresponds to 10x10 micrometers on the solar cell
- ax1_2.xaxis.set_ticklabels([0,5,10],fontsize=round(4/5*fontsize))
- ax1_2.xaxis.set_ticks([0-IRS_y,500-IRS_y,999-IRS_y]) # if 1000 instead of 999 it won't display
- ax1_2.yaxis.set_ticklabels([0,5,10],fontsize=round(4/5*fontsize))
- ax1_2.yaxis.set_ticks([0-IRS_z,500-IRS_z,999-IRS_z])
- ax1_2.xaxis.set_minor_locator(AutoMinorLocator(5)) # 1 minor tick for each micrometer
- ax1_2.yaxis.set_minor_locator(AutoMinorLocator(5))
- ax1_2.imshow(current_array, interpolation='nearest', cmap=cm.afmhot, origin='lower')
- ax1_2.plot([coordinate[0]],coordinate[1], "bo", markersize=4)
- # y and z labels
- ax1_2.set_xlabel("Position Y [μm]", labelpad = 0, style = "italic", fontsize=fontsize)
- ax1_2.set_ylabel("Position Z [μm]", labelpad = 0, style = "italic", fontsize=fontsize)
- print("Number of NaN values on shown IV curve:", str(len(np.where(np.isnan(pixelplotting_array[:,coordinate[0],coordinate[1]])))))
- if coordinate == None:
- countnumberlines = 0
- for y in np.linspace(set_region[0],set_region[1],1000/thinning,dtype=int):
- for z in np.linspace(set_region[2],set_region[3],1000/thinning,dtype=int):
- ax1.plot(voltages[A:B], pixelplotting_array[:,y,z], "-o", markersize=2, linewidth=0.2, color="blue")
- if showPosition:
- # Create a set of inset Axes: these should fill the bounding box allocated to them.
- ax1_2 = plt.axes([0,0,1,1])
- # Manually set the position and relative size of the inset axes within ax1
- ip = InsetPosition(ax1, [0.2,0.05,figsize[0]/120,figsize[0]/120])
- ax1_2.set_axes_locator(ip)
- # ticks and ticklabels need to be shifted according to Image Registration
- scan = scans_ordered[B-1] # show the scan of the last IV curve point as an example
- IRS_y = ImageRegistrationDic[scan][0][2] # IRS = Image Registration Shift (in y or z)
- IRS_z = ImageRegistrationDic[scan][1][2]
- # individual ticks: it's an extrapolated plot from 201x201 to 1000x1000 pixels, but this corresponds to 10x10 micrometers on the solar cell
- ax1_2.xaxis.set_ticklabels([0,5,10],fontsize=round(4/5*fontsize))
- ax1_2.xaxis.set_ticks([0-IRS_y,500-IRS_y,999-IRS_y]) # if 1000 instead of 999 it won't display
- ax1_2.yaxis.set_ticklabels([0,5,10],fontsize=round(4/5*fontsize))
- ax1_2.yaxis.set_ticks([0-IRS_z,500-IRS_z,999-IRS_z])
- ax1_2.xaxis.set_minor_locator(AutoMinorLocator(5)) # 1 minor tick for each micrometer
- ax1_2.yaxis.set_minor_locator(AutoMinorLocator(5))
- ax1_2.imshow(current_array, interpolation='nearest', cmap=cm.afmhot, origin='lower')
- ax1_2.plot(y,z, "bo", markersize=4)
- # y and z labels
- ax1_2.set_xlabel("Position Y [μm]", labelpad = 0, style = "italic", fontsize=fontsize)
- ax1_2.set_ylabel("Position Z [μm]", labelpad = 0, style = "italic", fontsize=fontsize)
- countnumberlines += 1
- print("Number of IV curves shown in plot:", str(countnumberlines))
- ax2 = fig.add_subplot(122)
- ax2.plot(voltages[A:B], current_mean, "-o")
- plt.title("Mean IV curve", pad = 15, fontsize=round(9/5*fontsize))
- ax2.tick_params(labelsize=fontsize)
- ax2.set_xticks(voltages[A:B])
- if annotations:
- for i in range(len(current_mean)):
- ax2.annotate("Scan " + str(scans_ordered[i+A]), xy=(voltages[i+A], current_mean[i]), xytext=(voltages[i+A], current_mean[i]+1.3), arrowprops=dict(facecolor='black', shrink=0.12, width=2, headwidth=8))
- end = time.time()
- print("Plotting took {} seconds.".format(str(round(end-start,2))))
- plt.show()
- if savepng:
- from datetime import datetime
- now = datetime.now()
- dt_string = now.strftime("%d-%m-%Y_%H_%M_%S")
- if dpi is None:
- fig.savefig("savefig/IV_curve_" + dt_string + ".png", dpi=fig.dpi, bbox_inches="tight")
- else:
- fig.savefig("savefig/IV_curve_" + dt_string + ".png", dpi=dpi, bbox_inches="tight")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement