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

Mary Haley haley at ucar.edu
Tue Jul 29 16:02:17 MDT 2014


Rabah,

I think the shift is happening because you are trying to draw the vectors
and map as two separate plots. This will cause the vectors to not be drawn
in the correct map projection.

There are a number of other unrelated issues that I feel I should point
out, because it's hard to tell what your code is supposed to do:

   - You've got triple do loops, but then the code inside the loops are
   randomly indented, so it's hard to tell what's going on.

   - You have some code inside a do loop that really shouldn't be there.
    If you have code that doesn't change inside of a do loop, then it should
   be moved outside the do loop. Otherwise this can cause your code to run
   much slower.

   - You are reading lat/lon separately off the file, but I don't think you
   need to do this, because you have "rectilinear" data. But, I'll leave that
   alone for now.

   - You are calling area_conserve_remap_Wrap to regrid some data, but then
   you never do anything with this data.

Please, in the future, if you send a script, please try to clean it up so
that the code has some level of indentation.  It is very hard to look at
someone else's code if there are triple do loops, and no indentation.

But, to deal with the vector/map problem first:  I suggest using
gsn_csm_vector_map, instead of gsn_csm_map and gsn_csm_vector separately.
 This will make sure your wind barbs get projected into the map space
correctly.

I've tried to modify your script to do this, but without your data, I can't
be sure it's going to run correctly.  I've attached the script.

--Mary


On Sun, Jul 27, 2014 at 6:06 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
wrote:

> 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/20140729/fdfa3b6c/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wind_temp_plot_mods.ncl
Type: application/octet-stream
Size: 4687 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140729/fdfa3b6c/attachment.obj 


More information about the ncl-talk mailing list