Missing Tiles #362
Unanswered
meteoDaniel
asked this question in
Q&A
Replies: 2 comments 6 replies
-
@meteoDaniel do you have any logs or data we can see ? also what kind of infra you are running this ? |
Beta Was this translation helpful? Give feedback.
1 reply
-
Here is my code: import asyncio
import math
import os
from concurrent.futures import ProcessPoolExecutor
from datetime import datetime
from pathlib import Path as posix_path
from typing import Callable, Dict, Type, Tuple, Union
import numpy as np
import fire
from fastapi import Path
from morecantile import TileMatrixSet
from rio_tiler.io import BaseReader, COGReader
from titiler.core.dependencies import (
ImageParams,
MetadataParams,
TMSParams,
DefaultDependency
)
from titiler.core.resources.enums import ImageType
from tile_server.routes import store_file
class LocalTilerFactory:
""" Factory to handle incoming tiling requests """
# Default reader is set to COGReader
reader: Type[BaseReader] = COGReader
# Endpoint Dependencies
metadata_dependency: Type[DefaultDependency] = MetadataParams
img_dependency: Type[DefaultDependency] = ImageParams
# TileMatrixSet dependency
tms_dependency: Callable[..., TileMatrixSet] = TMSParams
def tile(
self,
z: int = Path(..., ge=0, le=30, description="Tiles's zoom level"),
x: int = Path(..., description="Tiles's column"),
y: int = Path(..., description="Tiles's row"),
dt: datetime = datetime(2020, 1, 1),
):
"""Create map tile from a dataset."""
local_file = posix_path(f"{LOCAL_FILE_PATH}/{dt.strftime('%Y%m%d%H%M')}.tif")
if ~local_file.is_file():
asyncio.new_event_loop().run_until_complete(store_file(
f"{BASE_AWS_PATH}{dt.strftime('%Y%m%d%H%M')}.tif",
local_file))
src_path = str(local_file)
else:
src_path = str(local_file)
# try:
with self.reader(src_path) as src_dst:
data = src_dst.tile(
x,
y,
z,
)
dst_colormap = getattr(src_dst, "colormap", None)
# except:
# raise HTTPException(status_code=404, detail="Image not found")
format = ImageType.jpeg if data.mask.all() else ImageType.png
image = data.post_process(
)
content = image.render(
img_format=format.driver,
colormap=dst_colormap,
**format.profile,
)
return content
def process_local_tiling_store(dt: Union[str, datetime]) -> None:
""" handles tiling and storing of tilePyramid images """
if isinstance(dt, str):
dt = datetime.strptime(dt, DATE_TIME_PARSING_FORMAT)
required_tiles = required_tiles_per_zoom(
np.array([DEFAULT_BOUNDS[1], DEFAULT_BOUNDS[3]]),
np.array([DEFAULT_BOUNDS[0], DEFAULT_BOUNDS[2]]),
5,
9,
)
list_args = []
os.makedirs(f"{LOCAL_FILE_PATH}/{dt.strftime('%Y%m%d%H%M')}/", exist_ok=True)
for z in list(required_tiles.keys()):
for x in required_tiles[z]['x']:
for y in required_tiles[z]['y']:
list_args.append((dt, z, x, y))
with ProcessPoolExecutor(max_workers=4) as executor:
executor.map(run_tiling_and_store, list_args)
def run_tiling_and_store(argument_tuple: Tuple[datetime, int, int, int]) -> None:
""" wraps LocalTilerFactory to tile COG image into tile and store locally """
content = LocalTilerFactory().tile(dt=argument_tuple[0], x=argument_tuple[2],
y=argument_tuple[3], z=argument_tuple[1])
with open(f"{LOCAL_FILE_PATH}/{argument_tuple[0].strftime('%Y%m%d%H%M')}/"
f"{argument_tuple[1]}_{argument_tuple[2]}_{argument_tuple[3]}.png", 'wb') as file:
file.write(content) I use the TilerFactory to store the TileImages locally to improve access speed. Dynmaic Tiling (inclduing caching) is always slower than using the following API:
It serves the tiles that I have created and sotred locally. Actually I have to run the creating of the tiles multiple times be sure that all tiles are created. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear all I am observing a strange behaviour. Serving tiles dynamically will lead to some missing tiles. After a second attempt to request a tile it is available.
For me it sounds like a problem during concurrency jobs.
Do you have any notice about such a behaviour?
Hopefully there is a solution.
Beta Was this translation helpful? Give feedback.
All reactions