Comments (5)
Most warning flag is due to the fact that many variables' size would change during loops, so MATLAB automatically suggest parallel computation. But parallel computation is actually not suitable for this case. As what mentioned in manuscript, parallel computation is not suitable here as the size of the resultant MHW/MCS dataset would change with loops, which is against the rule that each loop should be independent of others in a parallel computation. It should be noted that parallel computation could be used if each detected event is stored independently. However, this would mean that another loop should be included to all events into one composite. We have tested this approach and found that it would not be faster than the version using simple loops
from m_mhw1.0.
My understanding of the JOSS review process is that it's supposed to help improve code not just check that it works. The comments below are given in that spirit, but I am quite happy for them to be ignored if I have misunderstood, and if the Editor feels these are not appropriate or necessary for publication.
Eliminating the warning flags would be a useful exercise especially if combined with improvements to readability and style throughout. The code is not easy to follow for several reasons: (1) there is a lack of comments within the functions describing what is going on; (2) some basic good practices are ignored, such as spaces around =
characters; (3) there are some very long lines that should be broken up with ...
.
-
The majority of your warning flags are due to unnecessary semi-colons, usually at the end of a for/if/while statement. While these don't cause any problems, they do make it much more difficult to spot other, more useful warnings. They require very little effort to remove.
-
You then have some unnecessary
find
statements, of the format:
vector_variable(find(logical_expression))
These work equally well - and marginally faster - if you simply put:
vector_variable(logical_expression)
-
You have some variables that are assigned within loops that are never used, which can simply be eliminated to avoid wasting memory.
-
Based on your reply above, I think you may be mixing up "parallel" with "preallocation". MATLAB does not suggest parallel computation in your code, it suggests that you preallocate some variables in your loops. This means that if you are assigning values into a vector one by one in a loop, you should ideally create an empty vector before the loop begins, of the correct size, into which the results are added.
For example, part of your code in detect()
looks something like this:
mhwint_max = [];
for le = 1:size(potential_event,1)
maxanom = <some code>;
mhwint_max = [mhwint_max; maxanom];
end
To preallocate you would change this to:
mhwint_max = NaN(size(potential_event,1),1);
for le = 1:size(potential_event,1)
maxanom = <some code>;
mhwint_max(le) = maxanom;
end
This allows your computer to use memory more efficiently and your code to run faster.
- One warning flag simply tells you it is faster to use
str2double
instead ofstr2num
. This is an extremely straightforward switch. Why resist?
from m_mhw1.0.
Thanks a lot for careful and thoughtful review. I have edited the script for your suggestion. Thanks a lot. Now most warning flag has been removed.
I need to mention that find
still needs to be used in potential_event(find(gaps<=vmaxGap),2)=potential_event(find(gaps<=vmaxGap)+1,2);
due to the fact that gaps
has different size from potential_event
, here I just use find
to determine the location that I want to fill in so I have to use find
, but MATLAB initially think gaps
has the same size with potential_event
so it suggests no find
.
Please see https://github.com/ZijieZhaoMMHW/m_mhw1.0/blob/master/detect.m.
from m_mhw1.0.
Hi @mvdh7. for your consideration, I send the toolbox to @codacy-badger and get the code quality A. Please see https://github.com/ZijieZhaoMMHW/m_mhw1.0
from m_mhw1.0.
Nice work. I hope this has helped improve the code.
Thank you for pointing out the code quality tester - I hadn't come across that before. However, I don't think it supports MATLAB, so the badge it has given may not be very meaningful.
from m_mhw1.0.
Related Issues (14)
- Non-OSI license HOT 6
- Error in evaluating .mat files HOT 2
- Update to detect (Adding date_peak and no use of toolbox)
- Problems with an_example.m
- an_example HOT 4
- event_line.m seems to only work correctly when data time series starts at the start of the year
- Matrix dimensions must agree in <= statement
- a ‘compound heatwave
- No DOIs in paper HOT 1
- Function inputs documentation HOT 4
- m_map required for testing HOT 1
- Results inconsistencies with other implementations HOT 1
- The use of quantile()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from m_mhw1.0.