[ncl-talk] regrid variable writing netcdf file
Mary Haley
haley at ucar.edu
Fri Mar 23 16:09:06 MDT 2018
Hello,
We have been looking into this offline.
For starters, since both of your grids are regional, you want to set:
Opt at DstRegional = True
Opt at SrcRegional = True
Secondly, you already have the triangular mesh defined on your file, which
will help the regridding go much faster, because NCL doesn't have to
generate it for you:
Opt at SrcTriangularMesh = sfile->element-1
; the minus one is important so indexes go from 0 to n-1
For plotting purposes, I set these for both plots:
res at cnLevelSelectionMode = "ManualLevels"
res at cnMinLevelValF = -6
res at cnMaxLevelValF = 6
res at cnLevelSpacingF = 0.25
I removed the file writing part for now, because there's something weird
about an attribute type, but I'll include the original script
(test_regrid.ncl) and the modified one without the file writing
(test_regrid_mod.ncl) and hopefully you can add back in the file writing
part. I was in a hurry so I just removed it, and now I have to run out the
door.
I'm not sure the regridding went well, but this could simply be the nature
of going from high-res to low-res, and also the fact that the two grids
don't have values in the same places. You will need to take a look at the
PNG image and see what you think.
--Mary
On Thu, Mar 22, 2018 at 9:58 AM, Rick Brownrigg <brownrig at ucar.edu> wrote:
> 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
>>
>>
>
> _______________________________________________
> 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/20180323/eea0e5cc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_regrid_mod.ncl
Type: application/octet-stream
Size: 5332 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180323/eea0e5cc/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unstruct_to_rect.png
Type: image/png
Size: 138245 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180323/eea0e5cc/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_regrid.ncl
Type: application/octet-stream
Size: 6170 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180323/eea0e5cc/attachment-0001.obj>
More information about the ncl-talk
mailing list