爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9321|回复: 4

[经验总结] regridding from lat-lon to lambert conformal conic (LLC) by ncl

[复制链接]
发表于 2013-10-30 15:53:05 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
本帖最后由 寒江雪(王训 于 2013-10-30 15:56 编辑

Recently, doing the regridding job for atmospheric model. There is a script I used to regrid the lat-lon to LLC.
The case likes:
                     Source: the soil organic matter data of China  whose resolution is  30 seconds
                     Goal: 36 km lambert conformal conic netcdf file
Here is the script. Enjoying!

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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"

begin
;---We want to write the results to netcdf file
    WRITE_RESULTS = True

;---The interpolation way we used
    INTERP_METHOD = "bilinear"

;---Data file containing source curvilinear grid
    src_file = "SOM.nc"                      ;;---Change (likely)
    sfile    = addfile(src_file,"r")
    src_lat  = sfile->lat                    ;;---Change (likely)
    src_lon  = sfile->lon                    ;;---Change (likely)

;---Get variable to regrid
    varname = "SOM"            ;;---Change (likely)
    var     = sfile->$varname$
    som     = var(0,:,:)

;---WRF file containing destination grid
    dst_file = "wrfout.nc"              ;;---Change (likely)
    dfile    = addfile(dst_file,"r")
    dst_lat  = dfile->XLAT(0,:,:)              ;;---Change (maybe)
    dst_lon  = dfile->XLONG(0,:,:)             ;;---Change (maybe)

;---Set up regridding options
    Opt                   = True

;---"bilinear" is the default. "patch" and "conserve" are other options.
    Opt@InterpMethod      = "bilinear"        ;;---Change (maybe)

    Opt@WgtFileName       = "rec_to_WRF.nc"

    Opt@SrcGridLat        = src_lat           ; source grid
    Opt@SrcGridLon        = src_lon
    Opt@SrcRegional       = True              ;;--Change (maybe)
    Opt@SrcInputFileName  = src_file          ; optional, but good idea
;    Opt@SrcMask2D         = where(.not.ismissing(var),1,0) ; Necessary if has
                                                           ; missing values.

    Opt@DstGridLat        = dst_lat           ; destination grid
    Opt@DstGridLon        = dst_lon
    Opt@DstRegional       = True              ;;--Change (maybe)

    Opt@ForceOverwrite    = True
    Opt@PrintTimings      = True
    Opt@Debug             = True

    var_regrid = ESMF_regrid(som,Opt)     ; Do the regridding

    printVarSummary(var_regrid)

;----------------------------------------------------------------------
; Plotting section
;
; This section creates filled contour plots of both the original
; data and the regridded data, and panels them.
;----------------------------------------------------------------------
    var@lat2d = src_lat     ; Needed for plotting. "var_regrid"
    var@lon2d = src_lon     ; already has these attrs attached.

    wks = gsn_open_wks("ps","curv_to_WRF")

    res                       = True

    res@gsnMaximize           = True

    res@gsnDraw               = False
    res@gsnFrame              = False

    res@cnFillOn              = True
    res@cnLinesOn             = False
    res@cnLineLabelsOn        = False
    res@cnFillMode            = "RasterFill"

    res@lbLabelBarOn          = False    ; Turn on later in panel

    res@mpMinLatF             = min(src_lat)
    res@mpMaxLatF             = max(src_lat)
    res@mpMinLonF             = min(src_lon)
    res@mpMaxLonF             = max(src_lon)

;;--Change (maybe)
    mnmxint = nice_mnmxintvl( min(var), max(var), 100, False)
    res@cnLevelSelectionMode = "ManualLevels"
    res@cnMinLevelValF       = mnmxint(0)
    res@cnMaxLevelValF       = mnmxint(1)
    res@cnLevelSpacingF      = mnmxint(2)

;---Resources for plotting regridded data
    res@gsnAddCyclic  = False            ;;---Change (maybe)
    res@tiMainString = "Data on WRF grid (" + Opt@InterpMethod + ")"

    plot_regrid = gsn_csm_contour_map(wks,var_regrid,res)

;---Resources for plotting original data
    res@gsnAddCyclic = False            ;;---Change (maybe)
    res@tiMainString = "Data on original grid"

    plot_orig = gsn_csm_contour_map(wks,som,res)  

;---Compare the plots in a panel
    pres                   = True
    pres@gsnMaximize       = True
    pres@gsnPanelLabelBar  = True

    gsn_panel(wks,(/plot_orig,plot_regrid/),(/2,1/),pres)

;----------------------------------------------------------------------
; Data writing section
;     Write the regridded data to a NetCDF file
;----------------------------------------------------------------------   
    if(WRITE_RESULTS) then
      rgrdFileName = "som_regrid.nc"
      system("rm -f " + rgrdFileName)
      rgrd_nc = addfile(rgrdFileName,"c")
      
;---Create variable to hold global file attributes
      global = True
      copy_VarAtts(sfile, global)

      if (isatt(sfile,"title")) then
        global@TITLE = "REMAPPED: " + sfile@title
      end if
      global@remap         = "NCL: ESMF_regrid_with_weights (NCL version '" + \
                             get_ncl_version() + "')"
      global@remap_method  = INTERP_METHOD
      global@creation_date = systemfunc("date")
   
      fileattdef( rgrd_nc, global )        ; copy global file attributes
;      filedimdef(rgrd_nc,"TIME",-1,True)   ; force an unlimited dimension


;--- Write variables to file. Coordinate arrays will be written
;--- automatically
;
     rgrd_nc->SOM       = (/var_regrid/)
    end if
end

密码修改失败请联系微信:mofangbao
 楼主| 发表于 2013-10-30 15:59:10 | 显示全部楼层
最后的效果图

curv_to_WRF.ps

293.17 KB, 下载次数: 31, 下载积分: 金钱 -5

密码修改失败请联系微信:mofangbao
发表于 2013-10-30 16:55:58 | 显示全部楼层
Thanks for your sharing.   I have a question. Where and how to get the soil organic matter data of China. Thanks in advance.
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2013-10-30 17:15:53 | 显示全部楼层
http://westdc.westgis.ac.cn/data ... 1-81a6-0c7c224112a0, 面向陆面模拟的中国土壤数据集
A China Dataset of Soil Properties for Land Surface Modeling
密码修改失败请联系微信:mofangbao
发表于 2019-10-24 10:08:19 来自手机 | 显示全部楼层
本帖最后由 木船渔人 于 2019-10-24 10:10 编辑

如何把36km的数据regridding到30秒呢?请指导一下。我的nc文件是个两维数据(lat, lon)没有时间这一维。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表