-
Notifications
You must be signed in to change notification settings - Fork 199
Warning gantry and couch angles + correct displayed progress #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Warning for different numbers of gantry and couch angles + correct progress displaying of the stf calculation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds warning/error messages when gantry and couch angles have different counts, and modifies the progress display mechanism during STF (steering file) calculation.
- Upgrades angle mismatch warnings to errors with more specific messages
- Introduces a new parameter to
matRad_progressto differentiate between two progress display scenarios - Modifies progress reporting in the beam generation loop to use different display modes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| matRad/util/matRad_progress.m | Adds a new scen parameter to control progress display behavior, replacing the previous backspace-based update mechanism with carriage return and mode-based logic |
| matRad/steering/matRad_StfGeneratorExternalRayBixelAbstract.m | Changes angle mismatch warnings to errors, adds error messages for angle count mismatches, and passes display mode parameter to progress function calls |
Comments suppressed due to low confidence (1)
matRad/util/matRad_progress.m:9
- The new parameter
scenis not documented in the function header. The documentation should be updated to include this new parameter, its purpose, and valid values (e.g., 1 for first progress update, 2 for subsequent updates).
% call
% matRad_progress(currentIndex, totalNumberOfEvaluations)
%
% input
% currentIndex: current iteration index
% totalNumberOfEvaluations: maximum iteration index
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if nBeams ~= numel(this.couchAngles) | ||
| matRad_cfg = MatRad_Config.instance(); | ||
| matRad_cfg.dispWarning('For some reason, we have a different number of beam and couch angles!'); | ||
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon at the end of this statement. In MATLAB, statements without semicolons print their output to the console, which would display the error message twice (once from dispError and once from the return value).
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.'); |
| if nBeams ~= numel(this.couchAngles) | ||
| matRad_cfg = MatRad_Config.instance(); | ||
| matRad_cfg.dispWarning('For some reason, we have a different number of beam and couch angles!'); | ||
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is inaccurate. This condition triggers when the number of gantry angles doesn't equal the number of couch angles, not specifically when there are "more gantry angles than couch angles". The message should be more generic to cover both cases (e.g., "The number of gantry angles and couch angles must be equal.").
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| matRad_cfg.dispError('The number of gantry angles and couch angles must be equal.') |
| if numel(this.gantryAngles) > numel(this.couchAngles) | ||
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | ||
| %Append Couch angles with zeros | ||
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | ||
| elseif numel(this.couchAngles) > numel(this.gantryAngles) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matRad_cfg variable is used but not defined in this scope. It needs to be instantiated with matRad_cfg = MatRad_Config.instance(); before calling dispError.
| if numel(this.gantryAngles) > numel(this.couchAngles) | |
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| %Append Couch angles with zeros | |
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | |
| elseif numel(this.couchAngles) > numel(this.gantryAngles) | |
| if numel(this.gantryAngles) > numel(this.couchAngles) | |
| matRad_cfg = MatRad_Config.instance(); | |
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| %Append Couch angles with zeros | |
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | |
| elseif numel(this.couchAngles) > numel(this.gantryAngles) | |
| matRad_cfg = MatRad_Config.instance(); |
|
|
||
| % --- first part of the progress --- | ||
| if scen == 1 | ||
| % new line |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "new line" is misleading. The \r escape sequence is a carriage return that moves the cursor to the beginning of the current line, not a new line. If a new line is actually needed, use \n instead. If the intent is to overwrite the current line (which seems correct given the context), update the comment to reflect this, e.g., "overwrite current line".
| % new line | |
| % overwrite current line |
|
|
||
| % --- for scenario 2, same line --- | ||
| if scen == 2 | ||
| fprintf(' Progress: %6.2f %%', percent); |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The progress display for scen == 2 will append " Progress: X.XX %" to whatever is currently on the console line without proper updating. This will create messy output if called multiple times. Consider using backspace characters (\b) to erase the previous output, or use \r to return to the beginning of the line and overwrite, similar to how scen == 1 works.
| fprintf(' Progress: %6.2f %%', percent); | |
| fprintf('\rProgress: %6.2f %%', percent); |
| if ~this.lockAngleUpdate | ||
| this.lockAngleUpdate = true; | ||
| if numel(this.gantryAngles) > numel(this.couchAngles) | ||
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon at the end of this statement. In MATLAB, statements without semicolons print their output to the console, which would display the error message twice (once from dispError and once from the return value).
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.'); |
| if numel(this.gantryAngles) > numel(this.couchAngles) | ||
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | ||
| %Append Couch angles with zeros | ||
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | ||
| elseif numel(this.couchAngles) > numel(this.gantryAngles) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matRad_cfg variable is used but not defined in this scope. It needs to be instantiated with matRad_cfg = MatRad_Config.instance(); before calling dispError.
| if numel(this.gantryAngles) > numel(this.couchAngles) | |
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| %Append Couch angles with zeros | |
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | |
| elseif numel(this.couchAngles) > numel(this.gantryAngles) | |
| if numel(this.gantryAngles) > numel(this.couchAngles) | |
| matRad_cfg = MatRad_Config.instance(); | |
| matRad_cfg.dispError('There are more gantry angles than couch angles. They have to have the same size.') | |
| %Append Couch angles with zeros | |
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | |
| elseif numel(this.couchAngles) > numel(this.gantryAngles) | |
| matRad_cfg = MatRad_Config.instance(); |
| %Append Couch angles with zeros | ||
| this.couchAngles = [this.couchAngles zeros(1,numel(this.gantryAngles)-numel(this.couchAngles))]; | ||
| elseif numel(this.couchAngles) > numel(this.gantryAngles) | ||
| matRad_cfg.dispError('There are more couch angles than gantry angles. They have to have the same size.') |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon at the end of this statement. In MATLAB, statements without semicolons print their output to the console, which would display the error message twice (once from dispError and once from the return value).
| matRad_cfg.dispError('There are more couch angles than gantry angles. They have to have the same size.') | |
| matRad_cfg.dispError('There are more couch angles than gantry angles. They have to have the same size.'); |
| function matRad_progress(currentIndex, totalNumberOfEvaluations) | ||
| function matRad_progress(currentIndex, totalNumberOfEvaluations,scen) | ||
| % matRad progress bar | ||
| % |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new scen parameter breaks backward compatibility with all existing calls to matRad_progress throughout the codebase. Many files call this function with only 2 parameters (see matRad_sampling.m, matRad_DoseEngineBase.m, etc.). Consider making scen an optional parameter with a default value, e.g., function matRad_progress(currentIndex, totalNumberOfEvaluations, scen) with logic like if nargin < 3, scen = 1; end.
| % | |
| % | |
| if nargin < 3 | |
| scen = 1; | |
| end |
| persistent isInitialized | ||
|
|
||
| if isempty(isInitialized) | ||
| isInitialized = true; | ||
| end | ||
|
|
||
| if (currentIndex > 1) | ||
| Length = numel(sprintf('%3.2f %%',(currentIndex-1)/totalNumberOfEvaluations*100)); | ||
| fprintf(repmat('\b',1,Length)); | ||
|
|
||
| percent = (currentIndex / totalNumberOfEvaluations) * 100; | ||
|
|
||
| % --- first part of the progress --- | ||
| if scen == 1 | ||
| % new line | ||
| fprintf('\rProgress: %6.2f %%', percent); | ||
| end | ||
|
|
||
| % Print the progress tool | ||
| fprintf('%3.2f %%',currentIndex/totalNumberOfEvaluations*100); | ||
|
|
||
| % After the last iteration print a newline command | ||
| if (currentIndex == totalNumberOfEvaluations) | ||
| fprintf('\n'); | ||
|
|
||
| % --- for scenario 2, same line --- | ||
| if scen == 2 | ||
| fprintf(' Progress: %6.2f %%', percent); | ||
| end | ||
|
|
||
|
|
||
| % --- finish line after the last angle --- | ||
| if currentIndex == totalNumberOfEvaluations && scen == 2 | ||
| fprintf('\n'); | ||
| clear isInitialized |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The persistent isInitialized variable is declared and set but never actually used to control any logic. It's only cleared when currentIndex == totalNumberOfEvaluations && scen == 2, but this clearing has no effect since the variable isn't checked anywhere. Consider removing this unused code or implementing the intended initialization logic.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #879 +/- ##
==========================================
- Coverage 53.88% 53.81% -0.07%
==========================================
Files 308 308
Lines 19954 19959 +5
==========================================
- Hits 10752 10741 -11
- Misses 9202 9218 +16 ☔ View full report in Codecov by Sentry. |
| % Show progress | ||
| if matRad_cfg.logLevel > 2 | ||
| matRad_progress(i,length(this.gantryAngles)); | ||
| matRad_progress(i,length(this.gantryAngles),2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this second call to matRad_progress
Test Results 3 files ±0 3 suites ±0 44m 48s ⏱️ +10s For more details on these failures, see this check. Results for commit dae8c3d. ± Comparison against base commit 162bde8. |
| if (currentIndex == 1) | ||
| fprintf('Progress: '); | ||
|
|
||
| persistent isInitialized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid the use of persistent variables for this as matRad_progress is also called outside of the stf generator. Also seems like it's not used.
| percent = (currentIndex / totalNumberOfEvaluations) * 100; | ||
|
|
||
| % --- first part of the progress --- | ||
| if scen == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we need a scen input, and seems like the output is never cleared, keeps adding the 'Progress '
|
This PR was automatically marked as stale it has been open 30 days with no activity. Please review/update/merge this PR. |
Warning for different numbers of gantry and couch angles + correct progress displaying of the stf calculation