[ncl-talk] regrid variable writing netcdf file
Rick Brownrigg
brownrig at ucar.edu
Thu Mar 22 09:58:15 MDT 2018
Hi,
Without the data, I can't run the script, but on visual inspection, it
*looks* like you have all the right elements in place to write the NetCDF
file. What's not happening for you -- any errors or odd results, or just
plain nothing?
Rick
On Thu, Mar 22, 2018 at 6:58 AM, Anil Kumar - NOAA Affiliate <
anil.kumar at noaa.gov> wrote:
> Hi,
>
> I am trying to write regrid variable (unstructured data to WRF grid),
> code creates var_regrid successfully at that point. I want to write
> var_regird variable in separate netcdf file with lat & lon dimension in it.
> Can anyone please help me on this. Thanks
> The var_regrid print summmary
> ********
>
> Variable: var_regrid
>
> Type: double
>
> Total Size: 1301864 bytes
>
> 162733 values
>
> Number of Dimensions: 2
>
> Dimensions and sizes: [353] x [461]
>
> Coordinates:
>
> Number Of Attributes: 10
>
> missing_value : -99999
>
> remap : remapped via ESMF_regrid_with_weights: Bilinear
>
> lon2d : <ARRAY of 162733 elements>
>
> lat2d : <ARRAY of 162733 elements>
>
> long_name : maximum water surface elevationabove geoid
>
> standard_name : maximum_sea_surface_height_above_geoid
>
> location : node
>
> mesh : adcirc_mesh
>
> units : m
>
> _FillValue : -99999
>
> ********
> here is the code
>
> begin
>
>
>
>
> src_file = "maxele.63.nc"
>
> sfile = addfile(src_file,"r")
>
>
> ;printVarSummary(sfile)
>
> lat1D = sfile->y
>
> lon1D = sfile->x
>
> var = sfile->zeta_max
>
>
> dst_file = "geo_em.d01.nc"
>
> dfile = addfile(dst_file,"r")
>
>
>
> ;---Set up regridding options
>
>
> Opt = True
>
>
> ;---"bilinear" is the default. "patch" and "conserve" are other options.
>
> Opt at InterpMethod = "bilinear" ;;---Change (maybe)
>
> Opt at WgtFileName = "unstruct_to_rect.nc"
>
>
> Opt at SrcGridLat = lat1D
>
> Opt at SrcGridLon = lon1D
>
> Opt at SrcRegional = False ;;--Change (maybe)
>
> Opt at SrcInputFileName = src_file ; optional, but good idea
>
>
> Opt at SrcMask2D = where(.not.ismissing(var),1,0) ; Necessary if
> has
>
> ; missing
> values.
>
>
> dst_lat = dfile->XLAT_M(0,:,:) ; Be sure to use
> appropriate names
>
> dst_lon = dfile->XLONG_M(0,:,:) ; here.
>
> Opt at DstGridLon = dst_lon
>
> Opt at DstGridLat = dst_lat
>
> Opt at DstRegional = True ;;--Change (maybe)
>
> ; Opt at DstMask2D = where(.not.ismissing(dst_lat).and.\
>
> ; .not.ismissing(dst_lon),1,0) ; Necessary if
> lat/lon
>
> ; has missing
> values.
>
> ; has missing
> values.
>
> Opt at ForceOverwrite = True
>
> Opt at Debug = True
>
> Opt at PrintTimings = True
>
>
> var_regrid = ESMF_regrid(var,Opt) ; Do the regridding
>
>
> printVarSummary(var_regrid)
>
>
>
> ; Code for writing netcdf format file with lat and long cordinate
>
> setfileoption("nc", "Format", "NetCDF4")
>
> fon = "ZETA_MAX_D01.nc"
>
> system("/bin/rm -f " + fon) ; remove if exists
>
> fnew = addfile(fon, "c")
>
>
>
> ;===================================================================
>
> ; create global attributes of the file (optional)
>
> ;===================================================================
>
> fAtt = True ; assign file attributes
>
> fAtt at title = "NCL Simple Approach to netCDF Creation"
>
> fAtt at source_file = "original-file.nc"
>
> fAtt at Conventions = "None"
>
> fAtt at creation_date = systemfunc ("date")
>
> fileattdef( fnew, fAtt ) ; copy file attributes
>
>
> filedimdef(fnew,(/"lat","lon"/),(/353,461/),(/False,False/))
>
> var_names2D = (/ "var_regrid" /)
>
> varvar_types2D = (/ "float" /)
>
>
> filevardef( fnew, var_names2D, varvar_types2D, (/ "lat", "lon" /) )
>
>
>
> var_regrid!0 = "lat"
>
> var_regrid!1 = "lon"
>
>
> var_regrid&lat = dst_lat
>
> var_regrid&lon = dst_lon
>
>
> var_regrid at long_name = "maximum water surface elevationabove geoid"
> ; assign attributes
>
> var_regrid at units = "m"
>
>
> fnew->ZETA_MAX = var_regrid ; name on file different
> from name in code
>
>
>
> end
>
>
> --
> Dr. Anil Kumar
> NWS/NCEP/EMC, Office# 2875
> NOAA Center for Weather and Climate Prediction (NCWCP)
> 5830 UNIVERSITY RESEARCH CT
> College Park, MD 20740-3818
> 301-683-0494 <(301)%20683-0494>
> anil.kumar at noaa.gov
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180322/8976b888/attachment.html>
More information about the ncl-talk
mailing list