Code Monkey home page Code Monkey logo

Comments (6)

tgoelles avatar tgoelles commented on June 12, 2024 1

Ok, thanks a lot. When I read it with rioxarray or in QGIS or rastervision it works. I need to investigate this further. This should now make it possible for me to solve this and you can close the issue.

from torchgeo.

adamjstewart avatar adamjstewart commented on June 12, 2024

Hi @tgoelles! Congrats on your paper: https://doi.org/10.3389/frsen.2023.1156519. Our lab was recently in Austria for our winter school and I mentioned your group as one of our TorchGeo users.

from torchgeo.

adamjstewart avatar adamjstewart commented on June 12, 2024

I was able to reproduce this issue without using any sampler:

import rasterio
from torchgeo.datasets import BoundingBox, RasterDataset

path = "data/05_model_input/pre_processed_multiband.tif"

# Original data does not contain NaNs
f = rasterio.open(path)
ar = f.read()
print(ar)
print("NaNs:", (ar == f.nodata).sum())

# But it does when read by TorchGeo
ds = RasterDataset(path)
query = BoundingBox(558648, 559048, 5184009, 5184409, 0, 1e19)
sample = ds[query]
image = sample["image"]
print(image)
print("NaNs:", (image == f.nodata).sum().item())

Still investigating...

from torchgeo.

adamjstewart avatar adamjstewart commented on June 12, 2024

I suspect that there is something wrong with the file itself. TorchGeo just uses rasterio.merge.merge to read the file. When I try to open the file without using TorchGeo:

import rasterio.merge

path = "data/05_model_input/pre_processed_multiband.tif"
rasterio.merge.merge([path])

I encounter the following error:

Traceback (most recent call last):
  File "/Users/Adam/torchgeo/test2.py", line 4, in <module>
    rasterio.merge.merge([path])
  File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.11/site-packages/rasterio/merge.py", line 344, in merge
    dst_window = windows.from_bounds(
                 ^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.11/site-packages/rasterio/windows.py", line 324, in from_bounds
    raise WindowError("Bounds and transform are inconsistent")
rasterio.errors.WindowError: Bounds and transform are inconsistent

How was the file created?

from torchgeo.

tgoelles avatar tgoelles commented on June 12, 2024

Hi,

Hi @tgoelles! Congrats on your paper: https://doi.org/10.3389/frsen.2023.1156519. Our lab was recently in Austria for our winter school and I mentioned your group as one of our TorchGeo users.

Thanks! Also for your quick answer.

Here is how the geotiff is generated. Its generated with rioxarray:

def export_to_multiband_geotiff(master_dataset: xarray.Dataset, paramters: dict) -> str:
    model_input_path = Path("/workspaces/avalanche/project/data/05_model_input")
    save_path = model_input_path / f"pre_processed_multiband.tif"

    bands_stack = xarray.concat([master_dataset["vv"], master_dataset["vh"], master_dataset["vvvh"]], dim="band")
    bands_stack = bands_stack.assign_coords(band=("band", ["vv", "vh", "vvvh"]))

    LOG.info(f"Saving multiband data to {save_path}")
    bands_stack = bands_stack.rio.write_crs(master_dataset.rio.crs)

    nodata_value = paramters["master_options"]["geotiff_nodata"]
    LOG.info(f"Setting nodata value to {nodata_value}")
    bands_stack.rio.write_nodata(nodata_value, inplace=True)
    bands_stack.rio.to_raster(save_path)

    return save_path.as_posix()

from torchgeo.

adamjstewart avatar adamjstewart commented on June 12, 2024

Could possibly be a bug in rioxarray. Might be worth reporting to them or to rasterio to see where the issue is. It doesn't seem to be a bug in TorchGeo though.

from torchgeo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.