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

RandomGeoSampler does not work with flipped geotifs #1746

Open
tanpinquan opened this issue Nov 28, 2023 · 2 comments
Open

RandomGeoSampler does not work with flipped geotifs #1746

tanpinquan opened this issue Nov 28, 2023 · 2 comments
Labels
datasets Geospatial or benchmark datasets

Comments

@tanpinquan
Copy link

tanpinquan commented Nov 28, 2023

Description

Certain geotifs have their axes flipped such as this one, which has the following transform flipping the direction of the x-axis:
Affine(-0.346241067933152, 0.2915401535597796, 366317.96341952495, 0.2915401535597782, 0.3462410679331555, 130406.04105973356).

Depending on the transform, I believe this affects how random bounding boxes bounds should be ordered . For the example geotif above with x-axis flipped, this line maybe should be bounds = (query.maxx, query.miny, query.minx, query.maxy) instead of bounds = (query.minx, query.miny, query.maxx, query.maxy). I have not tested it myself.

RandomGeoSampler and RasterDataset do not check for this, resulting in a Bounds and transform are inconsistent error

Steps to reproduce

  1. Download the sample data from here
  2. Run the following code to reproduce
from torch.utils.data import DataLoader
from torchgeo.datasets import RasterDataset
from torchgeo.samplers import RandomGeoSampler
   
   
class UmbraDataset(RasterDataset):

   # umbra tifs are named like: 2023-08-02-17-08-40_UMBRA-05_GEC.tif
   filename_glob = '*.tif'
   filename_regex = r"^(?P<date>\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2})"
   date_format = "%Y-%m-%d-%H-%M-%S"
   is_image = True
   separate_files = False 
   

dataset = UmbraDataset('/path/to/data/')

sampler = RandomGeoSampler(dataset, size=512, length=None)
dataloader = DataLoader(dataset, sampler=sampler, batch_size=2)

for i, batch in enumerate(dataloader):
   sample = batch

Version

0.5.1

@adamjstewart adamjstewart added the datasets Geospatial or benchmark datasets label Nov 30, 2023
@adamjstewart
Copy link
Collaborator

I'm able to reproduce this bug. @nilsleh this reminds me of a bug you had when working on rioxarray support.

I wonder if we could use something like min(query.minx, query.maxx) and max(query.minx, query.maxx) to solve this problem. But I'm not sure where all we would need to put it.

@nilsleh
Copy link
Collaborator

nilsleh commented Nov 30, 2023

For rioxarray support I encountered .nc files where the latitude and longitude coordinates were sometimes from -90 -> 90 or vice versa etc, but I think I handled that by sorting them to a common structure when reading the xarray.

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

No branches or pull requests

3 participants