Closed mx-moth closed 10 months ago
Constructing a DataArray where the first dimension has a size of 0 is possible if you do it explicitly:
xarray.DataArray(
data=numpy.zeros(shape=(0, 2)),
dims=['segment', 'bounds'],
)
Constructing a multi-dimensional DataArray from an iterator with size 0 can be done properly if everything is explicit:
xarray.DataArray(
data=numpy.fromiter(
((left, right) for left, right in self.segments),
count=len(self.segments),
dtype=numpy.dtype((float, 2)),
),
dims=['segments', 'bounds'],
)
Currently a cryptic error message is raised when constructing the distance bounds data array.
Detecting this case is as simple as intersecting the line with the dataset, or checking if the
Transect.segments
list is empty.The solution is either to generate an empty transect plot, or to raise a EmptyTransect error. Neither option is clearly preferable to the other.