Link Search Menu Expand Document

地面濃度模擬結果之整併與切割

Table of contents

背景

  • cmaq cctm的後處理包括:
    1. 就汙染物質的維度、整併PM與VOC(combine.exe)
    2. 就個別污染項目進行切割(shk.cs)
    3. 就時間維度將逐日檔案連接起來
    4. 進行濃度圖之繪製、並將逐時濃度圖檔儲存、傳送、或製作成gif動畫檔(aconc2gifm3nc2gif)
  • 國網上可以使用sbatch來平行執行combine.exe,這對後處理過程來說是一個強項。然而也因為sbatch的幕後執行特性,不利於連續批次操作。還是需要發展類似wait.cs的等待程式,待sbatch處理好後再繼續後續的工作。
  • 後續處理分別見以下各篇說明,此處說明環境設定及國網上的注意事項。
  • 雖然公版模式建議先將CCTM_ACONC連接起來,再執行combine.exe,但因為逐日結果檔案很大,除了濃度檔之外,粒狀物分率檔案也需要對等連接,不論是過程或結果檔案都很大,不利操作。
    • 解決方案就是先執行combine.exe,之後再視需要將其連接即可。
    • 由於每日執行預報,同一天的模擬結果會隨著模式的運作而覆蓋,如果是連接起來,將會更不方便。

環境

  • 整併拆解過程會需要NCO相關程式(rcec/tools)、繪圖則需要wrf-python等繪圖模組。
  • 前者只需load正確的模組即可
  • wrf-python需另安裝,rcec/python/wrfpost下的程式太舊(3.6)會報錯Segment Fault
    • 經排除log、NaNs等可能的錯誤,
    • 按照網友建議更新到最新版本、所有問題就迎刃而解。

module

module purge
module load rcec/tools pkg/Anaconda3
  • 後者沒有必要每次呼叫。python首句直接呼叫interpreter即可。

wrf-python之準備

  • 因為模組更新速度不太一樣,要小心安裝的順序。
  • 這裡選用python 3.10。經實證比較穩定(3.11也OK)。
  • 使用conda安裝也比pip來得完整
conda create -n py310 python==3.10
conda activate py310
conda install -c conda-forge wrf-python
conda install matplotlib cartopy

post.cs

這支程式串連了sbatch combine.sh(內含chk.cs)、以及後續地面濃度的繪製及整併

IO

  • 分兩種狀況,有引數(必須是comb)會只做sbatch
  • 沒有引數,則進行濃度圖的繪製

程式碼

#sinotec2@lgn302 /work/sinotec2/cmaq_recommend/work/2023-06/grid03/cctm.ContEms/daily
#$ cat post.cs
#!/usr/bin/bash
module purge
module load rcec/tools pkg/Anaconda3
work=/work/sinotec2/cmaq_recommend/work
ym=2023-06
nd=4
GRD=( 'grid45'     'grid09'  'grid03' )
DOM=(grid45 grid09 Taiwan)
ITs=( 1 1 1 )
BEGD=2023-06-14
dates=();datep=()
for id in {0..11};do dates=( ${dates[@]} $(date -d "$BEGD +${id}days" +%Y-%m-%d) ); datep=( ${datep[@]} $(date -d "$BEGD +${id}days" +%Y%m%d) ); done

BIN=/work/sinotec2/opt/cmaq_recommend/bin


i=2
if [[ $1 == "comb" ]];then
  idb=0
  for ((id=$idb;id <= $nd;d+=1));do nc=$work/$ym/${GRD[$i]}/cctm.ContEms/daily/CCTM_ACONC_v532_intel_${DOM[$i]}_${datep[$id]}.nc;if [[ -e $nc ]];then sbatch $work/combine.sh $nc;fi;done
  exit 0
fi

