用Python对CSV文件进行处理并生成符合要求的图表,在图表上继续截取符合条件的y值并进行功率P的计算

实习任务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的描述图在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值