@@ -281,6 +281,60 @@ def qgis_ebbi():
281281 return result
282282
283283
284+ @pytest .fixture
285+ def data_uint_dtype_normalized_ratio (dtype ):
286+ # test data for input data array of uint dtype
287+ # normalized ratio is applied with different bands for NBR, NBR2, NDVI, NDMI.
288+ band1 = xr .DataArray (np .array ([[1 , 1 ], [1 , 1 ]], dtype = dtype ))
289+ band2 = xr .DataArray (np .array ([[0 , 2 ], [1 , 2 ]], dtype = dtype ))
290+ result = np .array ([[1 , - 0.33333334 ], [0 , - 0.33333334 ]], dtype = np .float32 )
291+ return band1 , band2 , result
292+
293+
294+ @pytest .fixture
295+ def data_uint_dtype_arvi (dtype ):
296+ nir = xr .DataArray (np .array ([[1 , 1 ], [1 , 1 ]], dtype = dtype ))
297+ red = xr .DataArray (np .array ([[0 , 1 ], [0 , 2 ]], dtype = dtype ))
298+ blue = xr .DataArray (np .array ([[0 , 2 ], [1 , 2 ]], dtype = dtype ))
299+ result = np .array ([[1 , 0.2 ], [1 , - 0.14285715 ]], dtype = np .float32 )
300+ return nir , red , blue , result
301+
302+
303+ @pytest .fixture
304+ def data_uint_dtype_evi (dtype ):
305+ nir = xr .DataArray (np .array ([[1 , 1 ], [1 , 1 ]], dtype = dtype ))
306+ red = xr .DataArray (np .array ([[0 , 1 ], [0 , 2 ]], dtype = dtype ))
307+ blue = xr .DataArray (np .array ([[0 , 2 ], [1 , 2 ]], dtype = dtype ))
308+ result = np .array ([[1.25 , 0. ], [- 0.45454547 , 2.5 ]], dtype = np .float32 )
309+ return nir , red , blue , result
310+
311+
312+ @pytest .fixture
313+ def data_uint_dtype_savi (dtype ):
314+ nir = xr .DataArray (np .array ([[1 , 1 ], [1 , 1 ]], dtype = dtype ))
315+ red = xr .DataArray (np .array ([[0 , 1 ], [0 , 2 ]], dtype = dtype ))
316+ result = np .array ([[0.25 , 0. ], [0.25 , - 0.125 ]], dtype = np .float32 )
317+ return nir , red , result
318+
319+
320+ @pytest .fixture
321+ def data_uint_dtype_sipi (dtype ):
322+ nir = xr .DataArray (np .array ([[1 , 1 ], [1 , 1 ]], dtype = dtype ))
323+ red = xr .DataArray (np .array ([[0 , 0 ], [0 , 2 ]], dtype = dtype ))
324+ blue = xr .DataArray (np .array ([[0 , 2 ], [1 , 2 ]], dtype = dtype ))
325+ result = np .array ([[1 , - 1 ], [0 , 1 ]], dtype = np .float32 )
326+ return nir , red , blue , result
327+
328+
329+ @pytest .fixture
330+ def data_uint_dtype_ebbi (dtype ):
331+ red = xr .DataArray (np .array ([[0 , 0 ], [0 , 2 ]], dtype = dtype ))
332+ swir = xr .DataArray (np .array ([[1 , 1 ], [1 , 1 ]], dtype = dtype ))
333+ tir = xr .DataArray (np .array ([[0 , 2 ], [1 , 2 ]], dtype = dtype ))
334+ result = np .array ([[0.1 , 0.05773503 ], [0.07071068 , - 0.05773503 ]], dtype = np .float32 )
335+ return red , swir , tir , result
336+
337+
284338# NDVI -------------
285339def test_ndvi_data_contains_valid_values ():
286340 _x = np .mgrid [1 :0 :21j ]
@@ -310,6 +364,13 @@ def test_ndvi_cpu_against_qgis(nir_data, red_data, qgis_ndvi):
310364 general_output_checks (nir_data , result , qgis_ndvi , verify_dtype = True )
311365
312366
367+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
368+ def test_ndvi_uint_dtype (data_uint_dtype_normalized_ratio ):
369+ nir_data , red_data , result_ndvi = data_uint_dtype_normalized_ratio
370+ result = ndvi (nir_data , red_data )
371+ general_output_checks (nir_data , result , result_ndvi , verify_dtype = True )
372+
373+
313374@cuda_and_cupy_available
314375@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
315376def test_ndvi_gpu (nir_data , red_data , qgis_ndvi ):
@@ -325,6 +386,7 @@ def test_savi_zero_soil_factor_cpu_against_qgis(nir_data, red_data, qgis_ndvi):
325386 general_output_checks (nir_data , qgis_savi , qgis_ndvi , verify_dtype = True )
326387
327388
389+ @cuda_and_cupy_available
328390@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
329391def test_savi_zero_soil_factor_gpu (nir_data , red_data , qgis_ndvi ):
330392 # savi should be same as ndvi at soil_factor=0
@@ -339,6 +401,13 @@ def test_savi_cpu_against_qgis(nir_data, red_data, qgis_savi):
339401 general_output_checks (nir_data , result , qgis_savi )
340402
341403
404+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
405+ def test_savi_uint_dtype (data_uint_dtype_savi ):
406+ nir_data , red_data , result_savi = data_uint_dtype_savi
407+ result = savi (nir_data , red_data )
408+ general_output_checks (nir_data , result , result_savi , verify_dtype = True )
409+
410+
342411@cuda_and_cupy_available
343412@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
344413def test_savi_gpu (nir_data , red_data , qgis_savi ):
@@ -354,6 +423,13 @@ def test_arvi_cpu_against_qgis(nir_data, red_data, blue_data, qgis_arvi):
354423 general_output_checks (nir_data , result , qgis_arvi )
355424
356425
426+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
427+ def test_arvi_uint_dtype (data_uint_dtype_arvi ):
428+ nir_data , red_data , blue_data , result_arvi = data_uint_dtype_arvi
429+ result = arvi (nir_data , red_data , blue_data )
430+ general_output_checks (nir_data , result , result_arvi , verify_dtype = True )
431+
432+
357433@cuda_and_cupy_available
358434@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
359435def test_arvi_gpu (nir_data , red_data , blue_data , qgis_arvi ):
@@ -368,6 +444,13 @@ def test_evi_cpu_against_qgis(nir_data, red_data, blue_data, qgis_evi):
368444 general_output_checks (nir_data , result , qgis_evi )
369445
370446
447+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
448+ def test_evi_uint_dtype (data_uint_dtype_evi ):
449+ nir_data , red_data , blue_data , result_evi = data_uint_dtype_evi
450+ result = evi (nir_data , red_data , blue_data )
451+ general_output_checks (nir_data , result , result_evi , verify_dtype = True )
452+
453+
371454@cuda_and_cupy_available
372455@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
373456def test_evi_gpu (nir_data , red_data , blue_data , qgis_evi ):
@@ -396,6 +479,13 @@ def test_sipi_cpu_against_qgis(nir_data, red_data, blue_data, qgis_sipi):
396479 general_output_checks (nir_data , result , qgis_sipi )
397480
398481
482+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
483+ def test_sipi_uint_dtype (data_uint_dtype_sipi ):
484+ nir_data , red_data , blue_data , result_sipi = data_uint_dtype_sipi
485+ result = sipi (nir_data , red_data , blue_data )
486+ general_output_checks (nir_data , result , result_sipi , verify_dtype = True )
487+
488+
399489@cuda_and_cupy_available
400490@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
401491def test_sipi_gpu (nir_data , red_data , blue_data , qgis_sipi ):
@@ -410,6 +500,13 @@ def test_nbr_cpu_against_qgis(nir_data, swir2_data, qgis_nbr):
410500 general_output_checks (nir_data , result , qgis_nbr )
411501
412502
503+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
504+ def test_nbr_uint_dtype (data_uint_dtype_normalized_ratio ):
505+ nir_data , red_data , result_nbr = data_uint_dtype_normalized_ratio
506+ result = nbr (nir_data , red_data )
507+ general_output_checks (nir_data , result , result_nbr , verify_dtype = True )
508+
509+
413510@cuda_and_cupy_available
414511@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
415512def test_nbr_gpu (nir_data , swir2_data , qgis_nbr ):
@@ -424,6 +521,13 @@ def test_nbr2_cpu_against_qgis(swir1_data, swir2_data, qgis_nbr2):
424521 general_output_checks (swir1_data , result , qgis_nbr2 )
425522
426523
524+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
525+ def test_nbr2_uint_dtype (data_uint_dtype_normalized_ratio ):
526+ nir_data , red_data , result_nbr2 = data_uint_dtype_normalized_ratio
527+ result = nbr2 (nir_data , red_data )
528+ general_output_checks (nir_data , result , result_nbr2 , verify_dtype = True )
529+
530+
427531@cuda_and_cupy_available
428532@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
429533def test_nbr2_gpu (swir1_data , swir2_data , qgis_nbr2 ):
@@ -438,6 +542,13 @@ def test_ndmi_cpu_against_qgis(nir_data, swir1_data, qgis_ndmi):
438542 general_output_checks (nir_data , result , qgis_ndmi )
439543
440544
545+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
546+ def test_ndmi_uint_dtype (data_uint_dtype_normalized_ratio ):
547+ nir_data , red_data , result_ndmi = data_uint_dtype_normalized_ratio
548+ result = ndmi (nir_data , red_data )
549+ general_output_checks (nir_data , result , result_ndmi , verify_dtype = True )
550+
551+
441552@cuda_and_cupy_available
442553@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
443554def test_ndmi_gpu (nir_data , swir1_data , qgis_ndmi ):
@@ -452,6 +563,13 @@ def test_ebbi_cpu_against_qgis(red_data, swir1_data, tir_data, qgis_ebbi):
452563 general_output_checks (red_data , result , qgis_ebbi )
453564
454565
566+ @pytest .mark .parametrize ("dtype" , ["uint8" , "uint16" ])
567+ def test_ebbi_uint_dtype (data_uint_dtype_ebbi ):
568+ red_data , swir_data , tir_data , result_ebbi = data_uint_dtype_ebbi
569+ result = ebbi (red_data , swir_data , tir_data )
570+ general_output_checks (red_data , result , result_ebbi , verify_dtype = True )
571+
572+
455573@cuda_and_cupy_available
456574@pytest .mark .parametrize ("backend" , ["cupy" , "dask+cupy" ])
457575def test_ebbi_gpu (red_data , swir1_data , tir_data , qgis_ebbi ):
0 commit comments