Re: how to draw vector fields with the unstructured griddata

From: 朱学明 <zhuxm_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 08 2013 - 15:29:37 MDT

Hi Mary,
    I have tried to write a script to interpolate my FVCOM model results
to a rectilinear grid then plot it as follow:
    begin
;---Data file containing source grid
     unstructure_file = "pic_0001.nc" ;;---Change (likely)
     sfile = addfile(unstructure_file,"r")
     wgt_file = "fvcom_to_rect_weight.nc"
     dst_file = "rectilinear_grid.nc"
     src_file = "unstructured_grid.nc"

;---Get variable to regrid
     var_name = "u" ;;---Change (likely)
     u = sfile->$var_name$(0,1,:) ;;---Change (likely)
     var_name = "v" ;;---Change (likely)
     v = sfile->$var_name$(0,1,:) ;;---Change (likely)

     src_lat = sfile->latc ;;---Change (maybe)
     lat_min = min(src_lat)
     lat_max = max(src_lat)

     src_lon = sfile->lonc ;;---Change (maybe)
     lon_min = min(src_lon)
     lon_max = max(src_lon)

;---Set up regridding options
     Opt = True

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

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

     Opt@DstFileName = dst_file
     Opt@DstGridType = "1deg" ; destination grid
     Opt@DstTitle = "World Grid 0.25 degree resolution"
     Opt@DstLLCorner = (/lat_min, lon_min /)
     Opt@DstURCorner = (/lat_max, lon_max /)

     Opt@ForceOverwrite = True
     Opt@Debug = False ;True
     Opt@PrintTimings = True

     u_regrid = ESMF_regrid(u,Opt) ; Do the regridding

;
; For the second variable, since it is on the same grid, we
; can use weights generated from the previous ESMF_regrid
; call to do the regridding.
;
     Opt = True
     v_regrid = ESMF_regrid_with_weights(v,wgt_file,Opt)
     printVarSummary(v_regrid)

My questions are
(1) src_lon(lonc) and src_lat (latc) are the coordinates of cell, not
node, in my FVCOM grid. But they are used as the coordinated of node in
function ESMF_regrid. How can I let ESMF_regrid to know they are the
coordinates of cell? Or how can I let ESMF_regrid know my FVCOM grid
infortmation, just as specify the resource sfElementNodes for
gsn_csm_contour?
(2) How can I set masks for the destination grid? I want to set the mask
of nodes located in my model area as 1, other as 0. But there are no
masks in my FVCOM grid. Now I have got an error covered picture in land.

  Thanks.

Xueming Zhu 朱学明
Key Laboratory of Research on Marine Hazards Forecasting(LoMF),SOA
National Marine Environmental Forecasting Center(NMEFC)
No.8, Dahuisi Road, Haidian District, Beijing , 100081
People's Republic of China
Tel:+86-10-82481923

于 2013/7/8 7:31, Mary Haley 写道:
>
> On Jul 7, 2013, at 5:02 PM, zhuxm@nmefc.gov.cn
> <mailto:zhuxm@nmefc.gov.cn> wrote:
>
>> Hi Mary,
>>
>> Thank you for your responding so quickly.
>>
>> Can you send me some links on interpolating unstructured data to
>> regular grid data? Do you think ESMF_regrid is the best one?
>
> It depends on your data, but yes, in general, ESMF_regrid is the best
> one. You can start by looking at example ESMF_regrid_10.ncl, which
> goes from an unstructured grid to a 0.25 degree grid:
>
> http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex10
>
> We also have some ESMF templates available:
>
> http://www.ncl.ucar.edu/Applications/Templates/
>
> See either one of these ones:
>
> * *unstructured ---> 0.25 degree grid* (ESMF_unstruct_to_0.25deg.ncl
> <http://www.ncl.ucar.edu/Applications/Templates/ESMF_unstruct_to_0.25deg.ncl>)
> * *unstructured ---> rectilinear* (ESMF_unstruct_to_rect.ncl
> <http://www.ncl.ucar.edu/Applications/Templates/ESMF_unstruct_to_rect.ncl>)
>
>
> If ESMF_regrid looks too complex, then you can go to:
>
> http://www.ncl.ucar.edu/Document/Functions/interp.shtml
>
> and search for the word "unstructured". You will see several choices
> that involve interpolation or just placing points on a grid:
>
> cssgrid
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/cssgrid.shtml>
> Uses tension splines
> <http://www.ncarg.ucar.edu//ngmath/definitions.html#TensionSpline> to
> interpolate unstructured (randomly-spaced) data on a unit sphere to
> data values on a rectilinear grid.
>
>
>
> dsgrid2
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/dsgrid2.shtml>
> Interpolates data from an unstructured (randomly-spaced) grid to a
> rectilinear grid using inverse distance weighted interpolation.
>
>
>
> natgrid
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/natgrid.shtml>
> Interpolates data from an unstructured (randomly-spaced) grid to a
> rectilinear grid using natural neighbor interpolation.
>
>
> triple2grid
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/triple2grid.shtml>
> Places unstructured (randomly-spaced) data onto the nearest locations
> of a rectilinear grid.
>
>
> --Mary
>
>
>>
>>
>>
>> By the way, I want to make sure that once I interpolate the U/V
>> data to a regular grid, may I use gsn_vector_* or gsn_csm_vector_*
>> functions to display them?
>>
>> Thanks.
>>
>>
>>
>>
>>
>>
>>
>> Hi Xueming,
>> Yes, for now, you will need to interpolate your U/V data to a
>> rectilinear (regular) or curvilinear grid.
>> Or, you can try using the wmvect or wmvectmap procedures to plot
>> single vectors. These two routlines are rather limited. See:
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/wmvect.shtml
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/wmvectmap.shtml
>> Or see examples 8 and 9 at:
>> http://www.ncl.ucar.edu/Applications/weather_sym.shtml
>> We do have it high on our list to add capabilities for drawing
>> vectors on unstructured grids, but we're not sure when we'll get to it.
>> --Mary
>> On Jul 7, 2013, at 2:06 PM, zhuxm@nmefc.gov.cn
>> <mailto:zhuxm@nmefc.gov.cn> wrote:
>>
>>
>>> Hi,
>>>
>>> I want to plot vector fields with unstructured grid data from
>>> FVCOM output by NCL, which both u and v variables are only
>>> one-dimension like u(nele),v(nele). But all the vector functions
>>> (gsn_vector_*) in ncl need two dimensional u and v, such as
>>> u(:,:),v(:,:). How should I do for my unstructured grid data? Do I
>>> have to interpolate them to regular grid?
>>>
>>> Thanks.
>>>
>>> Xueming
>>>
>>> _______________________________________________
>>>
>>> ncl-talk mailing list
>>>
>>> List instructions, subscriber options, unsubscribe:
>>>
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

vector_map.png
Received on Mon Jul 8 15:31:04 2013

This archive was generated by hypermail 2.1.8 : Fri Jul 12 2013 - 16:37:39 MDT