-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3_sdp_to_plot.py
168 lines (159 loc) · 6.52 KB
/
3_sdp_to_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
##
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os,sys
from datetime import datetime
import COMMON as COM
##
plt.style.use(COM.MPLSTYLE)
plt.rcParams["font.family"] = "IPAexGothic"
plt.rcParams["font.sans-serif"] = "IPAexGothic"
########################################################
## GFSファイルからSDPリスト地点の気象量を抽出してCSV保存する
########################################################
## コマンドライン引数: SDPリスト
SDP_PLOT = sys.argv[1:]
CSV_PATH = COM.FCST_PATH #"./forecast"
OUT_PATH = COM.PLOT_PATH #"./graph"
print("enter:",sys.argv)
print(sys.argv[0], datetime.now())
print(sys.argv[0], CSV_PATH)
print(sys.argv[0], OUT_PATH)
os.makedirs(OUT_PATH, exist_ok=True)
########################################################
## 抽出地点と気象変数の指定
ENCODE = "cp932"
SDP_LIST = pd.read_csv(COM.INFO_PATH +"/"+ "sdp_list.csv", index_col="SDP",encoding=ENCODE)
SDP_PLOT = SDP_LIST.index if len(SDP_PLOT)==0 else SDP_PLOT
########################################################
#SDP_PLOT = SDP_PLOT[:2]
for SDP in SDP_PLOT:
SDP = int(SDP)
NAME = SDP_LIST.loc[SDP,"NAME"]
FUKEN = SDP_LIST.loc[SDP,"FUKEN"]
DF = pd.read_csv(CSV_PATH +"/"+ "%05d.csv"%SDP,parse_dates=[0],index_col=0)
DF = DF[:-(len(DF)%8)]
print(sys.argv[0], SDP,NAME)
########################################################
## データ準備
## 気温(degC)
T0K = 273.15
DF['TMP'] = DF['Temperature_height_above_ground_00'] - T0K
DF['DPT'] = DF['Dewpoint_temperature_height_above_ground_00'] - 273.15
## 雲量(0-1)
DF['TCDC'] = DF['Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average_00'] / 100.
#DF['High'] = DF['Total_cloud_cover_high_cloud_Mixed_intervals_Average_00'] / 100.
#DF['Middle'] = DF['Total_cloud_cover_middle_cloud_Mixed_intervals_Average_00'] / 100.
#DF['Low'] = DF['Total_cloud_cover_low_cloud_Mixed_intervals_Average_00'] / 100.
## 天気(0-1)
DF['CRAIN'] = DF['Categorical_Rain_surface_00']
DF['CSNOW'] = DF['Categorical_Snow_surface_00']
DF['CICEP'] = DF['Categorical_Ice_Pellets_surface_00']
## 大気放射(kW/m2)
DF['LWD'] = DF['Downward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average_00'] / 1000.
DF['SWD'] = DF['Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average_00'] / 1000.
## 大気安定度(kJ/kg)
DF['CAPE'] = DF['Convective_available_potential_energy_surface_00'] / 1000.
DF['CIN'] = DF['Convective_inhibition_surface_00'] / 1000.
## 高層気温(degC) @ isobaric6=[0,3,6,9,...,33]
"""
DF['T350mb'] = DF['Temperature_isobaric_18'] - T0K
DF['T500mb'] = DF['Temperature_isobaric_21'] - T0K
DF['T800mb'] = DF['Temperature_isobaric_27'] - T0K
DF['T925mb'] = DF['Temperature_isobaric_30'] - T0K
DF['T1000mb'] = DF['Temperature_isobaric_33'] - T0K
"""
## 視程(km)
DF['VIS'] = DF['Visibility_surface_00'] / 1000.
## 突風(m/s)
DF['GUST'] = DF['Wind_speed_gust_surface_00']
## リフト指数(K)
DF['4LFTX'] = DF['Best_4_layer_Lifted_Index_surface_00']
DF['LFTX'] = DF['Surface_Lifted_Index_surface_00']
## 湿度(%)
DF['RH'] = DF['Relative_humidity_height_above_ground_00']
## 暑さ指数(degC)
DF['WBGT'] = 0.735*DF['TMP'] + 0.0374*DF['RH'] + 0.00292*DF['TMP']*DF['RH'] + 7.619*DF['SWD'] - 4.557*DF['SWD']*DF['SWD'] - 0.0572*(DF['GUST']/2.0) - 4.064
########################################################
## プロット作成
#plt.ticklabel_format(useLocale=False)
fig, axes = plt.subplots(nrows=6,ncols=1,figsize=(5,8))
fig.suptitle('{0:05d} {1:} {2:} UTC {3}'.format(SDP,FUKEN,NAME,DF.reftime[0][:-3]))
## 気温(degC)
row = 0
for c in ['TMP','DPT','WBGT']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Temp. (C)")
axes[row].grid(True)
axes[row].legend(loc='right')
## 大気放射(kW/m2)
row = row + 1
for c in ['SWD','LWD']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Flux (kW/m2)")
axes[row].grid(True)
axes[row].legend(loc='right')
axes[row].set_ylim(0.0,1.05)
## 天気(0-1)
row = row + 1
for c in ['CRAIN','CSNOW','CICEP']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Cat. (0-1)")
axes[row].grid(True)
axes[row].legend(loc='right')
axes[row].set_ylim(0.0,1.05)
## 雲量(0-1)
row = row + 1
#for c in ['TCDC','High','Middle','Low']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
for c in ['TCDC']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Cloud (0-1)")
axes[row].grid(True)
axes[row].legend(loc='right')
axes[row].set_ylim(0,1.05)
## 視程(km)
row = row + 1
for c in ['VIS']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Visibility (km)")
axes[row].grid(True)
axes[row].legend(loc='right')
axes[row].set_ylim(0,30)
## 高層気温(degC)
"""
row = row + 1
for c in ['T800mb','T500mb','T350mb']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Temp. (C)")
axes[row].grid(True)
axes[row].legend(loc='right')
#axes[row].set_ylim(-2,2)
"""
## 大気安定度(kJ/kg)
"""
row = row + 1
for c in ['CAPE','CIN']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Stability (kJ/kg)")
axes[row].grid(True)
axes[row].legend(loc='right')
#axes[row].set_ylim(-2,2)
"""
## 大気安定度(K)
row = row + 1
for c in ['4LFTX','LFTX']: DF[c].plot(ax=axes[row],label=c,marker='.',sharex=True)
axes[row].set_ylabel("Stability (K)")
axes[row].grid(True)
axes[row].legend(loc='right')
#axes[row].set_ylim(-2,2)
########################################################
## PNG保存
plt.savefig(OUT_PATH +"/"+ "%05d.png"%SDP, transparent=COM.TRANSPARENT)
#plt.savefig(OUT_PATH +"/"+ "%05d.svg"%SDP)
plt.close(fig)
## CSV保存 for GSI Maps
DF["TNK"] = DF.apply(lambda x: (u"雪" if x.CSNOW else (u"雨" if x.CRAIN else (u"曇" if x.TCDC>0.8 else (u"晴" if x.TCDC>0.2 else u"快")))), axis=1)
COL = {"TNK":u"天気","TMP":u"気温","RH":u"湿度","TCDC":u"雲量","SWD":u"日射","GUST":u"突風","VIS":u"視程","WBGT":u"暑さ",}
DF = DF[list(COL)]
DF = DF.rename(columns=COL)
DF.to_csv(OUT_PATH +"/"+ "%05d.csv"%SDP, encoding=ENCODE)
########################################################
print("leave:",sys.argv)
sys.exit(0)