본문 바로가기
tools/NCL

체중변화 그래프

by ㄱ ㄴ 2013. 5. 7.

내가 참 별거 다 만들고 앉았다.
예정일에 체중이 과연 얼마나 나가게 될지 ㅎㅎㅎ 추세선까지 그려가며 예상몸무게 뽑아서 그려주는 스크립트를 만들어버렸지.
물론 귀찮지만 weight.dat파일에 몸무게를 기입해야한다....

0. csh_mkdate.csh
일단 날짜와 몸무게가 들어가있는 데이터파일을 만들어줘야한다. 그건 쉘로 ㅋㅋ
(예전에 막만든거라-_-;;; 필요에 따라 개인적으로 변환해서 쓰길..)

1. weight.dat
여기에 "-99"라고 쓰여있는 부분에 몸무게*10으로 기입해준다.
(integer로 읽으려고 그렇게 만들었다-_-)
ex) 30.5kg이라면, 305라고 기입.

20130508 -99
20130509 305
20130510 -99
20130511 -99


2. plot_w.ncl
실행하면 끝!


=============================================================================================


#!/bin/csh

# csh_mkdate.csh

# Made by Kyungna Kim (knakim@gmail.com)


set Y = 2013
while ( $Y <= 2013 )
set YM = `echo $Y | awk '{print $1%4}'`
if ( $YM == 0 ) then
 set YN = 29
else
 set YN = 28
endif

set M = 02
while ( $M <= 10 )
set MM = `echo $M | awk '{printf "%2.2i",$1}'`
set YY = $Y

if (${MM} == 01 ) set ED = 31
if (${MM} == 02 ) set ED = ${YN}
if (${MM} == 03 ) set ED = 31
if (${MM} == 04 ) set ED = 30
if (${MM} == 05 ) set ED = 31
if (${MM} == 06 ) set ED = 30
if (${MM} == 07 ) set ED = 31
if (${MM} == 08 ) set ED = 31
if (${MM} == 09 ) set ED = 30
if (${MM} == 10 ) set ED = 31
if (${MM} == 11 ) set ED = 30
if (${MM} == 12 ) set ED = 31

set D = 1
while ( $D <= ${ED} )
set DD = `echo $D | awk '{printf "%2.2i",$1}'`

echo ${YY}${MM}${DD}    -99

@ D++
end
@ M++
end
@ Y++
end 



;; plot_w.ncl

;; Made by Kyungna Kim (knakim@gmail.com)

;;========================================================

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;;========================================================
;; DATA
;;========================================================
  auj  = systemfunc("date")
  dir  = ""
  fi   = "weight.dat"
  odir = ""
  ofi  = "20130513"

  aa = asciiread(dir+fi,-1,"integer")
  aa@_FillValue = -99
  adsz = dimsizes(aa)
  dsz = adsz/2
  a = onedtond(aa,(/dsz,2/))

  b = a(:,0)-20130000
  c = b(::30)
  w = a(:,1)*0.1

  x_span = ispan(0,dsz-1,1)
  rc_w = regline(x_span,w)
  y_w  = rc_w*x_span + rc_w@yintercept
  e_w  = y_w(x_span(dsz-1))
printVarSummary(rc_w)

  d = new((/5,dsz/),"float")
  d(0,:) = w
  d(1,:) = y_w

;;========================================================

;; PLOT
;;========================================================
  wks = gsn_open_wks("eps",odir+ofi)
  gsn_merge_colormaps(wks,"default","wgne15")

  res = True    
     res@vpHeightF               = 0.4
     res@vpWidthF                = 0.6

     res@tmXBMajorLengthF        = 0.008
     res@tmXBMajorOutwardLengthF = 0.
     res@tmXBMinorLengthF        = 0.005
     res@tmXBMinorOutwardLengthF = 0.
     res@tmYLMajorLengthF        = 0.010
     res@tmYLMajorOutwardLengthF = 0.
     res@tmYLMinorLengthF        = 0.006
     res@tmYLMinorOutwardLengthF = 0.
     res@tmBorderThicknessF      = 5.

     res@gsnRightStringFontHeightF = 0.015
     res@gsnLeftStringFontHeightF = res@gsnRightStringFontHeightF
     res@gsnRightString = sprintf("%3.1f",e_w)+"kg"
     res@gsnLeftString = auj

     res@trYMaxF       = 55.
     res@trYMinF       = 45.
     res@trXMaxF       = dsz

     res@tmXBMode              = "Explicit"
     res@tmXBValues            = ispan(0,dsz-1,30)
     res@tmXBLabels            = sprinti("%4.4i",c)

     res@xyMarkLineModes = (/"Markers","Lines"/)
     res@xyMarker        = 12
     res@xyMarkerSizeF   = 0.005
     res@xyDashPatterns    = (/0,0/)
     res@xyLineThicknesses = (/1,0.5/)
     res@xyLineColors      = (/1,2/)

     res@tiXAxisFontHeightF = 0.015
     res@tiYAxisFontHeightF = res@tiXAxisFontHeightF
     res@tiXAxisString = "Date [mmdd]"
     res@tiYAxisString = "Weight [kg]"

  plot = gsn_csm_y(wks,d,res) 


'tools > NCL' 카테고리의 다른 글

ncl에서 nan처리  (0) 2024.08.27
get Attributes  (0) 2013.05.24
retrieve colormap  (0) 2012.11.19
시작전 마음준비  (0) 2012.11.11
NCL이란..  (0) 2012.11.11

댓글