[ncl-talk] solution for drawing a polyline (trajectory) with different colors for each line segment (e.g., without using loop) to avoid very slow script?

De Vries Andries andries.devries at env.ethz.ch
Thu Feb 11 14:40:40 MST 2021


Hello Rick,


Thank you so much for your response! I just sent the data (still copying as I speak) and actual script via the ftp using my email address as password. Is this helpful? Please, let me know if you need anything else.


In addition to the progressively slower running of the script, I m also curious to hear if there are faster ways to plot trajectories (polylines) with each segment having a different color (based on meteorological values) or if this is the only way as I have it.


Thank you so much!!


Wish you a good day!

Best,

Andries

________________________________
From: Rick Brownrigg <brownrig at ucar.edu>
Sent: 08 February 2021 21:42:10
To: De Vries Andries
Cc: ncl-talk at ucar.edu
Subject: Re: [ncl-talk] solution for drawing a polyline (trajectory) with different colors for each line segment (e.g., without using loop) to avoid very slow script?

Hi Andries,

I don't see anything that should cause the loop to run progressively slower, and that puzzles me.  Are you able to send your data and actual script (not the test script)?  You can send directly to me if you prefer.

Rick


On Mon, Feb 8, 2021 at 10:09 AM De Vries Andries via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:

Dear NCL team and NCL users,


Currently I use NCL to plot air parcel trajectories using the function gsn_add_polyline on a latlon map. For these polylines I would like to assign different colors to each line segment, for example defined by pressure. I have a script that works, it is practically the same as the example 2 under the link https://www.ncl.ucar.edu/Applications/traj.shtml, whereby the script loops over each pair of points, retrieves the right color, and then plots each individual line segment. In my application I have a huge set of trajectories each consisting of many segments (~72 per trajectory). It takes extremely long for NCL to complete the plot; in the beginning the script will run fast, but it gets slower and slower as the script proceeds over the number trajectories.


What solutions do I have to make the script faster?


I tried a few things, for example, plotting the polylines using arrays in stead of loops, and retrieving colors as arrays. That works, but then plotting the lines using an array of different colors fails.


In the attached script I send an example as well as the resulting plot and colorbar I used;

1) the working script with the loop over each line segment that works, but is in reality very slow (map1(0))

2) an attempt with retrieving the colors based on an array with Pressure, which works, but then using the 2-D color array assigned to the plotting resource (r2) fails (map1(1))

3) an attempt with named colors (in 1-D array), which also fails as only the first named color is used for all segments. (map1(2))


Any solutions that avoid using the loop, or make the script faster, are most welcome!!


Thank you so much!


Best,

Andries

_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210211/84bf0fc9/attachment.html>


More information about the ncl-talk mailing list