Skip to content

Commit f8b18ab

Browse files
committed
all the docs
1 parent fbab59b commit f8b18ab

15 files changed

+740
-54
lines changed

README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,62 @@ Read [the documentation](https://code.agilescientific.com/unmap)
2424

2525
## Example
2626

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

2929
```python
30+
from io import BytesIO
31+
32+
import requests
33+
import numpy as np
34+
from PIL import Image
35+
import matplotlib.pyplot as plt
36+
37+
3038
def get_image_from_web(uri):
3139
data = requests.get(uri).content
3240
img = Image.open(BytesIO(data)).convert('RGB')
3341
rgb_im = np.asarray(img)[..., :3] / 255.
3442
return rgb_im
3543

36-
# An image from Matteo Niccoli's blog:
37-
# https://mycartablog.com/2014/08/24/what-your-brain-does-with-colours-when-you-are-not-looking-part-1/
38-
img = get_image_from_web('https://i0.wp.com/mycartablog.com/wp-content/uploads/2014/03/spectrogram_jet.png')
44+
# An image from Hugh Pumprey's blog post Colours for Contours, licensed CC BY
45+
# https://blogs.ed.ac.uk/hughpumphrey/2017/06/29/colours-for-contours/
46+
uri = 'https://blogs.ed.ac.uk/hughpumphrey/wp-content/uploads/sites/958/2017/06/jeti.png'
47+
img = get_image_from_web(uri)
48+
```
49+
50+
The image looks like this:
3951

40-
import gio
52+
![Hugh_Pumphrey_CC-BY_original.png](./_static/Hugh_Pumphrey_CC-BY_original.png)
4153

42-
data = gio.unmap(img, cmap='jet')
54+
Now we'll unmap it:
55+
56+
```python
57+
import unmap
58+
59+
data = unmap.unmap(img, cmap='jet')
4360
plt.imshow(data)
4461
```
4562

63+
This results in:
64+
65+
![The unmapped data.](./_static/Hugh_Pumphrey_CC-BY_unmapped_1.png)
66+
67+
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:
68+
69+
```python
70+
data = unmap.unmap(img, cmap='jet', vrange=(0.400, 1.333), crop=(115, 72, 690, 647))
71+
```
72+
73+
Which gives us:
74+
75+
![The final result, cropped to the data area.](./_static/Hugh_Pumphrey_CC-BY_unmapped_2.png)
76+
77+
We could even plot this side by side with the original data, using the same colourmap, as a rough QC:
78+
79+
![Comparison between input and output.](./_static/Hugh_Pumphrey_CC-BY_compare.png)
80+
81+
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.
82+
4683

4784
## Testing
4885

docs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ help:
1515
.PHONY: help html
1616

1717
html:
18+
python process_ipynb.py $(SOURCEDIR)/notebooks
1819
$(SPHINXBUILD) -E -b html $(SPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
1920
python process_html.py $(BUILDDIR)/html
2021
@echo
86.2 KB
Loading
69.5 KB
Loading
166 KB
Loading
194 KB
Loading

docs/_static/unmap.png

316 KB
Loading

docs/conf.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,12 @@ def setup(app):
4444
extensions = ['sphinx.ext.githubpages',
4545
'sphinxcontrib.apidoc',
4646
'sphinx.ext.napoleon',
47-
'myst_parser',
47+
'myst_nb',
4848
'sphinx.ext.viewcode'
4949
]
5050

5151
myst_enable_extensions = ["dollarmath", "amsmath"]
52-
53-
54-
# Add any paths that contain templates here, relative to this directory.
55-
templates_path = ['_templates']
56-
57-
# List of patterns, relative to source directory, that match files and
58-
# directories to ignore when looking for source files.
59-
# This pattern also affects html_static_path and html_extra_path.
60-
exclude_patterns = ['_build']
52+
jupyter_execute_notebooks = "force"
6153

6254
# Apidoc automation
6355
# https://pypi.org/project/sphinxcontrib-apidoc/
@@ -68,6 +60,14 @@ def setup(app):
6860
apidoc_toc_file = False
6961
apidoc_separate_modules = False
7062

63+
# Add any paths that contain templates here, relative to this directory.
64+
templates_path = ['_templates']
65+
66+
# List of patterns, relative to source directory, that match files and
67+
# directories to ignore when looking for source files.
68+
# This pattern also affects html_static_path and html_extra_path.
69+
exclude_patterns = ['_build', 'notebooks']
70+
7171
# -- Options for HTML output -------------------------------------------------
7272

7373
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -105,4 +105,4 @@ def setup(app):
105105

106106
# Branding.
107107
html_favicon = '_static/favicon.ico'
108-
html_logo = '_static/unmap_logo.png'
108+
html_logo = '_static/unmap.png'

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ User guide
2020
:caption: User guide
2121

2222
readme
23+
userguide/Unmap_data_from_an_image.ipynb
2324

2425

2526
API reference

docs/make.bat

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)