Link Search Menu Expand Document

CMAQ綜合空品項目之計算(combine)

Table of contents

背景

  • 由於CCTM是按照日期進行檔案的輸出,污染項目也是按照226項細項輸出,因此如需複合之空品項目如PM、VOCs等,則需進行後處理combine.exe。
    • 如只是需要特定污染項目,直接使用ncks進行讀取切割較為簡便。
    • 注意如果直接讀取ACONC檔案,其氣狀物濃度單位為 ppm (或μg/M3)。
  • 測站定點濃度之讀取,需待combine處理產生COMB_ACONC檔案之後,另以write_site程式從中讀取指定座標之測站濃度時間變化序列。
  • combine.exe之執行在此詳述,write_site則見於測站模擬值之讀取

程式編譯

  • 位置:$CMAQ_Project/POST/combine/scripts/BLD_combine_v53_gcc
  • 執行:make
  • 修正:
    • /home/kuang/mac/cmaqruns/CMAQ_Project/POST/combine/scripts/BLD_combine_v53_gcc/module_evaluator.F
    • 與機器floating error有關的設定
      • LOG及LOG10的極小值:1E-19
      • EXP的極小值:-1.E-19

處理程序

  • 連續處理全年之combine與write_site腳本(do_post.csh)
#!/bin/csh
#kuang@node03 /nas1/cmaqruns/2016base
#$ cat  do_post.csh
foreach JOB (comb wsite)
foreach mm (`seq 1 12`)
  set mon=`printf '%02d' $mm`
  foreach DM ('d04')
      cd /nas1/cmaqruns/2016base
      source run_${JOB}MM_DM.csh $mon $DM >& ${JOB}_$mon$DM
    end
  end
end
end

腳本程式說明

程式名稱

I/O檔案

  • CCTM執行結果
    • CCTM_ACONC檔案:逐日小時平均濃度、共有226項空氣品質,含4項大氣要素
    • CCTM_APMDIAG檔案:網格點上各粒徑比例之小時平均紀錄
  • 氣象數據
    • METCRO3D
    • METCRO2D
  • 空品/沉降量定義檔:$SPECIES_DEF
  • 結果檔案OUTFILE
    • 小時平均濃度:${POSTDIR}/COMBINE_ACONC_${CTM_APPD},共有135項(在$SPECIES_DEF中定義)。
    • 小時沉降量:${POSTDIR}/COMBINE_DEP_${CTM_APPD}

執行方式

  • 讀取引數:2碼月份、批次序(5~12)、網格編號(d01/d02/d04、無d03)
    • CAS設定為TEDS編號,與年代有關,2019附近使用TEDS11

SPECIES_DEF檔案之設定

  • 參考github.USEPA樣板
  • !之後為註解沒作用,將回復到內設值。
  • #之後為變數名稱。
  • 層數之定義
    • 此範例將只會進行第1層(地面層)的整併。
    • 如加上!之後,程式將會按照CCTM_ACONC的層數進行合併
[kuang@DEVP 2018base]$ echo $SPEC_CONC
../CMAQ_Project/POST/combine/scripts/spec_def_files/SpecDef_cb6r3_ae7_aq.txt
[kuang@DEVP 2018base]$ head $SPEC_CONC
!#start   YYYYJJJ  000000
!#end     YYYYJJJ  230000
#layer    1
  • VOC之定義
VOC             ,ppbC      ,1000.0* (PAR[1] +2.0*ETHA[1] +3.0*PRPA[1] +MEOH[1]\
                            +2.0*ETH[1] +2.0*ETOH[1] +2.0*OLE[1] +3.0*ACET[1] \
                            +7.0*TOL[1] +8.0*XYLMN[1] +6.0*BENZENE[1] \
                            +FORM[1] +3.0*GLY[1] +4.0*KET[1] +2.0*ETHY[1] \
                           +2.0*ALD2[1] + 2.0*ETHA[1] + 4.0*IOLE[1] + 2.0*ALDX[1]  \
                           +5.0*ISOP[1] + 10.0*TERP[1]+ 10.0*NAPH[1] +10.*APIN[1])
  • PM2.5的定義
    • PM25AT[3]、PM25AC[3]、PM25CO[3]三個值即為CCTM_APMDIAG檔案內之Aitkenaccumulationcoarse mode。
    • ATOTI[0]、ATOTJ[0]、ATOTK[0]為CCTM_APMDIAG檔案內之3個mode之粒狀物濃度加總結果。
