[ncl-talk] getind_latlon2d with rectilinear grid

Jiaxin Zhang jiaxinzhang3 at gmail.com
Thu Sep 18 17:41:37 MDT 2014


Thank you so much, Dennis!

Sorry, I did modify the script, but I did not send the modified version of
the script to the list because I was thinking that it would be easier for
NCL users using that script instead of using my modified script.
My error was in the time do loop.

Thanks!

Jiaxin

2014-09-18 16:05 GMT-07:00 Dennis Shea <shea at ucar.edu>:

> Ummm ... You did not try anything. You just reformatted  and forwarded the
> question.
> The whole point was for *you* do to something. That is how you learn.
>
> I am responding because I don't want others to have to spend time and
> effort.
>
>
>
>
>
> On Thu, Sep 18, 2014 at 4:37 PM, Jiaxin Zhang <jiaxinzhang3 at gmail.com>
> wrote:
>
>> Dear NCL users,
>>
>> I am trying to extract variable values in some grids in specific
>> locations for different times.
>>
>> I am attaching the NCL script that Dennis kindly provided to extract the
>> values for 3 grids and 1 time only. The attached NCL script works well with
>> the attached file "cVeg_CanESM2_1time.nc" that only contains 1 time. But I
>> am having problems when I try to run the same script for the attached file
>> "cVeg_CanESM2_12months.nc" that contains variable values for 12 times.
>> After modifying the script to include time as dimension when reading the
>> input file, I am getting error messages. I guess I am missing something but
>> I can not figure out what is wrong.
>>
>> Could you please modify the attached script so that it works with the
>> file "cVeg_CanESM2_12months.nc"?
>>
>> Your help is very appreciated!
>> Many thanks in advance!
>>
>> Jiaxin
>>
>> 2014-09-18 13:22 GMT-07:00 Dennis Shea <shea at ucar.edu>:
>>
>> I'll respond here but I am quite busy and just can not answer multiple
>>> questions.
>>>
>>> Perhaps someone else can chime in?
>>>
>>> [1] The original file you provided had no explicit time dimension.
>>>      The 'time' was includes as an attribute of the variable.
>>>      Note that there are no attributes (eg: hours since ) associated
>>> with the time attribute.
>>>      Actually, I believe that netCDF does not allow an attribute (here
>>> 'time') to have
>>>      have an attribute.
>>>
>>> [2] In this case it is *user* responsibility to manually create a time
>>> dimension.
>>>      It is user responsibility to manually provide this information. It
>>> is not on the file.
>>>
>>> See attached
>>>
>>> **Please respond to ncl-talk only. Do not include a salutation to any
>>> individual. Thank You**
>>>
>>>
>>> On Wed, Sep 17, 2014 at 5:50 PM, Jiaxin Zhang <jiaxinzhang3 at gmail.com>
>>> wrote:
>>>
>>>> Thank you so much, Dennis!
>>>> This works perfectly!
>>>>
>>>> I just have a couple of questions. I am trying to do this for different
>>>> times using the attached script and data file (for 12 months). For
>>>> simplicity, in the attached script I am testing for only one site (instead
>>>> of 3 sites). Although the script apparently extracts the variable values
>>>> for that grid in all 12 times, I guess there are some errors in the script
>>>> because the new netcdf created with the extracted variable values does not
>>>> have the time variable. What is necessary to modify in the attached script
>>>> so that the original time information is copied in the new created netcdf?
>>>>
>>>> Another issue I noticed is that when extracting variable values from 3
>>>> sites (3 grids) at the same time and after that creating a new netcdf,
>>>> apparently the new netcdf has only the lat and lon for the last site but
>>>> not for the rest of the extracted sites. Would it be possible to keep the
>>>> lat and lon information for all the sites from the original file in the new
>>>> created netcdf?
>>>>
>>>> Thank you!
>>>>
>>>> Jiaxin
>>>>
>>>>
>>>> 2014-09-17 5:57 GMT-07:00 Dennis Shea <shea at ucar.edu>:
>>>>
>>>>> Using getind_latlon2d should have failed. The 1st two arguments are
>>>>> prototyped as 2-dimensional. You are inputting one-dimensional arrays.
>>>>>
>>>>>
>>>>> 	function getind_latlon2d (
>>>>> 		lat2d [*][*] : numeric,     <=== you are inputting lat[*]
>>>>> 		lon2d [*][*] : numeric,     <===                   lon[*]
>>>>> 		lat      [*] : numeric,
>>>>> 		lon      [*] : numeric
>>>>> 	)
>>>>>
>>>>> ==========
>>>>> Let NCL do it
>>>>>
>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>>>>
>>>>>     diri = "/Users/shea/Downloads/"
>>>>>     fili = "cVeg_CanESM2_1time.nc"
>>>>>     pthi = diri+fili
>>>>>     fi   = addfile(pthi,  "r")
>>>>>    ;print(fi)
>>>>>
>>>>>     latpt = (/ 42.5, 25.4, 35.0 /)
>>>>>     lonpt = (/-72.2,-81.1,-84.3 /)
>>>>>     lonpt = where(lonpt.lt.0, lonpt+360, lonpt)
>>>>>     npt   = dimsizes(latpt)
>>>>>
>>>>>     cVegpt= new ( npt, getfilevartypes(fi, "cVeg"), 1e20)
>>>>>
>>>>>     do np=0,npt-1
>>>>>        cVegpt(np) = fi->cVeg({latpt(np)},{lonpt(np)})
>>>>>     end do
>>>>>     print(cVegpt)
>>>>>
>>>>>
>>>>> On Tue, Sep 16, 2014 at 1:29 PM, Jiaxin Zhang <jiaxinzhang3 at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Dear NCL users,
>>>>>>
>>>>>> I am trying to follow the example provided for getind_latlon2d in:
>>>>>>
>>>>>>
>>>>>> http://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.shtml
>>>>>>
>>>>>> My data is in a rectilinear grid that can be completely described by
>>>>>> one dimensional lat and lon arrays, whereas getind_latlon2d requires 2d
>>>>>> arrays for lat and lon. How can I solve this problem? Is it better to use a
>>>>>> different function from getind_latlon2d for 1d lat and lon arrays?
>>>>>>
>>>>>> I am attaching my NCL script and my file. I have 3 different sites
>>>>>> (with given coordinates in attached script), that I would need to locate in
>>>>>> the data grid. After that I would need to extract the value in that
>>>>>> particular location (extract only the value of the 3 grids that contain the
>>>>>> 3 sites). I was using getind_latlon2d to locate the 3 points in the data
>>>>>> grid, but maybe there is better option to do that for rectilinear grids.
>>>>>>
>>>>>> Your help is very appreciated.
>>>>>> Thank you!
>>>>>>
>>>>>> Jiaxin
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140918/4d7d05b8/attachment.html 


More information about the ncl-talk mailing list