damyarou

python, GMT などのプログラム

流況曲線と運転パターン図

はじめに

同じような図は何回か作成しているのだが、また必要になったため、新しく作り直した。 最新版のプログラムをアップしておく。

成果図

f:id:damyarou:20200330084330p:plain

プログラム

import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt


def rdata1():
    fnameR='df_tank_nk.csv' # input file name
    df=pd.read_csv(fnameR, header=0, index_col=0) # read excel data
    df.index = pd.to_datetime(df.index, format='%Y/%m/%d')
    df=df['1985/01/01':'2017/12/31']
    return df


def fig_duration(ppp, qqq):
    qe=5.84
    qt0=7.0
    fsz=14
    xmin=0; xmax=100; dx=10
    ymin=0; ymax=40; dy=5
    plt.figure(figsize=(8,5),facecolor='w')
    plt.rcParams['font.size']=fsz
    plt.rcParams['font.family']='sans-serif'
    tstr='Typical operation pattern of units'
    plt.xlim([xmin,xmax])
    plt.ylim([ymin,ymax])
    plt.xlabel('Non-exceedance Probability (%)')
    plt.ylabel('River Discharge (m$^3$/s)')
    plt.xticks(np.arange(xmin,xmax+dx,dx))
    plt.yticks(np.arange(ymin,ymax+dy,dy))
    plt.grid(color='#999999',linestyle='solid')
    plt.title(tstr,loc='left',fontsize=fsz)
    qt1=np.zeros(len(qqq),dtype=np.float64)
    qt2=np.zeros(len(qqq),dtype=np.float64)
    qt3=np.zeros(len(qqq),dtype=np.float64)
    for i in range(len(qqq)):
        if qe+qt0*3<=qqq[i]: qt1[i]=qe+qt0*3
        if qe+qt0*2<=qqq[i]<qe+qt0*3: qt1[i]=qqq[i]
        if qqq[i]<qe+qt0*2: qt1[i]=0
    for i in range(len(qqq)):
        if qe+qt0*3<=qqq[i]: qt2[i]=qe+qt0*2
        if qe+qt0*2<=qqq[i]<qt0*3+qe: qt2[i]=qe+qt0+(qqq[i]-qt0-qe)/2.0
        if qe+qt0*1<=qqq[i]<qt0*2+qe: qt2[i]=qqq[i]
        if qqq[i]<qe+qt0*1: qt2[i]=0            
    for i in range(len(qqq)):
        if qe+qt0*3<=qqq[i]: qt3[i]=qt0+qe
        if qe+qt0*2<=qqq[i]<qe+qt0*3: qt3[i]=qe+qt0
        if qe+qt0*1<=qqq[i]<qe+qt0*2: qt3[i]=qe+(qqq[i]-qe)/2
        if qe+0.2*qt0<=qqq[i]<qe+qt0*1: qt3[i]=qqq[i]            
    
    plt.fill_between(ppp,qt1,0,facecolor='#00ffff',alpha=1.0)
    plt.fill_between(ppp,qt2,0,facecolor='#ffffcc',alpha=1.0)
    plt.fill_between(ppp,qt3,0,facecolor='#ffd700',alpha=1.0)
    plt.fill_between(ppp,qqq,0,where=qqq<qe,facecolor='#ff00ff',alpha=1.0)
    plt.fill_between(ppp,qe,0,where=qe<qqq,facecolor='#ff00ff',alpha=1.0)
    plt.plot(ppp,qqq,'-', lw=2,color='#000080')
    plt.plot([xmin,xmax],[qe+qt0*3,qe+qt0*3],'-',color='#000000',lw=1)
    plt.plot([xmin,xmax],[qe+qt0*2,qe+qt0*2],'-',color='#000000',lw=1)
    plt.plot([xmin,xmax],[qe+qt0*1,qe+qt0*1],'-',color='#000000',lw=1)
    plt.plot([xmin,xmax],[qe+qt0*0,qe+qt0*0],'-',color='#000000',lw=1)
    ss1='Qe + 3 x Qu'
    ss2='Qe + 2 x Qu'
    ss3='Qe + 1 x Qu'
    ss4='Qe'
    plt.text(xmax,qe+qt0*3,ss1,va='bottom',ha='right',fontsize=fsz)
    plt.text(xmax,qe+qt0*2,ss2,va='bottom',ha='right',fontsize=fsz)
    plt.text(xmax,qe+qt0*1,ss3,va='bottom',ha='right',fontsize=fsz)
    plt.text(xmax,qe+qt0*0,ss4,va='bottom',ha='right',fontsize=fsz)
    plt.text(10,qe+qt0*2.5,'No.3 unit',va='center',ha='left',fontsize=fsz)
    plt.text(10,qe+qt0*1.5,'No.2 unit',va='center',ha='left',fontsize=fsz)
    plt.text(10,qe+qt0*0.5,'No.1 unit',va='center',ha='left',fontsize=fsz)
    plt.text(10,qe*0.5,'Environmental flow',va='center',ha='left',fontsize=fsz)
    xs=xmin+0.97*(xmax-xmin)
    ys=ymin+0.95*(ymax-ymin)
    ss='Qu : turbine discharge per unit\nQe : environmental flow'
    props = dict(boxstyle='square', facecolor='#ffffff', alpha=1.0)
    plt.text(xs, ys, ss, fontsize=fsz-2,va='top',ha='right',bbox=props)
    fnameF='fig_operation.png'
    plt.savefig(fnameF, dpi=200, bbox_inches="tight", pad_inches=0.1)
    plt.show()


def main():
    df=rdata1()
    q0 = np.array(df['Qtank'])
    qqq=np.sort(q0)[::-1] # target discharge sort
    ppp=np.linspace(0,100,len(q0)) # non-exceedance probability
    fig_duration(ppp,qqq)
   

#==============
# Execution
#==============
if __name__ == '__main__': main()

以上