Skip to content
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

Simplify the BaseTilerFactory #820

Open
vincentsarago opened this issue Jun 5, 2024 · 0 comments · May be fixed by #943
Open

Simplify the BaseTilerFactory #820

vincentsarago opened this issue Jun 5, 2024 · 0 comments · May be fixed by #943

Comments

@vincentsarago
Copy link
Member

# ref: https://github.com/python/mypy/issues/5374
@dataclass # type: ignore
class BaseTilerFactory(metaclass=abc.ABCMeta):
"""BaseTiler Factory.
Abstract Base Class which defines most inputs used by dynamic tiler.
Attributes:
reader (rio_tiler.io.base.BaseReader): A rio-tiler reader (e.g Reader).
router (fastapi.APIRouter): Application router to register endpoints to.
path_dependency (Callable): Endpoint dependency defining `path` to pass to the reader init.
dataset_dependency (titiler.core.dependencies.DefaultDependency): Endpoint dependency defining dataset overwriting options (e.g nodata).
layer_dependency (titiler.core.dependencies.DefaultDependency): Endpoint dependency defining dataset indexes/bands/assets options.
render_dependency (titiler.core.dependencies.DefaultDependency): Endpoint dependency defining image rendering options (e.g add_mask).
colormap_dependency (Callable): Endpoint dependency defining ColorMap options (e.g colormap_name).
process_dependency (titiler.core.dependencies.DefaultDependency): Endpoint dependency defining image post-processing options (e.g rescaling, color-formula).
tms_dependency (Callable): Endpoint dependency defining TileMatrixSet to use.
reader_dependency (titiler.core.dependencies.DefaultDependency): Endpoint dependency defining BaseReader options.
environment_dependency (Callable): Endpoint dependency to define GDAL environment at runtime.
router_prefix (str): prefix where the router will be mounted in the application.
optional_headers(sequence of titiler.core.resources.enums.OptionalHeader): additional headers to return with the response.
"""
reader: Type[BaseReader]
# FastAPI router
router: APIRouter = field(default_factory=APIRouter)
# Path Dependency
path_dependency: Callable[..., Any] = DatasetPathParams
# Indexes/Expression Dependencies
layer_dependency: Type[DefaultDependency] = BidxExprParams
# Rasterio Dataset Options (nodata, unscale, resampling, reproject)
dataset_dependency: Type[DefaultDependency] = DatasetParams
# Post Processing Dependencies (algorithm)
process_dependency: Callable[
..., Optional[BaseAlgorithm]
] = available_algorithms.dependency
# Image rendering Dependencies
rescale_dependency: Callable[..., Optional[RescaleType]] = RescalingParams
color_formula_dependency: Callable[..., Optional[str]] = ColorFormulaParams
colormap_dependency: Callable[..., Optional[ColorMapType]] = ColorMapParams
render_dependency: Type[DefaultDependency] = ImageRenderingParams
# Reader dependency
reader_dependency: Type[DefaultDependency] = DefaultDependency
# GDAL ENV dependency
environment_dependency: Callable[..., Dict] = field(default=lambda: {})
# TileMatrixSet dependency
supported_tms: TileMatrixSets = morecantile_tms
default_tms: Optional[str] = None
# Router Prefix is needed to find the path for /tile if the TilerFactory.router is mounted
# with other router (multiple `.../tile` routes).
# e.g if you mount the route with `/cog` prefix, set router_prefix to cog and
router_prefix: str = ""
# add additional headers in response
optional_headers: List[OptionalHeader] = field(default_factory=list)
# add dependencies to specific routes
route_dependencies: List[Tuple[List[EndpointScope], List[DependsFunc]]] = field(
default_factory=list
)
extensions: List[FactoryExtension] = field(default_factory=list)
templates: Jinja2Templates = DEFAULT_TEMPLATES

The BaseTilerFactory has many attributes that are not use or might not be used by other Factories so we should defer the definition of those attribute to the children not in the base class

@vincentsarago vincentsarago linked a pull request Jul 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant