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

Dennis Shea shea at ucar.edu
Thu Aug 14 20:31:38 MDT 2014


Hello

[1]
Did you read the recommended documentation about "coordinate subscripting"?
Did you examine the output from

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

That read in a user specified region.

[2]
Bilinear interpolation: the function used the four nearest grid locations
to the user specified locations. Then it performed standard bilinear
interpolation.
It interpolated the grid values to the locations you specified.

[3]
I think you have to 'play' with the language and print out variables.

Good luck



On Thu, Aug 14, 2014 at 6:29 PM, Jiaxin Zhang <jiaxinzhang3 at gmail.com>
wrote:

> Thank you so much, Dennis!
>
> I only have a couple of questions:
>
> - After reading the documentation for linint2_points_Wrap, it is not very
> clear how the extracted values were obtained. After checking the extracted
> values for the variable in 3 sites using your script, it seems that these
> exact same values (9.391546, 4.136703, 7.228534) were not present in the
> original file (glodal netcdf). Is this correct? Does this mean that the
> bilinear interpolation uses information from some of the closest grids to
> extract the value? Is it possible to extract exactly the same value that is
> in the only 1 grid in the global netcdf that contains the site using
> linint2_points_Wrap? Could you please clarify this?
>
> - In case I would need to do something similar but need to extract a
> region, instead of different points, from the global netcdf. Is there a
> similar function to linint2_points_Wrap but for region instead of points?
>
> Thank you.
>
> Jiaxin
>
>
> 2014-08-14 6:38 GMT-07:00 Dennis Shea <shea at ucar.edu>:
>
> 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/ea363a50/attachment.html 


More information about the ncl-talk mailing list