diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e815b48a..1c96a793 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,7 @@ on: jobs: build: runs-on: windows-latest + if: github.event.pull_request.draft == false strategy: fail-fast: false diff --git a/docs/config.md b/docs/config.md index b0751479..6a64013b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -271,7 +271,7 @@ This file holds all the specifications of the microscope as necessary. It is imp **ranges** : In the child items, all the magnification ranges must be defined. They can be obtained through the API using: `ctrl.magnification.get_ranges()`. This will step through all the magnifications and return them as a dictionary. -**range/diff** +**ranges/diff** : List here the available camera lengths available on the microscope in ascending order: ```yaml ranges: @@ -279,6 +279,10 @@ ranges: 1200, 1500, 2000, 2500, 3000, 3500, 4000, 4500] ``` +!!! note + + For FEI/TFS machines, use `range/D` instead of `ranges/diff`. + **ranges/mag** : Here, mag must be one of the known mag ranges, i.e. `lowmag`, `mag1`, `samag`. What follows is a list of all available magnifications on the microscope in ascending order, for example: ```yaml @@ -289,3 +293,7 @@ ranges: 400000, 500000, 600000, 800000, 1000000, 1200000, 1500000, 2000000] ``` + +!!! note + + For FEI/TFS machines, the ranges are instead set as: `LM` (lowmag), `Mi` (low/intermediate mag), `SA` (high mag), `Mh` (highest mag), and `D` (diffraction mode). diff --git a/docs/setup.md b/docs/setup.md index 9947d917..906f155e 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -35,7 +35,7 @@ In order of priority: In `config/settings.yaml` define the camera interface you want to use. You can use the autoconfig tool or one of the example files and modify those. You can name these files anything you want, as long as the name under `microscope` matches the filename in `config/microscope` ### __3. Set up the magnifications and camera lengths__ - In the config file, i.e `config/microscope/jeol.yaml`, set the correct camera lengths (`range_diff`) and magnifications for your microscopes (`range_lowmag` and `range_mag1`). Also make sure you set the wavelength. Again, the autoconfig tool is your best friend, otherwise, the way to get those numbers is to simply write them down as you turn the magnification knob on the microcope. + In the config file, i.e `config/microscope/jeol.yaml`, set the correct camera lengths (`ranges/diff`) and magnifications for your microscopes (`ranges/lowmag` and `ranges/mag1`). Also make sure you set the wavelength. Again, the autoconfig tool is your best friend, otherwise, the way to get those numbers is to simply write them down as you turn the magnification knob on the microcope. ### __4. Set up the camera interface__ Specify the file you want to use for the camera interface, i.e. `camera: timepix` points to `config/camera/timepix.yaml`. In this file, make sure that the interface is set to your camera type and update the numbers as specified in the config documentation. If you do not want to set up the camera interface at this moment, you can use `camera: simulate` to fake the camera connection. diff --git a/instamatic/TEMController/fei_microscope.py b/instamatic/TEMController/fei_microscope.py index ce58659a..f92eb4d1 100644 --- a/instamatic/TEMController/fei_microscope.py +++ b/instamatic/TEMController/fei_microscope.py @@ -28,95 +28,21 @@ # 0.02: 0.593 # 0.01: 0.297 - FUNCTION_MODES = {0: 'LM', 1: 'Mi', 2: 'SA', 3: 'Mh', 4: 'LAD', 5: 'D'} -MagnificationMapping = { - 1: 45, - 2: 58, - 3: 73, - 4: 89, - 5: 115, - 6: 145, - 7: 185, - 8: 235, - 9: 300, - 10: 380, - 11: 470, - 12: 600, - 13: 760, - 14: 950, - 15: 1200, - 16: 1550, - 17: 3400, - 18: 4400, - 19: 5600, - 20: 7200, - 21: 8800, - 22: 11500, - 23: 14500, - 24: 18500, - 25: 24000, - 26: 30000, - 27: 38000, - 28: 49000, - 29: 61000, - 30: 77000, - 31: 100000, - 32: 130000, - 33: 165000, - 34: 215000, - 35: 265000, - 36: 340000, - 37: 430000, - 38: 550000, - 39: 700000, - 40: 890000, - 41: 1150000, - 42: 1250000, - 43: 960000, - 44: 750000, - 45: 600000, - 46: 470000, - 47: 360000, - 48: 285000, - 49: 225000, - 50: 175000, - 51: 145000, - 52: 115000, - 53: 89000, - 54: 66000, - 55: 52000, - 56: 41000, - 57: 32000, - 58: 26000, - 59: 21000, - 60: 8300, - 61: 6200, - 62: 3100} - -CameraLengthMapping = { - 1: 34, - 2: 42, - 3: 53, - 4: 68, - 5: 90, - 6: 115, - 7: 140, - 8: 175, - 9: 215, - 10: 265, - 11: 330, - 12: 420, - 13: 530, - 14: 680, - 15: 830, - 16: 1050, - 17: 1350, - 18: 1700, - 19: 2100, - 20: 2700, - 21: 3700} + +def get_magnification_mapping(): + functions = ('LM', 'Mi', 'SA', 'Mh') + values = (val for function in functions for val in config.microscope.ranges[function]) + return {num + 1: val for num, val in enumerate(values)} + + +def get_camera_length_mapping(): + return {num + 1: val for num, val in enumerate(config.microscope.ranges['D'])} + + +MagnificationMapping = get_magnification_mapping() +CameraLengthMapping = get_camera_length_mapping() class FEIMicroscope: diff --git a/instamatic/camera/camera_merlin.py b/instamatic/camera/camera_merlin.py index 00da822e..9fe93c74 100644 --- a/instamatic/camera/camera_merlin.py +++ b/instamatic/camera/camera_merlin.py @@ -47,6 +47,7 @@ def MPX_CMD(type_cmd: str = 'GET', cmd: str = 'DETECTORSTATUS') -> bytes: class CameraMerlin: """Camera interface for the Quantum Detectors Merlin camera.""" START_SIZE = 14 + MAX_NUMFRAMESTOACQUIRE = 42_949_672_950 def __init__(self, name='merlin'): """Initialize camera module.""" @@ -161,12 +162,12 @@ def setup_soft_trigger(self, exposure: float = None): self._frame_number = 0 - # Set NUMFRAMESTOACQUIRE to a large number - # Merlin will only collect this number of frames with SOFTTRIGGER - self.merlin_set('NUMFRAMESTOACQUIRE', 10_000) + # Set NUMFRAMESTOACQUIRE to maximum + # Merlin collects up to this number of frames with a single SOFTTRIGGER acquisition + self.merlin_set('NUMFRAMESTOACQUIRE', self.MAX_NUMFRAMESTOACQUIRE) - self.merlin_set('TRIGGERSTART', '5') - self.merlin_set('NUMFRAMESPERTRIGGER', '1') + self.merlin_set('TRIGGERSTART', 5) + self.merlin_set('NUMFRAMESPERTRIGGER', 1) self.merlin_cmd('STARTACQUISITION') start = self.receive_data(nbytes=self.START_SIZE) @@ -203,7 +204,10 @@ def getImage(self, exposure: float = None, **kwargs) -> np.ndarray: self.setup_soft_trigger(exposure=exposure) elif exposure != self._soft_trigger_exposure: logger.info('Change exposure to %s s', exposure) - self.teardown_soft_trigger() + self.setup_soft_trigger(exposure=exposure) + elif self._frame_number == self.MAX_NUMFRAMESTOACQUIRE: + logger.debug(('Maximum frame number reached for this acquisition, ' + 'resetting soft trigger.') % self.MAX_NUMFRAMESTOACQUIRE) self.setup_soft_trigger(exposure=exposure) self.merlin_cmd('SOFTTRIGGER') diff --git a/instamatic/config/autoconfig.py b/instamatic/config/autoconfig.py index b8c1ffe8..907d57d6 100644 --- a/instamatic/config/autoconfig.py +++ b/instamatic/config/autoconfig.py @@ -191,9 +191,11 @@ def main(): if cam_config: print(f' camera: {cam_name}_cam') print() - print(f'Todo: Check and update the pixelsizes in `{calib_config_fn}`') - print(' In real space, pixelsize in nm') - print(' In reciprocal space, pixelsize in px/Angstrom') + print('Todo:') + print(f' 1. Check and update the pixelsizes in `{calib_config_fn}`') + print(' - In real space, pixelsize in nm') + print(' - In reciprocal space, pixelsize in px/Angstrom') + print(f' 2. Check and update magnification ranges in `{microscope_config_fn}`') if __name__ == '__main__': diff --git a/instamatic/config/microscope/fei_simu.yaml b/instamatic/config/microscope/fei_simu.yaml index 23bca892..a4ae9044 100644 --- a/instamatic/config/microscope/fei_simu.yaml +++ b/instamatic/config/microscope/fei_simu.yaml @@ -1,10 +1,9 @@ interface: fei_simu ranges: - diff: [150, 200, 250, 300, 400, 500, 600, 800, 1000, 1200, 1500, 2000, 2500, 3000, - 3500, 4000, 4500] - lowmag: [50, 80, 100, 150, 200, 250, 300, 400, 500, 600, 800, 1000, 1200, 1500, - 2000, 2500, 3000, 5000, 6000, 8000, 10000, 12000, 15000] - mag1: [2500, 3000, 4000, 5000, 6000, 8000, 10000, 12000, 15000, 20000, 25000, 30000, - 40000, 50000, 60000, 80000, 100000, 120000, 150000, 200000, 250000, 300000, 400000, - 500000, 600000, 800000, 1000000, 1500000, 2000000] + LM: [45, 58, 73, 89, 115, 145, 185, 235, 300, 380, 470, 600, 760, 950, 1200, 1550] + Mi: [] + SA: [3400, 4400, 5600, 7200, 8800, 11500, 14500, 18500, 24000, 30000, 38000, 49000, 61000, 77000, 100000, 130000, 165000, 215000, 265000, 340000] + Mh: [430000, 550000, 700000, 890000, 1150000, 1250000, 960000, 750000, 600000, 470000, 360000, 285000, 225000, 175000, 145000, 115000, 89000, 66000, 52000, 41000, 32000, 26000, 21000, 8300, 6200, 3100] + D: [34, 42, 53, 68, 90, 115, 140, 175, 215, 265, 330, 420, 530, 680, 830, 1050, 1350, 1700, 2100, 2700, 3700] + LAD: [] wavelength: 0.019687 diff --git a/instamatic/config/microscope/fei_themisZ.yaml b/instamatic/config/microscope/fei_themisZ.yaml index 6153cc8f..408a8192 100644 --- a/instamatic/config/microscope/fei_themisZ.yaml +++ b/instamatic/config/microscope/fei_themisZ.yaml @@ -1,10 +1,8 @@ interface: fei ranges: - diff: [150, 200, 250, 300, 400, 500, 600, 800, 1000, 1200, 1500, 2000, 2500, 3000, - 3500, 4000, 4500] - lowmag: [50, 80, 100, 150, 200, 250, 300, 400, 500, 600, 800, 1000, 1200, 1500, - 2000, 2500, 3000, 5000, 6000, 8000, 10000, 12000, 15000] - mag1: [2500, 3000, 4000, 5000, 6000, 8000, 10000, 12000, 15000, 20000, 25000, 30000, - 40000, 50000, 60000, 80000, 100000, 120000, 150000, 200000, 250000, 300000, 400000, - 500000, 600000, 800000, 1000000, 1500000, 2000000] + LM: [45, 58, 73, 89, 115, 145, 185, 235, 300, 380, 470, 600, 760, 950, 1200, 1550] + Mi: [] + SA: [3400, 4400, 5600, 7200, 8800, 11500, 14500, 18500, 24000, 30000, 38000, 49000, 61000, 77000, 100000, 130000, 165000, 215000, 265000, 340000] + Mh: [430000, 550000, 700000, 890000, 1150000, 1250000, 960000, 750000, 600000, 470000, 360000, 285000, 225000, 175000, 145000, 115000, 89000, 66000, 52000, 41000, 32000, 26000, 21000, 8300, 6200, 3100] + D: [34, 42, 53, 68, 90, 115, 140, 175, 215, 265, 330, 420, 530, 680, 830, 1050, 1350, 1700, 2100, 2700, 3700] wavelength: 0.019687