def test_head_and_neck_paper_with_no_ground_truth_ids() -> None:
    """
    Check that passing num_structures = default generates all default structures.
    """
    ground_truth_ids = DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS
    config = HeadAndNeckPaper(local_dataset=Path("foo"), )
    assert config.ground_truth_ids == ground_truth_ids
Ejemplo n.º 2
0
def test_head_and_neck_paper_with_optional_params(
        ground_truth_count: int) -> None:
    """
    Check that optional parameters can be passed in.
    """
    ground_truth_ids = DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS[:
                                                              ground_truth_count]
    ground_truth_ids_display_names = generate_random_display_ids(
        ground_truth_count)
    colours = generate_random_colours_list(RANDOM_COLOUR_GENERATOR,
                                           ground_truth_count)
    fill_holes = generate_random_fill_holes(ground_truth_count)
    class_weights = generate_random_class_weights(ground_truth_count + 1)
    num_feature_channels = random.randint(1, ground_truth_count)
    slice_exclusion_rules = generate_random_slice_exclusion_rules(
        ground_truth_ids)
    summed_probability_rules = generate_random_summed_probability_rules(
        ground_truth_ids)
    config = HeadAndNeckPaper(
        num_structures=ground_truth_count,
        ground_truth_ids_display_names=ground_truth_ids_display_names,
        colours=colours,
        fill_holes=fill_holes,
        class_weights=class_weights,
        num_feature_channels=num_feature_channels,
        slice_exclusion_rules=slice_exclusion_rules,
        summed_probability_rules=summed_probability_rules)
    assert config.ground_truth_ids == ground_truth_ids
    assert config.ground_truth_ids_display_names == ground_truth_ids_display_names
    assert config.colours == colours
    assert config.fill_holes == fill_holes
    assert config.class_weights == class_weights
    assert config.feature_channels == [num_feature_channels]
    assert config.slice_exclusion_rules == slice_exclusion_rules
    assert config.summed_probability_rules == summed_probability_rules
def test_head_and_neck_paper_with_0_ground_truth_ids() -> None:
    """
    Check that passing num_structures = 0 raises ValueError exception.
    """
    with pytest.raises(ValueError) as e:
        assert HeadAndNeckPaper(local_dataset=Path("foo"), num_structures=0)
    assert str(
        e.value
    ) == f"num structures must be between 0 and {len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS)}"
Ejemplo n.º 4
0
def test_head_and_neck_paper_with_some_ground_truth_ids(
        ground_truth_count: int) -> None:
    """
    Check that passing a num_structures between 1 and len(defaults) generates the correct subset.
    """
    ground_truth_ids = DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS[:
                                                              ground_truth_count]
    config = HeadAndNeckPaper(num_structures=ground_truth_count)
    assert config.ground_truth_ids == ground_truth_ids
Ejemplo n.º 5
0
def test_head_and_neck_paper_with_too_many_ground_truth_ids() -> None:
    """
    Check that passing num_structures larger than len(defaults) raises ValueError exception.
    """
    ground_truth_count = len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS) + 2
    with pytest.raises(ValueError) as e:
        assert HeadAndNeckPaper(num_structures=ground_truth_count)
    assert str(
        e.value
    ) == f"num structures must be between 0 and {len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS)}"
Ejemplo n.º 6
0
def test_head_and_neck_paper_with_mismatched_fill_holes_raises() -> None:
    """
    Check that passing too many colours raises ValueError exception.
    """
    ground_truth_count = len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS) - 2
    fill_holes = generate_random_fill_holes(ground_truth_count - 1)
    with pytest.raises(ValueError) as e:
        assert HeadAndNeckPaper(num_structures=ground_truth_count,
                                fill_holes=fill_holes)
    assert str(
        e.value) == "len(ground_truth_ids_display_names)!=len(fill_holes)"
def test_head_and_neck_paper_with_mismatched_colours_raises() -> None:
    """
    Check that passing too many colours raises ValueError exception.
    """
    ground_truth_count = len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS) - 2
    colours = generate_random_colours_list(RANDOM_COLOUR_GENERATOR,
                                           ground_truth_count - 1)
    with pytest.raises(ValueError) as e:
        assert HeadAndNeckPaper(local_dataset=Path("foo"),
                                num_structures=ground_truth_count,
                                colours=colours)
    assert str(e.value) == "len(ground_truth_ids_display_names)!=len(colours)"
Ejemplo n.º 8
0
def test_head_and_neck_paper_with_mismatched_class_weights_raises() -> None:
    """
    Check that passing too many colours raises ValueError exception.
    """
    ground_truth_count = len(DEFAULT_HEAD_AND_NECK_GROUND_TRUTH_IDS) - 2
    class_weights = generate_random_class_weights(ground_truth_count - 1)
    with pytest.raises(ValueError) as e:
        assert HeadAndNeckPaper(num_structures=ground_truth_count,
                                class_weights=class_weights)
    assert str(
        e.value
    ) == "class_weights needs to be equal to number of ground_truth_ids + 1"