Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntersectionDataset: better error message when no overlap #1192

Merged
merged 3 commits into from
Mar 29, 2023

Conversation

adamjstewart
Copy link
Collaborator

To illustrate why this is needed, create two directories containing non-overlapping images, and run the following script:

from torch.utils.data import DataLoader

from torchgeo.datasets import Landsat8
from torchgeo.samplers import RandomGeoSampler

bands = ["B1", "B2", "B3"]

ds1 = Landsat8("data/dir1", bands=bands)
ds2 = Landsat8("data/dir2", bands=bands)

ds = ds1 & ds2
rs = RandomGeoSampler(ds, 256, 10)
dl = DataLoader(ds, sampler=rs)
for batch in dl:
    pass

Before

The previous error message was completely useless, and led to much confusion due to Toblerity/rtree#204:

Traceback (most recent call last):
  File "/Users/Adam/torchgeo/test.py", line 12, in <module>
    rs = RandomGeoSampler(ds, 256, 10)
  File "/Users/Adam/torchgeo/torchgeo/samplers/single.py", line 102, in __init__
    super().__init__(dataset, roi)
  File "/Users/Adam/torchgeo/torchgeo/samplers/single.py", line 37, in __init__
    roi = BoundingBox(*self.index.bounds)
  File "<string>", line 9, in __init__
  File "/Users/Adam/torchgeo/torchgeo/datasets/utils.py", line 246, in __post_init__
    raise ValueError(
ValueError: Bounding box is invalid: 'minx=1.7976931348623157e+308' > 'maxx=-1.7976931348623157e+308'

After

We now raise an error immediately when trying to compute the intersection with a clear and concise error message:

Traceback (most recent call last):
  File "/Users/Adam/torchgeo/test.py", line 11, in <module>
    ds = ds1 & ds2
  File "/Users/Adam/torchgeo/torchgeo/datasets/geo.py", line 134, in __and__
    return IntersectionDataset(self, other)
  File "/Users/Adam/torchgeo/torchgeo/datasets/geo.py", line 845, in __init__
    self._merge_dataset_indices()
  File "/Users/Adam/torchgeo/torchgeo/datasets/geo.py", line 859, in _merge_dataset_indices
    raise RuntimeError("Datasets have no spatiotemporal intersection")
RuntimeError: Datasets have no spatiotemporal intersection

Thanks to @TolgaAktas for reporting this!

@adamjstewart adamjstewart added this to the 0.4.1 milestone Mar 23, 2023
@github-actions github-actions bot added datasets Geospatial or benchmark datasets testing Continuous integration testing labels Mar 23, 2023
isaaccorley
isaaccorley previously approved these changes Mar 23, 2023
pmandiola
pmandiola previously approved these changes Mar 24, 2023
Copy link
Contributor

@pmandiola pmandiola left a comment

Choose a reason for hiding this comment

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

Looks ok to me! Makes a lot of sense to raise this no overlapping exception too.

@adamjstewart adamjstewart merged commit 0a5e1d9 into main Mar 29, 2023
@adamjstewart adamjstewart deleted the datasets/better-intersect-error branch March 29, 2023 01:27
calebrob6 pushed a commit that referenced this pull request Apr 10, 2023
* IntersectionDataset: better error message when no overlap

* Update split tests

* Document error
yichiac pushed a commit to yichiac/torchgeo that referenced this pull request Apr 29, 2023
…1192)

* IntersectionDataset: better error message when no overlap

* Update split tests

* Document error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasets Geospatial or benchmark datasets testing Continuous integration testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants