정보
-
업무명 : 파이썬 MOHID 해양순환모델 결과 (남동해역 유속, 수온, 염분)를 이용한 가시화
-
작성자 : 박진만
-
작성일 : 2019-09-02
-
설 명 : 한반도 동남해상 전체에 대한 유속, 수온, 염분 가시화
-
수정이력 :
내용
[특징]
-
소스 코드의 초기화 설정 (관련 URL)
-
NetCDF 및 shp 파일을 이용하여, 각각의 구성요소를 가시화 (동남해역 전체 범위)
[기능]
-
동남해역 전체 범위에 대한 유속, 수온 염분 매핑 (각 depth 별)
-
basemap 사용
[활용 자료]
-
없음
[자료 처리 방안 및 활용 분석 기법]
-
없음
[사용법]
-
1 단계 초기 설정한 후 소스 코드 실행 (python ##)
[사용 OS]
-
Window 10
[사용 언어]
-
Python v2.7
소스 코드
## 동남해역 유속 매핑 ##
arrow_magn=20.0
#%matplotlib inline
dep = [0,10,25,50,75]
depnum = [18,16,15,13,12] #surface / 10m / 25m / 50m / 75m
for i in range(0,1,1):
depcount = -1
for j in depnum:
#print(j)
depcount += 1
# fig Size
fig = plt.figure(figsize=(10, 12.5))
ax = fig.add_subplot(111)
# style
plt.style.use('seaborn-darkgrid')
# define font size
plt.rc("font", size=15)
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = 'New Century Schoolbook'
plt.rcParams["font.weight"] = "bold"
plt.rcParams['axes.labelsize'] = 26
plt.rcParams['xtick.labelsize'] = 26
plt.rcParams['ytick.labelsize'] = 26
plt.rcParams["axes.labelweight"] = "bold"
plt.rcParams["axes.titleweight"] = "bold"
plt.rcParams['contour.corner_mask'] = False
plt.rcParams.update({'figure.autolayout': True})
#vector extract
varU= ncfile.variables[u'u'][i,j,:,:]
varV= ncfile.variables[u'v'][i,j,:,:]
varVM= ncfile.variables[u'vm'][i,j,:,:]
varVM = switch(varVM,j) #마스크 계산 함수 호출...
varVM = np.ma.array(varVM, mask = varVM <= 0.0)
plt.contour(BS_X, BS_Y, varVM,cv_tick, linewidths=0,color='k')
bsmap.contourf(BS_X,BS_Y,varVM,cv_tick,cmap=cmap_jet,vmin = 0, vmax = 2, extend='both')
#color bar
colorbar = bsmap.colorbar(location='right',size=0.25, ticks=cv_cbar_tick, cmap=cmap_jet,extendrect='False')
colorbar.ax.set_yticklabels(colorbar.ax.get_yticklabels(), fontsize=11)
# vector mapping
meana = np.mean(varVM[points])
Q = bsmap.quiver(lon2D[points],lat2D[points],varU[points],varV[points],varVM[points],pivot='middle',cmap=vcmap,latlon=True, scale_units='inches',scale=meana*arrow_magn,minlength=0.1,headwidth=4.0)
plt.quiverkey(Q, 0.1, 0.95, 1, ''+str(int(1)) + 'm/s', labelpos='N', fontproperties={'weight': 'bold', 'size':'12'},labelsep=0.1)
plt.quiverkey(Q, 0.1, 0.95, 1, 'Reference Vector', labelpos='S', fontproperties={'weight': 'bold', 'size':'12'},labelsep=0.1)
BSPATCH = BSPOLY(bsmap)
JPPATCH = JPPOLY(bsmap)
ax.add_collection(PatchCollection(BSPATCH, facecolor= 'lightgray', edgecolor='k', linewidths=0.5, zorder=1))
ax.add_collection(PatchCollection(JPPATCH, facecolor= 'lightgray', edgecolor='k', linewidths=0.5, zorder=1))
# gray background
bsmap.drawparallels(np.arange(-150, 120, 2), labels=[0,0,0,0], dashes=[2,2], color='lightgray')
bsmap.drawmeridians(np.arange(-180, 180, 2), labels=[0,0,0,0], dashes=[2,2], color='lightgray')
bsmap.drawmapboundary(fill_color='white')
plt.title('Currend Vectors(m/s)', loc='left', size=20)
plt.suptitle('[depth : ' + str(int(dep[depcount])) + 'm]', x=0.365, y=0.86, size=15)
# lat label
#plt.annotate(u'32\N{DEGREE SIGN}N', xy=(bsmap(123.0, 32.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'34\N{DEGREE SIGN}N', xy=(bsmap(123.0, 34.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'36\N{DEGREE SIGN}N', xy=(bsmap(123.0, 36.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'38\N{DEGREE SIGN}N', xy=(bsmap(123.0, 38.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'40\N{DEGREE SIGN}N', xy=(bsmap(123.0, 40.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
# lon label
#plt.annotate(u'124\N{DEGREE SIGN}E', xy=(bsmap(124.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'126\N{DEGREE SIGN}E', xy=(bsmap(126.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'128\N{DEGREE SIGN}E', xy=(bsmap(128.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'130\N{DEGREE SIGN}E', xy=(bsmap(130.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'132\N{DEGREE SIGN}E', xy=(bsmap(132.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
# time label
plt.annotate('VALID :'+times[i] + ' UTC', xy=(0.0, -0.035), color='red', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate(local_dt[i] + ' KST', xy=(0.092, -0.065), color='black', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate('TIME :'+times[0] + ' UTC', xy=(0.7, -0.035), color='red', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate(local_dt[0] + ' KST', xy=(0.780, -0.065), color='black', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.savefig('BS_cv' + times[i] + 'h _' + str(int(dep[depcount])) + 'm_layer' + '.png')
print('BS_cv_' + times[i] + 'h_' + str(int(dep[depcount])) + 'm_layer' + '.png' + ' SUCCESS!!')
#plt.show()
## 동남해역 수온 매핑 ##
dep = [0,10,25,50,75]
depnum = [18,16,15,13,12] #surface / 10m / 25m / 50m / 75m
for i in range(0,1,1):
depcount = -1
for j in depnum:
#print(j)
depcount += 1
# fig Size
fig = plt.figure(figsize=(10, 12.5))
ax = fig.add_subplot(111)
# style
plt.style.use('seaborn-darkgrid')
# define font size
plt.rc("font", size=15)
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = 'New Century Schoolbook'
plt.rcParams["font.weight"] = "bold"
plt.rcParams['axes.labelsize'] = 26
plt.rcParams['xtick.labelsize'] = 26
plt.rcParams['ytick.labelsize'] = 26
plt.rcParams["axes.labelweight"] = "bold"
plt.rcParams["axes.titleweight"] = "bold"
plt.rcParams['contour.corner_mask'] = False
plt.rcParams.update({'figure.autolayout': True})
#vector extract
var = ncfile.variables[u'temperature'][i,j,:,:]
var = switch(var,j) #마스크 계산 함수 호출...
var = np.ma.array(var, mask = var <= 0.0)
cc = plt.contour(BS_X, BS_Y,var,tp_cont_tick, linewidths=1,cmap=vcmap)
bsmap.contourf(BS_X,BS_Y,var,tp_conf_tick,cmap=cmap_jet1,vmin = 0.0, vmax = 33.0, extend='both')
plt.clabel(cc, inline=True, fontsize=12, fmt ='%2i', colors='k',inline_spacing=3.0)
# FILL POLYGON COLOR AND PLOT BOUNDATY LINE
BSPATCH = BSPOLY(bsmap)
JPPATCH = JPPOLY(bsmap)
ax.add_collection(PatchCollection(BSPATCH, facecolor= 'lightgray', edgecolor='k', linewidths=0.5, zorder=1))
ax.add_collection(PatchCollection(JPPATCH, facecolor= 'lightgray', edgecolor='k', linewidths=0.5, zorder=1))
#color bar
colorbar = bsmap.colorbar(location='right',size=0.25, ticks=tp_cbar_tick, cmap=cmap_jet1,extendrect='False')
colorbar.ax.set_yticklabels(colorbar.ax.get_yticklabels(), fontsize=11)
# white background gray fill contin
bsmap.drawparallels(np.arange(-150, 120, 2), labels=[0,0,0,0], dashes=[2,2], color='lightgray')
bsmap.drawmeridians(np.arange(-180, 180, 2), labels=[0,0,0,0], dashes=[2,2], color='lightgray')
bsmap.drawmapboundary(fill_color='white')
plt.title('Currend Vectors(m/s)', loc='left', size=20)
plt.suptitle('[depth : ' + str(int(dep[depcount])) + 'm]', x=0.365, y=0.863, size=15)
# lat label
#plt.annotate(u'32\N{DEGREE SIGN}N', xy=(bsmap(123.0, 32.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'34\N{DEGREE SIGN}N', xy=(bsmap(123.0, 34.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'36\N{DEGREE SIGN}N', xy=(bsmap(123.0, 36.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'38\N{DEGREE SIGN}N', xy=(bsmap(123.0, 38.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'40\N{DEGREE SIGN}N', xy=(bsmap(123.0, 40.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
# lon label
#plt.annotate(u'124\N{DEGREE SIGN}E', xy=(bsmap(124.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'126\N{DEGREE SIGN}E', xy=(bsmap(126.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'128\N{DEGREE SIGN}E', xy=(bsmap(128.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'130\N{DEGREE SIGN}E', xy=(bsmap(130.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'132\N{DEGREE SIGN}E', xy=(bsmap(132.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
# time label
plt.annotate('VALID :'+times[i] + ' UTC', xy=(0.0, -0.03), color='red', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate(local_dt[i] + ' KST', xy=(0.092, -0.055), color='black', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate('TIME :'+times[0] + ' UTC', xy=(0.7, -0.03), color='red', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate(local_dt[0] + ' KST', xy=(0.780, -0.055), color='black', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.savefig('BS_temp' + times[i] + 'h _' + str(int(dep[depcount])) + 'm_layer' + '.png')
print('BS_temp_' + times[i] + 'h_' + str(int(dep[depcount])) + 'm_layer' + '.png' + ' SUCCESS!!')
#plt.show()
## 동남해역 염분 매핑 ##
dep = [0,10,25,50,75]
depnum = [18,16,15,13,12] #surface / 10m / 25m / 50m / 75m
for i in range(0,timelen,1):
depcount = -1
for j in depnum:
#print(j)
depcount += 1
# fig Size
fig = plt.figure(figsize=(10, 12.5))
ax = fig.add_subplot(111)
# style
plt.style.use('seaborn-darkgrid')
# define font size
plt.rc("font", size=15)
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = 'New Century Schoolbook'
plt.rcParams["font.weight"] = "bold"
plt.rcParams['axes.labelsize'] = 26
plt.rcParams['xtick.labelsize'] = 26
plt.rcParams['ytick.labelsize'] = 26
plt.rcParams["axes.labelweight"] = "bold"
plt.rcParams["axes.titleweight"] = "bold"
plt.rcParams['contour.corner_mask'] = False
plt.rcParams.update({'figure.autolayout': True})
#vector extract
var = ncfile.variables[u'salinity'][i,j,:,:]
var = switch(var,j) #마스크 계산 함수 호출...
var = np.ma.array(var, mask = var <= 0.0)
cc = plt.contour(BS_X, BS_Y,var,sa_cont_tick, linewidths=1,cmap=vcmap)
bsmap.contourf(BS_X,BS_Y,var,sa_conf_tick,cmap=cmap_jet1,vmin = 25.0, vmax = 35.0, extend='both')
plt.clabel(cc, inline=True, fontsize=12, fmt ='%2.1f', colors='k',inline_spacing=3.0)
# FILL POLYGON COLOR AND PLOT BOUNDATY LINE
BSPATCH = BSPOLY(bsmap)
JPPATCH = JPPOLY(bsmap)
ax.add_collection(PatchCollection(BSPATCH, facecolor= 'lightgray', edgecolor='k', linewidths=0.5, zorder=1))
ax.add_collection(PatchCollection(JPPATCH, facecolor= 'lightgray', edgecolor='k', linewidths=0.5, zorder=1))
#color bar
colorbar = bsmap.colorbar(location='right',size=0.25, ticks=sa_cbar_tick, cmap=cmap_jet1,extendrect='False')
colorbar.ax.set_yticklabels(colorbar.ax.get_yticklabels(), fontsize=11)
# white background gray fill contin
bsmap.drawparallels(np.arange(-150, 120, 2), labels=[0,0,0,0], dashes=[2,2], color='lightgray')
bsmap.drawmeridians(np.arange(-180, 180, 2), labels=[0,0,0,0], dashes=[2,2], color='lightgray')
bsmap.drawmapboundary(fill_color='white')
plt.title('Salinity(psu)', loc='left', size=20)
plt.suptitle('[depth : ' + str(int(dep[depcount])) + 'm]', x=0.255, y=0.863, size=15)
# lat label
#plt.annotate(u'32\N{DEGREE SIGN}N', xy=(bsmap(123.0, 32.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'34\N{DEGREE SIGN}N', xy=(bsmap(123.0, 34.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'36\N{DEGREE SIGN}N', xy=(bsmap(123.0, 36.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'38\N{DEGREE SIGN}N', xy=(bsmap(123.0, 38.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'40\N{DEGREE SIGN}N', xy=(bsmap(123.0, 40.04)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
# lon label
#plt.annotate(u'124\N{DEGREE SIGN}E', xy=(bsmap(124.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'126\N{DEGREE SIGN}E', xy=(bsmap(126.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'128\N{DEGREE SIGN}E', xy=(bsmap(128.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'130\N{DEGREE SIGN}E', xy=(bsmap(130.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
#plt.annotate(u'132\N{DEGREE SIGN}E', xy=(bsmap(132.3, 30.90)), color='lightgray', fontweight='bold', xycoords='data', horizontalalignment='center', verticalalignment='top', size=9)
# time label
plt.annotate('VALID :'+times[i] + ' UTC', xy=(0.0, -0.03), color='red', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate(local_dt[i] + ' KST', xy=(0.092, -0.055), color='black', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate('TIME :'+times[0] + ' UTC', xy=(0.7, -0.03), color='red', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.annotate(local_dt[0] + ' KST', xy=(0.780, -0.055), color='black', fontweight='bold', textcoords='axes fraction',verticalalignment='left',xycoords='data', size=15)
plt.savefig('BS_sa' + times[i] + 'h _' + str(int(dep[depcount])) + 'm_layer' + '.png')
print('BS_sa_' + times[i] + 'h_' + str(int(dep[depcount])) + 'm_layer' + '.png' + ' SUCCESS!!')
#plt.show()
[Github]
결과
-
염분
-
염분
-
수온
참고문헌
[논문]
- 없음
[보고서]
- 없음
[URL]
- 없음
블로그에 대한 궁금하신 점을 문의하시면 자세히 답변드리겠습니다.
E. sangho.lee.1990@gmail.com & saimang0804@gmail.com
'프로그래밍 언어 > Python' 카테고리의 다른 글
[Python] 파이썬 라디오미터 밝기온도 자료를 이용한 시계열 그래프 (0) | 2019.09.07 |
---|---|
[Python] 파이썬 과학 기술 계산 및 처리에 유용한 패키지 소개 (0) | 2019.09.05 |
[Python] 파이썬 바이너리 (Binary) 형식인 천리안위성 1A호 (COMS/MI) 기상 위성 자료를 이용한 가시화 (0) | 2019.09.03 |
[Python] 파이썬 아스키 (ASCII) 형식인 히마와리 8호 (Himawari-8/AHI) 및 Aqua/CERES 기상 위성 자료를 이용한 가시화 (0) | 2019.09.03 |
[Python] 파이썬 MOHID 해양순환모델 매핑 : 파일읽기 및 함수 설정 (0) | 2019.08.20 |
최근댓글