Skip to content

Conversation

@lisaseckler
Copy link

Warning for different numbers of gantry and couch angles + correct progress displaying of the stf calculation

Warning for different numbers of gantry and couch angles + correct progress displaying of the stf calculation
Copy link
Contributor

Copilot AI left a 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_progress to 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 scen is 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.')
Copy link

Copilot AI Dec 1, 2025

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).

Suggested change
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.');

Copilot uses AI. Check for mistakes.
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.')
Copy link

Copilot AI Dec 1, 2025

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.").

Suggested change
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.')

Copilot uses AI. Check for mistakes.
Comment on lines 69 to 73
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)
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
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();

Copilot uses AI. Check for mistakes.

% --- first part of the progress ---
if scen == 1
% new line
Copy link

Copilot AI Dec 1, 2025

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".

Suggested change
% new line
% overwrite current line

Copilot uses AI. Check for mistakes.

% --- for scenario 2, same line ---
if scen == 2
fprintf(' Progress: %6.2f %%', percent);
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
fprintf(' Progress: %6.2f %%', percent);
fprintf('\rProgress: %6.2f %%', percent);

Copilot uses AI. Check for mistakes.
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.')
Copy link

Copilot AI Dec 1, 2025

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).

Suggested change
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.');

Copilot uses AI. Check for mistakes.
Comment on lines 69 to 73
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)
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
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();

Copilot uses AI. Check for mistakes.
%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.')
Copy link

Copilot AI Dec 1, 2025

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).

Suggested change
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.');

Copilot uses AI. Check for mistakes.
function matRad_progress(currentIndex, totalNumberOfEvaluations)
function matRad_progress(currentIndex, totalNumberOfEvaluations,scen)
% matRad progress bar
%
Copy link

Copilot AI Dec 1, 2025

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.

Suggested change
%
%
if nargin < 3
scen = 1;
end

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +53
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
Copy link

Copilot AI Dec 1, 2025

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.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

❌ Patch coverage is 6.25000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.81%. Comparing base (162bde8) to head (dae8c3d).

Files with missing lines Patch % Lines
matRad/util/matRad_progress.m 0.00% 11 Missing ⚠️
...ring/matRad_StfGeneratorExternalRayBixelAbstract.m 20.00% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

% Show progress
if matRad_cfg.logLevel > 2
matRad_progress(i,length(this.gantryAngles));
matRad_progress(i,length(this.gantryAngles),2);
Copy link
Contributor

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

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Test Results

    3 files  ±0      3 suites  ±0   44m 48s ⏱️ +10s
  319 tests ±0    317 ✅  - 2  0 💤 ±0  2 ❌ +2 
1 053 runs  ±0  1 042 ✅  - 6  5 💤 ±0  6 ❌ +6 

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
Copy link
Contributor

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
Copy link
Contributor

@remocristoforetti remocristoforetti Dec 1, 2025

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 '

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

This PR was automatically marked as stale it has been open 30 days with no activity. Please review/update/merge this PR.

@github-actions github-actions bot added the stale Automatic label for stale issues label Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Automatic label for stale issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants