Skip to content

Commit

Permalink
Merge pull request #62 from haesleinhuepf/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
haesleinhuepf authored Oct 31, 2023
2 parents 861119b + c01b53f commit b03be51
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 373 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ BIA `bob` is a Jupyter-based assistant for interacting with data using generated

## Usage

You can initialize Bob like this:
You can initialize `bob` like this:
```
from bia_bob import bob
```

### Code generation

Afterwards, you can ask Bob to generate code like this:
You can ask Bob to generate code like this:
```
%bob Load blobs.tif and show it
```
Expand Down Expand Up @@ -64,14 +64,27 @@ mamba activate bt39
pip install bia-bob
```

Create an OpenAI API Key and add it to your environment variables as explained on [this page](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety).

## Development

If you want to contribute to `bia-bob`, you can install it in development mode like this:

```
git clone https://github.com/haesleinhuepf/bia-bob.git
cd bia-bob
pip install -e .
```

## Similar projects

There are similar projects offering LLM-based support in Jupyter notebooks:
* [jupyter-ai](https://github.com/jupyterlab/jupyter-ai)
* [napari-chatGPT](https://github.com/royerlab/napari-chatgpt)

## Issues

If you encounter any problems or want to provide feedback or suggestions, please create a thread on [image.sc](https://image.sc) along with a detailed description and tag [@haesleinhuepf].
If you encounter any problems or want to provide feedback or suggestions, please create a thread on [image.sc](https://image.sc) along with a detailed description and tag @haesleinhuepf .



Expand Down
92 changes: 43 additions & 49 deletions demo/analysis_workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
"data": {
"text/plain": [
"'0.3.1'"
"'0.4.0'"
]
},
"execution_count": 2,
Expand All @@ -42,7 +42,7 @@
{
"data": {
"text/markdown": [
"To load the \"blobs.tif\" image file and display it, you can use the following code:"
"To load the `blobs.tif` image and display it, you can use the following code:"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -59,7 +59,7 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "4b4ac42c-3124-4b25-8930-5f893ca291e8",
"id": "fa3e15f6-272b-4583-b07f-d213fc0d76b8",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -103,7 +103,7 @@
"import stackview\n",
"\n",
"# Load the image\n",
"image = imread(\"blobs.tif\")\n",
"image = imread('blobs.tif')\n",
"\n",
"# Display the image\n",
"stackview.insight(image)"
Expand All @@ -118,7 +118,7 @@
{
"data": {
"text/markdown": [
"To segment the image stored in the `image` variable using thresholding and connected component labeling, and to show the resulting label image, you can use the following code:"
"To segment the image stored in the variable `image` using thresholding and connected component labeling, you can use the following code:"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -138,13 +138,13 @@
{
"cell_type": "code",
"execution_count": 6,
"id": "53739416-bb77-4ee9-95e2-b219fe582618",
"id": "fc234779-cf32-4410-b475-73c10cb53460",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "edeecc98783d49a79bf185afd69b8deb",
"model_id": "316abfc1846540e3b1960252f37a9ddf",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -158,16 +158,15 @@
}
],
"source": [
"from skimage.filters import threshold_otsu\n",
"from skimage.measure import label\n",
"from skimage import filters, measure\n",
"import stackview\n",
"\n",
"# Threshold the image\n",
"threshold = threshold_otsu(image)\n",
"binary_image = image > threshold\n",
"# Threshold the image using Otsu's method\n",
"threshold_value = filters.threshold_otsu(image)\n",
"binary_image = image > threshold_value\n",
"\n",
"# Label the connected components\n",
"labels = label(binary_image)\n",
"# Perform connected component labeling\n",
"labels = measure.label(binary_image)\n",
"\n",
"# Display the label image\n",
"stackview.curtain(image, labels)"
Expand All @@ -182,7 +181,7 @@
{
"data": {
"text/markdown": [
"To measure the size and shape of the segmented objects and store the results in a Pandas DataFrame, you can use the following code:"
"To measure the size and shape of the segmented objects and store the results in a Pandas dataframe, you can use the following code:"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -202,50 +201,41 @@
{
"cell_type": "code",
"execution_count": 8,
"id": "656e41a8-a810-43da-bf98-800bed552f47",
"id": "ccdc9bc3-0976-4fc9-a8fd-4f9562c8cd72",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Label Area Perimeter Eccentricity\n",
"0 1 433 91.254834 0.876649\n",
"1 2 185 53.556349 0.828189\n",
"2 3 658 95.698485 0.352060\n",
"3 4 434 76.870058 0.341084\n",
"4 5 477 83.798990 0.771328\n",
".. ... ... ... ...\n",
"59 60 1 0.000000 0.000000\n",
"60 61 81 40.727922 0.947745\n",
"61 62 90 46.278175 0.971003\n",
"62 63 53 31.899495 0.939695\n",
"63 64 49 34.485281 0.974495\n",
" label area perimeter eccentricity extent\n",
"0 1 433 91.254834 0.876649 0.555128\n",
"1 2 185 53.556349 0.828189 0.800866\n",
"2 3 658 95.698485 0.352060 0.870370\n",
"3 4 434 76.870058 0.341084 0.820416\n",
"4 5 477 83.798990 0.771328 0.865699\n",
".. ... ... ... ... ...\n",
"59 60 1 0.000000 0.000000 1.000000\n",
"60 61 81 40.727922 0.947745 0.710526\n",
"61 62 90 46.278175 0.971003 0.782609\n",
"62 63 53 31.899495 0.939695 0.662500\n",
"63 64 49 34.485281 0.974495 0.720588\n",
"\n",
"[64 rows x 4 columns]\n"
"[64 rows x 5 columns]\n"
]
}
],
"source": [
"import pandas as pd\n",
"from skimage.measure import regionprops\n",
"from skimage import measure\n",
"\n",
"# Measure size and shape of segmented objects\n",
"props = regionprops(labels)\n",
"# Measure region properties of the labeled image\n",
"props = measure.regionprops_table(labels, properties=['label', 'area', 'perimeter', 'eccentricity', 'extent'])\n",
"\n",
"# Create a Pandas DataFrame to store the results\n",
"data = {'Label': [], 'Area': [], 'Perimeter': [], 'Eccentricity': []}\n",
"# Convert the measured properties to a pandas dataframe\n",
"df = pd.DataFrame(props)\n",
"\n",
"# Populate the DataFrame with measurements\n",
"for prop in props:\n",
" data['Label'].append(prop.label)\n",
" data['Area'].append(prop.area)\n",
" data['Perimeter'].append(prop.perimeter)\n",
" data['Eccentricity'].append(prop.eccentricity)\n",
"\n",
"df = pd.DataFrame(data)\n",
"\n",
"# Display the DataFrame\n",
"# Display the dataframe\n",
"print(df)"
]
},
Expand All @@ -258,7 +248,7 @@
{
"data": {
"text/markdown": [
"To plot the perimeter against eccentricity using the Seaborn library, you can use the following code:"
"To plot the perimeter against eccentricity using the seaborn library, you can use the following code:"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand All @@ -276,7 +266,7 @@
{
"cell_type": "code",
"execution_count": 10,
"id": "60851234-6838-452e-b6f4-935162a0d9ac",
"id": "9b82d119-965f-45da-a04d-6d63ec2df10d",
"metadata": {},
"outputs": [
{
Expand All @@ -292,12 +282,16 @@
],
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Plot the data\n",
"sns.scatterplot(data=df, x='Perimeter', y='Eccentricity')\n",
"# Create a scatter plot using seaborn\n",
"sns.scatterplot(data=df, x='perimeter', y='eccentricity')\n",
"\n",
"# Set the axis labels\n",
"plt.xlabel('Perimeter')\n",
"plt.ylabel('Eccentricity')\n",
"\n",
"# Show the plot\n",
"import matplotlib.pyplot as plt\n",
"plt.show()"
]
},
Expand Down
57 changes: 28 additions & 29 deletions demo/basic_demo.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit b03be51

Please sign in to comment.