Skip to main content

Unmap data from pseudocolor images.

Project description

unmap

Run tests Build docs PyPI version PyPI versions PyPI license

Unmap data from pseudocolor images, with knowledge of the colourmap (for now!).

Installation

You can install this package with pip:

pip install unmap

Documentation

Read the documentation

Example

We'll grab an image from the web and unmap it. First we'll download the image:

from io import BytesIO

import requests
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt


def get_image_from_web(uri):
    data = requests.get(uri).content
    img = Image.open(BytesIO(data)).convert('RGB')
    rgb_im = np.asarray(img)[..., :3] / 255.
    return rgb_im

# An image from Hugh Pumprey's blog post Colours for Contours, licensed CC BY
# https://blogs.ed.ac.uk/hughpumphrey/2017/06/29/colours-for-contours/
uri = 'https://blogs.ed.ac.uk/hughpumphrey/wp-content/uploads/sites/958/2017/06/jeti.png'
img = get_image_from_web(uri)

The image looks like this:

Hugh_Pumphrey_CC-BY_original.png

Now we'll unmap it:

import unmap

data = unmap.unmap(img, cmap='jet')
plt.imshow(data)

This results in:

The unmapped data.

Notice that the data is there, but so is the colourbar. Also, the new data's colourbar shows that our dataset ranges from 0 to 1, but we can see from the colourbar in the original plot that it should range from about 0.4 to 1.333. So let's add vrange and crop arguments to deal with these issues:

data = unmap.unmap(img, cmap='jet', vrange=(0.400, 1.333), crop=(115, 72, 690, 647))

Which gives us:

The final result, cropped to the data area.

We could even plot this side by side with the original data, using the same colourmap, as a rough QC:

Comparison between input and output.

The extents of the data area are different. We could pass the extent argument to plt.imshow to fix this, but an even better idea is to put the data in an xarray.DataArray, because then the coordinates are attached to the data in a much more useful way. You could do this on your own, or you can use the Gio library's unmap_to_dataarray() function to do it for you.

Testing

You can run the tests (requires pytest and pytest-cov) with

pytest

Building

This repo uses PEP 517-style packaging. Read more about this and about Python packaging in general.

Building the project requires build, so first:

pip install build

Then to build unmap locally:

python -m build

The builds both .tar.gz and .whl files, either of which you can install with pip.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unmap-0.1.1rc1.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

unmap-0.1.1rc1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file unmap-0.1.1rc1.tar.gz.

File metadata

  • Download URL: unmap-0.1.1rc1.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for unmap-0.1.1rc1.tar.gz
Algorithm Hash digest
SHA256 fa1b2f4d79a48f581bedbc469b10f7eb2a8983345edeeb4bec1010cec31b9d09
MD5 11c7568a291a91575af86e2778bda83e
BLAKE2b-256 fdc949b586b835821499f2ae4942f9eef27fa8c5a1d6f49d4eacbb02b2a067fc

See more details on using hashes here.

File details

Details for the file unmap-0.1.1rc1-py3-none-any.whl.

File metadata

  • Download URL: unmap-0.1.1rc1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for unmap-0.1.1rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bd15316980a2261d836ffd7022533d5683b473909f8c49f7b2eb029762a61be
MD5 c80741cff557f9589d01c685d553511f
BLAKE2b-256 1e0c4088641d74692d2805191f921e8ac4e26d113f29372d917024e981a52912

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page