Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
141 changes: 141 additions & 0 deletions notebooks/topostats_file_helper_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import needed libraries\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from h5glance import H5Glance\n",
"from IPython.display import clear_output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load topostats file"
]
},
{
"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",
"print(\"File loaded\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Print the structure of the file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Print the structure of the file\n",
"H5Glance(file)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Find data within the file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 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\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Retrieve data from the file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 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\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use the retrieved data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 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.xlabel(\"Cumulative distance (nm)\")\n",
"plt.ylabel(\"Height (nm)\")\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
}
2 changes: 2 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests of IO."""

from __future__ import annotations

import argparse
import json
import logging
Expand Down
Loading
Loading