it=${ITs[$i]}
dt=$(( 10#$it * 10000 ))
  for fn in $(ls PMs20*|tail -n${nd});do
    nt=$(( $($BIN/pr_tflag.py $fn|wc -l) - 1 ))
    j=$(echo $fn|cut -c4-11)
    for s in PM25_TOT PM10;do
      p=$s;test $p == "PM25_TOT" && p="PM2.5"
      ncks -O -d VAR,0 -d TSTEP,0,${nt},$it -v TFLAG,$s $fn ${p}_$j.nc
      ncatted -a TSTEP,global,o,i,$dt ${p}_$j.nc;done;done
  for s in SO2 CO O3 NO2;do for fn in $(ls CCTM_ACONC*|tail -n${nd});do
    j=$(echo $fn|cut -d'_' -f6)
    ncks -O -d LAY,0 -d VAR,0 -d TSTEP,0,${nt},$it -v TFLAG,$s $fn ${s}_$j
    ncatted -a TSTEP,global,o,i,$dt ${s}_$j;done;done
  for s in PM2.5 PM10 SO2 CO O3 NO2;do
    ncrcat -O ${s}_2*.nc ${s}.nc;rm ${s}_2*.nc;done
  for s in PM2.5 PM10 SO2 CO O3 NO2;do
    $BIN/m3nc2gif.py $s.nc;done
exit 0

combine.sh

  • 這個版本是bash版,有別於USEPA官網上的csh版,主要因應在命令列直接執行slurm指令。

引數與結果

  • 引數:逐日CCTM_ACONC結果檔案。必須含有絕對目錄。程式會從其中讀取路徑、網格、日期等設定
  • 結果:會在同一目錄下產生PMsYYYYMMDD.nc。目前並沒有開啟VOCs的整併,但有PM1、PM2.5、PM10等。
  • 會需要mcip下的檔案與CCTM_APMDIAG檔案。

combine程式碼

#$ cat $work/combine.sh
#!/bin/sh
#SBATCH -A *********             # Account name/project number
#SBATCH -J comb                  # Job name
#SBATCH -p ct56                  # Partiotion name
#SBATCH -n 10                    # Number of MPI tasks (i.e. processes)
#SBATCH -c 1                     # Number of cores per MPI task
#SBATCH -N 1                     # Maximum number of nodes to be allocated
#SBATCH --ntasks-per-node=10    # Maximum number of tasks on each node
#SBATCH -o rsl.out.%j            # Path to the standard output file
#SBATCH -e rsl.error.%j          # Path to the standard error ouput file
module load compiler/intel/2021 IntelMPI/2021 hdf5/1.12 netcdf/4.7.4 pnetcdf/1.12.2

nc=$1
ii=$(echo $nc|cut -d'/' -f7|cut -c5-6)
ymd=$(echo $nc|cut -d'_' -f7|cut -d'.' -f1)
ym=$(echo $nc|cut -d'/' -f6)

export BASE=/work/sinotec2/cmaq_recommend/work
export BLD=/work/sinotec2/opt/cmaq_recommend/POST/combine/scripts/BLD_combine_v532_intel
export EXEC=$BLD/combine_v532.exe
export m3input=${BASE}/$ym/grid$ii/mcip
export cctmout=${BASE}/$ym/grid$ii/cctm.ContEms/daily

# user define
#> File [1]: CMAQ conc/aconc file
#> File [2]: MCIP METCRO3D file
#> File [3]: CMAQ APMDIAG file
#> File [4]: MCIP METCRO2D file
export INFILE2=${m3input}/METCRO3D_Taiwan.nc
export INFILE4=${m3input}/METCRO2D_Taiwan.nc

# programs
export LC_ALL=C
export LANG=C
export GENSPEC=N
export SPECIES_DEF=${BASE}/SpecDef_cb6r3_ae7_aq.txt
export INFILE1=$nc
export INFILE3=${nc/ACONC/APMDIAG}
export OUTFILE=${cctmout}/out${ymd}.conc.nc
if [ -e ${OUTFILE} ]; then rm ${OUTFILE};fi

time mpirun -bootstrap slurm -n 10 ${EXEC} >& ${BASE}/cmb.out
if [ -e ${cctmout}/PMs$ymd.nc ];then rm ${cctmout}/PMs$ymd.nc;fi
${BASE}/shk.cs $OUTFILE ${cctmout}/PMs$ymd.nc
if [ -e ${OUTFILE} ]; then rm ${OUTFILE};fi

shk.cs

  • 這支程式會將combine好的結果檔當成輸入檔,拆解出需要的污染項目出來。
  • 需要2個引數,分別是個別CCTM_COMB檔與結果檔名。
  • 一般工作站版本沒有太大的差異。主要注意要將NCO設定到有效的目錄。