Skip to content

Commit

Permalink
Add jupyter notebooks for code instruction (#72)
Browse files Browse the repository at this point in the history
* Exclude notebooks from packages in `pyproject.toml`

* Add notebook

* Add current directory to top of the notebook for relative paths

* Add to notebook

* Change comment in pyproject.toml since tests are automatically excluded with flat layout

* Add tutorials to README

* Add `MultipleDicotPipeline` tutorial

* Add `DicotPipeline` tutorial

* Add `OlderMonocotPipeline` tutorial

* Add `YoungerMonocotPipeline` tutorial

* Add descriptions of each pipeline to notebooks

* Add group property to series docstring

* Update README

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update sleap_roots/series.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix `Series` docstring

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
eberrigan and coderabbitai[bot] authored Apr 4, 2024
1 parent c5544ba commit 4091d71
Show file tree
Hide file tree
Showing 7 changed files with 3,600 additions and 17 deletions.
67 changes: 50 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import sleap_roots as sr

plant = sr.Series.load(
"tests/data/canola_7do/919QDUH.h5",
primary_name="primary_multi_day",
lateral_name="lateral_3_nodes"
# Specify the names of the primary and lateral roots for trait calculation
primary_name="primary",
lateral_name="lateral"
)
pipeline = sr.DicotPipeline()
traits = pipeline.compute_plant_traits(plant, write_csv=True)
Expand All @@ -46,8 +47,9 @@ plant_paths = sr.find_all_series("tests/data/soy_6do")
plants = [
sr.Series.load(
plant_path,
primary_name="primary_multi_day",
lateral_name="lateral__nodes",
# Specify the names of the primary and lateral roots for trait calculation
primary_name="primary",
lateral_name="lateral",
) for plant_path in plant_paths]

pipeline = sr.DicotPipeline()
Expand All @@ -59,15 +61,20 @@ all_traits = pipeline.compute_batch_traits(plants, write_csv=True)
```py
import sleap_roots as sr
import numpy as np
import numpy as np
# Import utility for combining primary and lateral root points
from sleap_roots.points import get_all_pts_array

plant = sr.Series.load(
"tests/data/canola_7do/919QDUH.h5",
primary_name="primary_multi_day",
lateral_name="lateral_3_nodes"
primary_name="primary",
lateral_name="lateral"
)

primary, lateral = plant[10]
pts = np.concatenate([primary.numpy(), lateral.numpy()], axis=0).reshape(-1, 2)
frame_index = 0
primary_pts = plant.get_primary_points(frame_index)
lateral_pts = plant.get_lateral_points(frame_index)
pts = get_all_pts_array(primary_pts, lateral_pts)
convex_hull = sr.convhull.get_convhull(pts)
```

Expand All @@ -80,8 +87,8 @@ import sleap_roots as sr

plant = sr.Series.load(
"tests/data/rice_3do/0K9E8BI.h5",
primary_name="longest_3do_6nodes",
lateral_name="main_3do_6nodes"
primary_name="primary",
lateral_name="crown"
)
pipeline = sr.YoungerMonocotPipeline()
traits = pipeline.compute_plant_traits(plant, write_csv=True)
Expand All @@ -96,8 +103,8 @@ plant_paths = sr.find_all_series("tests/data/rice_3do")
plants = [
sr.Series.load(
plant_path,
primary_name="longest_3do_6nodes",
lateral_name="main_3do_6nodes"
primary_name="primary",
lateral_name="crown"
) for plant_path in plant_paths]

pipeline = sr.YoungerMonocotPipeline()
Expand All @@ -109,18 +116,42 @@ all_traits = pipeline.compute_batch_traits(plants, write_csv=True)
```py
import sleap_roots as sr
import numpy as np
from sleap_roots.points import get_all_pts_array

plant = sr.Series.load(
"tests/data/rice_3do/0K9E8BI.h5",
primary_name="longest_3do_6nodes",
lateral_name="main_3do_6nodes"
primary_name="primary",
lateral_name="crown"
)

primary, lateral = plant[10]
pts = np.concatenate([primary.numpy(), lateral.numpy()], axis=0).reshape(-1, 2)
frame_index = 0
primary_pts = plant.get_primary_points(frame_index)
lateral_pts = plant.get_lateral_points(frame_index)
pts = get_all_pts_array(primary_pts, lateral_pts)
convex_hull = sr.convhull.get_convhull(pts)
```

## Tutorials
Jupyter notebooks are located in this repo at `sleap-roots/notebooks`.

To use them, add Jupyter Lab to your conda environment (recommended):

```
conda activate sleap-roots
pip install jupyterlab
```

Then you can change directories to the location of the notebooks, and open Jupyter Lab:

```
cd notebooks
jupyter lab
```

Go through the commands in the notebooks to learn about each pipeline.
You can use the test data located at `tests/data` or copy the notebooks elsewhere for use with your own data!


## Development
For development, first clone the repository:
```
Expand Down Expand Up @@ -167,4 +198,6 @@ This repository was created by the [Talmo Lab](https://talmolab.org) and [Busch

### Citation

*Coming soon.*
E.M. Berrigan, L. Wang, H. Carrillo, K. Echegoyen, M. Kappes, J. Torres, A. Ai-Perreira, E. McCoy, E. Shane, C.D. Copeland, L. Ragel, C. Georgousakis, S. Lee, D. Reynolds,
A. Talgo, J. Gonzalez, L. Zhang, A.B. Rajurkar, M. Ruiz, E. Daniels, L. Maree, S. Pariyar, W. Busch, T.D. Pereira. "Fast and Efficient Root Phenotyping via Pose Estimation"
*Plant Phenomics* 0: DOI:[10.34133/plantphenomics.0175](https://doi.org/10.34133/plantphenomics.0175).
954 changes: 954 additions & 0 deletions notebooks/DicotPipeline.ipynb

Large diffs are not rendered by default.

623 changes: 623 additions & 0 deletions notebooks/MultipleDicotPipeline.ipynb

Large diffs are not rendered by default.

977 changes: 977 additions & 0 deletions notebooks/OlderMonocotPipeline.ipynb

Large diffs are not rendered by default.

990 changes: 990 additions & 0 deletions notebooks/YoungerMonocotPipeline.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ dynamic = ["version", "readme"]
version = {attr = "sleap_roots.__version__"}
readme = {file = ["README.md"], content-type="text/markdown"}

[tool.setuptools.packages.find]
include = ["sleap_roots"] # Include only the sleap_roots package
exclude = ["notebooks"] # Exclude the notebooks directory
namespaces = false

[project.optional-dependencies]
dev = [
"pytest",
Expand Down
1 change: 1 addition & 0 deletions sleap_roots/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Series:
Properties:
series_name: Name of the series derived from the HDF5 filename.
expected_count: Fetch the expected plant count for this series from the CSV.
group: Group name for the series from the CSV.
"""

h5_path: Optional[str] = None
Expand Down

0 comments on commit 4091d71

Please sign in to comment.