Unmap data from pseudocolor images.
Project description
unmap
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:
Now we'll unmap it:
import unmap
data = unmap.unmap(img, cmap='jet')
plt.imshow(data)
This results in:
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:
We could even plot this side by side with the original data, using the same colourmap, as a rough QC:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file unmap-0.1.1rc0.tar.gz
.
File metadata
- Download URL: unmap-0.1.1rc0.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d1f89d46ceca9c94936e557208c47b31ed9c6523e1d3c28e0073e76153d2652 |
|
MD5 | 310a6e5c06609ffe7d2fbf99e64be785 |
|
BLAKE2b-256 | 274af33f2aaf56cf840a8b003615966c50d4d37ddb9aa54e738c6f0f36946a98 |
File details
Details for the file unmap-0.1.1rc0-py3-none-any.whl
.
File metadata
- Download URL: unmap-0.1.1rc0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a364fd90aaae53b1759af3c2fe3d93777ea9bf61a5af1f505ba8516ef483926 |
|
MD5 | f948a8ae4546bcbf07e6605432822574 |
|
BLAKE2b-256 | b10c2cd8e7075c1d60e20b572b696be786d39c6e7581fd4e6eaf679052de7fda |