[ncl-talk] Adding text data in a contour plot

Kyle Griffin ksgriffin2 at wisc.edu
Wed Dec 2 09:22:58 MST 2015


What version of NCL are you using? I know some of the gsn_add_xxx functions
were made more efficient in recent NCL versions, but then again, I don't
see any official mention of those improvements including gsn_add_text.

Loops are notoriously inefficient in NCL. Could you try calling
gsn_add_text without the loop? Since you're using WRF, you may already have
2d lat and lon variables, but since your code doesn't have them here, you
may want to create them (likely with the "conform" function and the
wrf_user_latlon... functions).

If you are able to do that, you should then have 3 two-dimensional
variables: tc2, lat2d, and lon2d, containing the text to plot, the latitude
coordinate, and the longitude coordinate for every single point in the lat
x lon grid. At this point, you should be able to give each of these
variables to a single call of gsn_add_text and plot all the text at once,
rather than in 24*24 = 579 calls to the function.

There may be a simple method to do this with the WRF functions (such as
retrieving 'lat' or 'lon' from the grid rather than creating it yourself)
that I'm not as familiar with, so explore some if you can!


Kyle

----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
Room 1407
1225 W Dayton St, Madison, WI 53706
Email: ksgriffin2 at wisc.edu

On Wed, Dec 2, 2015 at 5:37 AM, Stefano Guerra <guerras90 at gmail.com> wrote:

> Hi Kyle, thank you for your answer.
>
> I tried this code, it works fine for my purpose, but there is a problem
> with time of execution. The first 7/8 "textlat" loops are sufficiently
> fast, but the following loops become very slow, than process fault.
>
> contour_tc = wrf_contour(a,wks,tf2,opts)
>       plot = wrf_map_overlays(a,wks,(/contour_tc/),platres,mpres)
> ;overlay per info confini
>       poly = gsn_add_shapefile_polylines(wks,plot,"reg2011_g.shp",pres)
> ;aggiungo shapefile confini regionali
>       latout = fspan(36,47,23)
>       lonout = fspan(7,18,23)
>       do textlat = 0,23,1
> print (textlat)
>          do textlon = 0,23,1
>          loc  = wrf_user_latlon_to_ij(a, latout(textlat), lonout(textlon))
>         text = gsn_add_text(wks,plot,sprintf("%0.0f",
> tc2(loc(0),loc(1))),lonout(textlon),latout(textlat),txres)
>         end do
>           end do
>
> draw(plot)
> frame(wks)
>
> Thank you again,
> Stefano.
>
> 2015-12-01 14:51 GMT+01:00 Kyle Griffin <ksgriffin2 at wisc.edu>:
>
>> Stefano,
>>
>> It'll take some additional lines of code, but gsn_add_text has the
>> functionality you are most likely looking for.
>>
>> https://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_text.shtml
>>
>> The biggest concern is that your x and y need to be individual pairs
>> corresponding to each and every grid point that you want the text at. In
>> essence, you would need a two-dimensional latitude array and
>> two-dimensional longitude array of only the points where you want text to
>> be plotted, as well as the values/strings you want plotted at those points.
>>
>> I would recommend trying this function with a small number of grid points
>> first to make sure it works and does what you want before trying to make
>> the function apply to an entire grid. This may prove to be a bit trickier
>> with a WRF grid, I have not worked with them myself so I'm not sure. Let
>> the list know if you have any problems/questions...
>>
>>
>> Kyle
>>
>> ----------------------------------------
>> Kyle S. Griffin
>> Department of Atmospheric and Oceanic Sciences
>> University of Wisconsin - Madison
>> Room 1407
>> 1225 W Dayton St, Madison, WI 53706
>> Email: ksgriffin2 at wisc.edu
>>
>> On Tue, Dec 1, 2015 at 5:31 AM, Stefano Guerra <guerras90 at gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> I tried to search this function, but I couldn't find how can I add text
>>> data (from a WRF output) on a contour plot.
>>>
>>> Maybe I can explain better with an example, I want realize something
>>> like this:
>>>
>>> http://modeles2.meteociel.fr/modeles_gfs/runs/2015120106/3-580.GIF?01-6
>>>
>>>
>>> Thank you for your help,
>>> Stefano.
>>>
>>> _______________________________________________
>>> 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 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/20151202/ae798e22/attachment.html 


More information about the ncl-talk mailing list