|
1 | 1 | # async-tiff
|
2 | 2 |
|
3 |
| -<!-- [![PyPI][pypi_badge]][pypi_link] |
| 3 | +[![PyPI][pypi_badge]][pypi_link] |
4 | 4 |
|
5 |
| -[pypi_badge]: https://badge.fury.io/py/geoindex-rs.svg |
6 |
| -[pypi_link]: https://pypi.org/project/geoindex-rs/ --> |
| 5 | +[pypi_badge]: https://badge.fury.io/py/async-tiff.svg |
| 6 | +[pypi_link]: https://pypi.org/project/async-tiff/ |
7 | 7 |
|
8 |
| -Fast, async TIFF and GeoTIFF reader for Python. |
| 8 | +Fast, low-level async TIFF and GeoTIFF reader for Python. |
9 | 9 |
|
10 |
| -<!-- This documentation is for the Python bindings. [Refer here for the Rust crate documentation](https://docs.rs/geo-index). --> |
| 10 | +This documentation is for the Python bindings. [Refer here for the Rust crate documentation](https://docs.rs/async-tiff). |
| 11 | + |
| 12 | +## Examples |
| 13 | + |
| 14 | +### Reading NAIP |
| 15 | + |
| 16 | +```py |
| 17 | +from async_tiff import TIFF |
| 18 | +from async_tiff.store import S3Store |
| 19 | + |
| 20 | +# You'll also need to provide credentials to access a requester pays bucket |
| 21 | +store = S3Store("naip-visualization", region="us-west-2", request_payer=True) |
| 22 | +path = "ny/2022/60cm/rgb/40073/m_4007307_sw_18_060_20220803.tif" |
| 23 | + |
| 24 | +tiff = await TIFF.open(path, store=store, prefetch=32768) |
| 25 | +primary_ifd = tiff.ifds[0] |
| 26 | + |
| 27 | +primary_ifd.geo_key_directory.citation |
| 28 | +# 'NAD83 / UTM zone 18N' |
| 29 | + |
| 30 | +primary_ifd.geo_key_directory.projected_type |
| 31 | +# 26918 |
| 32 | +# (EPSG code) |
| 33 | + |
| 34 | +primary_ifd.sample_format |
| 35 | +# [<SampleFormat.Uint: 1>, <SampleFormat.Uint: 1>, <SampleFormat.Uint: 1>] |
| 36 | + |
| 37 | +primary_ifd.bits_per_sample |
| 38 | +# [8, 8, 8] |
| 39 | + |
| 40 | +tile = await tiff.fetch_tile(0, 0, 4) |
| 41 | +decoded_bytes = await tile.decode_async() |
| 42 | + |
| 43 | +# Use rasterio and matplotlib for visualization |
| 44 | +import numpy as np |
| 45 | +from rasterio.plot import reshape_as_raster, show |
| 46 | + |
| 47 | +# Wrap the rust buffer into a numpy array |
| 48 | +arr = np.frombuffer(decoded_bytes, np.uint8) |
| 49 | + |
| 50 | +# We first need to reshape the array into the *existing* "image" axes |
| 51 | +arr = arr.reshape(512, 512, 3) |
| 52 | + |
| 53 | +# Then we need to reshape the "image" axes into "raster" axes |
| 54 | +# https://rasterio.readthedocs.io/en/stable/topics/image_processing.html |
| 55 | +arr = reshape_as_raster(arr) |
| 56 | +show(arr, adjust=True) |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +### Reading Sentinel 2 L2A |
| 63 | + |
| 64 | +```py |
| 65 | +from async_tiff import TIFF |
| 66 | +from async_tiff.store import S3Store |
| 67 | + |
| 68 | +store = S3Store("sentinel-cogs", region="us-west-2", skip_signature=True) |
| 69 | +path = "sentinel-s2-l2a-cogs/12/S/UF/2022/6/S2B_12SUF_20220609_0_L2A/B04.tif" |
| 70 | + |
| 71 | +tiff = await TIFF.open(path, store=store, prefetch=32768) |
| 72 | +primary_ifd = tiff.ifds[0] |
| 73 | +# Text readable citation |
| 74 | +primary_ifd.geo_key_directory.citation |
| 75 | +# EPSG code |
| 76 | +primary_ifd.geo_key_directory.projected_type |
| 77 | + |
| 78 | +primary_ifd.sample_format[0] |
| 79 | +# <SampleFormat.Uint: 1> |
| 80 | +primary_ifd.bits_per_sample[0] |
| 81 | +# 16 |
| 82 | + |
| 83 | +tile = await tiff.fetch_tile(0, 0, 0) |
| 84 | +decoded_bytes = await tile.decode_async() |
| 85 | +``` |
11 | 86 |
|
0 commit comments