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

Ymir imaging I/O helpers #38

Merged
merged 24 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
897848d
Back up
YooSunYoung Aug 27, 2024
3eb405b
Clean up imaging IO.
YooSunYoung Aug 28, 2024
4043380
Use scippnexus if possible. [skip ci]
YooSunYoung Sep 5, 2024
e5884d3
Fix image key based indexing [skip ci]
YooSunYoung Sep 5, 2024
5d6ba28
Add small image dataset for testing [skip ci].
YooSunYoung Sep 5, 2024
1095bd3
Add histogram mode detector IO example in the docs. [skip ci]
YooSunYoung Sep 5, 2024
ddd5a78
Update dataset to have integer dtype after reshaping. [skip ci]
YooSunYoung Sep 5, 2024
b80671f
Fix dark current and open beam image key value. [skip ci]
YooSunYoung Sep 5, 2024
46c50e0
Include attributes to copy.
YooSunYoung Sep 5, 2024
50c1669
Remove unnecessary loading.
YooSunYoung Sep 5, 2024
022a782
Update workflow. [skip ci]
YooSunYoung Sep 5, 2024
603690c
Added minimum IO tests. [skip ci]
YooSunYoung Sep 5, 2024
6f4bc9f
Manually assign counts unit to the histogram mode detector images.
YooSunYoung Sep 6, 2024
2bbc2ed
Load/separate image stacks by keys, without binning/grouping.
YooSunYoung Sep 10, 2024
2307879
Add explanation why the image keys are treated like this.
YooSunYoung Sep 10, 2024
d498454
Fix image slicing.
YooSunYoung Sep 10, 2024
6a4596d
Add positional coordinate params and cropping params.
YooSunYoung Sep 11, 2024
a96ecf2
Fix slicing and coordinate assignment.
YooSunYoung Sep 12, 2024
9313b90
Simplify coordinate assigning logic.
YooSunYoung Sep 12, 2024
2610708
Fix log coordinate broadcasting.
YooSunYoung Sep 13, 2024
a08fea4
Skip coordinate deriving
YooSunYoung Sep 13, 2024
969f223
Shallow copy to assign coordinate.
YooSunYoung Sep 13, 2024
3cb0306
Update src/ess/imaging/io.py
YooSunYoung Sep 13, 2024
38c8db6
Fix if condition.
YooSunYoung Sep 13, 2024
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
13 changes: 13 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
</br></br>
</span>

## Imaging Data Reduction Examples
````{card}

```{button-ref} user-guide/histogram_mode_detector
:class: stretched-link

Ymir - Histogram Mode Detector

```

````

