77import pytest
88
99from pdaltools import color
10+ from pdaltools .color import argument_parser
1011
1112cwd = os .getcwd ()
1213
1314TEST_PATH = os .path .dirname (os .path .abspath (__file__ ))
1415TMPDIR = os .path .join (TEST_PATH , "tmp" , "color" )
1516
1617INPUT_PATH = os .path .join (TEST_PATH , "data/test_noepsg_043500_629205_IGN69.laz" )
18+ INPUT_PATH_TILE = os .path .join (TEST_PATH , "data/test_data_77055_627760_LA93_IGN69.laz" )
19+
20+ RGB_IMAGE = os .path .join (TEST_PATH , "data/color/test_data_rgb.tif" )
21+ IRC_IMAGE = os .path .join (TEST_PATH , "data/color/test_data_irc.tif" )
22+
1723
1824OUTPUT_FILE = os .path .join (TMPDIR , "Semis_2021_0435_6292_LA93_IGN69.colorized.las" )
1925EPSG = "2154"
@@ -33,12 +39,12 @@ def test_epsg_fail():
3339 RuntimeError ,
3440 match = "EPSG could not be inferred from metadata: No 'srs' key in metadata." ,
3541 ):
36- color .color (INPUT_PATH , OUTPUT_FILE , "" , 0.1 , 15 )
42+ color .color_from_stream (INPUT_PATH , OUTPUT_FILE , "" , 0.1 , 15 )
3743
3844
3945@pytest .mark .geopf
4046def test_color_and_keeping_orthoimages ():
41- tmp_ortho , tmp_ortho_irc = color .color (INPUT_PATH , OUTPUT_FILE , EPSG , check_images = True )
47+ tmp_ortho , tmp_ortho_irc = color .color_from_stream (INPUT_PATH , OUTPUT_FILE , EPSG , check_images = True )
4248 assert Path (tmp_ortho .name ).exists ()
4349 assert Path (tmp_ortho_irc .name ).exists ()
4450
@@ -63,7 +69,7 @@ def test_color_narrow_cloud():
6369 input_path = os .path .join (TEST_PATH , "data/test_data_0436_6384_LA93_IGN69_single_point.laz" )
6470 output_path = os .path .join (TMPDIR , "color_narrow_cloud_test_data_0436_6384_LA93_IGN69_single_point.colorized.laz" )
6571 # Test that clouds that are smaller in width or height to 20cm are still colorized without an error.
66- color .color (input_path , output_path , EPSG )
72+ color .color_from_stream (input_path , output_path , EPSG )
6773 with laspy .open (output_path , "r" ) as las :
6874 las_data = las .read ()
6975 # Check all points are colored
@@ -75,10 +81,9 @@ def test_color_narrow_cloud():
7581
7682@pytest .mark .geopf
7783def test_color_standard_cloud ():
78- input_path = os .path .join (TEST_PATH , "data/test_data_77055_627760_LA93_IGN69.laz" )
7984 output_path = os .path .join (TMPDIR , "color_standard_cloud_test_data_77055_627760_LA93_IGN69.colorized.laz" )
8085 # Test that clouds that are smaller in width or height to 20cm are still colorized without an error.
81- color .color ( input_path , output_path , EPSG )
86+ color .color_from_stream ( INPUT_PATH_TILE , output_path , EPSG )
8287 with laspy .open (output_path , "r" ) as las :
8388 las_data = las .read ()
8489 # Check all points are colored
@@ -92,7 +97,7 @@ def test_color_epsg_2975_forced():
9297 input_path = os .path .join (TEST_PATH , "data/sample_lareunion_epsg2975.laz" )
9398 output_path = os .path .join (TMPDIR , "color_epsg_2975_forced_sample_lareunion_epsg2975.colorized.laz" )
9499
95- color .color (input_path , output_path , 2975 )
100+ color .color_from_stream (input_path , output_path , 2975 )
96101
97102
98103# the test is not working, the image is not detected as white
@@ -104,7 +109,7 @@ def test_color_epsg_2975_forced():
104109# output_path = os.path.join(TMPDIR, "sample_lareunion_epsg2975.colorized.white.laz")#
105110
106111# with pytest.raises(ValueError) as excinfo:
107- # color.color (input_path, output_path, check_images=True)
112+ # color.color_from_stream (input_path, output_path, check_images=True)
108113
109114# assert "Downloaded image is white" in str(excinfo.value)
110115
@@ -114,18 +119,17 @@ def test_color_epsg_2975_detected():
114119 input_path = os .path .join (TEST_PATH , "data/sample_lareunion_epsg2975.laz" )
115120 output_path = os .path .join (TMPDIR , "color_epsg_2975_detected_sample_lareunion_epsg2975.colorized.laz" )
116121 # Test that clouds that are smaller in width or height to 20cm are still clorized without an error.
117- color .color (input_path , output_path )
122+ color .color_from_stream (input_path , output_path )
118123
119124
120125def test_color_vegetation_only ():
121- """Test the color() function with only vegetation"""
122- input_path = os .path .join (TEST_PATH , "data/test_data_77055_627760_LA93_IGN69.laz" )
126+ """Test the color_from_stream() function with only vegetation"""
123127 output_path = os .path .join (TMPDIR , "test_color_vegetation.colorized.las" )
124128 vegetation_path = os .path .join (TEST_PATH , "data/mock_vegetation.tif" )
125129
126130 # Test with all parameters explicitly defined
127- color .color (
128- input_file = input_path ,
131+ color .color_from_stream (
132+ input_file = INPUT_PATH_TILE ,
129133 output_file = output_path ,
130134 proj = "2154" , # EPSG:2154 (Lambert 93)
131135 color_rvb_enabled = False , # RGB enabled
@@ -153,14 +157,13 @@ def test_color_vegetation_only():
153157
154158@pytest .mark .geopf
155159def test_color_with_all_parameters ():
156- """Test the color() function with all parameters specified"""
157- input_path = os .path .join (TEST_PATH , "data/test_data_77055_627760_LA93_IGN69.laz" )
160+ """Test the color_from_stream() function with all parameters specified"""
158161 output_path = os .path .join (TMPDIR , "test_color_all_params.colorized.las" )
159162 vegetation_path = os .path .join (TEST_PATH , "data/mock_vegetation.tif" )
160163
161164 # Test with all parameters explicitly defined
162- tmp_ortho , tmp_ortho_irc = color .color (
163- input_file = input_path ,
165+ tmp_ortho , tmp_ortho_irc = color .color_from_stream (
166+ input_file = INPUT_PATH_TILE ,
164167 output_file = output_path ,
165168 proj = "2154" , # EPSG:2154 (Lambert 93)
166169 pixel_per_meter = 2.0 , # custom resolution
@@ -196,3 +199,56 @@ def test_color_with_all_parameters():
196199 # Verify that the vegetation dimension is present
197200 assert "vegetation_dim" in las_data .point_format .dimension_names , "Vegetation dimension should be present"
198201 assert not np .all (las_data .vegetation_dim == 0 ), "Vegetation dimension should not be empty"
202+
203+
204+ def test_color_from_files ():
205+ output_path = os .path .join (TMPDIR , "color_standard_cloud_files_test_data_77055_627760_LA93_IGN69.colorized.laz" )
206+
207+ color .color_from_files (INPUT_PATH_TILE , output_path , RGB_IMAGE , IRC_IMAGE )
208+
209+ assert os .path .exists (output_path )
210+
211+ with laspy .open (output_path , "r" ) as las :
212+ las_data = las .read ()
213+
214+ # Verify that all points have been colorized (no 0 values)
215+ las_rgb_missing = (las_data .red == 0 ) & (las_data .green == 0 ) & (las_data .blue == 0 )
216+ assert not np .any (las_rgb_missing ), f"No point should have missing RGB, found { np .count_nonzero (las_rgb_missing )} "
217+ assert not np .any (las_data .nir == 0 ), "No point should have missing NIR"
218+
219+
220+ @pytest .mark .geopf
221+ def test_main_from_stream ():
222+ output_file = os .path .join (TMPDIR , "main_from_stream" , "output_main_from_stream.laz" )
223+ os .makedirs (os .path .dirname (output_file ))
224+ cmd = f"from_stream -i { INPUT_PATH_TILE } -o { output_file } -p { EPSG } --rvb --ir" .split ()
225+ args = argument_parser ().parse_args (cmd )
226+ args .func (args )
227+
228+ assert os .path .exists (output_file )
229+
230+ with laspy .open (output_file , "r" ) as las :
231+ las_data = las .read ()
232+
233+ # Verify that all points have been colorized (no 0 values)
234+ las_rgb_missing = (las_data .red == 0 ) & (las_data .green == 0 ) & (las_data .blue == 0 )
235+ assert not np .any (las_rgb_missing ), f"No point should have missing RGB, found { np .count_nonzero (las_rgb_missing )} "
236+ assert not np .any (las_data .nir == 0 ), "No point should have missing NIR"
237+
238+
239+ def test_main_from_files ():
240+ output_file = os .path .join (TMPDIR , "main_from_files" , "output_main_from_files.laz" )
241+ os .makedirs (os .path .dirname (output_file ))
242+ cmd = f"from_files -i { INPUT_PATH_TILE } -o { output_file } --image_RGB { RGB_IMAGE } --image_IRC { IRC_IMAGE } " .split ()
243+ args = argument_parser ().parse_args (cmd )
244+ args .func (args )
245+
246+ assert os .path .exists (output_file )
247+
248+ with laspy .open (output_file , "r" ) as las :
249+ las_data = las .read ()
250+
251+ # Verify that all points have been colorized (no 0 values)
252+ las_rgb_missing = (las_data .red == 0 ) & (las_data .green == 0 ) & (las_data .blue == 0 )
253+ assert not np .any (las_rgb_missing ), f"No point should have missing RGB, found { np .count_nonzero (las_rgb_missing )} "
254+ assert not np .any (las_data .nir == 0 ), "No point should have missing NIR"
0 commit comments