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

Update documentation #103

Merged
merged 5 commits into from
Nov 19, 2024
Merged
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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ repos:
rev: v0.2.0
hooks:
- id: nbcheckorder
# This notebook is not executed at all, which fails the check
exclude: |
(?x)^(
docs/examples/montage_processing.ipynb
)$
- repo: https://github.com/myint/docformatter
rev: master # https://github.com/PyCQA/docformatter/issues/293
hooks:
Expand Down
1 change: 0 additions & 1 deletion docs/api/TEMController_TEMController.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api/TEMController_deflectors.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api/TEMController_lenses.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api/TEMController_stage.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api/TEMController_states.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/api/components_deflectors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: instamatic.microscope.components.deflectors
1 change: 1 addition & 0 deletions docs/api/components_lenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: instamatic.microscope.components.lenses
1 change: 1 addition & 0 deletions docs/api/components_stage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: instamatic.microscope.components.stage
1 change: 1 addition & 0 deletions docs/api/components_states.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: instamatic.microscope.components.states
1 change: 1 addition & 0 deletions docs/api/controller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: instamatic.controller
876 changes: 748 additions & 128 deletions docs/examples/data_collection.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/examples/grid_montage_collection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
}
],
"source": [
"from instamatic import TEMController\n",
"from __future__ import annotations\n",
"\n",
"from instamatic import controller\n",
"from instamatic.formats import write_tiff\n",
"\n",
"ctrl = TEMController.initialize()"
"ctrl = controller.initialize()"
]
},
{
Expand Down
44 changes: 26 additions & 18 deletions docs/examples/montage_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
"metadata": {},
"outputs": [],
"source": [
"from instamatic.montage import *\n",
"import numpy as np\n",
"from __future__ import annotations\n",
"\n",
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"\n",
"from instamatic.montage import *\n",
"\n",
"np.set_printoptions(suppress=True)\n",
"\n",
"# work directory\n",
Expand Down Expand Up @@ -88,8 +93,8 @@
"outputs": [],
"source": [
"# Use cross correlation to get difference vectors\n",
"m.calculate_difference_vectors(threshold='auto', \n",
" method='skimage', \n",
"m.calculate_difference_vectors(threshold='auto',\n",
" method='skimage',\n",
" plot=False)\n",
"\n",
"# plot the fft_scores\n",
Expand Down Expand Up @@ -155,6 +160,7 @@
"outputs": [],
"source": [
"from pyserialem.navigation import sort_nav_items_by_shortest_path\n",
"\n",
"stagecoords = sort_nav_items_by_shortest_path(stagecoords, plot=True);"
]
},
Expand All @@ -171,8 +177,9 @@
"metadata": {},
"outputs": [],
"source": [
"from instamatic import TEMController\n",
"ctrl = TEMController.initialize()"
"from instamatic import controller\n",
"\n",
"ctrl = controller.initialize()"
]
},
{
Expand Down Expand Up @@ -228,11 +235,11 @@
"def acquire_func(ctrl):\n",
" # Align to template\n",
"# ctrl.align_to(ref_img, apply=True)\n",
" \n",
"\n",
" # obtain image\n",
" img, h = ctrl.get_image(binsize=binsize) \n",
" img, h = ctrl.get_image(binsize=binsize)\n",
" buffer.append(img)\n",
" \n",
"\n",
" # store stage position and image somewhere\n",
" pos = ctrl.stage.get()\n",
" stagepos.append(pos)"
Expand Down Expand Up @@ -273,6 +280,7 @@
"outputs": [],
"source": [
"from pyserialem import MapItem, write_nav_file\n",
"\n",
"from instamatic import config\n",
"\n",
"# reference image of a centered grid square\n",
Expand All @@ -285,7 +293,7 @@
"buffer = []\n",
"stagepos = []\n",
"\n",
" \n",
"\n",
"def write_mrc_stack(fn:str, data: list, overwrite: bool=True, mmap:bool = True):\n",
" \"\"\"Write a stack of images to an mrc file.\"\"\"\n",
" if mmap:\n",
Expand All @@ -301,21 +309,21 @@
" f = mrcfile.new(fn, data=data, overwrite=overwrite)\n",
" except OSError:\n",
" f.close()\n",
" \n",
"\n",
"\n",
"def post_acquire(ctrl):\n",
" fn_nav = work / 'instamatic.nav'\n",
" fn_mrc = work / 'mmm.mrc'\n",
" \n",
"\n",
" write_mrc_stack(fn_mrc, buffer)\n",
" \n",
"\n",
" items = []\n",
" \n",
"\n",
" magnification = ctrl.magnification.value\n",
" mode = ctrl.mode.get()\n",
" mapscalemat = config.calibration[mode]['stagematrix'][magnification]\n",
" mapscalemat = [item/binsize for item in mapscalemat]\n",
" \n",
"\n",
" for i, image in enumerate(buffer):\n",
" x, y, z, _, _ = stagepos[i]\n",
" shape = image.shape\n",
Expand All @@ -334,7 +342,7 @@
" items.append(map_item)\n",
"\n",
" write_nav_file(fn_nav, *items)\n",
" \n",
"\n",
" print(f\"Data saved to `{fn_nav}` and `{fn_mrc}` ({len(buffer)} images)\")"
]
},
Expand All @@ -352,8 +360,8 @@
"outputs": [],
"source": [
"sel = stagecoords[0:10] # Acquire at the first 10 items\n",
"ctrl.acquire_at_items(sel, \n",
" acquire=acquire_func, \n",
"ctrl.acquire_at_items(sel,\n",
" acquire=acquire_func,\n",
" post_acquire=post_acquire)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/gonio.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ goniotool_server_host: 'localhost'
goniotool_server_port: 8090
```

The controls are then available in the [`python API`][instamatic.TEMController.TEMController] via [`ctrl.stage`][instamatic.TEMController.stage.Stage] in your own script/notebook:
The controls are then available in the [`python API`][instamatic.controller] via [`ctrl.stage`][instamatic.microscope.components.Stage] in your own script/notebook:


```python
Expand Down
2 changes: 1 addition & 1 deletion docs/programs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ There are several programs coming with `instamatic`. These docs are autogenerate
These are the main tools to work with instamatic.

- [instamatic](#instamatic) (`instamatic.main:main`)
- [instamatic.controller](#instamaticcontroller) (`instamatic.TEMController.TEMController:main_entry`)
- [instamatic.controller](#instamaticcontroller) (`instamatic.controller:main_entry`)

**Experiments**

Expand Down
16 changes: 8 additions & 8 deletions docs/tem_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ The TEMController is at the heart of `instamatic`. Every routine depends on acce
In IPython/Jupyter:

```python
from instamatic import TEMController
ctrl = TEMController.initialize()
from instamatic import controller
ctrl = controller.initialize()
```

If no names for the camera/microscope are given, it reads the defaults from the config directory listed when TEMController is imported (`config/settings.yaml`). The config directory is generated on the first run of `instamatic`. By default these are set to load simulation of the camera/microscope. The simulation is is a good test to see if it works at all (a shortcut to this is to type `instamatic.controller.exe` in the terminal).
Expand All @@ -18,20 +18,20 @@ The config files work as follows: The global configurations are defined in `conf
You can override the defaults here, so on the microscope computer you could try:

```python
ctrl = TEMController.initialize(tem_name='jeol', cam_name='timepix', stream=True)
ctrl = controller.initialize(tem_name='jeol', cam_name='timepix', stream=True)
```

`stream` indicates that the camera can be streamed (like the timepix camera). Other cameras, like the gatan (orius/ultrascan) cameras communicate through DigitalMicrograph, and can therefore not be streamed. Instead the live stream can be shown in DM, and therefore needs DM to be open.

Otherwise, to skip camera initialization:

```python
ctrl = TEMController.initialize(tem_name='jeol', cam_name=None)
ctrl = controller.initialize(tem_name='jeol', cam_name=None)
```

Once a `ctrl` (control) object has been initialized, it becomes possible to play around with the lenses and stage interactively. Type `ctrl.` and hit `tab` to see the autocomplete options. Or write use `?` to request the doc string for a function (e.g. `TEMController.initialize?`).
Once a `ctrl` (control) object has been initialized, it becomes possible to play around with the lenses and stage interactively. Type `ctrl.` and hit `tab` to see the autocomplete options. Or write use `?` to request the doc string for a function (e.g. `controller.initialize?`).

Based on this you can write your own python scripts to control the microscope and/or camera. See in `src/instamatic/experiments/cred/experiment.py` for an idea how this is used. All the microscope control interface can be found in `src/instamatic/TEMController/`
Based on this you can write your own python scripts to control the microscope and/or camera. See in `src/instamatic/experiments/cred/experiment.py` for an idea how this is used. All the microscope control interface can be found in `src/instamatic/microscope/interface`

The `ctrl` object allows full control over the electron microscope. For example, to read out the position of the sample stage:
```python
Expand Down Expand Up @@ -250,9 +250,9 @@ An example rotation experiment could look something like this:

```python
from instamatic.formats import write_tiff
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()

exposure_time = 1.0
angles = range(-40, 40, 1)
Expand Down
10 changes: 5 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ nav:
- network.md
- Python API:
- instamatic.TEMController:
- TEMController: api/TEMController_TEMController.md
- Deflectors: api/TEMController_deflectors.md
- Lenses: api/TEMController_lenses.md
- States: api/TEMController_states.md
- Stage: api/TEMController_stage.md
- TEMController: api/controller.md
- Deflectors: api/components_deflectors.md
- Lenses: api/components_lenses.md
- States: api/components_states.md
- Stage: api/components_stage.md
- instamatic.tools: api/instamatic_tools.md
- instamatic.montage: api/instamatic_montage.md
- instamatic.gridmontage: api/instamatic_gridmontage.md
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ publishing = [

[project.scripts]
"instamatic" = "instamatic.main:main"
"instamatic.controller" = "instamatic.TEMController.TEMController:main_entry"
"instamatic.controller" = "instamatic.controller:main_entry"
# experiments
"instamatic.serialed" = "instamatic.experiments.serialed.experiment:main"
"instamatic.camera" = "instamatic.camera.camera:main_entry"
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ Alternatively, some of the methods implemented in `Instamatic` are described in:
* **`docs/`** - Documentation
* **`src/`** - Source code for instamatic
* **`src/instamatic/`**
* **`TEMController/`** - Microscope interaction code
* **`calibrate/`** - Tools for calibration
* **`camera/`** - Camera interaction code
* **`config/`** - Configuration management
* **`experiments/`** - Specific data collection routines
* **`formats/`** - Image formats and other IO
* **`gui/`** - GUI code
* **`microscope/`** - Microscope interaction code
* **`neural_network/`** - Crystal quality prediction
* **`processing/`** - Data processing tools
* **`server/`** - Manages interprocess/network communication
Expand All @@ -94,6 +94,7 @@ Alternatively, some of the methods implemented in `Instamatic` are described in:
* **`admin.py`** - Check for administrator
* **`banner.py`** - Appropriately annoying thank you message
* **`browser.py`** - Montage browsing class
* **`controller.py`** - Main instrument interaction code
* **`exceptions.py`** - Internal exceptions
* **`goniotool.py`** - Goniotool (JEOL) interaction code
* **`gridmontage.py`** - Grid montage data collection code
Expand Down
Loading