[ncl-talk] Plot values with gsn_add_text takes unreasonable time (fitting temperature values over a sub domain)

Rabah Hachelaf hachelaf at sca.uqam.ca
Sun Jul 27 18:06:22 MDT 2014


Thanks Mary,

Your recommendations were very helpful.

My real purpose is to write a generalized script plots wind barbs and
temperature values over a predefined sub domains.

my script (attached) reads geographical limits from the file
: sub_domain.data which contains these data :
1 -180 0 -90 0
2 0 180 -90 0
3 -180 0 0 90
4 0 180 0 90
nlat and nlon represent number of plots needed over latitude and longitude
axes

For now my script works and plot desired data for the 4 sub domains but i
have problem to coincide wind barbs plot with temperature values,
temperature plot seems to shift like in image attached.

Thanks.





2014-07-27 14:55 GMT-04:00 Mary Haley <haley at ucar.edu>:

> Rabah,
>
> There are a series of issues with your script, but not all of them have to
> do with why your code is taking so long.
>
> 1. You have mpMaxLatF and mpMinLatF set to the same value.
>
> 2. You've set gsnDraw to False, which will cause no text strings to be
> added:
>
>   txres at gsnDraw      =  False                   ; do not draw the plot
>
> 3. The txres at txFontThicknessF = 10 is going to cause your text strings to
> be 10x as thick. Do you want this on top of the text being bold-faced?
>
> 4. You are adding almost 260,000 strings to the plot. Is what you mean to
> do?
>
> 5. You are constructing the lat2d/lon2d arrays in two separate do loops.
> You can make this code simpler by using "conform_dims".
>
> 6. Using gsn_add_text is going to cause 259920 graphical objects to be
> created, because one has to be added for every string you create. This can
> get very memory intensive.
>
> If you are only planning to draw this one plot and not resize it later,
> then I suggest using gsn_text instead of gsn_add_text.  This will prevent
> the individual objects from being created, and will run faster.
>
> See the attached script. I didn't clean up the code to fix the various
> warnings from setting contour resources when you are only creating a map
> script, because I figured you were in the middle of debugging this.  But, I
> did clean it up to make it run faster.  This script took about 71 seconds
> on my Mac.  If you take out the "txFontThicknessF" setting, then it runs in
> about 62 seconds.
>
> Note that I put the "gsn_text" call inside a single do loop.  This seems
> to run faster than using a double do loop, or no do loop at all.  I think
> this has to do with trying to add 259,000+ strings to a plot all at once
> versus adding each string one at a time.  Instead, I'm adding 360 strings
> at a time, for each 720 iterations, which seems to be a happy balance.
>
> --Mary
>
>
>
> On Sun, Jul 27, 2014 at 1:25 AM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
> wrote:
>
>> Hi NCL users,
>>
>> I am using the ncl script below to plot temperature values from GFS data,
>> this script works great when i regrid my data to a lower resolution.
>> but when i want plotting the whole data (720 x 361 values) and after more
>> than 3 hours, ncl still running without generate any image or error message.
>> this very strange since NCL is supposed to be a powerful tool.
>>
>> Have you any suggest to this problem.
>>
>> Thanks a lot.
>>
>> Rabah
>>
>> ;************************************************
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> ;************************************************
>>  a = addfile("gfs.t00z.pgrb2f00.grib2","r")
>>     lon = a->lon_0
>>     lat = a->lat_0
>>     tt      = short2flt(a->TMP_P0_L100_GLL0({100000},:,:))
>>     tt = (/tt-273/)
>>
>> lat2d= new((/361,720/),float)
>> ;********* create 2D lat lon
>> do l=0,719
>>  lat2d(:,l)=lat(:)
>> end do
>>
>> lon2d= new((/361,720/),float)
>> do l=0,360
>>  lon2d(l,:)=lon(:)
>> end do
>> ;******************************************
>> wks_type="png"
>>
>>   wks_type at wkWidth = 4000
>>    wks_type at wkHeight = 4000
>>
>>   wks = gsn_open_wks(wks_type,"plot_val")
>>   gsn_define_colormap(wks,"gui_default")
>>
>>   res = True               ; plot mods desired
>> res at pmTickMarkDisplayMode = "Always"
>>   res at mpProjection      = "Mercator"       ; choose projection
>>   res at mpGridAndLimbOn   = False             ; turn on lat/lon lines
>>   res at mpPerimOn         = True             ; turn off box around plot
>>   res at mpGridLatSpacingF = 45.               ; spacing for lat lines
>>   res at mpGridLonSpacingF = 45.               ; spacing for lon lines
>>   res at mpFillOn          = False
>>    res at mpLimitMode  = "LatLon"
>>    res at mpMinLatF            =   85.0
>>     res at mpMaxLatF            =85.0
>>     res at mpMinLonF            = -180
>>     res at mpMaxLonF            = 180
>>
>>   res at cnFillOn          = False              ; color plot desired
>>    res at cnLineLabelsOn    = False             ; turn off contour lines
>>
>>   res at vpXF            = 0                 ; make plot bigger
>>   res at vpYF            = 1
>>   res at vpWidthF        = 1
>>   res at vpHeightF       = 1
>> map = gsn_csm_map(wks,res)
>>   txres               = True
>>   txres at txFontQuality = True
>>   txres at txFontHeightF = 0.00125
>>   txres at txFont        = "helvetica-bold"
>>   txres at txFontColor =1
>>   txres at txFontThicknessF= 10
>>   txres at gsnDraw      =  False                   ; do not draw the plot
>>   txres at gsnFrame     =  False
>> text = gsn_add_text(wks,map,sprintf("%2.0f", tt) , lon2d, lat2d,txres)
>> draw(wks)      ; Now draw map with text strings and
>> frame(wks)     ; advance the frame
>> end
>> --
>> ------------------------------
>> Cordialement,
>> Best regards,
>> Rabah Hachelaf
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>


-- 
------------------------------
Cordialement,
Best regards,
Rabah Hachelaf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140727/1e8f947c/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wx_map_zoom7_DOM_01000_06.png
Type: image/png
Size: 475892 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140727/1e8f947c/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wind_temp_plot.ncl
Type: application/octet-stream
Size: 5015 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140727/1e8f947c/attachment-0001.obj 


More information about the ncl-talk mailing list