반응형

     정보

    • 업무명    : 텍스트 (TXT) 형식인 기온 자료를 이용한 시각화

    • 작성자    : 이상호

    • 작성일    : 2020-12-03

    • 설   명    :

    • 수정이력 :

     

     내용

    [개요]

    • 안녕하세요? 기상 연구 및 웹 개발을 담당하고 있는 해솔입니다.

    • NCL (NCAR Command Language)은 미국의 NCAR (National Center for Atmospheric Research)에서 개발된 언어로서 지구과학/대기과학 분야에서 특화되었습니다. 이는 다양한 분야에서 널리 사용되는 Matlab과 비교할 때 라이브러리를 통해 쉽게 계산할 수 있습니다.

      특히 예전에 자주 사용되는 소프트웨어인 GrADS는 간단한 인터페이스로 초보자도 빨리 익힐 수 있으나 소프트웨어의 유연성이 떨어집니다.

    • 오늘 포스팅에서는 텍스트 (TXT) 형식인 기온 자료를 이용한 시각화를 소개합니다.

    • 추가로 온라인/오프라인 리눅스 환경에 따른 NCL 설치 방법을 소개한 링크를 보내드립니다.

     

    [NCL] 온라인/오프라인 리눅스 (Linux) 환경에 따른 NCL 설치 방법

     정보 업무명  : 온라인/오프라인 리눅스 (Linux) 환경에 따른 NCL 설치 방법 작성자  : 이상호 작성일  : 2020-01-15 설  명 : 수정이력 :  내용 [개요] 안녕하세요? 웹 개발 및 연구 개발을 담당하고

    shlee1990.tistory.com

     

     

    [특징]

    • NCL을 통해 시각화하기 위해서 자료 처리 기술이 요구되며 이 프로그램은 이러한 목적을 달성하기 위한 소프트웨어

     

    [기능]

    • 텍스트 파일을 이용하여 컬러바 부여

    • 각 위/경도에 따른 시각화

     

    [활용 자료]

    • 자료명 : max_temp.txt, min_temp

    • 자료 종류 : 최고 기온, 최저 기온

    • 확장자 : txt

    • 영역 : 대한민국 광주

    • 기간 : 2010년 07월 05일

    min_temp.txt
    0.00MB
    max_temp.txt
    0.00MB

     

     

    • 자료명 : gadm36_KOR_단계

    • 자료 종류 : 지도 경계선

    • 확장지 : shp

    MAP.zip
    3.35MB

     

     

    [자료 처리 방안 및 활용 분석 기법]

    • 없음

     

    [사용법]

    • 입력 자료를 동일 디렉터리에 위치

    • 소스 코드를 실행

    • 가시화 결과 확인

     

    [사용 OS]

    • Linux (CentOS v7.3)

    • VMware Workstation Pro v15.5

     

    [사용 언어]

    • NCL v6.6.2

     

     소스 코드

    • 작업 환경의 경우 2개 디렉터리로 구성되며 주 프로그램은 Visualization_Using_Text_Format.ncl로 구성되어 있습니다.

     

    • 소스 코드는 단계별로 수행하며 상세 설명은 다음과 같습니다.

      • 1 단계의 경우 사용자 설정을 통해 NCL을 실행하여 메모리상에 저장하고 시각화를 위한 초기 설정합니다.

      • 2 단계는 영상 장면 표출하여 이미지 형식으로 저장합니다.

     

    [명세]

    • [1 단계] 사용자 설정

      • 입력 자료 (dfData), 맵 세부 단계 (sShpName), 그림 저장 파일명 (sPngName) 설정합니다.

    begin
    
       ;=============================================
       ;  File Name
       ;=============================================
       dfData = asciiread("INPUT/DATA/max_temp.txt",(/48, 3/), "float")
       ; dfData = asciiread("INPUT/DATA/min_temp.txt",(/48, 3/), "float")
       sShpName = "INPUT/MAP/gadm36_KOR_2.shp"
       sPngName = "OUTPUT/Max"
    
       ;=============================================
       ;  Set Value
       ;=============================================
       nLon = dfData( : , 0)
       nLat = dfData( : , 1)
       nVal = dfData( : , 2)
    
       ;=============================================
       ;  Option
       ;=============================================
       wks = gsn_open_wks("png", sPngName)
       res = True
       res@gsnDraw               =  False                 ;-- don't draw the plot yet
       res@gsnFrame              =  False                 ;-- don't advance the frame
       res@txFont   = "helvetica"
       res@cnFillPalette          = "rainbow"                ;-- choose colormap
       res@gsnMaximize            =  True
       res@pmTickMarkDisplayMode  = "Always"    ; tick mark (위,경도) 표시
       ; res@cnLevelSelectionMode = "ExplicitLevels"   ; set explicit contour levels
       ; res@cnLevels    = (/0, 30, 60, 90/)   ; set levels
       res@cnLevelSelectionMode   = "ManualLevels"     ; set manual contour levels
       
       ; Max
       res@cnMinLevelValF         =  300           ;-- contour min. value
       res@cnMaxLevelValF         =  320           ;-- contour max. value
       
       ; Min
       ; res@cnMinLevelValF         =  290           ;-- contour min. value
       ; res@cnMaxLevelValF         =  310           ;-- contour max. value
       
       ;   res@cnLevelSpacingF        =  1           ;-- contour interval(200)
       ;   res@lbLabelStride          =  3            ;-- label every 5th values on labelbar
       res@cnLinesOn = False;
       res@mpOutlineOn = False; 
       res@mpLandFillColor = "white" 
       res@lbBoxLinesOn = False
    
       res@mpMaxLatF = 35.27972
       res@mpMinLatF = 35.00472
       res@mpMaxLonF = 127.0567
       res@mpMinLonF = 126.6037
    
       ; res@mpMaxLatF = 38.27972 
       ; res@mpMinLatF = 30.00472 
       ; res@mpMaxLonF = 136.0567
       ; res@mpMinLonF = 122.6037 
       
       res@cnFillOn               = True               ; color fill 
       res@cnLinesOn              = False             ; no contour lines
       res@cnLineLabelsOn         = False             ; no contour labels
       res@cnFillMode             = "RasterFill"     ;-- use CellFill method
       ; res@tiMainString           = "NOAA Optimum Interpolation (OI) SST V2 (December 1st, 1981)"  ; title string
       res@tiMainFontHeightF      =  0.02            ;-- title font size
       res@tiMainFont             = "times-bold"
       ; res@pmLabelBarHeightF     = 0.3               ; default is taller
       res@gsnStringFontHeightF = 0.018              ; sub title size
       res@tmXBLabelFontHeightF = 0.017              ; xlab, ylab size
       res@lbLabelFontHeightF   = 0.017              ; colorbar font size
       res@tmXTMajorLengthF = 0                      ; tick length 
       ; res@cnInfoLabelOn              = True               ; turn off info label
       ; res@cnLineLabelBackgroundColor = "white"             ; background for labels
       res@trGridType = "TriangularMesh"
    
       res@sfXArray = nLon 
       res@sfYArray = nLat 
    
       ; set shapefile resources
       shpres                    =  True
       shpres@gsLineThicknessF   =  1.0                   ;-- increase line thickness
       shpres@gsLineColor        = "black"             ;-- line color
       
       ;=============================================
       ;  Plot
       ;=============================================
       plot = gsn_csm_contour_map(wks, nVal, res)
    
       dumstr1        = unique_string("poly")
       plot@$dumstr1$ = gsn_add_shapefile_polylines(wks, plot, sShpName, shpres)  
    
       draw(plot)
       frame(wks)
    
    end

     

    • [2 단계] NCL 실행 및 그림 저장

      • ncl Visualization_Using_Text_Format.ncl 명령어를 통해 실행 및 그림 저장을 합니다.

     

    • 최고 기온

     

    • 최저 기온

     

    [전체]

    • Visualization_Using_Text_Format.ncl

    begin
    
       ;=============================================
       ;  File Name
       ;=============================================
       dfData = asciiread("INPUT/DATA/max_temp.txt",(/48, 3/), "float")
       ; dfData = asciiread("INPUT/DATA/min_temp.txt",(/48, 3/), "float")
       sShpName = "INPUT/MAP/gadm36_KOR_2.shp"
       sPngName = "OUTPUT/Max"
    
       ;=============================================
       ;  Set Value
       ;=============================================
       nLon = dfData( : , 0)
       nLat = dfData( : , 1)
       nVal = dfData( : , 2)
    
       ;=============================================
       ;  Option
       ;=============================================
       wks = gsn_open_wks("png", sPngName)
       res = True
       res@gsnDraw               =  False                 ;-- don't draw the plot yet
       res@gsnFrame              =  False                 ;-- don't advance the frame
       res@txFont   = "helvetica"
       res@cnFillPalette          = "rainbow"                ;-- choose colormap
       res@gsnMaximize            =  True
       res@pmTickMarkDisplayMode  = "Always"    ; tick mark (위,경도) 표시
       ; res@cnLevelSelectionMode = "ExplicitLevels"   ; set explicit contour levels
       ; res@cnLevels    = (/0, 30, 60, 90/)   ; set levels
       res@cnLevelSelectionMode   = "ManualLevels"     ; set manual contour levels
       
       ; Max
       res@cnMinLevelValF         =  300           ;-- contour min. value
       res@cnMaxLevelValF         =  320           ;-- contour max. value
       
       ; Min
       ; res@cnMinLevelValF         =  290           ;-- contour min. value
       ; res@cnMaxLevelValF         =  310           ;-- contour max. value
       
       ;   res@cnLevelSpacingF        =  1           ;-- contour interval(200)
       ;   res@lbLabelStride          =  3            ;-- label every 5th values on labelbar
       res@cnLinesOn = False;
       res@mpOutlineOn = False; 
       res@mpLandFillColor = "white" 
       res@lbBoxLinesOn = False
    
       res@mpMaxLatF = 35.27972
       res@mpMinLatF = 35.00472
       res@mpMaxLonF = 127.0567
       res@mpMinLonF = 126.6037
    
       ; res@mpMaxLatF = 38.27972 
       ; res@mpMinLatF = 30.00472 
       ; res@mpMaxLonF = 136.0567
       ; res@mpMinLonF = 122.6037 
       
       res@cnFillOn               = True               ; color fill 
       res@cnLinesOn              = False             ; no contour lines
       res@cnLineLabelsOn         = False             ; no contour labels
       res@cnFillMode             = "RasterFill"     ;-- use CellFill method
       ; res@tiMainString           = "NOAA Optimum Interpolation (OI) SST V2 (December 1st, 1981)"  ; title string
       res@tiMainFontHeightF      =  0.02            ;-- title font size
       res@tiMainFont             = "times-bold"
       ; res@pmLabelBarHeightF     = 0.3               ; default is taller
       res@gsnStringFontHeightF = 0.018              ; sub title size
       res@tmXBLabelFontHeightF = 0.017              ; xlab, ylab size
       res@lbLabelFontHeightF   = 0.017              ; colorbar font size
       res@tmXTMajorLengthF = 0                      ; tick length 
       ; res@cnInfoLabelOn              = True               ; turn off info label
       ; res@cnLineLabelBackgroundColor = "white"             ; background for labels
       res@trGridType = "TriangularMesh"
    
       res@sfXArray = nLon 
       res@sfYArray = nLat 
    
       ; set shapefile resources
       shpres                    =  True
       shpres@gsLineThicknessF   =  1.0                   ;-- increase line thickness
       shpres@gsLineColor        = "black"             ;-- line color
       
       ;=============================================
       ;  Plot
       ;=============================================
       plot = gsn_csm_contour_map(wks, nVal, res)
    
       dumstr1        = unique_string("poly")
       plot@$dumstr1$ = gsn_add_shapefile_polylines(wks, plot, sShpName, shpres)  
    
       draw(plot)
       frame(wks)
    
    end

     

     참고 문헌

    [논문]

    • 없음

    [보고서]

    • 없음

    [URL]

    • 없음

     

     문의사항

    [기상학/프로그래밍 언어]

    • sangho.lee.1990@gmail.com

    [해양학/천문학/빅데이터]

    • saimang0804@gmail.com
    반응형
    • 네이버 블러그 공유하기
    • 네이버 밴드에 공유하기
    • 페이스북 공유하기
    • 카카오스토리 공유하기