Need Way to calculate Line-of-Sight through Terrain that is faster than los2

8 次查看(过去 30 天)
Hello,
My code calculates among other things the Line-of-sight from multiple points in an aircraft orbit to a target on the ground. To do this I enter arrays of coordinates into los2. Everything works accurately but the runtime is just unacceptable. To do one orbit against one target takes about 20 seconds. This code will be used with others to test the suitability of several orbits against several targets. Those 20 seconds add up quickly and I'm looking at a code that takes an hour to run a simple case.
Has anyone experienced this slow of a runtime with los2? Is there an alternative method (and/or function) that would be faster than los2?
Any suggestions are welcome!
  1 个评论
MCM
MCM 2015-7-8
I want to clarify that los2 is Matlab function from the Mapping Toolbox. Running thousands of points through los2 is the bottle neck, every other portion of the code runs in fractions of a second.
I need a way to calculate line-of-sight using DTED terrain data that is faster than los2

请先登录,再进行评论。

采纳的回答

Kelly Kearney
Kelly Kearney 2015-7-9
编辑:Kelly Kearney 2015-7-9
If you profile a simple example, you'll see that nearly all the computation time of los2 is being spent on the cummax subfunction. There is a built-in cummax.m function, but for some reason (probably legacy), the los2-called function calculateLOS.m has it's own local non-builtin version of cummax that's much, much, much slower than the builtin. I opened the calculateLOS.m file (<matlabroot>/toolbox/map/map/private/calculateLOS.m) and commented out the cummax subfunction at the very end; an los2 call speeds up dramatically after that (I haven't double-checked to make sure the results are the same, so you should definitely do that, though).
The Mapping Toolbox, unfortunately, is full of little inefficiencies like this one, which aren't very noticeable when running toy examples but really add up when trying to apply them to complex datasets.
  6 个评论
Kelly Kearney
Kelly Kearney 2015-7-9
编辑:Kelly Kearney 2015-7-9
I'm confused... I'm running the 2015b prerelease, and the slow cummax subfunction is still in there (in toolbox/map/map/private/calculateLOS.m, not the main los2.m), so you should be able to get even more speed out of things by commenting that out. On my computer, that brought a 1000-point test from 18.225517 sec to 0.414691.
MCM
MCM 2015-11-2
Yep, you are right. 2015a still has the slow cummax subfunction. I was looking in los2 and not calculateLOS. Made the change you suggested and WOW what a difference. Thanks!!!

请先登录,再进行评论。

更多回答(2 个)

amberly hadden
amberly hadden 2015-7-8
Hi-- The one way to speed up such simulation is to define your output matrices or vector before loop. You can use for instance you want displacement from such observation du = zeros(m,n); dh= zeroes(m,n);....so on
tic for i = .... ...... ..... end toc
sorry if I misunderstood your question
  1 个评论
MCM
MCM 2015-7-8
编辑:MCM 2015-7-8
Thanks for replying! While a good suggestion in general, your answer doesn't apply because I don't use a loop. I tried looping by calculating line of sight from each orbit point to target one at a time just to see if that was faster. But that was twice as slow (no surprise with Matlab).
What I do is create 4 arrays; oblat,oblon,tgtlat,tgtlon. oblat and oblong have an entry for every orbit point. tgtlat and tgtlon are just the target's lat/lon position repeated. These are my inputs to los2. The output is the array, vis, whose value is 1 if the orbit point has line-of-sight to target and 0 o.w.
This works great for small arrays. But for my purposes, I'm testing 7,000 points at once (aka 7000 x 1 array inputs) and it takes 20+ seconds. (Looping took over 40 seconds)

请先登录,再进行评论。


Sean de Wolski
Sean de Wolski 2015-7-8
You could consider using the Parallel Computing Toolbox to calculate multiple lines-of-sight at the same time with parfor or parfeval
  4 个评论
Sean de Wolski
Sean de Wolski 2015-7-9
You're not using parfeval correctly. What is Topo? That should be the number of outputs. Also, for parallel computing, you could not include the opening and closing of the pool in the computation cost since this is a one time thing that can remain open (no reason to close the pool unless you need to free up resources).
Also, depending on how many times you have to do this, scaling the parallel work up to a cluster or cloud with MDCS or MATLAB Compiler might be an option. How many times do you have to run this?
MCM
MCM 2015-7-9
Good news, I updated to R2015a and los2 now runs about three times faster than when I had R2014a.
I tried using parfor in R2015a to see if I could get even more time savings but it actually ran slower. Process 100,000 point pairs took 90 seconds using los2 and 136 seconds with los2 in a parfor loop.
My guess is that it ran slower because parfor is a loop. Would parfeval run faster since it isn't a loop? If yes, then please tell me how to fix the aforementioned error. If not, let me know so I can ditch the parallel computing idea.
Thanks

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by