Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/sedona/spark/raster/sample_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def as_numpy(self, data_buffer: DataBuffer) -> np.ndarray:
if self.scanline_stride == self.width and self.pixel_stride == 1:
# Fast path: no gaps between pixels
band_arrs = []
for bank_index in self.bank_indices:
for k, bank_index in enumerate(self.bank_indices):
bank_data = data_buffer.bank_data[bank_index]
offset = self.band_offsets[bank_index]
offset = self.band_offsets[k]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we calculate the effective start here (data_buffer.offsets[bank_index] + self.band_offsets[k]) and always slice a width * height window? I may be missing an invariant, but a component model can have a zero band offset with a padded backing bank; then the current branch seems to pass the whole bank to reshape(). The slow path may need the buffer offset too. A zero-offset case in the new test would help confirm it.

if offset != 0:
bank_data = bank_data[offset : (offset + self.width * self.height)]
band_arr = bank_data.reshape(self.height, self.width)
Expand Down
47 changes: 47 additions & 0 deletions python/tests/raster/test_sample_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import numpy as np

from sedona.spark.raster.data_buffer import DataBuffer
from sedona.spark.raster.sample_model import ComponentSampleModel


def test_component_sample_model_fast_path_uses_band_offsets() -> None:
sample_model = ComponentSampleModel(
DataBuffer.TYPE_INT,
2,
2,
1,
2,
[1, 0],
[3, 1],
)
data_buffer = DataBuffer(
DataBuffer.TYPE_INT,
[
np.array([10, 11, 12, 13, 14, 15, 16]),
np.array([20, 21, 22, 23, 24, 25, 26]),
],
7,
[0, 0],
)

np.testing.assert_array_equal(
sample_model.as_numpy(data_buffer),
np.array([[[23, 24], [25, 26]], [[11, 12], [13, 14]]]),
)
Loading