Skip to content

Commit 73adace

Browse files
committed
Update python bindings
1 parent 00a6e72 commit 73adace

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

python/Cargo.lock

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from async_tiff.store import S3Store
2121
store = S3Store("naip-visualization", region="us-west-2", request_payer=True)
2222
path = "ny/2022/60cm/rgb/40073/m_4007307_sw_18_060_20220803.tif"
2323

24-
tiff = await TIFF.open(path, store=store, prefetch=32768)
24+
tiff = await TIFF.open(path, store=store)
2525
primary_ifd = tiff.ifds[0]
2626

2727
primary_ifd.geo_key_directory.citation
@@ -68,7 +68,7 @@ from async_tiff.store import S3Store
6868
store = S3Store("sentinel-cogs", region="us-west-2", skip_signature=True)
6969
path = "sentinel-s2-l2a-cogs/12/S/UF/2022/6/S2B_12SUF_20220609_0_L2A/B04.tif"
7070

71-
tiff = await TIFF.open(path, store=store, prefetch=32768)
71+
tiff = await TIFF.open(path, store=store)
7272
primary_ifd = tiff.ifds[0]
7373
# Text readable citation
7474
primary_ifd.geo_key_directory.citation

python/python/async_tiff/_tiff.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ class TIFF:
1717
*,
1818
store: ObjectStore | ObspecInput,
1919
prefetch: int = 32768,
20+
multiplier: int | float = 2.0,
2021
) -> TIFF:
2122
"""Open a new TIFF.
2223
2324
Args:
2425
path: The path within the store to read from.
2526
store: The backend to use for data fetching.
2627
prefetch: The number of initial bytes to read up front.
28+
multiplier: The multiplier to use for readahead size growth. Must be
29+
greater than 1.0. For example, for a value of `2.0`, the first metadata
30+
read will be of size `prefetch`, and then the next read will be of size
31+
`prefetch * 2`.
2732
2833
Returns:
2934
A TIFF instance.

python/src/tiff.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::sync::Arc;
22

3-
use async_tiff::metadata::{PrefetchBuffer, TiffMetadataReader};
3+
use async_tiff::metadata::cache::ReadaheadMetadataCache;
4+
use async_tiff::metadata::TiffMetadataReader;
45
use async_tiff::reader::AsyncFileReader;
56
use async_tiff::TIFF;
6-
use pyo3::exceptions::{PyFileNotFoundError, PyIndexError, PyTypeError};
7+
use pyo3::exceptions::{PyIndexError, PyTypeError};
78
use pyo3::prelude::*;
89
use pyo3::types::PyType;
910
use pyo3_async_runtimes::tokio::future_into_py;
@@ -21,20 +22,21 @@ pub(crate) struct PyTIFF {
2122
#[pymethods]
2223
impl PyTIFF {
2324
#[classmethod]
24-
#[pyo3(signature = (path, *, store, prefetch=32768))]
25+
#[pyo3(signature = (path, *, store, prefetch=32768, multiplier=2.0))]
2526
fn open<'py>(
2627
_cls: &'py Bound<PyType>,
2728
py: Python<'py>,
2829
path: String,
2930
store: StoreInput,
3031
prefetch: u64,
32+
multiplier: f64,
3133
) -> PyResult<Bound<'py, PyAny>> {
3234
let reader = store.into_async_file_reader(path);
3335

3436
let cog_reader = future_into_py(py, async move {
35-
let metadata_fetch = PrefetchBuffer::new(reader.clone(), prefetch)
36-
.await
37-
.map_err(|err| PyFileNotFoundError::new_err(err.to_string()))?;
37+
let metadata_fetch = ReadaheadMetadataCache::new(reader.clone())
38+
.with_initial_size(prefetch)
39+
.with_multiplier(multiplier);
3840
let mut metadata_reader = TiffMetadataReader::try_open(&metadata_fetch).await.unwrap();
3941
let ifds = metadata_reader
4042
.read_all_ifds(&metadata_fetch)

python/tests/test_cog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def test_cog_s3():
1111
"""
1212
path = "sentinel-s2-l2a-cogs/12/S/UF/2022/6/S2B_12SUF_20220609_0_L2A/B04.tif"
1313
store = S3Store("sentinel-cogs", region="us-west-2", skip_signature=True)
14-
tiff = await TIFF.open(path=path, store=store, prefetch=32768)
14+
tiff = await TIFF.open(path=path, store=store)
1515

1616
ifds = tiff.ifds
1717
assert len(ifds) == 5

0 commit comments

Comments
 (0)