### Setup for Titiler Examples Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_Statistics.ipynb Initializes necessary libraries and defines endpoint and data URLs for subsequent examples. ```python import httpx import json titiler_endpoint = ( "https://titiler.xyz" # Developmentseed Demo endpoint. Please be kind. ) cog_url = "https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif" ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_CloudOptimizedGeoTIFF_simple.ipynb Install the necessary libraries for this demo. Uncomment the line if you need to install them. ```python # Uncomment this line if you need to install the dependencies # !pip install folium httpx ``` -------------------------------- ### AWS CDK Bootstrap and Deployment Source: https://github.com/developmentseed/titiler/blob/main/docs/src/deployment/aws/lambda.md These commands demonstrate the initial setup and deployment process for an AWS CDK stack. It includes installing CDK, bootstrapping the AWS environment, synthesizing the CloudFormation template, and deploying the stack. ```bash # Download titiler repo git clone https://github.com/developmentseed/titiler.git cd titiler/deployment/aws # Install NodeJS dependencies npm install -g aws-cdk@2.159.1 uv run cdk bootstrap # Deploys the CDK toolkit stack into an AWS environment # or in specific region uv run cdk bootstrap aws://${AWS_ACCOUNT_ID}/eu-central-1 ``` ```bash uv run cdk synth # Synthesizes and prints the CloudFormation template for this stack ``` ```bash uv run cdk deploy mytiler-lambda-dev # Deploys the stack(s) titiler-lambda-dev in cdk/app.py # Deploy in specific region AWS_DEFAULT_REGION=eu-central-1 AWS_REGION=eu-central-1 uv run cdk -- deploy mytiler-lambda-dev ``` -------------------------------- ### Setup for Titiler Xarray Zarr Examples Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_Zarr.ipynb Imports necessary libraries and defines the Titiler endpoint and a sample Zarr dataset URL. Ensure you have a local Titiler instance running or use the provided demo endpoint. ```python # setup import httpx import json from IPython.display import Image # Developmentseed Demo endpoint. Please be kind. Ref: https://github.com/developmentseed/titiler/discussions/1223 # titiler_endpoint = "https://xarray.titiler.xyz" # Or launch your own local instance with: # uv run --group server uvicorn titiler.xarray.main:app --host 127.0.0.1 --port 8080 --reload titiler_endpoint = "http://127.0.0.1:8080" zarr_url = "https://nasa-power.s3.us-west-2.amazonaws.com/syn1deg/temporal/power_syn1deg_temporal_lst.zarr" ``` -------------------------------- ### Install and Run Default TiTiler Application Source: https://github.com/developmentseed/titiler/blob/main/docs/src/user_guide/getting_started.md Installs the necessary TiTiler packages and starts the default application using uvicorn. This provides endpoints for COG, STAC, and MosaicJSON. ```bash # Update pip python -m pip install -U pip # Install titiler packages python -m pip install uvicorn titiler.application # Start application using uvicorn uvicorn titiler.application.main:app > INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) ``` -------------------------------- ### Install Titiler Core Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/core.md Instructions for installing Titiler Core from PyPI or from source. ```bash python -m pip install -U pip # From Pypi python -m pip install titiler.core # Or from sources git clone https://github.com/developmentseed/titiler.git cd titiler && python -m pip install -e src/titiler/core ``` -------------------------------- ### Development Installation and Run Source: https://github.com/developmentseed/titiler/blob/main/README.md Install TiTiler from source for development. This involves cloning the repository, navigating to the directory, and using uv commands to install dependencies and run the application with hot-reloading. ```bash git clone https://github.com/developmentseed/titiler.git cd titiler uv sync --group server uv run uvicorn titiler.application.main:app --reload ``` -------------------------------- ### Install ipyleaflet and httpx Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_nonWebMercatorTMS.ipynb Uncomment and run this command if you need to install the required modules within the notebook environment. ```python # Uncomment if you need to install those module within the notebook # !pip install ipyleaflet httpx ``` -------------------------------- ### TilerFactory Example Source: https://github.com/developmentseed/titiler/blob/main/docs/src/advanced/endpoints_factories.md This example demonstrates how to create a FastAPI application and a `TilerFactory` instance with various endpoints enabled. ```APIDOC ## TilerFactory Factory meant to create endpoints for single dataset using [*rio-tiler*'s `Reader`](https://cogeotiff.github.io/rio-tiler/readers/#rio_tileriorasterioreader). ### Attributes - **reader**: Dataset Reader **required**. - **reader_dependency**: Dependency to control options passed to the reader instance init. Defaults to `titiler.core.dependencies.DefaultDependency` - **path_dependency**: Dependency to use to define the dataset url. Defaults to `titiler.core.dependencies.DatasetPathParams`. - **layer_dependency**: Dependency to define band indexes or expression. Defaults to `titiler.core.dependencies.BidxExprParams`. - **dataset_dependency**: Dependency to overwrite `nodata` value, apply `rescaling` and change the `I/O` or `Warp` resamplings. Defaults to `titiler.core.dependencies.DatasetParams`. - **tile_dependency**: Dependency to define `buffer` and `padding` to apply at tile creation. Defaults to `titiler.core.dependencies.TileParams`. - **stats_dependency**: Dependency to define options for *rio-tiler*'s statistics method used in `/statistics` endpoints. Defaults to `titiler.core.dependencies.StatisticsParams`. - **histogram_dependency**: Dependency to define *numpy*'s histogram options used in `/statistics` endpoints. Defaults to `titiler.core.dependencies.HistogramParams`. - **img_preview_dependency**: Dependency to define image size for `/preview` and `/statistics` endpoints. Defaults to `titiler.core.dependencies.PreviewParams`. - **img_part_dependency**: Dependency to define image size for `/bbox` and `/feature` endpoints. Defaults to `titiler.core.dependencies.PartFeatureParams`. - **process_dependency**: Dependency to control which `algorithm` to apply to the data. Defaults to `titiler.core.algorithm.algorithms.dependency`. - **colormap_dependency**: Dependency to define the Colormap options. Defaults to `titiler.core.dependencies.ColorMapParams` - **render_dependency**: Dependency to control output image rendering options. Defaults to `titiler.core.dependencies.ImageRenderingParams` - **environment_dependency**: Dependency to define GDAL environment at runtime. Default to `lambda: {}`. - **supported_tms**: List of available TileMatrixSets. Defaults to `morecantile.tms`. - **templates**: *Jinja2* templates to use in endpoints. Defaults to `titiler.core.factory.DEFAULT_TEMPLATES`. - **render_func**: Image rendering method. Defaults to `titiler.core.utils.render_image`. - **add_preview**: Add `/preview` endpoint to the router. Defaults to `True`. - **add_part**: Add `/bbox` and `/feature` endpoints to the router. Defaults to `True`. - **add_viewer**: Add `/{TileMatrixSetId}/map.html` endpoints to the router. Defaults to `True`. - **add_ogc_maps**: Add `/map` endoint (OGC Maps API) to the router. Defaults to `False`. ### Endpoints ```python from fastapi import FastAPI from titiler.core.factory import TilerFactory # Create FastAPI application app = FastAPI() # Create router and register set of endpoints cog = TilerFactory( add_preview=True, add_part=True, add_viewer=True, add_ogc_maps=True, ) app.include_router(cog.router, prefix="/cog") ``` ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_MosaicJSON.ipynb Use this command to install the necessary Python libraries for the notebook. Uncomment the line if dependencies are not already installed. ```python # Uncomment this line if you need to install the dependencies #!pip install rasterio folium tqdm httpx rio-tiler geojson_pydantic cogeo-mosaic ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_STAC.ipynb Use this command to install the necessary Python libraries for the notebook. It's recommended to uncomment the line if you haven't installed them yet. ```bash # Uncomment this line if you need to install the dependencies # !pip install rasterio folium httpx tqdm ``` -------------------------------- ### Initialize TilerFactory for Cloud Optimized GeoTIFFs Source: https://github.com/developmentseed/titiler/blob/main/CHANGES.md This example initializes a TilerFactory for Cloud Optimized GeoTIFFs (COGs) with default Web Mercator Tile Matrix Set support. It includes basic setup for a FastAPI application. ```python from titiler.endpoints.factory import TilerFactory from rio_tiler.io import COGReader from fastapi import FastAPI app = FastAPI() cog = TilerFactory() app.include_router(cog.router, tags=["Cloud Optimized GeoTIFF"]) ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/developmentseed/titiler/blob/main/CONTRIBUTING.md Clone the repository and install the package in editable mode with development dependencies using 'uv'. ```bash git clone https://github.com/developmentseed/titiler.git cd titiler # Install the package in editable mode, plus the "dev" dependency group. # You can add "--group" arguments to add more groups, e.g. "--group notebook". uv sync ``` -------------------------------- ### Install TiTiler Extensions Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/extensions.md Install TiTiler and its extensions from PyPI or from source. ```bash python -m pip install -U pip # From Pypi python -m pip install titiler.extensions # Or from sources git clone https://github.com/developmentseed/titiler.git cd titiler && python -m pip install -e src/titiler/core -e src/titiler/extensions ``` -------------------------------- ### Install Titiler Application Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/application.md Install the titiler.application package from PyPI. For development, clone the repository and install from sources. ```bash python -m pip install -U pip # From Pypi python -m pip install titiler.application # Or from sources git clone https://github.com/developmentseed/titiler.git cd titiler && python -m pip install -e src/titiler/core -e src/titiler/extensions -e src/titiler/mosaic -e src/titiler/xarray -e src/titiler/application ``` -------------------------------- ### TilerFactory Usage Example Source: https://github.com/developmentseed/titiler/blob/main/docs/src/advanced/endpoints_factories.md Example of how to instantiate and use the TilerFactory for creating custom endpoints. ```python from fastapi import FastAPI from titiler.mosaic.factory import MosaicTilerFactory from cogeo_mosaic.backends import MosaicBackend as MosaicJSONBackend # Create FastAPI application app = FastAPI() # Create router and register set of endpoints mosaic = MosaicTilerFactory( backend=MosaicJSONBackend, add_part=True, # default to False add_statistics=True, # default to False add_ogc_maps=True, # default to False ) # add router endpoint to the main application app.include_router(mosaic.router) ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_STAC_simple.ipynb Install necessary Python libraries for working with STAC and TiTiler. Uncomment the line if dependencies are not already installed. ```python # Uncomment this line if you need to install the dependencies # !pip install folium requests rasterio ``` -------------------------------- ### MosaicTilerFactory Setup Source: https://context7.com/developmentseed/titiler/llms.txt Initialize `MosaicTilerFactory` with a `MosaicBackend` to serve tiles from a MosaicJSON file. This setup enables viewer, statistics, and additional endpoints like `/bbox` and `/feature`. ```python from fastapi import FastAPI from cogeo_mosaic.backends import MosaicBackend from titiler.mosaic.factory import MosaicTilerFactory from titiler.mosaic.extensions.mosaicjson import MosaicJSONExtension from titiler.mosaic.extensions.wmts import wmtsExtension app = FastAPI() mosaic = MosaicTilerFactory( backend=MosaicBackend, router_prefix="/mosaicjson", add_viewer=True, add_statistics=True, # POST /statistics endpoint add_part=True, # /bbox and /feature endpoints extensions=[ MosaicJSONExtension(), # GET / and /validate wmtsExtension(), # WMTSCapabilities.xml ], ) app.include_router(mosaic.router, prefix="/mosaicjson", tags=["MosaicJSON"]) ``` -------------------------------- ### Install Titiler Xarray Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/xarray.md Install Titiler with Xarray support. Use `[full]` for all dependencies or `[minimal]` for essential ones. Alternatively, install from source. ```bash python -m pip install -U pip # From Pypi python -m pip install "titiler.xarray[full]" # Or from sources git clone https://github.com/developmentseed/titiler.git cd titiler && python -m pip install -e src/titiler/core -e "src/titiler/xarray" ``` -------------------------------- ### Install Titiler Mosaic Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/mosaic.md Install the titiler.mosaic package from PyPI or from source. Also install cogeo-mosaic for MosaicJSON support. ```bash python -m pip install -U pip # From Pypi python -m pip install titiler.mosaic # Or from sources git clone https://github.com/developmentseed/titiler.git cd titiler && python -m pip install -e src/titiler/core -e src/titiler/mosaic # install cogeo-mosaic for MosaicJSON support python -m pip install cogeo-mosaic ``` -------------------------------- ### Install and Launch TiTiler Application Source: https://context7.com/developmentseed/titiler/llms.txt Install TiTiler packages and launch the application using uvicorn. Docker is also supported for running the pre-built image. ```bash pip install titiler.application uvicorn # Launch the built-in demo application uvicorn titiler.application.main:app --reload # → http://127.0.0.1:8000/docs (OpenAPI UI) ``` ```bash # Or install only core for a minimal custom tiler pip install titiler.core uvicorn ``` ```bash # Docker: run the pre-built image docker run \ --platform=linux/amd64 \ -p 8000:8000 \ --rm -it ghcr.io/developmentseed/titiler:latest \ uvicorn titiler.application.main:app --host 0.0.0.0 --port 8000 --workers 1 ``` -------------------------------- ### MosaicTilerFactory Example Source: https://github.com/developmentseed/titiler/blob/main/docs/src/advanced/endpoints_factories.md This example demonstrates how to create a FastAPI application and include the MosaicTilerFactory router. It shows how to configure the factory with a specific backend and enable optional features like adding partial mosaics, statistics, and OGC map tiles. ```python from fastapi import FastAPI from titiler.mosaic.factory import MosaicTilerFactory from cogeo_mosaic.backends import MosaicBackend as MosaicJSONBackend # Create FastAPI application app = FastAPI() # Create router and register set of endpoints mosaic = TilerFactory( backend=MosaicJSONBackend, add_part=True, # default to False add_statistics=True, # default to False add_ogc_maps=True, # default to False ) # add router endpoint to the main application app.include_router(mosaic.router) ``` -------------------------------- ### Install and Run Pre-commit Hooks Source: https://github.com/developmentseed/titiler/blob/main/docs/src/contributing.md Install the `pre-commit` hooks to ensure code quality checks like linting and formatting are performed before committing. You can also run these checks manually on all files. ```bash uv run pre-commit install # If needed, you can run pre-commit script manually uv run pre-commit run --all-files ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/developmentseed/titiler/blob/main/CONTRIBUTING.md Install pre-commit hooks to ensure code quality checks like linting and formatting are performed before committing. ```bash uv run pre-commit install ``` ```bash # If needed, you can run pre-commit script manually uv run pre-commit run --all-files ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_Algorithm.ipynb Installs the necessary libraries: folium and httpx. These are required for making HTTP requests and visualizing map data. ```bash !pip install folium httpx ``` -------------------------------- ### Install TiTiler and Uvicorn Source: https://github.com/developmentseed/titiler/blob/main/docs/src/user_guide/getting_started.md Install the core TiTiler package and Uvicorn, a fast ASGI server, using pip. Note that the 'titiler' metapackage is no longer supported. ```bash pip install titiler.core uvicorn ``` -------------------------------- ### Install TiTiler with Telemetry Support Source: https://github.com/developmentseed/titiler/blob/main/docs/src/advanced/telemetry.md Install the titiler.core package with the [telemetry] extra to include all necessary OpenTelemetry dependencies. This can be done from PyPI or from local sources. ```bash python -m pip install -U pip # From Pypi python -m pip install titiler.core[telemetry] # Or from sources git clone https://github.com/developmentseed/titiler.git cd titiler && python -m pip install -e src/titiler/core[telemetry] ``` -------------------------------- ### Build Documentation Source: https://github.com/developmentseed/titiler/blob/main/CONTRIBUTING.md Clone the repository and build the project documentation using MkDocs. ```bash git clone https://github.com/developmentseed/titiler.git cd titiler # Build docs uv run --group docs mkdocs build -f docs/mkdocs.yml ``` -------------------------------- ### Setup Cache on Startup Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/code/tiler_with_cache.md Configure cache on application startup using event handlers. Ensure exception handlers are also added. ```python app.add_event_handler("startup", setup_cache) add_exception_handlers(app, DEFAULT_STATUS_CODES) app.include_router(cog.router, tags=["Cloud Optimized GeoTIFF"]) ``` -------------------------------- ### Serve Documentation with Hot-reloading Source: https://github.com/developmentseed/titiler/blob/main/CONTRIBUTING.md Serve the project documentation locally with live reloading enabled during development. ```bash uv run --group docs mkdocs serve -f docs/mkdocs.yml --livereload ``` -------------------------------- ### Install TiTiler Packages Source: https://github.com/developmentseed/titiler/blob/main/README.md Install TiTiler packages from PyPI. Ensure pip is up to date. Specific packages can be installed, or the 'titiler.application' package installs all core components. ```bash python -m pip install -U pip ``` ```bash python -m pip install titiler.{package} # e.g., # python -m pip install titiler.core # python -m pip install titiler.xarray # python -m pip install titiler.extensions # python -m pip install titiler.mosaic # python -m pip install titiler.application (also installs core, extensions, xarray and mosaic) ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_NumpyTile.ipynb Installs the necessary Python libraries: numpy and mercantile. Uncomment the line if you need to install them. ```python # Uncomment this line if you need to install the dependencies # !pip install numpy mercantile ``` -------------------------------- ### Install TiTiler and Uvicorn Source: https://github.com/developmentseed/titiler/blob/main/docs/src/user_guide/getting_started.md Install TiTiler and Uvicorn using pip. This command also installs core and mosaic dependencies. ```bash python -m pip install titiler.application uvicorn # also installs titiler.core and titiler.mosaic ``` -------------------------------- ### Create a TilerFactory Instance Source: https://github.com/developmentseed/titiler/blob/main/docs/src/advanced/endpoints_factories.md Instantiate TilerFactory with custom options to enable specific endpoints and features. This example shows how to enable preview endpoints and set default values for other options. ```python from fastapi import FastAPI from titiler.xarray.factory import TilerFactory # Create FastAPI application app = FastAPI() # Create router and register set of endpoints md = TilerFactory( add_part=True, # default to True add_viewer=True, # default to True add_preview=True, # default to False ) # add router endpoint to the main application app.include_router(md.router) ``` -------------------------------- ### List Available Algorithms Source: https://github.com/developmentseed/titiler/blob/main/docs/src/endpoints/algorithms.md Use this endpoint to get a list of all supported algorithms and their general information. The output includes algorithm titles, descriptions, input/output specifications, and configurable parameters. ```bash $ curl https://myendpoint/algorithms | jq { "hillshade": { "title": "Hillshade", "description": "Create hillshade from DEM dataset.", "inputs": { "nbands": 1 }, "outputs": { "nbands": 1, "dtype": "uint8", "min": null, "max": null }, "parameters": { "azimuth": { "default": 90, "maximum": 360, "minimum": 0, "title": "Azimuth", "type": "integer" }, "angle_altitude": { "default": 90.0, "maximum": 90.0, "minimum": -90.0, "title": "Angle Altitude", "type": "number" }, "buffer": { "default": 3, "maximum": 99, "minimum": 0, "title": "Buffer", "type": "integer" } } }, ... } ``` -------------------------------- ### Install MosaicJSON Support Source: https://github.com/developmentseed/titiler/blob/main/docs/src/migrations/v1_migration.md The `cogeo-mosaic` package is now optional. Install it with MosaicJSON support using `pip install "titiler.mosaic[mosaicjson]"` if you use MosaicJSON functionality. ```bash # Before (0.26) pip install titiler.mosaic # Now (1.0) - Install with MosaicJSON support pip install "titiler.mosaic[mosaicjson]" ``` -------------------------------- ### Import Libraries and Setup Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_NumpyTile.ipynb Imports required libraries including httpx, mercantile, BytesIO, and numpy. Also sets up inline plotting for notebooks. ```python import httpx import mercantile from io import BytesIO import numpy %pylab inline ``` -------------------------------- ### Install TiTiler Packages via Pip Source: https://github.com/developmentseed/titiler/blob/main/docs/src/index.md Install specific TiTiler packages or the full application package using pip. Ensure pip is up-to-date before installation. The `titiler.application` package includes all other core packages. ```bash python -m pip install -U pip ``` ```bash python -m pip install titiler.{package} ``` ```bash # e.g.,\n# python -m pip install titiler.core\n# python -m pip install titiler.xarray\n# python -m pip install titiler.extensions\n# python -m pip install titiler.mosaic\n# python -m pip install titiler.application (also installs core, extensions, xarray and mosaic) ``` ```bash # Install uvicorn to run the FastAPI application locally\npython -m pip install uvicorn ``` ```bash # Launch application locally\nuvicorn titiler.application.main:app ``` -------------------------------- ### FastAPI Application Setup Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/code/mosaic_from_urls.md Sets up the main FastAPI application, includes the custom mosaic router, and adds exception handlers for both core titiler errors and mosaic-specific errors. ```python """app. app/main.py """ from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers from titiler.mosaic.errors import MOSAIC_STATUS_CODES from fastapi import FastAPI from .routers import mosaic app = FastAPI() app.include_router(mosaic.router) add_exception_handlers(app, DEFAULT_STATUS_CODES) add_exception_handlers(app, MOSAIC_STATUS_CODES) ``` -------------------------------- ### Initialize Viewer with URL Parameters Source: https://github.com/developmentseed/titiler/blob/main/src/titiler/extensions/titiler/extensions/templates/cog_viewer.html Listens for the map 'load' event to parse URL parameters and load a COG if a URL is provided. ```javascript map.on('load', () => { const params = parseParams(window.location.search) if (params.url) { scope.url = params.url document.getElementById('selector').classList.toggle('none') addCogeo() } }) ``` -------------------------------- ### Install Dependencies Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/notebooks/Working_with_CloudOptimizedGeoTIFF.ipynb Installs necessary Python libraries for working with geospatial data, AWS, and visualization. ```python # Uncomment this line if you need to install the dependencies # !pip install rasterio boto3 folium requests tqdm ``` -------------------------------- ### Asset Band Indexing in Titiler Source: https://github.com/developmentseed/titiler/blob/main/CHANGES.md Demonstrates how to specify band indices for multiple assets. The 'now' example simplifies this by using a single 'bidx' parameter for all specified assets. ```python # merge band 1 form asset1 and asset2 # before httpx.get( "/stac/preview", params=( ("url", "stac.json"), ("assets", "asset1"), ("assets", "asset2"), ("asset_bidx", "asset1|1"), ("asset_bidx", "asset2|1"), ) ) # now httpx.get( "/stac/preview", params=( ("url", "stac.json"), ("assets", "asset1"), ("assets", "asset2"), ("bidx", 1), ) ) ``` -------------------------------- ### Initialize Benchmark Data and Rendering Source: https://github.com/developmentseed/titiler/blob/main/docs/src/benchmark.html Sets up the benchmark data by collecting results per test case and initializes the page elements like the last update date and repository link. It also prepares data for chart rendering. ```javascript 'use strict'; (function() { // Colors from https://github.com/github/linguist/blob/master/lib/linguist/languages.yml const toolColors = { cargo: '#dea584', go: '#00add8', benchmarkjs: '#f1e05a', benchmarkluau: '#000080', pytest: '#3572a5', googlecpp: '#f34b7d', catch2: '#f34b7d', julia: '#a270ba', jmh: '#b07219', benchmarkdotnet: '#178600', customBiggerIsBetter: '#38ff38', customSmallerIsBetter: '#ff3838', _: '#333333' }; function init(data) { function collectBenchesPerTestCase(entries) { const map = new Map(); for (const entry of entries) { const {commit, date, tool, benches} = entry; for (const bench of benches) { const result = { commit, date, tool, bench }; const arr = map.get(bench.name); if (arr === undefined) { map.set(bench.name, [result]); } else { arr.push(result); } } } return map; } // Render header document.getElementById('last-update').textContent = new Date(data.lastUpdate).toString(); const repoLink = document.getElementById('repository-link'); repoLink.href = data.repoUrl; repoLink.textContent = data.repoUrl; // Render footer document.getElementById('dl-button').onclick = () => { const dataUrl = 'data:,' + JSON.stringify(data, null, 2); const a = document.createElement('a'); a.href = dataUrl; a.download = 'benchmark_data.json'; a.click(); }; // Prepare data points for charts return Object.keys(data.entries).map(name => ({ name, dataSet: collectBenchesPerTestCase(data.entries[name]), })); } function renderAllChars(dataSets) { function renderGraph(parent, name, dataset) { const canvas = document.createElement('canvas'); canvas.className = 'benchmark-chart'; parent.appendChild(canvas); const color = toolColors[dataset.length > 0 ? dataset[0].tool : '_']; const data = { labels: dataset.map(d => d.commit.id.slice(0, 7)), datasets: [ { label: name, data: dataset.map(d => d.bench.value), borderColor: color, backgroundColor: color + '60', // Add alpha for #rrggbbaa }, ], }; const options = { scales: { xAxes: [ { scaleLabel: { display: true, labelString: 'commit', }, } ], yAxes: [ { scaleLabel: { display: true, labelString: dataset.length > 0 ? dataset[0].bench.unit : '', }, ticks: { beginAtZero: true, } } ], }, tooltips: { callbacks: { afterTitle: items => { const {index} = items[0]; const data = dataset[index]; return '\n' + data.commit.message + '\n\n' + data.commit.timestamp + ' committed by @' + data.commit.committer.username + '\n'; }, label: item => { let label = item.value; const { range, unit } = dataset[item.index].bench; label += ' ' + unit; if (range) { label += ' (' + range + ')'; } return label; }, afterLabel: item => { const { extra } = dataset[item.index].bench; return extra ? '\n' + extra : ''; } } }, onClick: (_mouseEvent, activeElems) => { if (activeElems.length === 0) { return; } // XXX: Undocumented. How can we know the index? const index = activeElems[0]._index; const url = dataset[index].commit.url; window.open(url, '_blank'); }, }; new Chart(canvas, { type: 'line', data, options, }); } function renderBenchSet(name, benchSet, main) { const setElem = document.createElement('div'); setElem.className = 'benchmark-set'; main.appendChild(setElem); const nameElem = document.createElement('h1'); nameElem.className = 'benchmark-title'; nameElem.textContent = name; setElem.appendChild(nameElem); const graphsElem = document.createElement('div'); graphsElem.className = 'benchmark-graphs'; setElem.appendChild(graphsElem); for (const [benchName, benches] of benchSet.entries()) { renderGraph(graphsElem, benchName, benches) } } const main = document.getElementById('main'); for (c ``` -------------------------------- ### COG Statistics (GET) Source: https://github.com/developmentseed/titiler/blob/main/docs/src/endpoints/cog.md Retrieves advanced raster statistics for a Cloud Optimized GeoTIFF using GET request. ```APIDOC ## GET /cog/statistics ### Description Retrieves advanced raster statistics for a Cloud Optimized GeoTIFF. ### Endpoint `/cog/statistics` ### Query Parameters - **url** (str): Cloud Optimized GeoTIFF URL. **Required** - **bidx** (array[int]): Dataset band indexes (e.g `bidx=1`, `bidx=1&bidx=2&bidx=3`). - **expression** (str): rio-tiler's band math expression (e.g `expression=b1/b2`). - **max_size** (int): Max image size from which to calculate statistics, default is 1024. - **height** (int): Force image height from which to calculate statistics. - **width** (int): Force image width from which to calculate statistics. - **nodata** (str, int, float): Overwrite internal Nodata value. - **unscale** (bool): Apply dataset internal Scale/Offset. - **resampling** (str): RasterIO resampling algorithm. Defaults to `nearest`. - **algorithm** (str): Custom algorithm name (e.g `hillshade`). - **algorithm_params** (str): JSON encoded algorithm parameters. - **categorical** (bool): Return statistics for categorical dataset, default is false. - **c** (array[float]): Pixels values for categories. - **p** (array[int]): Percentile values. - **histogram_bins** (str): Histogram bins. - **histogram_range** (str): Comma (',') delimited Min,Max histogram bounds. ### Request Example ``` https://myendpoint/cog/statistics?url=https://somewhere.com/mycog.tif&bidx=1,2,3&categorical=true&c=1&c=2&c=3&p=2&p98 ``` ``` -------------------------------- ### Run FastAPI Application Source: https://github.com/developmentseed/titiler/blob/main/docs/src/examples/code/tiler_with_custom_stac+xarray.md Command to run the FastAPI application using uvicorn. Ensure you have uvicorn installed (`pip install uvicorn`). ```bash uvicorn app:app --port 8080 --reload ``` -------------------------------- ### Set Up Python Virtual Environment Source: https://github.com/developmentseed/titiler/blob/main/docs/src/user_guide/getting_started.md Create and activate a Python virtual environment to isolate project dependencies. This is crucial for managing different project requirements. ```bash python -m venv titiler ``` ```bash # For Linux/macOS: source titiler/bin/activate ``` ```bash # For Windows: titiler\Scripts\activate ``` -------------------------------- ### Create a FastAPI Application with Titiler Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/core.md Example of setting up a FastAPI application and integrating Titiler's TilerFactory to create COG endpoints. ```python from fastapi import FastAPI from titiler.core.factory import TilerFactory # Create a FastAPI application app = FastAPI( description="A lightweight Cloud Optimized GeoTIFF tile server", ) # Create a set of COG endpoints cog = TilerFactory() # Register the COG endpoints to the application app.include_router(cog.router, tags=["Cloud Optimized GeoTIFF"]) ``` -------------------------------- ### Titiler Application Installation and Execution Change Source: https://github.com/developmentseed/titiler/blob/main/CHANGES.md Details the updated installation and execution commands for running the Titiler application after the project was split into namespaces. ```bash # before $ pip install titiler $ uvicorn titiler.main:app --reload # now $ pip install titiler.application uvicorn $ uvicorn titiler.application.main:app --reload ``` -------------------------------- ### Fix Histogram Range Examples in OpenAPI Spec Source: https://github.com/developmentseed/titiler/blob/main/docs/src/release-notes.md Corrected examples for `histogram_range` in the OpenAPI specification to accurately reflect usage. This was contributed by @guillemc23. ```python # No code change required, this is an OpenAPI specification fix. ``` -------------------------------- ### Deploy Documentation Source: https://github.com/developmentseed/titiler/blob/main/CONTRIBUTING.md Manually deploy the project documentation to GitHub Pages using MkDocs. Note: This is typically handled automatically by GitHub Actions. ```bash uv run --group docs mkdocs gh-deploy -f docs/mkdocs.yml ``` -------------------------------- ### Mosaic Point Endpoint Migration Example Source: https://github.com/developmentseed/titiler/blob/main/docs/src/migrations/v1_migration.md This example demonstrates the transformation of a mosaic `/point` endpoint response from the 0.26 structure to the 1.0 structure. ```python # Before (0.26) response = { "coordinates": [-122.5, 37.5], "values": [ ("asset1", [100.0, 200.0], ["B1", "B2"]), ("asset2", [150.0, 250.0], ["B1", "B2"]) ] } # Now (1.0) response = { "coordinates": [-122.5, 37.5], "assets": [ { "name": "asset1", "values": [100.0, 200.0], "band_names": ["B1", "B2"], "band_descriptions": None }, { "name": "asset2", "values": [150.0, 250.0], "band_names": ["B1", "B2"], "band_descriptions": None } ] } ``` -------------------------------- ### Launch Titiler Application Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/application.md Install uvicorn and launch the Titiler demo application using uvicorn. The `--reload` flag enables hot-reloading. ```bash python -m pip install uvicorn $ uvicorn titiler.application.main:app --reload ``` -------------------------------- ### Get WMTS Capabilities Source: https://github.com/developmentseed/titiler/blob/main/docs/src/endpoints/cog.md Returns OGC WMTS Get Capabilities XML document for the Cloud Optimized GeoTIFF. This endpoint utilizes the `wmtsExtension`. ```APIDOC ## GET /cog/WMTSCapabilities.xml ### Description Return OGC WMTS Get Capabilities (from `titiler.extensions.wmts.wmtsExtension`). ### Method GET ### Endpoint /cog/WMTSCapabilities.xml ``` -------------------------------- ### Create Mosaic Tile Server with FastAPI Source: https://github.com/developmentseed/titiler/blob/main/docs/src/packages/mosaic.md Set up a FastAPI application with Mosaic endpoints using the MosaicTilerFactory and MosaicBackend from cogeo-mosaic. ```python from fastapi import FastAPI from titiler.mosaic.factory import MosaicTilerFactory from cogeo_mosaic.backends import MosaicBackend # Create a FastAPI application app = FastAPI( description="A Mosaic tile server", ) # Create a set of Mosaic endpoints using MosaicJSON backend from cogeo-mosaic project mosaic = MosaicTilerFactory(backend=MosaicBackend) # Register the Mosaic endpoints to the application app.include_router(mosaic.router, tags=["MosaicJSON"]) ``` -------------------------------- ### Install Titiler with Helm Source: https://github.com/developmentseed/titiler/blob/main/deployment/k8s/README.md Use this command to install the Titiler application on your Kubernetes cluster using Helm. Ensure you are in the k8s directory and have a Chart.yaml file. ```bash minikube start kubectl config use-context minikube helm init --wait # in the k8s directory helm install -f titiler/Chart.yaml titiler ```