实习任务2:在实习任务1的基础上并在给定的电流的情况下确定其功率并用图表显示出来
计算公式为 P= I*U
代码如下:
from matplotlib import pyplot as plt
import csv
import glob
import numpy as np
from os.path import basename
for n in range(9,14): #Dateien von Modul_9 bis zu Modul_13
plt.figure(1) # Subdiagramm 1 plotten
plt.figure(dpi = 128, figsize=(10,6))
ax1 = plt.subplot(121)
plt.title("PIDrecovery_I-V_Kennlinie",fontsize = 16)
plt.xlabel("Spannnung [V]", fontsize = 16)
plt.ylabel("Strom [A]", fontsize = 16)
def name_konfiguration(n): # beim Name von Modul_9 muss noch ein '0' davor einfuegen
if n == 9:
return str("09")
else:
return str(n)
files = sorted(glob.glob("F:\Python_Aufgabe\Aufgabe_2\P09-P13_PIDre\DIV_CSP_PIDre_MZ_2_P" + name_konfiguration(n) + "*.csv")) #list of files
print("processin raw files")
mpp_liste= [] # eine liste fuer MPP erstellen
for file in files:
filename = basename(file).rsplit('.', 1)[0] # each file in list of files
print('\r'+ filename + " ", flush = True) # progress information
with open(file) as f: #'with' will auto close after loop
csvreader = csv.reader(f, delimiter = ",", quotechar='"') #read into csv object
for line in range(48): #skip header
next (csvreader)
voltage = [] #init lists
current = []
for row in csvreader:
voltage.append(float(row[6])) #process each row
current.append(float(row[3])) #extract column
Imp = np.linspace(9,9,len(voltage)) # Isc auf dem Diagramm anzeigen
idx = np.argwhere(np.diff(np.sign(Imp - current))).flatten() # entsprchende X-wert einsammeln
print(int(idx))
print(float(np.array(current,dtype=np.float)[idx]))
print(float(np.array(voltage,dtype=np.float)[idx]))
get_mpp=float(np.array(current,dtype=np.float)[idx] * np.array(voltage,dtype=np.float)[idx]) # multiplizieren
mpp_liste.append(get_mpp) # die Liste von MPP ausfuellen
print("MPP: " + str(get_mpp))
print("mpp_liste: " + str(mpp_liste[:]))
plt.plot(voltage,Imp, label= filename) #actual plot
plt.plot(voltage, current)
plt.plot(np.array(voltage,dtype=np.float)[idx], np.array(Imp,dtype=np.float)[idx], 'ro') # kritische Punkte auf dem Diagramm anzeigen
plt.legend()
ax2 = plt.subplot(122) # Subdiagramm 2 plotten
plt.title("MPP_Kennlinie",fontsize = 16)
plt.xlabel("Datei_nummer", fontsize = 16)
plt.ylabel("MPP[W]", fontsize = 16)
file_number= np.linspace(1,13,len(mpp_liste))
plt.plot(np.array(file_number),np.array(mpp_liste), label="DIV_CSP_PIDre_MZ_2_P" + name_konfiguration(n) + "MPP_Kennlinie")
plt.legend()
print("Done processing " + str(len(files)) + " files.") #final information
plt.savefig("F:\Python_Aufgabe\Aufgabe_2\P09-P13_PIDre\DIV_CSP_PIDre_MZ_2_P" + name_konfiguration(n) + ".png", dpi = 300) #save plot as file
plt.show() #present plot
这是针对光伏模块09的描述图