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

Update utils.py #2395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update utils.py #2395

wants to merge 1 commit into from

Conversation

lvxiaojie111
Copy link

fix the bug!
when running code:
dataset = naip & chesapeake
from https://torchgeo.readthedocs.io/en/stable/tutorials/getting_started.html;
it generates an err:
ValueError: Bounding boxes BoundingBox(minx=440055.0, maxx=446085.0, miny=4295910.600000001, maxy=4303429.2, mint=1541260800.0, maxt=1541347199.999999) and BoundingBox(minx=402172.2959946942, maxx=532531.001762003, miny=4244077.01658443, maxy=4414067.523828775, mint=1356969600.0, maxt=1388505599.999999) do not overlap.

This new request fix the err .

fix the bug!
when running "dataset = naip & chesapeake" from https://torchgeo.readthedocs.io/en/stable/tutorials/getting_started.html;  it generates an err: ValueError: Bounding boxes BoundingBox(minx=440055.0, maxx=446085.0, miny=4295910.600000001, maxy=4303429.2, mint=1541260800.0, maxt=1541347199.999999) and BoundingBox(minx=402172.2959946942, maxx=532531.001762003, miny=4244077.01658443, maxy=4414067.523828775, mint=1356969600.0, maxt=1388505599.999999) do not overlap.

This new request  fix the err .
@github-actions github-actions bot added the datasets Geospatial or benchmark datasets label Nov 6, 2024
Copy link
Collaborator

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

  1. I am unable to reproduce the issue you reported, the tutorials all pass
  2. The fix is incorrect, you are performing a union, not an intersection

@lvxiaojie111
Copy link
Author

lvxiaojie111 commented Nov 6, 2024 via email

@lvxiaojie111
Copy link
Author

  1. I am unable to reproduce the issue you reported, the tutorials all pass
  2. The fix is incorrect, you are performing a union, not an intersection
def __and__(self, other: BoundingBox) -> BoundingBox:
    """The intersection operator.

    Args:
        other: another bounding box

    Returns:
        the intersection of self and other

    Raises:
        ValueError: if self and other do not intersect

    .. versionadded:: 0.2
    """
    try:
        print("**************begin******************************")
        print(max(self.minx, other.minx))
        print(min(self.maxx, other.maxx))
        print(max(self.miny, other.miny))
        print(min(self.maxy, other.maxy))
        print(max(self.mint, other.mint))
        print(min(self.maxt, other.maxt))
        print("**************end********************************")
        return BoundingBox(
            max(self.minx, other.minx),
            min(self.maxx, other.maxx),
            max(self.miny, other.miny),
            min(self.maxy, other.maxy),
            # max(self.mint, other.mint),
            # min(self.maxt, other.maxt),
            # 更改 时间 最小值和最大值
            min(self.mint, other.mint),
            max(self.maxt, other.maxt),
        #     445390.2,
        # 451507.8,
        # 4288884.0,
        # 4296510.6,
        # 1388505599.999999,1534262400.0,

            
            
        )
    except ValueError:
        # pass
        raise ValueError(f'Bounding boxes {self} and {other} do not overlap')

the above code:

  1. Whether it is a union or an intersection, the time should be from small to large, and there is no time in reverse order.
  2. In the intersection operation, when comparing the times, whether there is a problem of becoming a negative number,
  3. I think this is not just a syntax error, it is a principle error.
  4. please think carefully.

@adamjstewart
Copy link
Collaborator

Can you tell me how to reproduce the error you are reporting? When I run the tutorial on Google Colab everything runs without issue. Did you modify the tutorial in any way?

@lvxiaojie111
Copy link
Author

Can you tell me how to reproduce the error you are reporting? When I run the tutorial on Google Colab everything runs without issue. Did you modify the tutorial in any way?

`import os
import tempfile
import time
import planetary_computer
from torch.utils.data import DataLoader

from torchgeo.datasets import NAIP, ChesapeakeDE, stack_samples
from torchgeo.datasets.utils import download_url
from torchgeo.samplers import RandomGeoSampler

naip_root = os.path.join(tempfile.gettempdir(), 'naip')

naip_url = (
'https://naipeuwest.blob.core.windows.net/naip/v002/de/2018/de_060cm_2018/38075/'
)

tiles = [
'm_3807511_ne_18_060_20181104.tif',
'm_3807511_se_18_060_20181104.tif',
'm_3807512_nw_18_060_20180815.tif',
'm_3807512_sw_18_060_20180815.tif',
]

for tile in tiles:
url = planetary_computer.sign(naip_url + tile)
download_url(url, naip_root, filename=tile)

naip = NAIP(naip_root)

chesapeake_root = os.path.join(tempfile.gettempdir(), 'chesapeake')
os.makedirs(chesapeake_root, exist_ok=True)

chesapeake = ChesapeakeDE(chesapeake_root, crs=naip.crs, res=naip.res, download=True)

dataset = naip & chesapeake

`
environment:
torchgeo==0.6.1
torch==2.5.0
plat==window
python==3.10.0

@adamjstewart
Copy link
Collaborator

I'm not able to reproduce the error, and all of the tests are failing with this change. Can you try to reproduce the error on Google Colab?

@adamjstewart
Copy link
Collaborator

@lvxiaojie111 are you still seeing this issue? If so, how can I reproduce it? If not, then maybe we can close this PR.

@lvxiaojie111
Copy link
Author

@lvxiaojie111 are you still seeing this issue? If so, how can I reproduce it? If not, then maybe we can close this PR.

I can only reproduce this problem on Windows. I'm trying to figure out how to reproduce this problem for you.

@adamjstewart
Copy link
Collaborator

I'm also not able to reproduce the problem on Windows: https://github.com/microsoft/torchgeo/actions/runs/11931373820/job/33254106741?pr=2419

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

Successfully merging this pull request may close these issues.

2 participants