[ncl-talk] Average values over a specified region

Mary Haley haley at ucar.edu
Tue Jan 26 09:09:20 MST 2016


Hi folks,

Just a minor correction here. Since this is WRF data, we have specific
functions for extracting the index locations of a grid given lat/lon
values.  See "wrf_user_ll_to_ij":

http://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_user_ll_to_ij.shtml

This is similar to closest_val, except you give both lon, lat points (in
that order) and it gives you the i,j index values back in one call.

You can see a graphical example of this function at:

http://www.ncl.ucar.edu/Applications/wrfdebug.shtml

(example wrf_debug_4.ncl)

Good luck,

--Mary


On Tue, Jan 26, 2016 at 7:47 AM, Karin Meier-Fleischer <
meier-fleischer at dkrz.de> wrote:

> Sorry, little mistake in coloring the lines. It must be:
>
>
>   *lat13*  =  closest_val(13,lat)       ;-- return index of closest
> latitude to 13 deg
>   *lon80*  =  closest_val(80,lon)       ;-- return index of closest
> longitude to 80 deg
>
>   print("lat({13}) (closest value) = "+*lat({13})*+"   Index of
> closest_val: "+lat13)
>   print("------------------")
>   print("lon({80}) (closest value) = "+*lon({80})*+"   Index of
> closest_val: "+lon80)
>   print("------------------")
>
>   lat_box = lat(lat13-2:lat13+2)     ;-- using indices to get the lats
> around lat 13 deg.
>   lon_box = lon(lon80-2:lon80+2)     ;-- using indices to get the lons
> around lon 80 deg.
>
>   print(""+lat_box)
>   print("------------------")
>   print(""+lon_box)
>   print("--------------------------------------")
>
>   lat_box2 = lat({lat13-2:lat13+2})   ;-- Don't do this: this would use
> the index as latitude value !!
>   lon_box2 = lon({lon80-2:lon80+2})   ;-- Don't do this: this would use
> the index as longitude value !!
>
>   print(""+lat_box2)
>   print(""+lon_box2)
>   print("------------------")
>
> It will returns, e.g
>
> (0)    lat({13}) (closest value) = *12.12418712345578*   Index of
> closest_val: *41*
> (0)    ------------------
> (0)    lon({80}) (closest value) = *80.625*              Index of
> closest_val: *139*
> (0)    ------------------
> (0)    15.85470386969488
> (1)    13.98944571235667
> (2)    12.12418712345578       ; <--- closest value
> (3)    10.25892816800639
> (4)    8.393668907692385
> (0)    ------------------
> (0)    76.875
> (1)    78.75
> (2)    80.625                  ; <--- closest value
> (3)    82.5
> (4)    84.375
> (0)    --------------------------------------
> (0)    40.1029793042494    ;-- Don't do this: this would use the index as
> latitude value !!
> (1)    41.96822026907537   ;-- Don't do this: this would use the index as
> latitude value !!
> (0)    138.75              ;-- Don't do this: this would use the index as
> longitude value !!
> (1)    140.625             ;-- Don't do this: this would use the index as
> longitude value !!
> (0)    ------------------
>
>
>
> Am 26.01.16 um 15:43 schrieb Karin Meier-Fleischer:
>
> Do you mean something like  var({lat13-2:lat13+2},{lon80-2:lon80+2})  ?
>
> Then the answer is no, the coordinate subscripting gets the value of the
> closest grid cell and not the indices.
>
> lat({13}) will use the latitude value which is the closest to 13 degrees,
> e.g. 12.12418.
>
> Let us assume the following snippet of a script:
>
>   *lat13*  =  closest_val(13,lat)       ;-- return index of closest
> latitude to 13 deg
>   *lon80*  =  closest_val(80,lon)       ;-- return index of closest
> longitude to 80 deg
>
>   print("lat({13}) (closest value) = "+*lat({13})*+"   Index of
> closest_val: "+lat13)
>   print("------------------")
>   print("lon({80}) (closest value) = "+*lon({80})*+"   Index of
> closest_val: "+lon80)
>   print("------------------")
>
>   lat_box = lat(lat13-2:lat13+2)     ;-- using indices to get the lats
> around lat 13 deg.
>   lon_box = lon(lon80-2:lon80+2)     ;-- using indices to get the lons
> around lon 80 deg.
>
>   print(""+lat_box)
>   print("------------------")
>   print(""+lon_box)
>   print("--------------------------------------")
>
>   lat_box2 = *lat({lat13-2:lat13+2})*   ;-- Don't do this: this would use
> the index as latitude value !!
>   lon_box2 = *lon({lon80-2:lon80+2})*   ;-- Don't do this: this would use
> the index as longitude value !!
>
>   print(""+lat_box2)
>   print(""+lon_box2)
>   print("------------------")
>
> It will returns, e.g
>
> (0)    lat({13}) (closest value) = *12.12418712345578*   Index of
> closest_val: *41*
> (0)    ------------------
> (0)    lon({80}) (closest value) = *80.625*              Index of
> closest_val: *139*
> (0)    ------------------
> (0)    15.85470386969488
> (1)    13.98944571235667
> (2)    12.12418712345578       ; <--- closest value
> (3)    10.25892816800639
> (4)    8.393668907692385
> (0)    ------------------
> (0)    76.875
> (1)    78.75
> (2)    80.625                  ; <--- closest value
> (3)    82.5
> (4)    84.375
> (0)    --------------------------------------
> (0)    *40.1029793042494*    ;-- Don't do this: this would use the index
> as latitude value !!
> (1)    *41.96822026907537*   ;-- Don't do this: this would use the index
> as latitude value !!
> (0)    *138.75*              ;-- Don't do this: this would use the index
> as longitude value !!
> (1)    *140.625*             ;-- Don't do this: this would use the index
> as longitude value !!
> (0)    ------------------
>
>
> Hope this helps for understanding coordinate subscripting.
>
> Bye,
> Karin
>
>
>
> Am 26.01.16 um 15:13 schrieb Guido Cioni:
>
> Shouldn’t the coordinate subscripting do the same thing?
> Like say {lat13-2:lat13+2,  lon80-2:lon80+2}
>
> Guido Cioni
> <http://guidocioni.altervista.org>http://guidocioni.altervista.org
>
> On 26 Jan 2016, at 15:04, Karin Meier-Fleischer <meier-fleischer at dkrz.de>
> wrote:
>
> Hi Krishna,
>
> you can use the function *closest_val* to retrieve an index of an value.
>
>   lat13  =  closest_val(13,lat)
>   lon80  =  closest_val(80,lon)
>
>   print("Index: "+lat13+" -  "+lat(lat13))
>   print("Index: "+lon80+" -  "+lon(lon80))
>
> To plot 2 more grid boxes of lat/lon than you can use e.g.
>
>   plot = gsn_csm_contour_map(wks, var(lat13-2:lat13+2,lon80-2:lon80+2),res)
>
>
> Bye,
> Karin
>
> Am 26.01.16 um 14:13 schrieb Krishna C:
>
> Hi
>
>
> Let us say i need a 2 by 2 box around 13 degree lat and 80 degree lon .
> How do i know the respective indices.
> Please correct if i am wrong.
>
> Regards
> -Krishna-
>
> On Tue, Jan 26, 2016 at 5:14 PM, Guido Cioni < <guidocioni at gmail.com>
> guidocioni at gmail.com> wrote:
>
>> Yes there is, but you should have a look at the documentation on the page
>> ;-)
>> The function that you need is dim_avg_n, then you just need to restrict
>> the latitude and longitude with brackets {43:45}. Again, just go on ncl
>> documentation and you'll definitely find a way
>> Il 26 gen 2016 11:52 AM, "Krishna C" < <chandrakrishna.90 at gmail.com>
>> chandrakrishna.90 at gmail.com> ha scritto:
>>
>>> Hi,
>>>
>>>
>>> I am trying to extract precipitation values from WRF output, over a
>>> small 2 by 2 lat  lon box and average it. Is there any explicit way of
>>> doing it in ncl
>>>
>>> With warm regards
>>>
>>>
>>> -Krishna-
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>
>
> _______________________________________________
> ncl-talk mailing listncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> --
> Dipl. Geophys. Karin Meier-Fleischer
> Visualization, NCL
> Application Support
>
> Deutsches Klimarechenzentrum GmbH (DKRZ)
> Bundesstrasse 45a - D20146 Hamburg - Germany
>
> Phone:    +49 (0)40 460094 126
> Fax:      +49 (0)40 460094 270
> E-Mail:   meier-fleischer at dkrz.de
> URL:      www.dkrz.de
>
> Geschäftsführer: Prof. Dr. Thomas Ludwig
> Sitz der Gesellschaft: Hamburg
> Amtsgericht Hamburg HRB 39784
>
>
> _______________________________________________
> 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/20160126/b51831eb/attachment-0001.html 


More information about the ncl-talk mailing list