Skip to content

Commit 2121140

Browse files
authored
Merge pull request #9 from azazellochg/devel
3.0b3
2 parents 7d2caf6 + 98f2927 commit 2121140

30 files changed

Lines changed: 475 additions & 261 deletions

.github/workflows/publish_and_tag.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ env:
1212
jobs:
1313
deploy:
1414
runs-on: ubuntu-latest
15+
permissions:
16+
# IMPORTANT: this permission is mandatory for Trusted Publishing
17+
id-token: write
1518
steps:
1619
- uses: actions/checkout@v4
1720
- uses: actions/setup-python@v5
@@ -24,13 +27,10 @@ jobs:
2427
- name: Check extra requirements
2528
if: ${{ hashFiles('requirements.txt') != '' }}
2629
run: pip install -r requirements.txt
27-
- name: publish
28-
env:
29-
TWINE_USERNAME: __token__
30-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
31-
run: |
32-
python -m build --no-isolation
33-
twine upload dist/*
30+
- name: Build dist
31+
run: python -m build --no-isolation
32+
- name: Publish package distributions to PyPI
33+
uses: pypa/gh-action-pypi-publish@release/v1
3434
- name: Get version and tag
3535
run: |
3636
export PACKAGE_VERSION=$(python -c "import $FOLDER_WITH_VERSION; print('VERSION', 'v'+$FOLDER_WITH_VERSION.__version__)" | grep VERSION | sed "s/VERSION //g")

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ New changes and this whole product is distributed under either version 3 of the
3434
Documentation
3535
-------------
3636

37+
The source code is available at https://github.com/azazellochg/pytemscript
38+
3739
The documentation can be found at https://pytemscript.readthedocs.io
3840

3941
Quick example

docs/acquisition.rst

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
Image acquisition
2+
=================
3+
4+
The acquisition can become quite cumbersome due to many different cameras from various manufacturers installed on a microscope.
5+
Here we describe supported / tested cameras and explain how they can be controlled by ``pytemscript``
6+
7+
List of tested cameras:
8+
9+
* Orius CCD (SC200W (830), SC200B (830))
10+
* Ceta 16M
11+
* Ceta D
12+
* Falcon 3EC
13+
* Falcon 4(i)
14+
* K2
15+
* K3
16+
17+
All methods described below return a 16-bit unsigned integer (equivalent to MRC mode 6) :meth:`~pytemscript.modules.Image` object.
18+
If movies are being acquired asynchronously, their format can be different.
19+
20+
Standard scripting
21+
------------------
22+
23+
Gatan CCD cameras are usually embedded by TFS and can be controlled via standard scripting. This requires both Digital Micrograph
24+
and TIA to be opened as well as the current camera selected in the Microscope User Interface (CCD/TV camera panel).
25+
26+
.. code-block:: python
27+
28+
microscope = Microscope()
29+
acq = microscope.acquisition
30+
img = acq.acquire_tem_image("BM-Orius", AcqImageSize.FULL, exp_time=1.0, binning=2)
31+
32+
.. warning:: If you need to change the camera, after doing so in the Microscope interface, you have to reconnect the microscope client since the COM interface needs to be reinitialised.
33+
34+
For Gatan K2/K3 cameras (if they are embedded by TFS), standard scripting can only return unaligned average image,
35+
there are no options to acquire movies or change the mode (linear/counting).
36+
You can only modify binning or exposure time.
37+
38+
TecnaiCCD plugin
39+
----------------
40+
41+
FEI has created their own plugin for Gatan CCD cameras. The plugin needs to be installed on Gatan PC inside Digital Micrograph.
42+
Digital Micrograph and TIA need to be opened as well as the current camera selected in the Microscope User Interface (CCD/TV camera panel).
43+
The advantage of this method over standard scripting is ~20 % speed improvement for both acquisition and image return, because the plugin
44+
interacts directly with Digital Micrograph and does not return the image to TIA.
45+
46+
.. code-block:: python
47+
48+
microscope = Microscope(useTecnaiCCD=True)
49+
acq = microscope.acquisition
50+
img = acq.acquire_tem_image("BM-Orius", AcqImageSize.FULL, exp_time=1.0, binning=2, use_tecnaiccd=True)
51+
52+
SerialEMCCD plugin
53+
------------------
54+
55+
David Mastronarde has created a SerialEM `plugin <https://github.com/mastcu/SerialEMCCD>`_ to control both Gatan CCDs and advanced cameras like K2 or K3.
56+
The plugin has to be installed on Gatan PC inside Digital Micrograph, which is normally done during SerialEM installation.
57+
The connection to the plugin is established via a socket interface created by ``pytemscript`` (same way as Leginon does it).
58+
Digital Micrograph needs to be opened. SerialEM does not have to be running.
59+
60+
The plugin provides multiple options for movie acquisition, frame alignment etc.
61+
62+
.. warning:: In development, not available yet
63+
64+
Advanced scripting
65+
------------------
66+
67+
This scripting interface was developed by TFS for their newer cameras like Ceta and Falcon.
68+
The currently supported cameras are Ceta 1, Ceta 2, Falcon 3 and Falcon 4(i).
69+
The interface includes new features like movie acquisition, counting mode, EER format etc.
70+
Movies are offloaded asynchronously to the storage server, while the returned image is an average (aligned or not).
71+
72+
There's no need to open TIA or select the camera in the microscope interface.
73+
74+
See details for :meth:`~pytemscript.modules.Acquisition.acquire_tem_image`
75+
76+
.. code-block:: python
77+
78+
microscope = Microscope()
79+
acq = microscope.acquisition
80+
img = acq.acquire_tem_image("BM-Falcon", AcqImageSize.FULL, exp_time=5.0, binning=1, electron_counting=True, align_image=True, group_frames=2)
81+
82+
.. note:: Advanced scripting features like "Camera Electron Counting" and "Camera Dose Fractions" require separate licenses from TFS.
83+
84+
Speed up the acquisition
85+
------------------------
86+
87+
By default, ``pytemscript`` will use `AsSafeArray` method to convert the COM image object to a numpy array via standard or advanced scripting.
88+
Depending on the image size this method can be very slow (several seconds). There's a trick to save the image object to a temporary file
89+
(`AsFile` COM method) and then read it, which seems to work much faster (up to 3x). However, this requires an extra `imageio` dependency for reading the temporary file.
90+
91+
.. warning:: On some systems, saving to a file can fail with a COM error due to incomplete implementation, so you will have to stick to the default `AsSafeArray` method.
92+
93+
If you want to try this method, add a couple of kwargs to your acquisition command:
94+
95+
.. code-block:: python
96+
97+
microscope = Microscope()
98+
acq = microscope.acquisition
99+
img = acq.acquire_tem_image("BM-Falcon", AcqImageSize.FULL, exp_time=5.0, use_safearray=False, use_asfile=True)
100+
101+
102+
STEM acquisition
103+
----------------
104+
105+
STEM detectors have to be embedded by FEI and selected in the Microscope User Interface (STEM user panel). They are controlled by standard scripting.
106+
107+
.. note:: Be aware that the acquisition starts immediately without waiting for STEM detectors insertion to finish. It's probably better to manually insert them first in the microscope interface.

docs/changelog.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ Version 3.0
2323
- Tundra (Win10, Python 3.11)
2424
- Titan Krios G1 (Win7, Python 3.6), G2, G3i (Win10, Python 3.8), G4 (Win10, Python 3.8)
2525

26-
* Future plans:
27-
28-
- UTAPI client
29-
- Acquisition series
30-
3126
Version 2.0.0
3227
^^^^^^^^^^^^^
3328

docs/components/events.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ You can receive events from hand panel buttons when using the local client on th
55
can be assigned with a custom Python function that will be executed upon pressing. We provide the :meth:`~pytemscript.modules.ButtonHandler` class
66
that takes care of assigning events.
77

8-
.. warning:: Don't forget to clear the custom button assignment at the end using `clear()` method. This will restore the previous assignment.
8+
.. note:: Don't forget to clear the custom button assignment at the end using `clear()` method. This will restore the previous assignment.
99

1010
See example below:
1111

docs/components/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Vectors
7171
-------
7272

7373
Some attributes handle two dimensional vectors that have X and Y values (e.g. image shift or gun tilt). These
74-
attributes accept and return a :meth:`~pytemscript.modules.Vector` of two floats. Vectors can be multiplied, subtracted etc.:
74+
attributes accept and return a :meth:`~pytemscript.modules.Vector` of two floats. Vectors can be multiplied, subtracted etc. as shown below.
75+
You can also use a list or a tuple to set vector attributes.
7576

7677
.. code-block:: python
7778
@@ -80,6 +81,8 @@ attributes accept and return a :meth:`~pytemscript.modules.Vector` of two floats
8081
shift += (0.4, 0.2)
8182
shift *= 2
8283
microscope.optics.illumination.beam_shift = shift
84+
projection.image_shift = (0.05, 0.1)
85+
projection.image_shift = [0.05, 0.1]
8386
8487
.. autoclass:: pytemscript.modules.Vector
8588
:members: set_limits, check_limits, get, set

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
author = 'Tore Niermann, Grigory Sharov'
2222

2323
# The full version, including alpha/beta/rc tags
24-
release = '3.0b1'
24+
release = '3.0b3'
2525

2626
# -- General configuration ---------------------------------------------------
2727
# If your documentation needs a minimal Sphinx version, state it here.

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ New changes and this whole product is distributed under either version 3 of the
1818
Documentation
1919
-------------
2020

21+
The source code is available at https://github.com/azazellochg/pytemscript
22+
2123
The documentation can be found at https://pytemscript.readthedocs.io
2224

2325
.. toctree::
@@ -27,6 +29,7 @@ The documentation can be found at https://pytemscript.readthedocs.io
2729
installation
2830
components/index
2931
getting_started
32+
acquisition
3033
remote
3134
changelog
3235

docs/installation.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
Installation
22
============
33

4-
Requirements:
4+
Prerequisites for the FEI or Thermo Fisher Scientific microscope:
5+
6+
* TEM Scripting
7+
* TEM Advanced scripting (optional)
8+
* LowDose (optional)
9+
* TecnaiCCD plugin for Digital Micrograph (optional)
10+
* SerialEMCCD plugin for Digital Micrograph (optional)
11+
12+
Requirements for this package:
513

614
* python 3.4 or newer
715
* comtypes
816
* mrcfile (to save MRC files)
917
* numpy
1018
* pillow (to save non-MRC files)
19+
* imageio (optional, to speed up image acquisition)
1120

1221
Online installation on Windows
1322
##############################

docs/remote.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Socket-based client
1212
In this mode the pytemscript socket server must run on the microscope PC (Windows).
1313
By default, it will listen for clients on port 39000.
1414

15-
.. warning::
15+
.. danger::
1616

1717
The server provides no means of security or authorization control itself.
1818
Thus it is highly recommended to let the server only listen to internal networks or at least route it through a reverse proxy, which implements sufficient security.
@@ -42,7 +42,7 @@ Then you can connect to the server as shown below:
4242
4343
Diagnostic messages are saved to ``socket_client.log`` and ``socket_server.log`` as well as printed to the console. Log files are rotated weekly at midnight.
4444

45-
To shutdown pytemscript-server, press Ctrl+C in the console.
45+
To shutdown pytemscript-server, press Ctrl+C in the server console.
4646

4747
UTAPI client
4848
------------
@@ -55,7 +55,8 @@ you can search for ``utapi_server.exe`` in the Task Manager. The server is liste
5555
**46699**. Under the hood UTAPI utilizes gRPC (Google Remote Procedure Calls) framework that uses protocol
5656
buffers for communication.
5757

58-
Pytemscript converts its API commands to UTAPI calls. The client requires extra dependencies to be installed:
58+
Pytemscript converts its API commands to UTAPI calls. The client only supports Python 3.8+ and requires
59+
a few extra dependencies to be installed:
5960

6061
.. code-block:: python
6162

0 commit comments

Comments
 (0)