X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 19 May 2016 05:23 PM by  anon
Symbol Function Slow
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



Basic Member


Posts:143
Basic Member


--
19 May 2016 05:23 PM
    A user is running into an issue in which the SYMBOL function is very slow. The user provided the following code snippet: ;plot fires-- waaay slow fire_comp=alog10(fire_comp+1.) /2.0 ofire_comp=alog10(ofire_comp+1.) /2.0 asize=size(fire_comp) for i=0,asize[1]-1 do begin for j=0,asize[2]-1 do begin if fire_comp[i,j] gt 0.0 and finite(fire_comp[i,j]) then $ fsym = symbol(rcm_x_2d[i,j], rcm_y_2d[i,j], /data, symbol="triangle", SYM_SIZE=fire_comp[i,j],$ FSC_Color('black'),target=img1) if ofire_comp[i,j] gt 0.0 and finite(ofire_comp[i,j]) then $ fsym = symbol(rcm_x_2d[i,j], rcm_y_2d[i,j], /data, symbol="+", SYM_SIZE=ofire_comp[i,j],$ FSC_Color('black'),target=img1) endfor endfor

    Deleted User



    Basic Member


    Posts:143
    Basic Member


    --
    19 May 2016 05:53 PM
    To increase the performance of the SYMBOL function, create arrays with all of the symbol locations and then plot them all at the same time. I think you would want to modify you code to be something like the following (NOTE: I haven't tested this code, but this is an example of how it might be done): ;plot fires-- waaay slow fire_comp=alog10(fire_comp+1.) /2.0 ofire_comp=alog10(ofire_comp+1.) /2.0 sym_x = list() sym_y = list() o_sym_x = list() o_sym_y = list() asize=size(fire_comp) for i=0,asize[1]-1 do begin for j=0,asize[2]-1 do begin if fire_comp[i,j] gt 0.0 and finite(fire_comp[i,j]) then begin sym_x.add, rcm_x_2d[i,j] sym_y.add, rcm_y_2d[i,j] endif if ofire_comp[i,j] gt 0.0 and finite(ofire_comp[i,j]) then begin o_sym_x.add, rcm_x_2d[i,j] o_sym_x endif endfor endfor fsym = symbol(rcm_x_2d[i,j], rcm_y_2d[i,j], /data, symbol="triangle",sym_color='red',target=img1) ofsym = symbol(rcm_x_2d[i,j], rcm_y_2d[i,j], /data, symbol="triangle", sym_color='blue', target=img1) Unfortunately, you won't be able to specify the size of each symbol the way you did in your code. An alternative approach is to use Bubbleplot (but you can't change the symbol) or SCATTERPLOT (you can adjust the color for each symbol but not the size).

    Deleted User



    New Member


    Posts:7
    New Member


    --
    23 May 2016 10:10 AM
    A hybrid of your code and mine speeds plotting up dramatically and I can vary the symbol size. I just fine-bin the fires across the range of size and plot all of those of the same size at once using your suggestion. It turns out to be very fast and any differences compared to plotting one at a time are indistinguishable. ;plot fires-- very fast fire_comp=alog10(fire_comp+1.)/2.0 ofire_comp=alog10(ofire_comp+1.)/2.0 fsize=findgen(80,increment=0.05, start = 0.05) for nfsize = 0, n_elements(fsize)-2 do begin find1=where(fire_comp ge fsize[nfsize] and fire_comp lt fsize[nfsize+1] and finite(fire_comp),count1) if count1 GT 0 then fsym = symbol(rcm_x_2d[find1], rcm_y_2d[find1], /data, symbol="triangle", SYM_SIZE=fsize[nfsize+1],$ FSC_Color('black'), target=img1) find2=where(ofire_comp ge fsize[nfsize] and ofire_comp lt fsize[nfsize+1] and finite(ofire_comp),count2) if count2 GT 0 then fsym = symbol(rcm_x_2d[find2], rcm_y_2d[find2], /data, symbol="+", SYM_SIZE=fsize[nfsize+1],$ FSC_Color('black'), target=img1) endfor
    You are not authorized to post a reply.