Source code for tests.test_features.test_features_urbanmask

#!/usr/bin/env python
# coding: utf8
#
# Copyright (C) 2022-2024 CNES
#
# This file is part of slurp
#
"""Test urban mask with differents features and different arguments values"""

import sys

import pytest

import slurp.masks.urbanmask
from tests.utils import get_aux_path, get_output_path


[docs]def write_command_compute_urbanmask( nb_workers, main_config, features_test_img, output_dir, ref_dir, valid_stack=None, ): """Builds a command string to compute an urban mask using the urbanmask module.""" output_image = get_output_path( features_test_img, "urbanmask", output_dir, remove=True ) if valid_stack is None: valid_stack = get_aux_path(features_test_img, "valid_stack", ref_dir) return ( f"urbanmask.py {main_config} " f"-file_vhr {features_test_img} " f"-n_workers {nb_workers} " f"-urbanmask {output_image} " f"-valid {valid_stack} " )
[docs]@pytest.mark.features @pytest.mark.parametrize("vegmask_min_value", [0, 21, 1000]) def test_vegmask_max_value( vegmask_min_value, main_config, features_test_img, output_dir, ref_dir ): """Tests the urban mask computation with different vegetation mask minimum values. vegmask_min_value: Vegetation min value for vegetated areas : all pixels with lower value will be predicted""" command = ( write_command_compute_urbanmask( 1, main_config, features_test_img, output_dir, ref_dir ) + f"-vegmask_min_value {vegmask_min_value} " ).split() sys.argv = command slurp.masks.urbanmask.main()
[docs]@pytest.mark.ci @pytest.mark.parametrize("vegmask_min_value", [0, 21, 1000]) def test_vegmask_max_value_ci( vegmask_min_value, main_config, features_test_img, output_dir, ref_dir, valid_stack, ): """Run the test test_vegmask_max_value with a specified valid_stack (for GithubCI).""" command = ( write_command_compute_urbanmask( 1, main_config, features_test_img, output_dir, ref_dir, valid_stack ) + f"-vegmask_min_value {vegmask_min_value}" ).split() sys.argv = command slurp.masks.urbanmask.main()
[docs]@pytest.mark.features @pytest.mark.parametrize( "nb_samples_other,nb_samples_urban", [(0, 0), (5000, 1000)] ) def test_nb_samples( nb_samples_other, nb_samples_urban, main_config, features_test_img, output_dir, ref_dir, ): """Tests the urban mask computation with different sample counts for other and urban classes. nb_samples_other: Number of samples in other for learning. nb_samples_urban: Number of samples in buildings for learning""" command = ( write_command_compute_urbanmask( 1, main_config, features_test_img, output_dir, ref_dir ) + f"-nb_samples_other {nb_samples_other} -nb_samples_urban {nb_samples_urban}" ).split() sys.argv = command slurp.masks.urbanmask.main()
[docs]@pytest.mark.ci @pytest.mark.parametrize( "nb_samples_other,nb_samples_urban", [(0, 0), (5000, 1000)] ) def test_nb_samples_ci( nb_samples_other, nb_samples_urban, main_config, features_test_img, output_dir, ref_dir, valid_stack, ): """Run test_nb_samples with a specified valid_stack (for GithubCI).""" command = ( write_command_compute_urbanmask( 1, main_config, features_test_img, output_dir, ref_dir, valid_stack ) + f"-nb_samples_other {nb_samples_other} -nb_samples_urban {nb_samples_urban}" ).split() sys.argv = command slurp.masks.urbanmask.main()