@@ -579,7 +579,8 @@ def vegetation_roughness(
579579def _veg_roughness_nlcd_numpy (data , lut ):
580580 data = np .asarray (data )
581581 out = np .full (data .shape , np .nan , dtype = np .float64 )
582- mask = (data >= 0 ) & (data < len (lut )) & ~ np .isnan (data .astype (np .float64 ))
582+ not_nan = ~ np .isnan (data ) if data .dtype .kind == 'f' else True
583+ mask = (data >= 0 ) & (data < len (lut )) & not_nan
583584 idx = data [mask ].astype (np .intp )
584585 out [mask ] = lut [idx ]
585586 return out
@@ -590,8 +591,8 @@ def _veg_roughness_nlcd_cupy(data, lut):
590591 lut_gpu = cp .asarray (lut )
591592 data = cp .asarray (data )
592593 out = cp .full (data .shape , cp .nan , dtype = cp .float64 )
593- data_f = data . astype ( cp .float64 )
594- mask = (data >= 0 ) & (data < len (lut_gpu )) & ~ cp . isnan ( data_f )
594+ not_nan = ~ cp .isnan ( data ) if data . dtype . kind == 'f' else True
595+ mask = (data >= 0 ) & (data < len (lut_gpu )) & not_nan
595596 idx = data [mask ].astype (cp .intp )
596597 out [mask ] = lut_gpu [idx ]
597598 return out
@@ -732,12 +733,12 @@ def _veg_cn_numpy(lc, sg, lut):
732733 sg = np .asarray (sg )
733734 max_code , max_sg = lut .shape
734735 out = np .full (lc .shape , np .nan , dtype = np .float64 )
735- lc_f = lc . astype ( np .float64 )
736- sg_f = sg . astype ( np .float64 )
736+ lc_ok = ~ np .isnan ( lc ) if lc . dtype . kind == 'f' else True
737+ sg_ok = ~ np .isnan ( sg ) if sg . dtype . kind == 'f' else True
737738 mask = (
738739 (lc >= 0 ) & (lc < max_code )
739740 & (sg >= 0 ) & (sg < max_sg )
740- & ~ np . isnan ( lc_f ) & ~ np . isnan ( sg_f )
741+ & lc_ok & sg_ok
741742 )
742743 lc_idx = lc [mask ].astype (np .intp )
743744 sg_idx = sg [mask ].astype (np .intp )
@@ -752,12 +753,12 @@ def _veg_cn_cupy(lc, sg, lut):
752753 sg = cp .asarray (sg )
753754 max_code , max_sg = lut_gpu .shape
754755 out = cp .full (lc .shape , cp .nan , dtype = cp .float64 )
755- lc_f = lc . astype ( cp .float64 )
756- sg_f = sg . astype ( cp .float64 )
756+ lc_ok = ~ cp .isnan ( lc ) if lc . dtype . kind == 'f' else True
757+ sg_ok = ~ cp .isnan ( sg ) if sg . dtype . kind == 'f' else True
757758 mask = (
758759 (lc >= 0 ) & (lc < max_code )
759760 & (sg >= 0 ) & (sg < max_sg )
760- & ~ cp . isnan ( lc_f ) & ~ cp . isnan ( sg_f )
761+ & lc_ok & sg_ok
761762 )
762763 lc_idx = lc [mask ].astype (cp .intp )
763764 sg_idx = sg [mask ].astype (cp .intp )
0 commit comments