Skip to content

cumulative_viewshed and visibility_frequency raise TypeError on cupy-backed rasters #3192

@brendancol

Description

@brendancol

cumulative_viewshed allocates its count accumulator as a numpy array on the non-dask path, even when the raster is cupy-backed. viewshed() returns a cupy DataArray for cupy input, so this line adds numpy to cupy and raises TypeError: Unsupported type numpy.ndarray:

count = count + (vs_data != INVISIBLE).astype(np.int32)

visibility_frequency delegates to cumulative_viewshed, so it fails the same way.

Repro:

import numpy as np, xarray as xr, cupy
from xrspatial.visibility import cumulative_viewshed
data = np.random.RandomState(42).rand(15, 15).astype(float) * 100
r = xr.DataArray(data, dims=['y', 'x'],
                 coords={'y': np.arange(15.), 'x': np.arange(15.)})
r.data = cupy.asarray(data)
cumulative_viewshed(r, [{'x': 7.0, 'y': 7.0, 'observer_elev': 50}])  # TypeError

A flat raster fails earlier inside viewshed for an unrelated reason (OptiX needs positive elevation variance), so the repro uses random terrain.

The fix should allocate count with the same array module as raster.data, or pull vs_data to numpy before accumulating.

Found by the test-coverage sweep. The test PR adds a strict xfail that must be removed when this is fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions