Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Add in unit tests and prototype for new config classes #336

Merged
merged 15 commits into from
Dec 11, 2020

Conversation

JonathanTripp
Copy link
Contributor

@JonathanTripp JonathanTripp commented Dec 8, 2020

Split the existing HeadAndNeckBase into two classes. HeadAndNeckPaper contains the original functionality and HeadAndNeckBase is a new base class that has good defaults. Similarly ProstateBase has been split into ProstateBase and ProstatePaper. Deleted the unused ProstatePaperBase.

Please follow the guidelines for PRs contained here. Checklist:

  • Ensure that your PR is small, and implements one change.
  • Add unit tests for all functions that you introduced or modified.
  • Run PyCharm's code cleanup tools on your Python files.
  • Link the correct GitHub issue for tracking.
  • Update the Changelog file: Describe your change in terms of
    Added/Changed/Removed/... in the "Upcoming" section.
  • When merging your PR, replace the default merge message with a description of your PR,
    and if needed a motivation why that change was required.

Sorry, something went wrong.

@JonathanTripp JonathanTripp requested a review from ant0nsc December 8, 2020 11:33
@JonathanTripp JonathanTripp self-assigned this Dec 8, 2020
@ghost
Copy link

ghost commented Dec 8, 2020

CLA assistant check
All CLA requirements met.

Copy link
Contributor

@ant0nsc ant0nsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just finishing off this initial review so that my comments are visible

super().__init__(
kwargs)

def check_hn_ground_truths(config,expected_ground_truth_ids:List[str]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these things are also done in .validate(), I'd suggest you also call config.validate()

ground_truth_ids=DEFAULT_PROSTATE_GROUND_TRUTH_IDS
config=ProstatePaper(num_structures=ground_truth_count)
check_hn_ground_truths(config, ground_truth_ids)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should also be some similar tests for a "HeadAndNeckBase" and "ProstateBase" class that people should use

ant0nsc
ant0nsc previously approved these changes Dec 8, 2020
Copy link
Contributor

@ant0nsc ant0nsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Some small fry comments.

Please also make a note of the changes in CHANGELOG, and extend the documentation in building_models.md to say how people would build a Prostate and a HeadAndNeck model with their custom structures.

'''
# Number of structures to predict; if positive but less than the length of STRUCTURE_LIST, the relevant prefix
# of STRUCTURE_LIST will be predicted.
if (num_structures is None) or num_structures <= 0 or num_structures > len(STRUCTURE_LIST):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd fail if num_structures<=0 or >len(STRUCTURE_LIST).

# by converting brainstem voxels to cord, as the latter is clinically more sensitive.
# We do the same to separate SPC and MPC; in this case, the direction of change is unimportant,
# so we choose SPC-to-MPC arbitrarily.
slice_exclusion_rules = []
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 apply the same logic with kwargs.pop here. If they are set explicitly, use them, otherwise branch into the logic here. Also, logging.info should say that these are added automagically.

ant0nsc
ant0nsc previously approved these changes Dec 10, 2020
@ant0nsc ant0nsc marked this pull request as ready for review December 11, 2020 10:46
@JonathanTripp JonathanTripp linked an issue Dec 11, 2020 that may be closed by this pull request
ant0nsc
ant0nsc previously approved these changes Dec 11, 2020
if not self.disable_extra_postprocessing:
if self.slice_exclusion_rules is not None:
for rule in self.slice_exclusion_rules:
if rule.higher_class not in self.ground_truth_ids:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be better placed in an instance method "validate", similar to SummedProbRule

Comment on lines 143 to 146
with pytest.raises(Exception):
_ = HeadAndNeckBase(
ground_truth_ids=ground_truth_ids,
slice_exclusion_rules=slice_exclusion_rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it very important to check that it fails for the reason you expect. check that the raised exception has the expected message.
_ =... is very F#y, but not sure it's pythonic?

Comment on lines 155 to 158
with pytest.raises(ValueError):
_ = HeadAndNeckBase(
ground_truth_ids=ground_truth_ids,
summed_probability_rules=summed_probability_rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, check that it fails for the right reason

Comment on lines 167 to 170
with pytest.raises(ValueError):
_ = HeadAndNeckBase(
ground_truth_ids=ground_truth_ids,
summed_probability_rules=summed_probability_rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

Comment on lines 179 to 182
with pytest.raises(ValueError):
_ = HeadAndNeckBase(
ground_truth_ids=ground_truth_ids,
summed_probability_rules=summed_probability_rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

"""
ground_truth_count = len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS) + 2
with pytest.raises(ValueError):
_ = HeadAndNeckPaper(num_structures=ground_truth_count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

Comment on lines 261 to 263
with pytest.raises(ValueError):
_ = HeadAndNeckPaper(num_structures=ground_truth_count,
ground_truth_ids_display_names=ground_truth_ids_display_names)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

Comment on lines 292 to 293
with pytest.raises(ValueError):
_ = HeadAndNeckPaper(num_structures=ground_truth_count, class_weights=class_weights)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

Comment on lines 282 to 283
with pytest.raises(ValueError):
_ = HeadAndNeckPaper(num_structures=ground_truth_count, fill_holes=fill_holes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

Comment on lines 272 to 273
with pytest.raises(ValueError):
_ = HeadAndNeckPaper(num_structures=ground_truth_count, colours=colours)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for reason

@JonathanTripp JonathanTripp merged commit 70f7861 into master Dec 11, 2020
@JonathanTripp JonathanTripp deleted the v-jontri/simplify_models branch December 11, 2020 17:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify inheriting from model templates
3 participants