원하는 데이터의 값만 선택해서 그래프를 그리고 싶습니다.

게시판 IDL Q&A 원하는 데이터의 값만 선택해서 그래프를 그리고 싶습니다.

3 답변 글타래를 보이고 있습니다
  • 글쓴이
    • #2265 Reply
      익명
      비활성

      코드는 아래와 같이 작성하였습니다.
      날짜와 시간 외에 55개의 물질이 존재하는 원하는 물질의 평균과 그래프를 작성하고 싶습니다.
      readcol 을 사용하여 데이터를 읽었는데
      spc에 원하는 물질만 입력했을경우 그 물질만의 평균과 그래프가 작성되게 하고싶습니다. 도움 부탁드립니다.

      pro daily_avg

      dir_in=
      dir_out=

      spc=’Ethane’
      month=’12’
      S_day=julday(12, 1, 2013)
      F_day=julday(12, 30, 2013)

      ;—————————————————————————————

      input_file=dir_in+month+’.txt’
      FMT = ‘L,I’

      readcol, input_file, F=FMT, Date, Time, Ethane, Ethylene, Propane, $
      Propylene, i-Butane, n-Butane, Acethylene, t-2-Butene, 1-Butene, $
      c-2-Butene, Cyclopentane, i-Pentane, n-Pentane, t-2-Pentene, 1-Pentene, $
      c-2-Pentene, 2_2-Dimethylbutane, 2_3-Dimethylbutane, 2-Methylpentane, $
      3-Methylpentane, Isoprene, 1-Hexene, n-Hexane, MeCycloC5, 2_4-DMeC5, $
      Benzene, Cyclohexane, 2-Methylhexane, 2_3-Dimethylpentane, 3-Methylhexane, $
      2_2_4-Trimethylpentane, n-Heptane, MeCyclohexane, 2_3_4-TriMethylpentane, $
      Toluene, 2-Methylheptane, 3-Methylheptane, n-Octane, Ethylbenzene, $
      m/p-Xylene, Styrene, o-Xylene, n-Nonane, Isopropylbenzene, n-Propylbenzene, $
      m-Ethyltoluene, p-Ethyltoluene, 1_3_5-TMB, o-Ethyltoluene, 1_2_4-TMB, $
      n-Decane, 1_2_3-TMB, m-Diethylbenzene, p-Diethylbenzene, n-Undecane

      t=timegen(start=S_day, final=F_day, unit= ‘day’)
      t_str=string(t, format='(C(CYI04CMOI02CDI02))’)
      x=byte(t[*]-t[0]+1)
      avg=findgen(x[-1])

      for i=0, n_elements(t)-1 do begin
      ok=where(date eq t_str[i], ct)
      if (ct eq 0) then begin
      avg[i] = 0
      endif else begin
      avg[i]=mean(Ethane[ok])
      endelse

      endfor

      forprint, t_str, avg, TEXTOUT=(dir_out+’Daily_Avg_’+spc+’_’+month+’.txt’), comment=’Date/Avg’

      y=avg
      plot_margin = [0.15, 0.25, 0.15, 0.15] ; leave room for bottom & right axes
      p_wspd = plot(x, y, ‘r’, $
      axis_style=1, $ ; make only x & y axes, not box axes
      margin=plot_margin, $
      xrange=[x[0],x[-1]],$
      yrange=[0,max(avg)+1], $
      xmajor=4, $ ; 3-hr intervals
      ymajor=10, $
      dimensions=[700,600], $ ; embiggen window to fit extra axes
      name=spc, $
      xtitle=’Date’, $
      ytitle=spc+'(ppbV)’, $
      title=’Daily_’+ spc+’_’+month, $
      buffer=0)
      p_wspd.Save, dir_out+’Daily_Avg_’+spc+’_’+month+’.jpeg’

      end

    • #2266 Reply
      익명
      비활성

      코드를 아래와같이 수정하였습니다. v1~v55는 각 물질을 번호로 나타낸 것입니다.
      spc에 원하는 물질을 넣을 경우 그 물질에 해당하는 v의 값을 자동으로 선택하도록 만들고 싶습니다
      도움 부탁드립니다.

      pro daily_avg
      dir_in=
      dir_out=
      month=’11’
      spc=’Ethane’
      ;—————————————————————————————
      input_file=dir_in+month+’.txt’
      FMT = ‘L,I’
      readcol, input_file, F=FMT, Date, Time, v1,V2,v3,v4,v5,v6,v7,v8,v9,v10,$
      v11,v12,v13,v14,v15,V16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26,v27,$
      v28,v29,v30,v31,v32,v33,v34,v35,v36,v37,v38,v39,v40,v41,v42,v43,v44,$
      v45,v46,v47,v48,v49,v50,v51,v52,v53,v54,v55
      ;——————————————————————————————
      data=v1

      A=[1,3,5,7,8,10,12]
      B=[4,6,9,11]
      wh_a=where(A eq month, ct_A)
      wh_b=where(B eq month, ct_B)
      if (ct_A gt 0) then begin
      end_d=31
      endif else begin
      if (ct_B gt 0) then end_d=30 else end_d=28
      endelse

      S_day=julday(month, 1, 2013)
      F_day=julday(month, end_d, 2013)

      t=timegen(start=S_day, final=F_day, unit= ‘day’)
      t_str=string(t, format='(C(CYI04CMOI02CDI02))’)
      x=byte(t[*]-t[0]+1)
      avg=findgen(x[-1])

      for i=0, n_elements(t)-1 do begin
      ok=where(date eq t_str[i], ct)
      if (ct eq 0) then begin
      avg[i] = 0
      endif else begin
      avg[i]=mean(data[ok])
      endelse

      endfor

      forprint, t_str, avg, TEXTOUT=(dir_out+spc+’\’+’Daily_Avg_’+spc+’_’+month+’.txt’), comment=’Date/Avg’

      y=avg
      plot_margin = [0.15, 0.25, 0.15, 0.15] ; leave room for bottom & right axes
      p_wspd = plot(x, y, ‘r’, $
      axis_style=1, $ ; make only x & y axes, not box axes
      margin=plot_margin, $
      xrange=[x[0],x[-1]],$
      yrange=[0,max(avg)+1], $
      xmajor=4, $ ; 3-hr intervals
      ymajor=10, $
      dimensions=[700,600], $ ; embiggen window to fit extra axes
      name=spc, $
      xtitle=’Date’, $
      ytitle=spc+'(ppbV)’, $
      title=’Daily_’+ spc+’_’+month, $
      buffer=0)
      p_wspd.Save, dir_out+spc+’\’+’Daily_Avg_’+spc+’_’+month+’.jpeg’

      end

    • #2267 Reply
      익명
      비활성

      각 물질들이 규칙이 없는 값이므로
      if를 55번 사용해서 나타내야 할까요..

    • #2278 Reply
      Jonghyuk
      회원

      앞에 답변 드린 내용과 같은 문제인 것 같습니다.

      If를 55번 사용하는 것도 문제를 해결할 수는 있을 것 같습니다.
      하지만 앞에 답변 드렸듯이 1번은 Ethane, 2번은 Ethylene 등의 정의가 이미 되어 있으므로,
      1차원 배열을 하나로 합쳐 2차원 배열을 만들고, Ethylene 인 경우 2번이 나오게 where를 만들어,
      2차원 배열에서 V2를 찾아내는 것이 좋겠습니다.

      Execute() 라는 함수를 이용하면, where의 리턴값을 변수명으로 합칠 수도 있는데, 권장할만한 방법은 아니라고 생각합니다.

3 답변 글타래를 보이고 있습니다
'원하는 데이터의 값만 선택해서 그래프를 그리고 싶습니다.'에 답변달기
글쓴이 정보: