[ncl-talk] Issue regridding with ESMF from unstructured

Dennis Shea shea at ucar.edu
Sun Jul 1 22:03:01 MDT 2018


Andrew

I looked at the script and the file.
The script is a bit 'busy.'  There is a lot of not needed code. This makes
the task tedious.

I  ran the script a with two minor changes:
(a) file path
(b) manually set the date

==
ANSWER: reorder the dimension of the variable to be regridded

REPLACE


*t_regrid = ESMF_regrid(t(0,:),Opt)*WITH
 * t_regrid = ESMF_regrid(t(HAMSR_levels|:, time|:),Opt  *       ; reorder
the variable
===
printVarSummary(*t_regrid*)

Variable:* t_regrid*
Type: float
Total Size: 62400 bytes
            15600 values
Number of Dimensions: 3
Dimensions and sizes:    *[HAMSR_levels | 25] x [lat | 12] x [lon | 52]
<== gridded data*


*Coordinates:             lat:
[28.3080005645752..29.79000091552734]            lon:
[269.6179809570312..275.9960021972656]*

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;                OTHER comments
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[1] A comment on the file.

%> ncdump -v time HAMSR_L2DB_realtime_20161005T2100_20161005T2200.nc | less

netcdf HAMSR_L2DB_realtime_20161005T2100_20161005T2200 {
dimensions:
        HAMSR_levels = 25 ;
        time = 1197 ;
variables:
        double *time*(*time*) ;
                time:units = "seconds" ;
                time:comment = "seconds since 2000-01-01 00:00:00.0" ;
                time:scale_factor = 1. ;
                time:long_name = "Measurement time" ;

Almost universally, when a netCDF file contains a variable with  a
structure such as: time(time)
[ latitude(latitude), etc]., it is assumed to be a *coordinate variable*.
What is a *coordinate variable?*

Specifically, by netCDF convention, a *coordinate variable is *a
one-dimensional variable in which
the variable name and variable dimension are the same
**AND**
the values are monotonically {in/de}creasing*.*

   See: https://www.unidata.ucar.edu/software/netcdf/workshops/2011/
datamodels/NcCVars.html

Obviously, the time values on the file are *not* monotonic.  Technically,
there is nothing wrong with *time(time)*.
However, in practice, I strongly suggest that this not be done.

The file creator should simply

CHANGE
     time(time)
TO
     TIME(time)

=======
CODING: There are lots of things I do not understand ... why
========
time at units = "seconds since 2000-01-01 00:00:00.0"    ; why ?

lev := lev(0:24)                                         ; why ?
t at units = "K"                                            ; why ?

t at _FillValue = -999                                  ; why ?
q at _FillValue = -999                                 ; why
time at _FillValue = -999                             ; No! Should not be done.

; first filter out dates which are -nan (undefined) in the original dataset
good_data=ind(*time.ne <http://time.ne>."-nan"*)
; No! Will not work

; use:* isnan_ieee*

http://www.ncl.ucar.edu/Document/Functions/Built-in/isnan_ieee.shtml

I'll stop there.
Good Luck

On Fri, Jun 29, 2018 at 11:56 AM, Anil Kumar - NOAA Affiliate <
anil.kumar at noaa.gov> wrote:

> It should work actually. Are you reading a variable in correct order of
> dimensions? You mention (lev, time) and your data looks (time, lev). please
> check.
> Maybe some reading issue of file data...
>
> -Anil
>
>
> On Fri, Jun 29, 2018 at 1:38 PM, Andrew Kren - NOAA Affiliate <
> andrew.kren at noaa.gov> wrote:
>
>> Thanks Anil. I tried a few additions from your code but still ran into
>> issues. It is still giving me the same error.
>>
>> On Fri, Jun 29, 2018 at 1:14 PM, Anil Kumar - NOAA Affiliate <
>> anil.kumar at noaa.gov> wrote:
>>
>>> Andrew,
>>> I did similar thing to regrid unstructed data on to wrf grid (
>>> geo_em_d01.nc)  here is the code and worked successfully with ncl 6.4
>>> version.
>>> Hope this help.
>>>
>>> src_file = "maxele.63.nc"
>>>
>>>  sfile = addfile(src_file,"r")
>>>
>>>
>>> ;printVarSummary(sfile)
>>>
>>>  lat1D = sfile->y
>>>
>>>  lon1D = sfile->x
>>>
>>>  var = sfile->zeta_max(0,:)   ; zeta is function of time and variable.
>>>
>>>
>>>  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     = "neareststod"        ;;---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)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Fri, Jun 29, 2018 at 11:56 AM, Andrew Kren - NOAA Affiliate <
>>> andrew.kren at noaa.gov> wrote:
>>>
>>>> Dear ncl-talk,
>>>>
>>>> I'm trying to regrid from an unstructured grid of temperature and
>>>> moisture retrievals from an aircraft. The data are a function of
>>>> (lev,time), with each time corresponding to a different lat/lon location. I
>>>> wrote some code to regrid to a triangular mesh using ESMF, but ran into
>>>> some issues. I got this error:
>>>>
>>>> (0) get_src_grid_info: source lat dims = (14398)
>>>>
>>>> (0) get_src_grid_info: source lon dims = (14398)
>>>>
>>>> (0) get_src_grid_info: SrcGridType and/or SrcGridLat/SrcGridLon were
>>>> not set.
>>>>
>>>> (0)           Cannot determine the source grid type.
>>>>
>>>> I have attached my code and a sample file it reads. I am confused b/c I
>>>> am setting the SrcGridLat and Lon explicitly.
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> Andrew Kren
>>>> Assistant Scientist
>>>> CIMAS - NOAA/AOML
>>>> 314-322-0867
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>
>>>
>>> --
>>> Dr. Anil Kumar
>>> NWS/NCEP/EMC, Office# 2875
>>> NOAA Center for Weather and Climate Prediction (NCWCP)
>>> 5830 UNIVERSITY RESEARCH CT
>>> <https://maps.google.com/?q=5830+UNIVERSITY+RESEARCH+CT+College+Park,+MD+20740&entry=gmail&source=g>
>>> College Park, MD 20740
>>> <https://maps.google.com/?q=5830+UNIVERSITY+RESEARCH+CT+College+Park,+MD+20740&entry=gmail&source=g>
>>> -3818
>>> 301-683-0494
>>> anil.kumar at noaa.gov
>>>
>>>
>>
>>
>> --
>> Andrew Kren
>> Assistant Scientist
>> CIMAS - NOAA/AOML
>> 314-322-0867
>>
>
>
>
> --
> 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
> 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/20180701/6d164ae8/attachment.html>


More information about the ncl-talk mailing list