load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" begin ; Using rgrid2rcm to interpolate EDGAR v4.2 to FL_ANTCO2 in wrfinput of WRF-GHG ;------------------------------------------------------------------------------- ; netcdf v42_CO2_2008_TOT.0.1x0.1 { ; dimensions: ; lat = 1800 ; ; lon = 3600 ; ; variables: ; float lat(lat) ; ; lat:standard_name = "latitude" ; ; lat:long_name = "latitude" ; ; lat:units = "degrees_north" ; ; lat:comment = "center_of_cell" ; ; float lon(lon) ; ; lon:standard_name = "longitude" ; ; lon:long_name = "longitude" ; ; lon:units = "degrees_east" ; ; lon:comment = "center_of_cell" ; ; float emi_co2(lat, lon) ; ; emi_co2:standard_name = "tendency_of_atmos._mass_cont._of_co2_due_to_emi" ; ; emi_co2:long_name = "Emissions of CO2 - " ; ; emi_co2:units = "kg m-2 s-1" ; ; emi_co2:cell_method = "time: mean (interval: 1 year, 366 days)" ; ; emi_co2:total_emi_co2 = "5.19137e+013 kg/year" ; ;------------------------------------------------------------------------------- ; rgrid2rcm ; Interpolates data on a rectilinear lat/lon grid to a curvilinear grid ; like those used by the RCM, WRF and NARR models/datasets. ; Prototype ; function rgrid2rcm ( ; lat [*] : numeric, ; lon [*] : numeric, ; fi : numeric, ; lat2d [*][*] : numeric, ; lon2d [*][*] : numeric, ; Option : numeric ; ) ; return_val : numeric ;------------------------------------------------------------------------------- path_edgar = "/home/xhu2/Codes/WRFV3.8.1/V3.8.1_chem/test/em_real/" ; path_wrf = "/home/lc/caserun/CO2_case_2011/" fn_co2 = "v42_CO2_2008_TOT.0.1x0.1.nc" fn_ch4 = "v42_CH4_2008_TOT.0.1x0.1.nc" fn_co = "v42_CO_2008_TOT.0.1x0.1.nc" fn_so2 = "v42_SO2_2008_TOT.0.1x0.1.nc" fn_no2 = "v42_NO2_2008_TOT.0.1x0.1.nc" f_co2 = addfile(path_edgar+fn_co2,"r") f_co = addfile(path_edgar+fn_co,"r") ; f_ch4 = addfile(path_edgar+fn_ch4,"r") ; f_so2 = addfile(path_edgar+fn_so2,"r") ; f_no2 = addfile(path_edgar+fn_no2,"r") elat = f_co2->lat elon = f_co2->lon emi_co = f_co->emi_co ; emi_ch4 = f_ch4->emi_ch4 ; emi_so2 = f_so2->emi_so2 ; emi_no2 = f_no2->emi_no2 ;------------------------------------------------------------------------------- ; system("cp /home/xhu2/Codes/WRFV3.8.1/V3.8.1_chem/test/em_real/wrfchemi_12z_d01_CONUS_NEI2011 wrfchemi_12z_d01_valueFromEdgar.nc") ; ftarget = addfile("wrfchemi_12z_d01_valueFromEdgar.nc","w") system("cp /home/xhu2/Codes/WRFV3.8.1/V3.8.1_chem/test/em_real/wrfchemi_00z_d01_CONUS_NEI2011 wrfchemi_00z_d01_valueFromEdgar_neareststod.nc") ftarget = addfile("wrfchemi_00z_d01_valueFromEdgar_neareststod.nc","w") ; temp = fwrf->T(:,0:1,:,:) ; temp!1 = "emissions_zdim" ; temp@units = "mol km^-2 hr^-1" ; dims = dimsizes(temp) ; dimNames = (/"Time", "emissions_zdim", "south_north", "west_east"/) ; dimSizes = (/ -1 , dims(1), dims(2), dims(3)/) ; dimUnlim = (/ True , False, False, False/) ; filedimdef(ftarget,dimNames,dimSizes,dimUnlim) ; printVarSummary(temp) ftarget->E_CO2 = ftarget->E_CO print("finish copying E_CO to E_CO2") ftarget->E_CO2 = 0. print("finish zero") ;---Input files sfile = f_co2 emi_co2 = f_co2->emi_co2 fwrf = addfile("wrfinput_d01.nc","r") lat2d = fwrf->XLAT(0,:,:) lon2d = fwrf->XLONG(0,:,:) ;---Output (and input) files Opt = True ; Opt@SrcFileName = "CCSM4_SCRIP.nc" ; output file names ; Opt@DstFileName = "EASE_ESMF.nc" Opt@ForceOverwrite = True ; Opt@SrcInputFileName = srcFileName ; optional, but good idea ; Opt@DstInputFileName = dstFileName ;;Needed if you want to regrid without generating these files again. Opt@SkipSrcGrid = False Opt@SkipDstGrid = False Opt@SkipWgtGen = False Opt@DstGridLat = lat2d Opt@DstGridLon = lon2d ;---lat/lon missing in same locations (doesn't seem to have an effect) ; Opt@DstMask2D = where(.not.ismissing(lat2d),1,0) ; Opt@InterpMethod = "patch" ; with slight negative values Opt@InterpMethod = "neareststod" ; with slight negative values Opt@Debug = True Opt@PrintTimings = True Opt@CopyVarCoords = False ; we can't copy the coords because ; the weights on the file are only ; for the non-missing lat/lon values. emi_co2_regrid = ESMF_regrid(emi_co2,Opt) ; Regrid emi_co2 ; dummy1 = rgrid2rcm (elat, elon, emi_co2, lat2d, lon2d, 0) ; print("finish interpolation for co2") ; dummy3 = rgrid2rcm (elat, elon, emi_co, lat2d, lon2d, 0) ; print("finish interpolation for co") ; EDGAR in kg m-2 s-1 WRFchem need mol km^-2 hr^-1 conv = 1e9*3600/44 ; do itime = 0, 11 ftarget->E_CO2(itime,0,:,:) = (/emi_co2_regrid*conv /) end do ; conv = 1e9*3600/28 ; ; ftarget->E_CO(0,0,:,:) = (/dummy3*conv /) delete(lat2d) delete(lon2d) ; delete(dummy1) ; delete(dummy3) end