Skip to content

WIP: Add functionality to virtualize GeoTIFFs using async_tiff #524

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

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

maxrjones
Copy link
Member

This PR is a new attempt to refactor the TIFFVirtualBackend to use async_tiff (closes #291) (would supersede #295, #297, #292)

  • Closes #xxxx
  • Tests added
  • Tests passing
  • Full type hint coverage
  • Changes are documented in docs/releases.rst
  • New functions/methods are listed in api.rst
  • New functionality has documentation

Copy link
Member

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

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

This looks really nice already - ManifestStore paying off!


from xarray import Dataset, Index
import dataclasses
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to be used in this file? (and the linter should have detected that...)

Comment on lines 13 to 30
@dataclasses.dataclass
class ZstdProperties:
level: int


@dataclasses.dataclass
class ShuffleProperties:
elementsize: int


@dataclasses.dataclass
class ZlibProperties:
level: int


class CFCodec(TypedDict):
target_dtype: np.dtype
codec: Codec
Copy link
Member

Choose a reason for hiding this comment

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

This stuff probably deserves to be in a dedicated codecs.py file (which I think we already have?

virtual_backend_kwargs: Optional[dict] = None,
reader_options: Optional[dict] = None,
) -> xr.Dataset:
raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

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

Once I've merged #522 I think we will be able to enable this reader immediately.

Comment on lines +158 to +159
newargs = object_store.__getnewargs_ex__()
at_store = ATStore(*newargs[0], **newargs[1])
Copy link
Member

Choose a reason for hiding this comment

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

deserves a comment to explain whatever this is!

Comment on lines +96 to +99
if not ifd.tile_height or not ifd.tile_width:
raise NotImplementedError(
f"TIFF reader currently only supports tiled TIFFs, but {path} has no internal tiling."
)
Copy link
Member

Choose a reason for hiding this comment

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

Possibly ignorant question, but can't we represent a non-tiled TIFF as a single virtual chunk?

Copy link
Member Author

Choose a reason for hiding this comment

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

there are three categories:

  • no chunks (yes, would map to a single virtual chunk)
  • tiled TIFFs (as implemented)
  • striped TIFFs (basically only chunked along the y dimension

None of these are hard to represent as a manifest array, but it's just a matter of finding/using the proper tags to determine the chunk structure

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do the striped TIFFs have compression applied independently along each line?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, striped as single lines or in a group, same as any other tiling

Comment on lines +100 to +101
chunks = (ifd.tile_height, ifd.tile_height)
shape = (ifd.image_height, ifd.image_width)
Copy link
Member

Choose a reason for hiding this comment

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

This is so neat

codec_configs = [
numcodec_config_to_configurable(codec.get_config()) for codec in codecs
]
dimension_names = ("y", "x") # Folllowing rioxarray's behavior
Copy link
Member

Choose a reason for hiding this comment

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

Probably worth noting this in a public docstring somewhere

Comment on lines +23 to +24
with xr.tutorial.open_dataset("air_temperature") as ds:
ds.isel(time=0).rio.to_raster(filepath, driver="COG", COMPRESS="DEFLATE")
Copy link
Member

Choose a reason for hiding this comment

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

I like that you've been able to test this without adding data to the repo

assert isinstance(ds, xr.Dataset)
expected = rioxarray.open_rasterio(geotiff_file).data.squeeze()
observed = ds["0"].data.squeeze()
np.testing.assert_allclose(observed, expected)
Copy link
Member

Choose a reason for hiding this comment

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

Can you not use xarray.testing.assert_allclose?

Co-authored-by: Tom Nicholas <tom@earthmover.io>
@maxrjones maxrjones mentioned this pull request Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request readers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

open_virtual_dataset fails to open tiffs
4 participants