[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
Mon Feb 8 10:09:19 MST 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210208/3ce7595d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: traj_segm_colors.ncl
Type: application/octet-stream
Size: 8083 bytes
Desc: traj_segm_colors.ncl
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210208/3ce7595d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: path_color_test1.pdf
Type: application/pdf
Size: 67763 bytes
Desc: path_color_test1.pdf
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210208/3ce7595d/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: amwg_blueyellowred_av2red.rgb
Type: image/x-rgb
Size: 166 bytes
Desc: amwg_blueyellowred_av2red.rgb
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210208/3ce7595d/attachment.rgb>


More information about the ncl-talk mailing list