centreborelli / s2p

Satellite Stereo Pipeline
GNU Affero General Public License v3.0
190 stars 67 forks source link

s2p ValueError: Number of columns or rows must be non-negative - with small tile_size (~<2000) #122

Open Vierod opened 2 years ago

Vierod commented 2 years ago

Get the following error when attempting to process a relatively large area of Pleiades triples (2x 3):

s2p ValueError: Number of columns or rows must be non-negative

Roots back to rasterio/windows.py validate_length_values.

EDIT - Full output:

Exception in pointing_correction
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/s2p/parallel.py", line 43, in tilewise_wrapper
    out = fun(*args)
  File "/usr/local/lib/python3.7/dist-packages/s2p/__init__.py", line 67, in pointing_correction
    cfg['sift_match_thresh'], cfg['max_pointing_error']
  File "/usr/local/lib/python3.7/dist-packages/s2p/pointing_accuracy.py", line 125, in compute_correction
    method, sift_thresh, epipolar_threshold)
  File "/usr/local/lib/python3.7/dist-packages/s2p/sift.py", line 272, in matches_on_rpc_roi
    p2 = image_keypoints(im2, x2, y2, w2, h2, thresh_dog=thresh_dog)
  File "/usr/local/lib/python3.7/dist-packages/s2p/sift.py", line 112, in image_keypoints
    in_buffer = ds.read(window=rio.windows.Window(x, y, w, h))
  File "<attrs generated init rasterio.windows.Window>", line 8, in __init__
    __attr_validator_width(self, __attr_width, self.width)
  File "/usr/local/lib/python3.7/dist-packages/rasterio/windows.py", line 512, in validate_length_value
    raise ValueError("Number of columns or rows must be non-negative")
ValueError: Number of columns or rows must be non-negative

Happens specifically if I use a lower tile window size, raising the tile size to 2000 fixes it so I'm guessing it might be something to do with empty blocks but unsure. Running fine now but thought I'd raise this, can provide more detail if useful.

Thanks, Alex

gfacciol commented 2 years ago

Thanks Alex, From the stack trace it seems that the sift that is applied on the "corresponding_roi" (line 272), is actually trying to read a tile outside of the image domain that's why rasterio is returning the error

https://github.com/centreborelli/s2p/blob/ca589efeeefceb2dfddaa375365a5905bedfcb5a/s2p/sift.py#L261-L276

We should fix that.

Vierod commented 2 years ago

Is there anything I can do to help? I can't share the actual imagery but I could share something of the same dimensions and the RPC info if required. Specifically it's two sets of three images that overlap, one of the sets is just a small corner of the scene, the other three images are much larger covering most of the scene (maybe like 90%+).

carlodef commented 2 years ago

Hi @Vierod, this error usually happens when the input ROI is not entirely contained in the reference input image. Could you please share your input config.json and the dimensions of the images?

When the tile size is large enough, all tiles intersect the reference image. But with a smaller tile size, you may have a tile that is completely outside of the reference image, and this is what triggers the error.