-
Notifications
You must be signed in to change notification settings - Fork 11
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
SylviaWhittle
wants to merge
9
commits into
main
Choose a base branch
from
SylviaWhittle/topo-file-helper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bed84a2
Add topostats file helper
SylviaWhittle a327e20
Add find data function
SylviaWhittle 3cd66ff
Add data info function
SylviaWhittle a9c3f82
Add get data function
SylviaWhittle 0c806ee
Add pretty-print-structure function
SylviaWhittle d90ef91
Add partial search function
SylviaWhittle 1677ecd
Add class documentation with examples
SylviaWhittle 831f1c8
Add example notebook for loading topostats file data
SylviaWhittle 89b6475
Add tests for TopoFileHelper class (WIP)
SylviaWhittle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).