PM25_TOT        ,ug m-3     ,ATOTI[0]*PM25AT[3]+ATOTJ[0]*PM25AC[3]+ATOTK[0]*PM25CO[3]

分段說明

  • 原腳本說明段
$ cat -n ~/GitHub/cmaq_relatives/combine/run_combMM_R_DM.csh
     1	#! /bin/csh -f
     2	
     3	# ====================== COMBINE_v5.3 Run Script ======================== 
     4	# Usage: run.combine.uncoupled.csh >&! combine_v53_uncoupled.log &                                
     5	#
     6	# To report problems or request help with this script/program:     
     7	#             http://www.epa.gov/cmaq    (EPA CMAQ Website)
     8	#             http://www.cmascenter.org  (CMAS Website)
     9	# ===================================================================  
    10	
    11	# ==================================================================
    12	#> Runtime Environment Options
    13	# ==================================================================
    14	
    15	#> Choose compiler and set up CMAQ environment with correct
    16	#> libraries using config.cmaq. Options: intel | gcc | pgi
  • 基本環境變數設定
    • 編譯器版本gcc
    • 程式碼位置
    • 程式I/O檔案目錄
    17	 setenv compiler gcc
    18	
    19	#> Set location of CMAQ repo.  This will be used to point to the correct species definition files.
    20	 setenv REPO_HOME  ../CMAQ_Project
    21	 #> Source the config.cmaq file to set the build environment
    22	 source $REPO_HOME/config_cmaq.csh gcc
    23	 setenv CMAQ_HOME $PWD
    24	 setenv CMAQ_DATA  /nas1/cmaqruns/2018base/data
    25	
    26	set MO         = $argv[1]
    27	set RUN        = $argv[2]
    28	set DM         = $argv[3]
    29	
    30	       
  • 一般定義
    • 年代、TEDS版本須手動修改
    31	#> Set General Parameters for Configuring the Simulation
    32	 set VRSN      = v53               #> Code Version
    33	 set PROC      = mpi               #> serial or mpi
    34	 set MECH      = cb6r3_ae7_aq      #> Mechanism ID
    35	 set APPL      = 18${MO}              #> Application Name (e.g. Gridname)
    36	 set STKCASEE  = 11   
    37	                                                      
  • 執行程式位置
    • 此環境變數不易修改,如欲切換執行其他工作批次檔,「應」跳出此次csh另外定義(使用tmux)。
   38	#> Define RUNID as any combination of parameters above or others. By default,
    39	#> this information will be collected into this one string, $RUNID, for easy
    40	#> referencing in output binaries and log files as well as in other scripts.
    41	 setenv RUNID  ${VRSN}_${compilerString}_${APPL}
    42	
    43	#> Set the build directory if this was not set above 
    44	#> (this is where the CMAQ executable is located by default).
    45	#if ( ! $?BINDIR ) then
    46	  setenv BINDIR $REPO_HOME/POST/combine/scripts/BLD_combine_${VRSN}_${compilerString}
    47	#endif
    48	
    49	#> Set the name of the executable.
    50	 setenv EXEC combine_${VRSN}.exe
    51	
    52	
    53	#> Set working, input and output directories
    54	if ( $DM == 'd01' ) then
    55	  setenv GRID_NAME  EAsia_81K        
    56	else if ( $DM == 'd02' ) then
    57	  setenv GRID_NAME  sChina_27k        
    58	else if( $DM == 'd04' ) then
    59	  setenv GRID_NAME  TWN_3X3           
    60	else
    61	  echo "Error input d02/d04"
    62	  exit 1
    63	endif
    64	
  • 輸入/輸出檔案及路徑
    65	# setenv GRID_NAME TWN_3X3                 #> check GRIDDESC file for GRID_NAME options
    66	 setenv CCTMOUTDIR ${CMAQ_DATA}/output_CCTM_${RUNID}      #> CCTM Output Directory
    67	 setenv POSTDIR    ${CCTMOUTDIR}/POST                     #> Location where combine file will be written
    68	
    69	  if ( ! -e $POSTDIR ) then
    70		  mkdir $POSTDIR
    71	  endif
    72	
    73	
    74	
    75	# =====================================================================
    76	#> COMBINE Configuration Options
    77	# =====================================================================
    78	
  • 日期、日數之計算
    79	#> Set Start and End Days for looping
    80	 set BEG_DATE = `date -ud "2018-${MO}-15 -1 month" +%Y-%m-%d `
    81	 set END_DATE = `date -ud "2018-${MO}-01 +1 month" +%Y-%m-%d `
    82	#  echo ${APPL}|cut -d'n' -f2
    83	# set MRUN = `echo ${APPL}|cut -d'n' -f2`
    84	 set MRUN = 4 
    85	  @ NDYS = $MRUN * 4
    86	 set START_DATE = `date -ud "${BEG_DATE} +${NDYS}days" +%Y-%m-%d `
    87	 set END_DATE = `date -ud "${START_DATE} +32days" +%Y-%m-%d`
    88	 
  • 物質名稱之定義
    • VOC、PM2.5、PM10之開啟與其詳細計算公式
    • 「輸出檔的層數」也在此檔案內修改
    • 濃度與沉降量2大類
    89	#> Set location of species definition files for concentration and deposition species.
    90	 setenv SPEC_CONC $REPO_HOME/POST/combine/scripts/spec_def_files/SpecDef_${MECH}.txt
    91	 setenv SPEC_DEP  $REPO_HOME/POST/combine/scripts/spec_def_files/SpecDef_Dep_${MECH}.txt
    92	
    93	#> Use GENSPEC switch to generate a new specdef file (does not generate output file).
    94	 setenv GENSPEC N
    95	
    96	
    97	# =====================================================================
    98	#> Begin Loop Through Simulation Days to Create ACONC File
    99	# =====================================================================
   100	
   101	#> Set the species definition file for concentration species.
   102	 setenv SPECIES_DEF $SPEC_CONC
   103	 
  • 日數之迴圈
   104	#> Loop through all days between START_DAY and END_DAY
   105	 set TODAYG = ${START_DATE}
   106	 set TODAYJ = `date -ud "${START_DATE}" +%Y%j` #> Convert YYYY-MM-DD to YYYYJJJ
   107	 set STOP_DAY = `date -ud "${END_DATE}" +%Y%j` #> Convert YYYY-MM-DD to YYYYJJJ
   108	 set I = 0
   109	 while ($TODAYJ <= $STOP_DAY )  #>Compare dates in terms of YYYYJJJ
   110	   @ R = 6 # $I / 4 + 5
   111	   echo 'kuang' $I run$R
   112	   if ( $R > 12 ) exit 0
  • 詳細I/O檔名之定義
   113	  #> Retrieve Calendar day Information
   114	   set YYYY = `date -ud "${TODAYG}" +%Y`
   115	   set YY = `date -ud "${TODAYG}" +%y`
   116	   set MM = `date -ud "${TODAYG}" +%m`
   117	   set DD = `date -ud "${TODAYG}" +%d`
   118	   if ( "${STKCASEE}" != "" ) then
   119	     setenv CTM_APPL ${RUNID}_run${R}_$YYYY$MM${DD}_${GRID_NAME}_${STKCASEE}
   120	  else
   121	     setenv CTM_APPL ${RUNID}_$YYYY$MM${DD}_${GRID_NAME}
   122	  endif
   123	  #> for files that are indexed with Julian day:
   124	   #  set YYYYJJJ = `date -ud "${TODAYG}" +%Y%j` 
   125	
   126	  #> Define name of combine output file to save hourly average concentration.
   127	  #> A new file will be created for each month/year.
   128	   setenv OUTFILE ${POSTDIR}/COMBINE_ACONC_${CTM_APPL}.nc
   129	
   130	  #> Define name of input files needed for combine program.
   131	  #> File [1]: CMAQ conc/aconc file
   132	  #> File [2]: MCIP METCRO3D file
   133	  #> File [3]: CMAQ APMDIAG file
   134	  #> File [4]: MCIP METCRO2D file
   135	 setenv METDIR    ${CMAQ_DATA}/mcip/${APPL}_run${R}/${GRID_NAME}            #> Met Output Directory
   136	   setenv INFILE1 $CCTMOUTDIR/CCTM_ACONC_${CTM_APPL}.nc
   137	   setenv INFILE2 $METDIR/METCRO3D_${APPL}_run${R}.nc
   138	   setenv INFILE3 $CCTMOUTDIR/CCTM_APMDIAG_${CTM_APPL}.nc
   139	   setenv INFILE4 $METDIR/METCRO2D_${APPL}_run${R}.nc
   140	
  • 程式之執行
   141	  #> Executable call:
   142	 if ( $RUN == $R) then
   143	   ${BINDIR}/${EXEC}
   144	 endif
   145	
   146	  #> Increment both Gregorian and Julian Days
   147	   set TODAYG = `date -ud "${TODAYG}+1days" +%Y-%m-%d` #> Add a day for tomorrow
   148	   set TODAYJ = `date -ud "${TODAYG}" +%Y%j` #> Convert YYYY-MM-DD to YYYYJJJ
   149	   @ I = $I + 1 
   150	 end #Loop to the next Simulation Day
   151	
   152	
  • 沉降量計算部分
   153	# =====================================================================
   154	#> Begin Loop Through Simulation Days to Create DEP File
   155	# =====================================================================
   156	
   157	#> Set the species definition file for concentration species.
   158	 setenv SPECIES_DEF $SPEC_DEP
   159	 
   160	#> Loop through all days between START_DAY and END_DAY
   161	 set TODAYG = ${START_DATE}
   162	 set TODAYJ = `date -ud "${START_DATE}" +%Y%j` #> Convert YYYY-MM-DD to YYYYJJJ
   163	 set STOP_DAY = `date -ud "${END_DATE}" +%Y%j` #> Convert YYYY-MM-DD to YYYYJJJ
   164	 set I = 0
   165	 while ($TODAYJ <= $STOP_DAY )  #>Compare dates in terms of YYYYJJJ
   166	   @ R = 6 #$I / 4 + 5
   167	   echo 'kuang' $I run$R
   168	   if ( $R > 12 ) exit 0
   169	  #> Retrieve Calendar day Information
   170	   set YYYY = `date -ud "${TODAYG}" +%Y`
   171	   set YY = `date -ud "${TODAYG}" +%y`
   172	   set MM = `date -ud "${TODAYG}" +%m`
   173	   set DD = `date -ud "${TODAYG}" +%d`
  • 詳細I/O檔名之定義
   174	   if ( "${STKCASEE}" != "" ) then
   175	     setenv CTM_APPL ${RUNID}_run${R}_$YYYY$MM${DD}_${GRID_NAME}_${STKCASEE}
   176	     setenv CTM_APPD ${RUNID}_run${R}_$YYYY${MM}_${GRID_NAME}_${STKCASEE}
   177	  else
   178	     setenv CTM_APPL ${RUNID}_$YYYY$MM$DD
   179	     setenv CTM_APPD ${RUNID}_$YYYY$MM
   180	  endif
   181	  #> for files that are indexed with Julian day:
   182	   #  set YYYYJJJ = `date -ud "${TODAYG}" +%Y%j` 
   183	
   184	  #> Define name of combine output file to save hourly total deposition.
   185	  #> A new file will be created for each month/year.
   186	   setenv OUTFILE ${POSTDIR}/COMBINE_DEP_${CTM_APPD}
   187	  #> Define name of input files needed for combine program.
   188	  #> File [1]: CMAQ DRYDEP file
   189	  #> File [2]: CMAQ WETDEP file
   190	  #> File [3]: MCIP METCRO2D
   191	  #> File [4]: {empty}
   192	   setenv METDIR    ${CMAQ_DATA}/mcip/${APPL}_run${R}/${GRID_NAME}            #> Met Output Directory
   193	   setenv INFILE1 $CCTMOUTDIR/CCTM_DRYDEP_${CTM_APPL}.nc
   194	   setenv INFILE2 $CCTMOUTDIR/CCTM_WETDEP1_${CTM_APPL}.nc
   195	   setenv INFILE3 $METDIR/METCRO2D_${APPL}_run${R}.nc
   196	   setenv INFILE4
   197	
  • 程式之執行
   198	  #> Executable call:
   199	 if ( $RUN == $R) then
   200	   mpirun -np 10 ${BINDIR}/${EXEC}
   201	 endif
   202	
   203	  #> Increment both Gregorian and Julian Days
   204	   set TODAYG = `date -ud "${TODAYG}+1days" +%Y-%m-%d` #> Add a day for tomorrow
   205	   set TODAYJ = `date -ud "${TODAYG}" +%Y%j` #> Convert YYYY-MM-DD to YYYYJJJ
   206	   @ I = $I + 1 
   207	 end #Loop to the next Simulation Day
   208	
   209	 
   210	 exit()

bash版本

Reference

  • Aitken Nuclei - an overview | ScienceDirect Topics (n.d.). Available at sciencedirect (Accessed 3 January 2022).