跳转到主要内容

在Rasterio中检查HEAD/LIST/GET请求

项目描述

tilebench

tilebench

在Rasterio中检查HEAD/LIST/GET请求

Test Coverage Package version Downloads Downloads


源代码: https://github.com/developmentseed/tilebench


在Rasterio中检查HEAD/GET请求。

注意:在GDAL 3.2中,为/vsicurl, /vsis3等添加了日志功能(参考: https://github.com/OSGeo/gdal/pull/2742)。

安装

您可以使用pip安装tilebench

$ python -m pip install -U pip
$ python -m pip install -U tilebench

或从源代码安装

git clone https://github.com/developmentseed/tilebench.git
cd tilebench

python -m pip install -U pip
python -m pip install -e .

API

from tilebench import profile
import rasterio

[@profile](https://github.com/profile)()
def info(src_path: str):
    with rasterio.open(src_path) as src_dst:
        return src_dst.meta

meta = info("https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif")

> 2023-10-18T23:00:11.184745+0200 | TILEBENCH | {"HEAD": {"count": 1}, "GET": {"count": 1, "bytes": 32768, "ranges": ["0-32767"]}, "Timing": 0.7379939556121826}
from tilebench import profile
from rio_tiler.io import Reader

[@profile](https://github.com/profile)()
def _read_tile(src_path: str, x: int, y: int, z: int, tilesize: int = 256):
    with Reader(src_path) as cog:
        return cog.tile(x, y, z, tilesize=tilesize)

img = _read_tile(
    "https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif",
    9114,
    13216,
    15,
)

> 2023-10-18T23:01:00.572263+0200 | TILEBENCH | {"HEAD": {"count": 1}, "GET": {"count": 2, "bytes": 409600, "ranges": ["0-32767", "32768-409599"]}, "Timing": 1.0749869346618652}

命令行界面(CLI)

$ tilebench --help
Usage: tilebench [OPTIONS] COMMAND [ARGS]...

  Command line interface for the tilebench Python package.

Options:
  --help  Show this message and exit.

Commands:
  get-zooms  Get Mercator Zoom levels.
  profile    Profile COGReader Mercator Tile read.
  random     Get random tile.
  viz        WEB UI to visualize VSI statistics for a web mercator tile request

示例

$ tilebench get-zooms https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif | jq
{
  "minzoom": 14,
  "maxzoom": 19
}

$ tilebench random https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif --zoom 15
15-9114-13215

$ tilebench profile https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif --tile 15-9114-13215 --config GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR | jq
{
  "HEAD": {
    "count": 1
  },
  "GET": {
    "count": 2,
    "bytes": 409600,
    "ranges": [
      "0-32767",
      "32768-409599"
    ]
  },
  "Timing": 0.9715230464935303
}

$ tilebench profile https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif --tile 15-9114-13215 --config GDAL_DISABLE_READDIR_ON_OPEN=FALSE | jq
{
  "HEAD": {
    "count": 8
  },
  "GET": {
    "count": 3,
    "bytes": 409600,
    "ranges": [
      "0-32767",
      "32768-409599"
    ]
  },
  "Timing": 2.1837549209594727
}

Starlette中间件

警告: 这是非常实验性的,不应该在生产中使用 (https://github.com/developmentseed/tilebench/issues/6)

除了viz CLI,我们还添加了一个Starlette中间件,以便轻松地将VSI统计信息集成到您的Web服务中。

from fastapi import FastAPI

from tilebench.middleware import VSIStatsMiddleware

app = FastAPI()
app.add_middleware(VSIStatsMiddleware)

中间件将在响应的headers中添加一个vsi-stats条目,格式如下:

vsi-stats: list;count=1, head;count=1, get;count=2;size=196608, ranges; values=0-65535|65536-196607

某些路径可以通过exclude_paths参数排除,不经过中间件处理。

app.add_middleware(VSIStatsMiddleware, exclude_paths=["/foo", "/bar"])

GDAL配置选项

  • CPL_TIMESTAMP:在GDAL日志中添加计时信息
  • GDAL_DISABLE_READDIR_ON_OPEN:允许或禁用目录中文件的列表(例如外部概述)
  • GDAL_INGESTED_BYTES_AT_OPEN:控制GDAL在打开数据集时将摄入多少字节(当文件头很大时很有用)
  • CPL_VSIL_CURL_ALLOWED_EXTENSIONS:限制有效的外部文件
  • GDAL_CACHEMAX:缓存大小
  • GDAL_HTTP_MERGE_CONSECUTIVE_RANGES
  • VSI_CACHE
  • VSI_CACHE_SIZE

完整列表请参阅https://gdal.org/user/configoptions.html

内部瓦片与墨卡托网格

$ tilebench viz https://noaa-eri-pds.s3.amazonaws.com/2022_Hurricane_Ian/20221002a_RGB/20221002aC0795145w325100n.tif --config GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR

蓝色线条代表特定缩放级别的墨卡托网格,红色线条代表内部瓦片的边界

然后我们可以点击墨卡托瓦片,查看GDAL/RASTERIO做了多少请求。

Docker

可用的Docker镜像可以在GitHub仓库中找到。

docker run \
  --volume "$PWD":/data \
  --platform linux/amd64 \
  --rm -it -p 8080:8080 ghcr.io/developmentseed/tilebench:latest \
  tilebench viz --host 0.0.0.0 https://noaa-eri-pds.s3.us-east-1.amazonaws.com/2020_Nashville_Tornado/20200307a_RGB/20200307aC0865700w360900n.tif

贡献与发展

请参阅CONTRIBUTING.md

许可证

请参阅LICENSE

作者

请参阅contributors获取个人贡献者列表。

变更

请参阅CHANGES.md

变更日志

0.12.1 (2024-04-18)

  • 修复GET范围解析
  • 添加对python 3.12的官方支持

0.12.0 (2024-01-24)

  • 在CLI(profilerandomget-zooms)中允许tms选项以选择TileMatrixSet

0.11.0 (2023-10-18)

  • 更新依赖项

    • rio-tiler>=6.0,<7.0
    • fastapi>=0.100.0
    • rasterio>=1.3.8
  • 移除wurlitzer依赖项

  • 仅使用rasterio日志

  • 移除LIST信息(破坏性变更

0.10.0 (2023-06-02)

  • 更新rio-tiler要求
  • 修复设置CPL_TIMESTAMP=ON时的日志解析问题

0.9.1 (2023-03-24)

  • 处理跨越日界线的数据集并移除pydantic序列化

0.9.0 (2023-03-14)

  • 更新pre-commit并修复starlette>=0.26的问题
  • NoCacheMiddleware重写为纯ASGI中间件
  • analyse_logs重命名为parse_logs
  • 添加python 3.11支持

0.8.2 (2022-11-21)

  • 更新hatch配置

0.8.1 (2022-10-31)

  • 修复在没有概述时最小/最大缩放级别的问题
  • 从block_shapes计算窗口

0.8.0 (2022-10-25)

  • 更新rio-tiler/rasterio依赖项
  • 移除python 3.7支持
  • 添加python 3.10支持
  • 添加图像端点以显示数据足迹
  • 从mapbox切换到maplibre

0.7.0 (2022-06-14)

  • 添加cProfile统计信息

0.6.1 (2022-04-19)

  • tilebench viz中移除对VSIStatsMiddleware的使用

0.6.0 (2022-04-19)

  • 切换到pyproject.toml

0.5.1 (2022-03-04)

  • 确保在使用tilebench profile而没有--tile选项时不要缓存之前的请求

0.5.0 (2022-02-28)

  • 更新rio-tiler要求
  • 添加reader选项

0.4.1 (2022-02-14)

  • 更新Fastapi要求
  • 使用WarpedVRT获取epsg:4326中的数据集边界

0.4.0 (2021-12-13)

0.3.0 (2021-03-05)

0.2.1 (2021-02-19)

  • 修复UI中的拼写错误

0.2.0 (2021-01-28)

  • profile CLI输出中添加warp-kernels
  • 在输出中添加rasterio/curl stdout
  • 在Viz中添加数据读取时间

0.1.1 (2021-01-27)

  • 更新依赖项

0.1.0 (2021-01-04)

  • 添加VSI stats可视化的Web UI
  • 添加starlette中间件

0.0.2 (2020-12-15)

  • 对rio-tiler==2.0.0rc3的更新

0.1.0 (2020-07-13)

  • 初始发布

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

tilebench-0.12.1.tar.gz (23.4 kB 查看哈希值)

上传时间

构建分发

tilebench-0.12.1-py3-none-any.whl (22.5 kB 查看哈希值)

上传时间 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面