Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topostats file helper class #945

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions notebooks/topostats_file_helper_example.ipynb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Notebook would be easier to read if the comments were moved to Markdown sections to delineate the code examples. Otherwise may as well just include a codeblock in docs/advanced/topostats_file_helper.md and be a simpler solution to documentation as its a web-page people can go to, they wouldn't need to activate a virtual environment and then start a Jupyter. Code chunks could be copy and pasted (I'd have to work out how to enable a button to support that though).

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import needed libraries\n",
"import numpy as np\n",
"from topostats.io import TopoFileHelper\n",
"from IPython.display import clear_output\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load topostats file\n",
"file = \"./tests/resources/file.topostats\"\n",
"helper = TopoFileHelper(file)\n",
"# Clear logging output\n",
"clear_output(wait=False)\n",
"\n",
"# Print the structure of the file\n",
"helper.pretty_print_structure()\n",
"\n",
"# Find the name of the data we want, we know it contains \"ordered_trace_heights\" and we want grain 2, but don't know\n",
"# what keys precede it\n",
"helper.find_data([\"ordered_trace_heights\", \"2\"])\n",
"\n",
"# Get some data from the file\n",
"cropped_image = helper.get_data(\"grain_trace_data/above/cropped_images/2\")\n",
"ordered_trace_heights = helper.get_data(\"grain_trace_data/above/ordered_trace_heights/2\")\n",
"cumulative_distances = helper.get_data(\"grain_trace_data/above/ordered_trace_cumulative_distances/2\")\n",
"ordered_traces = helper.get_data(\"grain_trace_data/above/ordered_traces/2\")\n",
"\n",
"# Plot the image\n",
"plt.imshow(cropped_image)\n",
"# Create a basic colour scale for the moleucle trace\n",
"c = np.arange(0, len(ordered_traces))\n",
"# Plot the molecule trace\n",
"plt.scatter(ordered_traces[:, 1], ordered_traces[:, 0], c=c, s=10)\n",
"plt.show()\n",
"# Plot the height of the molecule trace against the cumulative distance in nanometres\n",
"plt.plot(cumulative_distances, ordered_trace_heights)\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "topo-unet",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading