[ncl-talk] extract some grids with given lat and lon from global netcdf

Dennis Shea shea at ucar.edu
Thu Aug 14 07:38:43 MDT 2014


The grids are rectiulinear:    lat(lat),    lon(lon)

============================

Please read about NCL's 'coordinate subscripting' in the 'Mini-Language
Manual'

    https://www.ncl.ucar.edu/Document/Manuals/

In fact, if you are new to NCL, read the above document.

============================
Also, search for 'coordinate subscripting' on the NCL page

=============================

The most important rule of data processing is **Look at the Data"
The longitudes on the netCDF files span 0 to 360. Your examples all use
-180 to 180.
You *must* use the values consistent with those on the file.

=================================

The script below will bilinearly interpolate to 3 specified locations.

PLease read the documentation for:

https://www.ncl.ucar.edu/Document/Functions/Contributed/linint2_points_Wrap.shtml

================================


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

    diri = "./"
    fili = "cVeg_CanESM2_1time.nc"
    pthi = diri+fili
    fi   = addfile(pthi,  "r")

    latSite = (/ 42.5, 25.4, 35.0 /)
    lonSite = (/-72.2,-81.1,-84.3 /)
    lonSite = where(lonSite.lt.0, lonSite+360, lonSite)

    buf     = 5.0              ; buffer around region (arbitrary)
    latS    = min(latSite)-buf
    latN    = max(latSite)+buf
    lonL    = min(lonSite)-buf
    lonR    = max(lonSite)+buf

; Read a region of globe that includes the specified points

    cVegRegion = fi->cVeg({latS:latN},{lonL:lonR})
    printVarSummary(cVegRegion)

    y = linint2_points_Wrap(cVegRegion&lon,cVegRegion&lat,cVegRegion,
False, lonSite,latSite, 0)
    y!0 = "Site"
    printVarSummary(y)

; netCDF

    diro = "./"
    filo = "cVeg_CanESM2_site.nc"
    ptho = diro+filo

    system("/bin/rm -f "+ptho)
    fout         = addfile(ptho, "c")
    fout at title   = "cVeg at selected sites"
    fout at method  = "NCL: linint2_points_Wrap: bilinear interpolation"
    fout at source  = fili
    fout at creation_date = systemfunc("date")
    fout->cVeg   = y

+++++++++++++++++++++++++++++++++++++

Variable: y
Type: float
Total Size: 12 bytes
            3 values
Number of Dimensions: 1
Dimensions and sizes:    [Site | 3]
Coordinates:
            Site: [0..2]
Number Of Attributes: 13
  _FillValue :    1e+20
  time :    56924.5
  standard_name :    vegetation_carbon_content
  long_name :    Carbon Mass in Vegetation
  units :    kg m-2
  original_name :    CVEG
  cell_methods :    time: mean area: mean where land
  cell_measures :    area: areacella
  history :    2011-03-17T21:17:57Z altered by CMOR: replaced missing value
flag (1e+38) with standard missing value (1e+20).
  associated_files :    baseURL:
http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile:
gridspec_land_fx_CanESM2_esmHistorical_r0i0p0.nc areacella:
areacella_fx_CanESM2_esmHistorical_r0i0p0.nc
  missing_value :    1e+20
  xcoord :    ( 287.8, 278.9, 275.7 )   <===== lon locations
  ycoord :    ( 42.5, 25.4, 35 )            <===== lat locations




On Wed, Aug 13, 2014 at 7:03 PM, Jiaxin Zhang <jiaxinzhang3 at gmail.com>
wrote:

> Dear NCL users,
>
>
>
> I want to extract a few grids with given lon and lat from global netcdf of
> CMIP5.
>
>
>
> I have extracted one grid in a specific lat and lon using the attcahed
> script ("extract_grid.ncl") for site1, but I did this part manually (I mean
> I had to look at all the values of lat and lon in the global netcdf, found
> the ones that were the closest to the given lat and lon and use the lat and
> lon indices that correspond to this grid to extract it). I guess that there
> are most efficient ways to do this, right? What is the best way to do it?
> What would be the recommended way to simoultaneously extract moret han one
> grid (for instance site1, site2 and site3)?
>
>
>
> In addition, some of the files that correspond to different CMIP5 models
> have different spatial resolution, and this means that the lat and lon for
> the same location would have different indices for lat and lon in different
> models.
>
> Could you please give some adivice about the best way to extract some
> grids (in specific lat and lon) from global netcdf with different spatial
> resolution?
>
>
>
> Attached is the code I used for site 1. Also attached are two different
> global netcdf (for just 1 time) from 2 models that use different spatial
> resolution. Is it possible to modify the script so I can use it for netcdf
> with different spatial resolutions?
>
>
>
> Thank you!
>
>
>
> Jiaxin
>
> _______________________________________________
> ncl-talk mailing list
> 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/20140814/4447daae/attachment.html 


More information about the ncl-talk mailing list