Describe your feature request
spatialBehaviour and temporalBehaviour are kind of slow to run. For exemple, it takes 37.5s on my computer (mac osx 2020, 2 GHz Intel Core i5 four cores) to run the spatialBehaviour function for only 7 storms:
ds <- defStormsDataset()
s <- defStormsList(ds)
s <- defStormsList(ds, loi="New Caledonia")
=== Storms processing ... ===
-> Making buffer: Done
-> Searching storms from 2015 to 2021 ...
-> Identifying Storms: 9 potential candidates...
-> Gathering storm(s) ...
|===================================================================================================================================| 100%
=== DONE with run time 1.182287 sec ===
SUMMARY:
(*) LOI: New Caledonia
(*) Buffer size: 300 km
(*) Remove Tropical Depressions (< 18 m/s in sshs): yes
(*) Number of storms: 7
Name - Tropical season - SSHS - Number of observation within buffer:
PAM - 2015 - 5 - 5
SOLO - 2015 - 0 - 15
ULA - 2016 - 4 - 9
UESI - 2020 - 1 - 16
GRETEL - 2020 - 1 - 11
LUCAS - 2021 - 1 - 16
NIRAN - 2021 - 5 - 10
msw <- spatialBehaviour(s)
We want the code to be faster.
Describe the solution you'd like
Three things must be considered to improve efficency when doing the computation of storms behaviour:
- analyze bottlenecks and find where
spatialBehaviour spends most of its time
- implement the computing functions in C++ using
Rcpp library
- implement parallel looping
- We must use a profiling library to analyse the time spent in different functions:
library(profvis)
profvis(spatialBehaviour(s))
First analysis with the exemple above shows that :
- overall time in this function is 35170ms
- computational time in
spatialBehaviour itself is 5800ms
- all the remaining time is spent in
.External functions, which are tipicaly sf functions.
This means that we should consider means to lower the number of calls to sf functions.
- Code in
Rcpp the computing functions, including:
computeAsymmetry
willoughby
holland
boose
computeDirectionBoose
computeDirection
although as stated above, this is limited to a small fraction of the total computational time
- Test the parallel-looping when available:
- auto detect number of cores
- implement parallel-looping (keeping order) using
foreach library when relevent (and possible)
Describe alternatives you've considered
Additional context
No response
Describe your feature request
spatialBehaviourandtemporalBehaviourare kind of slow to run. For exemple, it takes 37.5s on my computer (mac osx 2020, 2 GHz Intel Core i5 four cores) to run thespatialBehaviourfunction for only 7 storms:We want the code to be faster.
Describe the solution you'd like
Three things must be considered to improve efficency when doing the computation of storms behaviour:
spatialBehaviourspends most of its timeRcpplibraryFirst analysis with the exemple above shows that :
spatialBehaviouritself is 5800ms.Externalfunctions, which are tipicalysffunctions.This means that we should consider means to lower the number of calls to
sffunctions.Rcppthe computing functions, including:computeAsymmetrywilloughbyhollandboosecomputeDirectionBoosecomputeDirectionalthough as stated above, this is limited to a small fraction of the total computational time
foreachlibrary when relevent (and possible)Describe alternatives you've considered
sffunctions callsRcppforeachlibraryAdditional context
No response