Project

General

Profile

Masking, remapping or some other way to reduce the file to some extent

Added by Nikolay Yasinskiy over 5 years ago

I try to reduce the extent by remapnn and other remapping operators, also with masklonlatbox, sellonlatbox etc. I get from the ECMWF grib unrealistic values and sometimes they are incorrectly interpolated, showing horisontal lines fexample. Is the ECMWF projection of this file special and how should I work with it, as I had no problems while remapping another grib file in the same way?
The WRFPRS file is the target extent.


Replies (2)

RE: Masking, remapping or some other way to reduce the file to some extent - Added by Karin Meier-Fleischer over 5 years ago

Hi Nicolay,

in my opinion CDO can't remap those files. But I found a way to do it with NCL. The following NCL script reads the source and target file, regrid it using ESMF_regrid function, write the regridded variable to a new netCDF file and create a plot to compare the data.

script.ncl:

begin

;-- source (input) file
  sourcefile = addfile("agro.ecmwf.t00z.072612001.grb","r")
  sourcevar  = sourcefile->E_GDS0_SFC
  lat_src    = sourcefile->g0_lat_0
  lon_src    = sourcefile->g0_lon_1

;-- regridding

  DO_REGRID = True

  if(DO_REGRID) then

  ;-- target grid file
    targetgrid = addfile("WRFPRS_d01.03.0735.grb","r")
    lat_dst    = targetgrid->g3_lat_0
    lon_dst    = targetgrid->g3_lon_1 

    dimnames = getvardims(lat_dst)
    dims     = dimsizes(lat_dst)
    nlat     = dims(0)
    nlon     = dims(1)

  ;-- ESMF-regridding resources
    Opt                 =  True
    Opt@InterpMethod    = "bilinear"                  ;-- interpolation method
    Opt@ForceOverwrite  =  True                       ;-- force overwrite 
    Opt@DstGridType     = "curvilinear"               ;-- Destination grid
    Opt@DstGridLon      =  lon_dst
    Opt@DstGridLat      =  lat_dst
    Opt@Debug           =  True

  ;-- call ESMF_regrid
    regridded   = ESMF_regrid(sourcevar,Opt)
    regridded!0 = dimnames(0)                         ;-- named coordinate
    regridded!1 = dimnames(1)                         ;-- named coordinate
    regridded@coordinates = "lon lat"                 ;-- add coordinates attribute          
    delete(regridded@lat2d)                           ;-- delete attribute array lat2d
    delete(regridded@lon2d)                           ;-- delete attribute array lon2d

  ;-- write regridded data to new netCDF file
    system("rm -rf out_regrid_ncl.nc")
    fout = addfile("out_regrid_ncl.nc","c")

  ;-- predefine the coordinate variables and their dimensionality
    dimNames = (/dimnames(0), dimnames(1)/)           ;-- curvilinear grid: dimensions not lat/lon 
    dimSizes = (/nlon,  nlat/)                        ;-- dimension size of destination y/x
    dimUnlim = (/False, False/)   
    filedimdef(fout,dimNames,dimSizes,dimUnlim)

  ;-- predefine the the dimensionality of the variables to be written out
    filevardef(fout, "lat",        typeof(lat_dst),   getvardims(lat_dst)) ;-- variable lat not dimension                    
    filevardef(fout, "lon",        typeof(lon_dst),   getvardims(lon_dst)) ;-- variable lon not dimension                  
    filevardef(fout, "E_GDS0_SFC", typeof(regridded), getvardims(regridded))

  ;-- copy attributes associated with each variable to output file
    filevarattdef(fout,"lat",        lat_dst)         ;-- copy attributes from destination lat
    filevarattdef(fout,"lon",        lon_dst)         ;-- copy attributes from destination lon
    filevarattdef(fout,"E_GDS0_SFC", regridded)       ;-- copy var_regrid attributes

  ;-- explicitly exit file definition mode (not required)
    setfileoption(fout,"DefineMode",False)

  ;-- write data to new file
    fout->E_GDS0_SFC = (/regridded/)
    fout->lat        = (/lat_dst/)
    fout->lon        = (/lon_dst/)
    delete(fout) ;-- close fout

  end if

;-------------------------------------------------------
;-- plot source and regridded data in a panel
;-------------------------------------------------------
;-- open file and read variables
  f = addfile("out_regrid_ncl.nc","r")
  var       = f->E_GDS0_SFC
  var@lon2d = f->lon
  var@lat2d = f->lat

;-- open a workstation
  wks = gsn_open_wks("png","plot_regridded")

;-- plot resource settings
  res                 = True
  res@gsnDraw         = False
  res@gsnFrame        = False
  res@cnFillOn        = True
  res@cnLinesOn       = False
  res@cnLevelSelectionMode = "ManualLevels" 
  res@cnMinLevelValF  = -0.015
  res@cnMaxLevelValF  =  0.001
  res@cnLevelSpacingF =  0.001

  res@mpMinLatF       =  39.
  res@mpMaxLatF       =  56.5
  res@mpMinLonF       =  27.
  res@mpMaxLonF       =  57.

;-- create plot of source data
  res@gsnCenterString = "source data" 
  plot0 = gsn_csm_contour_map(wks,sourcevar,res)

;-- create plot of regridded data
  res@trGridType      = "TriangularMesh" 
  res@gsnCenterString = "regridded data" 
  plot1 = gsn_csm_contour_map(wks,var,res)

;-- draw the panel
  gsn_panel(wks,(/plot0,plot1/),(/2,1/),True)

end

ncl script.ncl

-Karin

RE: Masking, remapping or some other way to reduce the file to some extent - Added by Karin Meier-Fleischer over 5 years ago

By the way the agro.ecmwf.t00z.072612001.grb (latlon grid) can be remaped with CDO to other grids, the problem is the WRF file as target grid.

    (1-2/2)