Skip to main content

projectile

PyPI - Python Version PyPI - Wheel PyPI - Downloads Tests

A tile-on-demand tile server built with PIL and Tornado.

Motivation

We want to store a high-resolution image in memory on the server as a numpy array. Then when a client requests a particular tile, we can make the PNG of the requested tile by slicing the numpy array and using PIL to write the resulting PNG back to the client through a StringIO stream.

This is primarily intended for building interactive visualizations in research settings where we might want to skip the time- and/or disk-intensive tile generation step required by typical tile servers.

Demo

Install projectile

$ pip install projectile

Serve a test image from the USC-SIPI Image Database:

$ projectile sanfran

Manually request a particular tile by navigating to http://localhost:8000/2/1/2.png.

Try zooming and panning in the demo client by navigating to http://localhost:8000/.

Serve one of your own images (any format readable by PIL) with

$ projectile some_image.tiff

or, if you have data in a numpy .npy file,

$ projectile some_image.npy

Load an image in grayscale mode and apply a colormap:

$ projectile --mode L --cmap viridis pentagon

Stress testing

To test the performance limits of on-demand tiling, download this high resolution map of Great Britain (8,150 × 13,086 pixels, file size: 102.74 MB) from Wikimedia Commons.

Grayscale performance test:

$ projectile britain.jpg -m L

Reducing tile resolution when running in color:

$ projectile britain.jpg --tile_size 128

Dependencies

  • numpy>=1.13.3
  • Pillow>=4.3.0
  • tornado>=4.5.2
  • matplotlib>=2.1.0

API

URL scheme

The server will serve grayscale and RGB images in their original colors at

/<z>/<x>/<y>/<s>.png

where <z> is the zoom level, <x> and <y> specify the coordinates of the tile at that zoom level (0/0 is the top left tile), and <s> specifies the image tile resolution in pixels (must be a power of 2).

The server will serve colormapped versions of a grayscale image at

/<z>/<x>/<y>/<s>/<cmap>/<vmin>/<vmax>.png

where <cmap> is the name of a matplotlib colormap, and <vmin> and <vmax> specify the range of image pixel values linearly interpolate against the colormap (pixel values outside this range will be clipped).

Using a custom client

If you like the projectile backend but just want to use a simple custom client contained in a single HTML file custom_client.html, you can run

$ projectile array.npy --client custom_client.html

to make projectile serve your client instead of the included demo client.

Using projectile in your existing Tornado web application

The core functionality is exposed in the TileHandler class defined in server.py, which you can use in your own Tornado web applications:

from tornado import web
from projectile.server import TileHandler

...

app = web.Application([
    (r'/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+).png', TileHandler,
     dict(array=array)),
    ...
])

...

Launching projectile from your own Python code

You can also launch a server from your own Python code with the run() function defined in server.py:

from projectile.server import run

run(array)

Credits

The demo client is lifted from http://bl.ocks.org/mbostock/5914438, with the addition of a small filtering check to prevent the client from requesting tiles which lie beyond the image boundaries.

Release files for projectile 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for projectile 0.0.6
File Size Uploaded
projectile-0.0.6.tar.gz 26.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for projectile 0.0.6
File Interpreter ABI Platform
projectile-0.0.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 35.3 kB

Release files / projectile-0.0.6.tar.gz

Download URL projectile-0.0.6.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c3b02ec78dec050b4b1e90ed88f06f3e7c5e422780dda9652602a7787f7ef12e
BLAKE2b-256 checksum
How to use checksums
b6a75b44db5905657b7b37179e9fe99e9dca035dab2726da73e4dcfe59a306e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release files / projectile-0.0.6-py2.py3-none-any.whl

Download URL projectile-0.0.6-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5ca4d4f5adf00a60067897664c0df8ccf84f87ade248280c51d64bf13c8604e6
BLAKE2b-256 checksum
How to use checksums
3cff965a46ef8085c6c050995ad64d0d7dd5e1469beeb2be478265e993501653
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

3 release files

0.0.4

2 release files

0.0.3

3 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page