Simplify Python examples and use JupyterLab#129
Conversation
add ipywidgets to avoid errors, and add instructions for MacOS
Thank you!Thank you for your pull request 😃 🤖 This automated message can help you check the rendered files in your submission for clarity. If you have any questions, please feel free to open an issue in {sandpaper}. If you have files that automatically render output (e.g. R Markdown), then you should check for the following:
Rendered Changes🔍 Inspect the changes: https://github.com/HealthBioscienceIDEAS/microscopy-novice/compare/md-outputs..md-outputs-PR-129 The following changes were observed in the rendered markdown documents: What does this mean?If you have source files that require output and figures to be generated (e.g. R Markdown), then it is important to make sure the generated figures and output are reproducible. This output provides a way for you to inspect the output in a diff-friendly manner so that it's easy to see the changes that occur due to new software versions or randomisation. ⏱️ Updated at 2026-06-12 17:13:54 +0000 |
thompson318
left a comment
There was a problem hiding this comment.
This works really nicely, a big improvement on messing around with the Napari console. I've added a few minor suggestions (mostly typos I think).
I also think we should finish it with a note about saving/reusing/sharing the workflow.
|
Thanks for putting this together @stellaprins - looks great! I think this will make it much easier to handle these code blocks in Jupyter + it's nice for learners to leave the course with a fully reproducible script 🎉 I'm part-way through reviewing the PR, but getting a bit side tracked with preparing notes for teaching tomorrow. Will hopefully submit a review by the end of today, but otherwise will finish reviewing on Friday after the course. It's already looking great for teaching this round 😄 |
|
@thompson318 thanks! I've added your suggestions. RE
Good idea. I was thinking this too, and have added the following section at the end.
|
thompson318
thompson318
left a comment
There was a problem hiding this comment.
I think this is good to merge if it makes teaching logistics easier, we can always make changes afterwards.
K-Meech
left a comment
There was a problem hiding this comment.
Thanks for putting this together @stellaprins ! (sorry for the delay in getting back to you on this)
I've put some comments below - mostly minor suggestions on wording / typos. Take a look through and let me know what you think 😄
| ### 1. Activate your Napari environment | ||
| Open Miniforge Prompt and activate the environment you created for Napari: | ||
| ``` bash | ||
| activate napari-env |
There was a problem hiding this comment.
| activate napari-env | |
| conda activate napari-env |
| activate napari-env | ||
| ``` | ||
| ### 2. Create and navigate to your workshop folder | ||
| It is best practice to keep all your project files together in a dedicated folder. |
There was a problem hiding this comment.
I wonder if we want something here about moving to a location they can find again (like /Documents, /Desktop) to create this folder? At least on windows miniforge prompt opens by default in: C:\Users\username which is tough to find again through the standard file browser.
Potentially, we could do this moving / folder creation via the jupyter interface to avoid multiple bash commands. E.g. if they open juptyer lab in the default location, they could then use the file browser at the left side of jupyter to move to a sensible location and create a new folder. What do you think?
| Renaming your notebook immediately helps keep your workflow tidy and makes it easier to find later. | ||
|
|
||
| `File > Open Sample > napari builtins > Cells (3D + 2Ch)` | ||
| Right click the default name at the top of the notebook tab (e.g., *Untitled.ipynb*). |
There was a problem hiding this comment.
| Right click the default name at the top of the notebook tab (e.g., *Untitled.ipynb*). | |
| Right click the default name at the top of the notebook tab (e.g., *Untitled.ipynb*), and select `Rename Notebook...`. |
|
|
||
| For this workshop, we will only use **Code Cells**. | ||
|
|
||
| When you run a Code Cell, the output typically appears underneath it. This could be a number, text, a table, an error message. |
There was a problem hiding this comment.
| When you run a Code Cell, the output typically appears underneath it. This could be a number, text, a table, an error message. | |
| When you run a Code Cell, the output typically appears underneath it. This could be a number, text, a table, or an error message. |
|
|
||
| First, let's open one of Napari's sample images with: | ||
| ### 1. Activate your Napari environment | ||
| Open the Miniforge Prompt (or whichever other environment manager you used when installing Napari), and activate the environment you created for Napari: |
There was a problem hiding this comment.
| Open the Miniforge Prompt (or whichever other environment manager you used when installing Napari), and activate the environment you created for Napari: | |
| Open the terminal (the same one you used for Napari installation: see 'Opening a terminal' section of [the setup instructions](http://127.0.0.1:4321/index.html#install-python-packages)), and activate the environment you created for Napari: |
Even when participants are using the same environment manager (miniforge), they will access it in different ways on different operating systems (miniforge prompt for windows, standard terminal for mac / linux etc). Maybe make this more generic by referring to a terminal + linking to the setup instructions?
| ```python | ||
| print(nucleus_pixels) | ||
| # Quick stats using pandas | ||
| props_df["volume_um3"].describe() |
There was a problem hiding this comment.
This is a great shortcut for getting the summary stats! I'd forgotten about .describe
| A tidy notebook is easier to understand for others (and for your future self). | ||
|
|
||
| ``` | ||
| Good practice include: |
There was a problem hiding this comment.
| Good practice include: | |
| Good practice includes: |
|
|
||
| - Organising the notebook into clear sections (e.g. imports, loading data, segmentation, measurements, exporting results). | ||
|
|
||
| - Removing unused cells and tidy temporary experiments. |
There was a problem hiding this comment.
| - Removing unused cells and tidy temporary experiments. | |
| - Removing unused cells and tidying temporary experiments. |
|
|
||
| # Find the range of nucleus sizes (maximum - minimum). | ||
| print(f"Range of nucleus volumes = {nucleus_volume.max() - nucleus_volume.min():.2f} cubic micrometres.") | ||
| Your notebook contains all the analysis steps, but it won’t run correctly unless the software environment is the same. |
There was a problem hiding this comment.
This is a good point, but I wonder if showing the conda env export commands is too much for this beginners lesson? Some points:
- If we want to include this, we'd need to be clear about where to run it i.e. in the terminal once the notebook has been closed. (I imagine people will try running it in jupyter notebook)
- These files often don't work for installation across different operating systems - as they may include platform-specific dependencies (e.g. if someone created it on windows, someone else probably couldn't use it to make the same env on a mac)
- There is
--from-historywhich can help with this; but it doesn't seem to work with ournapari-env
Maybe remove the specific commands and just link to the documentation? What do you think?
| @@ -1,3 +1,3 @@ | |||
| --- | |||
| title: 'Instance segmentation and measurements' | |||
| teaching: 45 | |||
There was a problem hiding this comment.
As this adds more content, could you update the teaching time estimate here? It's in minutes
I'd probably go for at least 1hr teaching time, then maybe 20 minutes for exercises? That total of 1hr20 matches the size of the session after the lunch break which sounds about right.
I used RStudio to locally build the webpage, and fixed any unexpected issues with formatting.