```{toctree}
---
hidden:
---

user-guide/index
api-reference/index
developer/index
about/index
Expand Down
193 changes: 193 additions & 0 deletions docs/user-guide/histogram_mode_detector.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Histogram Mode Detector\n",
"\n",
"## IO\n",
"\n",
"I/O providers can load white beam images and slice them according to the image key.\n",
"\n",
"Note that not like the ``rotation_angle``, ``image_key`` is not assigned as a coordinate.\n",
"\n",
"Instead, we slice the data according to the ``image_key`` and separate image stacks earlier due to performance limitation of 3-dimensional data binning.\n",
"\n",
"> For example, for 400 images of 2_048 x 2_048 pixels couldn't be done in the regular laptop."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ess.imaging.data import get_ymir_images_path\n",
"from ess.imaging.io import (\n",
" FilePath,\n",
" SampleImageStacks,\n",
" RawSampleImageStacks,\n",
" OpenBeamImageStacks,\n",
" DarkCurrentImageStacks,\n",
" AllImageStacks,\n",
")\n",
"from ess.imaging.workflow import (\n",
" YmirWorkflow,\n",
" ImageDetectorName,\n",
" RotationMotionSensorName,\n",
")\n",
"\n",
"wf = YmirWorkflow()\n",
"wf[FilePath] = get_ymir_images_path()\n",
"wf[ImageDetectorName] = 'orca'\n",
"wf[RotationMotionSensorName] = 'motion_cabinet_2'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"image_stack_types = (\n",
" AllImageStacks,\n",
" RawSampleImageStacks,\n",
" OpenBeamImageStacks,\n",
" DarkCurrentImageStacks,\n",
" SampleImageStacks,\n",
")\n",
"wf.visualize(image_stack_types)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results = wf.compute(image_stack_types)\n",
"results[SampleImageStacks]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save Individual Frame"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ess.imaging.io import export_image_stacks_as_tiff, ImageKey\n",
"\n",
"from pathlib import Path\n",
"from tqdm import tqdm\n",
"\n",
"\n",
"output_dir = Path(\"images\")\n",
"export_image_stacks_as_tiff(\n",
" output_dir=output_dir,\n",
" image_stacks=results[AllImageStacks],\n",
" merge_image_by_key=False,\n",
" overwrite=True,\n",
" progress_wrapper=tqdm,\n",
" image_prefix_map={\n",
" ImageKey.SAMPLE: \"sample\",\n",
" ImageKey.DARK_CURRENT: \"dc\",\n",
" ImageKey.OPEN_BEAM: \"ob\",\n",
" },\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sorted(output_dir.iterdir())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save All Frames in One File"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ess.imaging.io import export_image_stacks_as_tiff, ImageKey\n",
"from tqdm import tqdm\n",
"from pathlib import Path\n",
"\n",
"\n",
"output_dir = Path(\"images\")\n",
"export_image_stacks_as_tiff(\n",
" output_dir=output_dir,\n",
" image_stacks=results[AllImageStacks],\n",
" merge_image_by_key=True,\n",
" overwrite=True,\n",
" progress_wrapper=tqdm,\n",
" image_prefix_map={\n",
" ImageKey.SAMPLE: \"sample\",\n",
" ImageKey.DARK_CURRENT: \"dc\",\n",
" ImageKey.OPEN_BEAM: \"ob\",\n",
" },\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tuple(output_dir.iterdir())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"!rm -rf images"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "img-dev-310",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
10 changes: 10 additions & 0 deletions docs/user-guide/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# User guide


```{toctree}
---
maxdepth: 1
---
installation
histogram_mode_detectors
```
16 changes: 16 additions & 0 deletions docs/user-guide/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Installation

To install `essimaging` and all of its dependencies, use

`````{tab-set}
````{tab-item} pip
```sh
pip install essimaging
```
````
````{tab-item} conda
```sh
conda install -c conda-forge -c scipp essimaging
```
````
`````
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies = [
"scipp>=23.8.0",
"scippnexus>=23.11.1",
"essreduce",
"tifffile",
]

dynamic = ["version"]
Expand Down
44 changes: 44 additions & 0 deletions src/ess/imaging/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
import pathlib

import pooch

_version = '0'


def _make_pooch():
return pooch.create(
path=pooch.os_cache('essimaging'),
env='BEAMLIME_DATA_DIR',
retry_if_failed=3,
base_url='https://public.esss.dk/groups/scipp/ess/imaging/',
version=_version,
registry={
'small_ymir_images.hdf': 'md5:5fbc52595f3e6117a2be2bb50866806a',
'README.md': 'md5:6ca6b4a79bcff2965a81767e12474617',
},
)


_pooch = _make_pooch()
_pooch.fetch('README.md')


def get_path(name: str) -> pathlib.Path:
"""
Return the path to a data file bundled with ess.imaging test helpers.

This function only works with example data and cannot handle
paths to custom files.
"""

return pathlib.Path(_pooch.fetch(name))


def get_ymir_images_path() -> pathlib.Path:
"""
Return the path to the small YMIR images HDF5 file.
"""

return get_path('small_ymir_images.hdf')
Loading