Skip to content

Commit

Permalink
Merge pull request #357 from Living-with-machines/rw_docs
Browse files Browse the repository at this point in the history
Update worked example notebooks
  • Loading branch information
rwood-97 authored Feb 22, 2024
2 parents a429260 + 1d1ca54 commit 4ae6026
Show file tree
Hide file tree
Showing 19 changed files with 4,144 additions and 11,608 deletions.
2 changes: 1 addition & 1 deletion docs/source/Contribution-guide/Contribution-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Pre-requisites
Regardless of how you will be contributing to MapReader, you will need to:

1. Ensure you have a `GitHub account <https://docs.github.com/en/get-started/signing-up-for-github/signing-up-for-a-new-github-account>`_ set up.
2. Be able to use GitHub issues and pull requests - if you are unfamiliar with these, please look at our :doc:`GitHub guide <Contribution-guide/GitHub-guide>` before continuing.
2. Be able to use GitHub issues and pull requests - if you are unfamiliar with these, please look at our :doc:`GitHub guide </Contribution-guide/GitHub-guide>` before continuing.
3. Set up a virtual python environment and install MapReader (as per our :doc:`Installation instructions </Install>`).
4. Have read this guide.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/Developers-guide.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Developer's Guide
================
=================

Managing version numbers
------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/Project-cv.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Project Curriculum Vitae
===========
=========================

.. Notes to editors:
.. 1. Add links to slides/videos (always add slides to [email protected] drive)
Expand Down
76 changes: 53 additions & 23 deletions docs/source/Worked-examples/Worked-examples.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
Worked Examples
================

.. todo:: Explain these different use cases

.. list-table::
:widths: 25 25 25
:header-rows: 0
:stub-columns: 0

* - **classification_one_inch_maps**
.. image:: https://raw.githubusercontent.com/Living-with-machines/MapReader/main/figs/tutorial_classification_one_inch_maps_001.png
:width: 200px
- **classification_plant_phenotype**
.. image:: https://raw.githubusercontent.com/Living-with-machines/MapReader/main/figs/tutorial_classification_plant_phenotype.png
:width: 200px
- **classification_mnist**
.. image:: https://raw.githubusercontent.com/Living-with-machines/MapReader/main/figs/tutorial_classification_mnist.png
:width: 200px

.. toctree::
:maxdepth: 1

Classification of one-inch OS maps <one_inch_pipeline>
Classification of plant phenotypes <plant_pipeline>
Classification of mnist dataset <mnist_pipeline>
We have provided a number of worked examples to demonstrate how to use the MapReader package.
These examples can be found in the `worked_examples <https://github.com/Living-with-machines/MapReader/tree/main/worked_examples>`_ directory of the repository.

Maps and geospatial images
--------------------------

MapReader was developed for maps and geospatial images.

Classification of one-inch OS maps
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. image:: https://raw.githubusercontent.com/Living-with-machines/MapReader/main/figs/tutorial_classification_one_inch_maps_001.png
:width: 400px
:target: https://github.com/Living-with-machines/MapReader/tree/main/worked_examples/geospatial

We have provided two examples of how to use MapReader to identify railspace patches in one-inch OS maps.
Both examples demonstrate how to use MapReader with maps hosted on a tileserver.

Our examples show a full end-to-end use of the MapReader pipeline, including downloading, loading and patchifying map images, annotating patches to create training data, training a model and using the model to classify patches.

The first examples demonstrates how to use MapReader to classify patches using a standard patch-level classification model in which patches are used as inputs to the model.
It can be found `here <https://github.com/Living-with-machines/MapReader/blob/main/worked_examples/geospatial/classification_one_inch_maps/Pipeline.ipynb>`__.

The second example demonstrates how to use MapReader to classify patches using a context-level classification model in which patches and their surrounding patches (i.e. context) are used as inputs to the model.
It can be found `here <https://github.com/Living-with-machines/MapReader/blob/main/worked_examples/geospatial/context_classification_one_inch_maps/Pipeline.ipynb>`__.

Non-geospatial images
---------------------

MapReader can also for non-geospatial images.
We have provided two examples of this.

Classification of plant phenotypes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. image:: https://raw.githubusercontent.com/Living-with-machines/MapReader/main/figs/tutorial_classification_plant_phenotype.png
:width: 400px
:target: https://github.com/Living-with-machines/MapReader/blob/main/worked_examples/non-geospatial/classification_plant_phenotype/Pipeline.ipynb

In our plant phenotypes example, we demonstrate how to use MapReader to classify plant phenotypes in images of plants.
Importantly, this worked example demonstrates how to use MapReader with non-georeferenced images (e.g. non-georeferenced map images).
It can be found `here <ttps://github.com/Living-with-machines/MapReader/blob/main/worked_examples/non-geospatial/classification_plant_phenotype/Pipeline.ipynb>`__.

Classification of MNIST digits
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. image:: https://raw.githubusercontent.com/Living-with-machines/MapReader/main/figs/tutorial_classification_mnist.png
:width: 400px
:target: https://github.com/Living-with-machines/MapReader/blob/main/worked_examples/non-geospatial/classification_mnist/Pipeline.ipynb

In our MNIST example, we demonstrate how to use MapReader to classify MNIST digits.
Importantly, this example demonstrates how to use MapReader to classify whole images instead of patches and therefore how MapReader can generalize to much broader use cases.
It can be found `here <https://github.com/Living-with-machines/MapReader/blob/main/worked_examples/non-geospatial/classification_mnist/Pipeline.ipynb>`__.
1,289 changes: 0 additions & 1,289 deletions docs/source/Worked-examples/mnist_pipeline.ipynb

This file was deleted.

3,026 changes: 0 additions & 3,026 deletions docs/source/Worked-examples/one_inch_pipeline.ipynb

This file was deleted.

2,724 changes: 0 additions & 2,724 deletions docs/source/Worked-examples/plant_pipeline.ipynb

This file was deleted.

4 changes: 2 additions & 2 deletions mapreader/annotate/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def render(self) -> None:
else:
display(image.convert("RGB"))
add_ins = []
if self.at[ix, "url"]:
if "url" in self.loc[ix].keys():
url = self.at[ix, "url"]
text = f'<p><a href="{url}" target="_blank">Click to see entire map.</a></p>'
add_ins += [widgets.HTML(text)]
Expand Down Expand Up @@ -968,7 +968,7 @@ def get_labelled_data(
)

return filtered_df[
self.label_col, self.patch_paths_col, "parent_id", "pixel_bounds"
[self.label_col, self.patch_paths_col, "parent_id", "pixel_bounds"]
]

@property
Expand Down
3 changes: 3 additions & 0 deletions mapreader/load/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,9 @@ def _add_patch_to_parent(self, patch_id: str) -> None:
"""
patch_parent = self.patches[patch_id]["parent_id"]

if patch_parent is None:
return

if patch_parent not in self.parents.keys():
self.load_parents(parent_ids=patch_parent)

Expand Down
Loading

0 comments on commit 4ae6026

Please sign in to comment.