diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d704a0dc..56f5d072 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,16 +1,16 @@ [bumpversion] -current_version = 1.10.0 +current_version = 2.0.0 [comment] comment = The contents of this file cannot be merged with that of setup.cfg until https://github.com/c4urself/bump2version/issues/185 is resolved -[bumpversion:file:instamatic/__init__.py] +[bumpversion:file:src/instamatic/__init__.py] search = __version__ = '{current_version}' replace = __version__ = '{new_version}' -[bumpversion:file:setup.cfg] -search = version = {current_version} -replace = version = {new_version} +[bumpversion:file:pyproject.toml] +search = version = "{current_version}" +replace = version = "{new_version}" [bumpversion:file:CITATION.cff] search = version: "{current_version}" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 70d8f9c5..a421b953 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,16 +12,16 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: '3.11' - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine - python setup.py sdist bdist_wheel + pip install -U build setuptools wheel + python -m build --no-isolation - name: Publish package - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c96a793..6ba97346 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: id: cache-python-env with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-${{ hashFiles('setup.cfg') }} + key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} - name: Install if: steps.cache-python-env.outputs.cache-hit != 'true' diff --git a/CITATION.cff b/CITATION.cff index 02567761..10d6fc42 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -27,5 +27,5 @@ doi: "10.5281/zenodo.1090388" license: "BSD-3-Clause" message: "If you use this software, please cite it using these metadata." title: Instamatic -version: "1.10.0" +version: "2.0.0" ... diff --git a/MANIFEST.in b/MANIFEST.in index ee7d494f..9f4fd525 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -13,17 +13,17 @@ include setup_win.bat include tests/*.py include tests/config/*.yaml include tests/config/*/*.yaml -include instamatic/camera/*.dll -include instamatic/camera/*.h -include instamatic/camera/*.lockfile -include instamatic/camera/*.md -include instamatic/camera/tpx/*.bpc -include instamatic/camera/tpx/*.dacs -include instamatic/camera/tpx/*.txt -include instamatic/config/*.yaml -include instamatic/config/alignments/*.yaml -include instamatic/config/calibration/*.yaml -include instamatic/config/camera/*.yaml -include instamatic/config/microscope/*.yaml -include instamatic/config/scripts/*.md -include instamatic/neural_network/*.p +include src/instamatic/camera/*.dll +include src/instamatic/camera/*.h +include src/instamatic/camera/*.lockfile +include src/instamatic/camera/*.md +include src/instamatic/camera/tpx/*.bpc +include src/instamatic/camera/tpx/*.dacs +include src/instamatic/camera/tpx/*.txt +include src/instamatic/config/*.yaml +include src/instamatic/config/alignments/*.yaml +include src/instamatic/config/calibration/*.yaml +include src/instamatic/config/camera/*.yaml +include src/instamatic/config/microscope/*.yaml +include src/instamatic/config/scripts/*.md +include src/instamatic/neural_network/*.p diff --git a/docs/config.md b/docs/config.md index 6a64013b..262afddb 100644 --- a/docs/config.md +++ b/docs/config.md @@ -26,7 +26,7 @@ instamatic.autoconfig.exe ``` To help generate some of the input files (in particular templates for the microscope/calibration files). -Examples of configuration files can be found [here](https://github.com/instamatic-dev/instamatic/tree/main/instamatic/config). +Examples of configuration files can be found [here](https://github.com/instamatic-dev/instamatic/tree/main/src/instamatic/config). ## settings.yaml diff --git a/docs/examples/montage_processing.ipynb b/docs/examples/montage_processing.ipynb index 346f4a64..0d5e3dd5 100644 --- a/docs/examples/montage_processing.ipynb +++ b/docs/examples/montage_processing.ipynb @@ -319,7 +319,7 @@ " for i, image in enumerate(buffer):\n", " x, y, z, _, _ = stagepos[i]\n", " shape = image.shape\n", - " # binsize = ctrl.cam.getBinning()\n", + " # binsize = ctrl.cam.get_binning()\n", "\n", " d = {}\n", " d['StageXYZ'] = x / 1000, y / 1000, z / 1000\n", diff --git a/docs/merlin.md b/docs/merlin.md index cdcdc87d..bd5dd15e 100644 --- a/docs/merlin.md +++ b/docs/merlin.md @@ -4,7 +4,7 @@ The [MerlinEM detector](https://quantumdetectors.com/products/merlinem/) by Quan Instamatic communicates with the Merlin control software via TCP/IP connection. This means that there is a fast connection with little overhead when collecting data. -In continous read/write mode, instamatic can achieve gapless data acquisition `MerlinCamera.getMovie()`. When continuously collecting single images using `MerlinCamera.getImage()`, there is a ~3 ms overhead per frame. +In continous read/write mode, instamatic can achieve gapless data acquisition `MerlinCamera.get_movie()`. When continuously collecting single images using `MerlinCamera.get_image()`, there is a ~3 ms overhead per frame. ## Setup @@ -16,7 +16,7 @@ camera: merlin You can set up the parameters for the Merlin camera through `camera/merlin.yaml` in your config directory. -For an example config file, see: [`camera/merlin.yaml`](https://github.com/instamatic-dev/instamatic/blob/main/instamatic/config/camera/merlin.yaml). [Click here](/config.md#camerayaml) to go to the page with all common camera configuration parameters. +For an example config file, see: [`camera/merlin.yaml`](https://github.com/instamatic-dev/instamatic/blob/main/src/instamatic/config/camera/merlin.yaml). [Click here](/config.md#camerayaml) to go to the page with all common camera configuration parameters. In addition, the Merlin camera has the following parameters to configure: @@ -34,18 +34,24 @@ host: '10.0.0.123' **detector_config** : The parameters under `detector_config` are directly sent to the Merlin software when instamatic starts. -These can be used to put the Merlin in the desired state for data acquisition. Check the Merlin documention for more information. +These can be used to put the Merlin in the desired state for data acquisition. Any command with a `SET` type can be adjusted. Check the Merlin EM documention for more information. + +: The default sets continuous read-write mode and 12-bit mode to minimize the gap between frames. It also disables automatic file writing (`FILEENABLE`) and image processing by Merlin, and enables headless `RUNHEADLESS` mode for faster throughput. If you don't want this, you can delete these lines or modify them. -: For example: +```yaml +detector_config: + CONTINUOUSRW: 1 + COUNTERDEPTH: 12 + FILEENABLE: 0 + RUNHEADLESS: 1 +``` + +: You could for example also set the thresholds and bias in the instamatic config by adding these lines: ```yaml detector_config: THRESHOLD0: 120 THRESHOLD1: 40 HVBIAS: 511 - COUNTERDEPTH: 12 - FILEENABLE: 0 - CONTINUOUSRW: 1 - RUNHEADLESS: 0 ``` ## Notes on using instamatic with Merlin diff --git a/docs/programs.md b/docs/programs.md index 9ffcff83..5708d641 100644 --- a/docs/programs.md +++ b/docs/programs.md @@ -604,7 +604,7 @@ instamatic.xdsserver [-h] ## instamatic.temserver_fei -Utility script to enable rotation control from a dmscript. See [https://github.com/instamatic-dev/instamatic/tree/master/dmscript] for usage. +Utility script to enable rotation control from a dmscript. See [https://github.com/instamatic-dev/InsteaDMatic] for usage. **Usage:** ```bash diff --git a/docs/tem_api.md b/docs/tem_api.md index 9085bf77..ea7b577e 100644 --- a/docs/tem_api.md +++ b/docs/tem_api.md @@ -31,7 +31,7 @@ ctrl = TEMController.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?`). -Based on this you can write your own python scripts to control the microscope and/or camera. See in `instamatic/instamatic/experiments/cred/experiment.py` for an idea how this is used. All the microscope control interface can be found in `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/TEMController/` The `ctrl` object allows full control over the electron microscope. For example, to read out the position of the sample stage: ```python diff --git a/docs/tvips.md b/docs/tvips.md index 023da7c9..d02a6962 100644 --- a/docs/tvips.md +++ b/docs/tvips.md @@ -71,7 +71,7 @@ Stop live view : Stop the live view in EMMENU. Search -: Switch the microscope to search mode. Internally, these are defined as [`instamatic` scripts](https://github.com/instamatic-dev/instamatic/tree/main/instamatic/config/scripts) and can therefore be easily modified. The parameters of the search mode are defined in `$instamatic\scripts\search_mode.py`, for example to put the screen down, unblank the beam, and switch to MAG1 mode: +: Switch the microscope to search mode. Internally, these are defined as [`instamatic` scripts](https://github.com/instamatic-dev/instamatic/tree/main/src/instamatic/config/scripts) and can therefore be easily modified. The parameters of the search mode are defined in `$instamatic\scripts\search_mode.py`, for example to put the screen down, unblank the beam, and switch to MAG1 mode: ```python ctrl.screen.down() diff --git a/mkdocs.yml b/mkdocs.yml index 1b4ee9b1..ac963432 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -86,5 +86,5 @@ plugins: include_source: True watch: - - instamatic/ + - src/instamatic/ - docs/ diff --git a/pyproject.toml b/pyproject.toml index 78516176..86594571 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,125 @@ [build-system] -requires = ["setuptools>=40.6.0", "wheel"] +requires = ["setuptools>=61.2"] build-backend = "setuptools.build_meta" +# https://packaging.python.org/en/latest/specifications/declaring-project-metadata/ +[project] +name = "instamatic" +version = "2.0.0" +description = "Python program for automated electron diffraction data collection" +readme = "README.md" +requires-python = ">=3.7" +authors = [ + {name = "Stef Smeets", email = "s.smeets@esciencecenter.nl"}, +] +keywords = [ + "electron-crystallography", + "electron-microscopy", + "electron-diffraction", + "serial-crystallography", + "3D-electron-diffraction", + "micro-ed", + "data-collection", + "automation", +] +license = {text = "BSD License"} +classifiers = [ + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Operating System :: Microsoft :: Windows", + "Topic :: Scientific/Engineering :: Human Machine Interfaces", + "Topic :: Scientific/Engineering :: Chemistry", + "Topic :: Software Development :: Libraries", +] +dependencies = [ + "comtypes >= 1.1.7", + "h5py >= 2.10.0", + "ipython >= 7.11.1", + "lmfit >= 1.0.0", + "matplotlib >= 3.1.2", + "mrcfile >= 1.1.2", + "numpy >= 1.17.3", + "pandas >= 1.0.0", + "pillow >= 7.0.0", + "pywinauto >= 0.6.8", + "pyyaml >= 5.3", + "scikit-image >= 0.17.1", + "scipy >= 1.3.2", + "tifffile >= 2019.7.26.2", + "tqdm >= 4.41.1", + "virtualbox >= 2.0.0", + "pyserialem >= 0.3.2", +] + +[project.urls] +homepage = "https://github.com/instamatic-dev/instamatic" +issues = "http://github.com/instamatic-dev/instamatic/issues" +documentation = "https://instamatic.readthedocs.io" +changelog = "https://github.com/instamatic-dev/instamatic/releases" + +[project.optional-dependencies] +develop = [ + "bump2version", + "check-manifest", + "pre-commit", + "pytest >= 5.4.1", + "coverage", +] +serval = [ + "serval-toolkit" +] +docs = [ + "markdown-include", + "mkdocs", + "mkdocs-jupyter", + "mkdocs-gen-files", + "mkdocs-material", + "mkdocstrings[python]", +] +publishing = [ + "twine", + "wheel", + "build", +] + +[project.scripts] +"instamatic" = "instamatic.main:main" +"instamatic.controller" = "instamatic.TEMController.TEMController:main_entry" +# experiments +"instamatic.serialed" = "instamatic.experiments.serialed.experiment:main" +"instamatic.camera" = "instamatic.camera.camera:main_entry" +# calibrate +"instamatic.calibrate_stage_lowmag" = "instamatic.calibrate.calibrate_stage_lowmag:main_entry" +"instamatic.calibrate_stage_mag1" = "instamatic.calibrate.calibrate_stage_mag1:main_entry" +"instamatic.calibrate_beamshift" = "instamatic.calibrate.calibrate_beamshift:main_entry" +"instamatic.calibrate_directbeam" = "instamatic.calibrate.calibrate_directbeam:main_entry" +"instamatic.calibrate_stagematrix" = "instamatic.calibrate.calibrate_stagematrix:main_entry" +"instamatic.flatfield" = "instamatic.processing.flatfield:main_entry" +"instamatic.stretch_correction" = "instamatic.processing.stretch_correction:main_entry" +# tools +"instamatic.browser" = "scripts.browser:main" +"instamatic.viewer" = "scripts.viewer:main" +"instamatic.defocus_helper" = "instamatic.gui.defocus_button:main" +"instamatic.find_crystals" = "instamatic.processing.find_crystals:main_entry" +"instamatic.find_crystals_ilastik" = "instamatic.processing.find_crystals_ilastik:main_entry" +"instamatic.learn" = "scripts.learn:main_entry" +# server +"instamatic.temserver" = "instamatic.server.tem_server:main" +"instamatic.camserver" = "instamatic.server.cam_server:main" +"instamatic.dialsserver" = "instamatic.server.dials_server:main" +"instamatic.VMserver" = "instamatic.server.vm_ubuntu_server:main" +"instamatic.xdsserver" = "instamatic.server.xds_server:main" +"instamatic.temserver_fei" = "instamatic.server.TEMServer_FEI:main" +"instamatic.goniotoolserver" = "instamatic.server.goniotool_server:main" +# setup +"instamatic.autoconfig" = "instamatic.config.autoconfig:main" + [tool.ruff] # Enable Pyflakes `E` and `F` codes by default. select = [ diff --git a/readme.md b/readme.md index 4e431e66..014a7ecd 100644 --- a/readme.md +++ b/readme.md @@ -26,7 +26,7 @@ Cameras supported: Instamatic has been developed on a JEOL-2100 with a Timepix camera, and a JEOL-1400 and JEOL-3200 with TVIPS cameras (XF416/F416). -[1]: Support for Gatan cameras is somewhat underdeveloped. As an alternative, a DigitalMicrograph script for collecting cRED data on a OneView camera (or any other Gatan camera) can be found at [dmscript](https://github.com/instamatic-dev/InsteaDMatic). +[1]: Support for Gatan cameras is somewhat underdeveloped. As an alternative, a DigitalMicrograph script for collecting cRED data on a OneView camera (or any other Gatan camera) can be found [here](https://github.com/instamatic-dev/InsteaDMatic). ## Installation @@ -50,7 +50,7 @@ The package requires Windows 7 or higher. It has been mainly developed and teste ## Package dependencies -Check [setup.cfg](setup.cfg) for the full dependency list and versions. +Check [pypoject.toml](pypoject.toml) for the full dependency list and versions. ## Documentation @@ -76,7 +76,8 @@ Alternatively, some of the methods implemented in `Instamatic` are described in: * **`demos/`** - Jupyter demo notebooks * **`docs/`** - Documentation -* **`instamatic/`** +* **`src/`** - Source code for instamatic +* **`src/instamatic/`** * **`TEMController/`** - Microscope interaction code * **`calibrate/`** - Tools for calibration * **`camera/`** - Camera interaction code @@ -103,5 +104,4 @@ Alternatively, some of the methods implemented in `Instamatic` are described in: * **`navigation.py`** - Optimize navigation paths * **`tools.py`** - Collection of functions used throughout the code * **`scripts/`** - Helpful scripts -* **`setup.cfg`** - Dependency/build system declaration -* **`setup.py`** - Old-style build script +* **`pyproject.toml`** - Dependency/build system declaration diff --git a/scripts/process_dm.py b/scripts/process_dm.py index 918beb5c..1de82c9b 100644 --- a/scripts/process_dm.py +++ b/scripts/process_dm.py @@ -7,7 +7,7 @@ from instamatic.processing.ImgConversionDM import ImgConversionDM as ImgConversion # Script to process cRED data collecting using the DigitalMicrograph script `insteaDMatic` -# https://github.com/instamatic-dev/instamatic/tree/master/dmscript +# https://github.com/instamatic-dev/InsteaDMatic # # To use: # Run `python process_dm.py cred_log.txt` diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index a958b753..00000000 --- a/setup.cfg +++ /dev/null @@ -1,118 +0,0 @@ -# see documentation, e.g. -# - https://packaging.python.org/tutorials/packaging-projects/#configuring-metadata -# - https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html -# - https://www.python.org/dev/peps/pep-0314/ - -[metadata] -author = Stef Smeets -author_email = s.smeets@esciencecenter.nl -classifiers = - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Development Status :: 5 - Production/Stable - Intended Audience :: Science/Research - License :: OSI Approved :: BSD License - Operating System :: Microsoft :: Windows - Topic :: Scientific/Engineering :: Human Machine Interfaces - Topic :: Scientific/Engineering :: Chemistry - Topic :: Software Development :: Libraries -description = Python program for automated electron diffraction data collection -keywords = - electron-crystallography - electron-microscopy - electron-diffraction - serial-crystallography - 3D-electron-diffraction - micro-ed - data-collection - automation -long_description = file: README.md -long_description_content_type = text/markdown -name = instamatic -project_urls = - Bug Tracker = http://github.com/instamatic-dev/instamatic/issues - Documentation = https://instamatic.readthedocs.io/ -url = http://github.com/instamatic-dev/instamatic -version = 1.10.0 - - -[options] -zip_safe = False -include_package_data = True -packages = find: -install_requires = - comtypes >= 1.1.7 - h5py >= 2.10.0 - ipython >= 7.11.1 - lmfit >= 1.0.0 - matplotlib >= 3.1.2 - mrcfile >= 1.1.2 - numpy >= 1.17.3 - pandas >= 1.0.0 - pillow >= 7.0.0 - pywinauto >= 0.6.8 - pyyaml >= 5.3 - scikit-image >= 0.17.1 - scipy >= 1.3.2 - tifffile >= 2019.7.26.2 - tqdm >= 4.41.1 - virtualbox >= 2.0.0 - pyserialem >= 0.3.2 - - -[options.extras_require] -develop = - bump2version - check-manifest - pre-commit - pytest >= 5.4.1 - coverage -serval = - serval-toolkit -docs = - markdown-include - mkdocs - mkdocs-jupyter - mkdocs-gen-files - mkdocs-material - mkdocstrings[python] - - -[options.packages.find] -include = instamatic, instamatic.*, instamatic.experiments.* - -[options.entry_points] -console_scripts = - instamatic = instamatic.main:main - instamatic.controller = instamatic.TEMController.TEMController:main_entry - # experiments - instamatic.serialed = instamatic.experiments.serialed.experiment:main - instamatic.camera = instamatic.camera.camera:main_entry - # calibrate - instamatic.calibrate_stage_lowmag = instamatic.calibrate.calibrate_stage_lowmag:main_entry - instamatic.calibrate_stage_mag1 = instamatic.calibrate.calibrate_stage_mag1:main_entry - instamatic.calibrate_beamshift = instamatic.calibrate.calibrate_beamshift:main_entry - instamatic.calibrate_directbeam = instamatic.calibrate.calibrate_directbeam:main_entry - instamatic.calibrate_stagematrix = instamatic.calibrate.calibrate_stagematrix:main_entry - instamatic.flatfield = instamatic.processing.flatfield:main_entry - instamatic.stretch_correction = instamatic.processing.stretch_correction:main_entry - # tools - instamatic.browser = scripts.browser:main - instamatic.viewer = scripts.viewer:main - instamatic.defocus_helper = instamatic.gui.defocus_button:main - instamatic.find_crystals = instamatic.processing.find_crystals:main_entry - instamatic.find_crystals_ilastik = instamatic.processing.find_crystals_ilastik:main_entry - instamatic.learn = scripts.learn:main_entry - # server - instamatic.temserver = instamatic.server.tem_server:main - instamatic.camserver = instamatic.server.cam_server:main - instamatic.dialsserver = instamatic.server.dials_server:main - instamatic.VMserver = instamatic.server.vm_ubuntu_server:main - instamatic.xdsserver = instamatic.server.xds_server:main - instamatic.temserver_fei = instamatic.server.TEMServer_FEI:main - instamatic.goniotoolserver = instamatic.server.goniotool_server:main - # setup - instamatic.autoconfig = instamatic.config.autoconfig:main diff --git a/setup.py b/setup.py deleted file mode 100644 index 60684932..00000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup() diff --git a/setup_win.bat b/setup_win.bat deleted file mode 100644 index d45b8df4..00000000 --- a/setup_win.bat +++ /dev/null @@ -1,3 +0,0 @@ -@setlocal -@python setup.py install -pause diff --git a/instamatic/TEMController/TEMController.py b/src/instamatic/TEMController/TEMController.py similarity index 93% rename from instamatic/TEMController/TEMController.py rename to src/instamatic/TEMController/TEMController.py index 54099d43..94febe95 100644 --- a/instamatic/TEMController/TEMController.py +++ b/src/instamatic/TEMController/TEMController.py @@ -271,7 +271,7 @@ def get_stagematrix(self, binning: int = None, mag: int = None, mode: int = None if not mag: mag = self.magnification.value if not binning: - binning = self.cam.getBinning() + binning = self.cam.get_binning() stagematrix = config.calibration[mode]['stagematrix'][mag] stagematrix = np.array(stagematrix).reshape(2, 2) * binning # um -> nm @@ -520,7 +520,7 @@ def get_raw_image(self, exposure: float = None, binsize: int = None) -> np.ndarr arr : np.array Image as 2D numpy array. """ - return self.cam.getImage(exposure=exposure, binsize=binsize) + return self.cam.get_image(exposure=exposure, binsize=binsize) def get_future_image(self, exposure: float = None, binsize: int = None) -> 'future': """Simplified function equivalent to `get_image` that returns the raw @@ -645,7 +645,7 @@ def get_image(self, # k['ImageRotation'] = config.calibration[mode]['rotation'][mag] h['ImageComment'] = comment h['ImageCameraName'] = self.cam.name - h['ImageCameraDimensions'] = self.cam.getCameraDimensions() + h['ImageCameraDimensions'] = self.cam.get_camera_dimensions() if verbose: print(f'Image acquired - shape: {arr.shape}, size: {arr.nbytes / 1024:.0f} kB') @@ -660,6 +660,51 @@ def get_image(self, return arr, h + def get_movie(self, + n_frames: int, + *, + exposure: float = None, + binsize: int = None, + out: str = None) -> Tuple[np.ndarray]: + """Collect a stack of images using the camera's movie mode, if + available. + + This minimizes the gap between frames. + + Parameters + ---------- + n_frames : int + Number of frames to collect + exposure : float, optional + Exposure time in seconds + binsize : int, optional + Binning to use for the image, must be 1, 2, or 4, etc + out : str, optional + Path or filename to which the image/header is saved (defaults to tiff) + + Returns + ------- + stack : Tuple[np.ndarray] + List of numpy arrays with image data. + """ + if not self.cam: + raise AttributeError(f"{self.__class__.__name__} object has no attribute 'cam' (Camera has not been initialized)") + + if not binsize: + binsize = self.cam.default_binsize + if not exposure: + exposure = self.cam.default_exposure + + if self.autoblank: + self.beam.unblank() + + stack = self.cam.get_movie(n_frames=n_frames, exposure=exposure, binsize=binsize) + + if self.autoblank: + self.beam.blank() + + return stack + def store_diff_beam(self, name: str = 'beam', save_to_file: bool = False): """Record alignment for current diffraction beam. Stores Guntilt (for dose control), diffraction focus, spot size, brightness, and the diff --git a/instamatic/TEMController/__init__.py b/src/instamatic/TEMController/__init__.py similarity index 100% rename from instamatic/TEMController/__init__.py rename to src/instamatic/TEMController/__init__.py diff --git a/instamatic/TEMController/deflectors.py b/src/instamatic/TEMController/deflectors.py similarity index 100% rename from instamatic/TEMController/deflectors.py rename to src/instamatic/TEMController/deflectors.py diff --git a/instamatic/TEMController/fei_microscope.py b/src/instamatic/TEMController/fei_microscope.py similarity index 99% rename from instamatic/TEMController/fei_microscope.py rename to src/instamatic/TEMController/fei_microscope.py index f92eb4d1..7afa5e42 100644 --- a/instamatic/TEMController/fei_microscope.py +++ b/src/instamatic/TEMController/fei_microscope.py @@ -82,7 +82,7 @@ def __init__(self, name='fei'): raise TEMCommunicationError('Cannot establish microscope connection (timeout).') logger.info('Microscope connection established') - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) self.name = name self.FUNCTION_MODES = FUNCTION_MODES @@ -400,7 +400,7 @@ def setDiffShift(self, x, y): self.tem.Projection.DiffractionShift = ds1 - def releaseConnection(self): + def release_connection(self): comtypes.CoUninitialize() logger.info('Connection to microscope released') print('Connection to microscope released') diff --git a/instamatic/TEMController/fei_simu_microscope.py b/src/instamatic/TEMController/fei_simu_microscope.py similarity index 99% rename from instamatic/TEMController/fei_simu_microscope.py rename to src/instamatic/TEMController/fei_simu_microscope.py index af0f46d2..a4a9de02 100644 --- a/instamatic/TEMController/fei_simu_microscope.py +++ b/src/instamatic/TEMController/fei_simu_microscope.py @@ -52,7 +52,7 @@ def __init__(self, name='fei_simu'): raise TEMCommunicationError('Cannot establish microscope connection (timeout).') logger.info('Microscope connection established') - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) self.name = name self.FUNCTION_MODES = FUNCTION_MODES @@ -286,7 +286,7 @@ def setDiffShift(self, x, y): self.DiffractionShift_x = x self.DiffractionShift_y = y - def releaseConnection(self): + def release_connection(self): comtypes.CoUninitialize() logger.info('Connection to microscope released') print('Connection to microscope released') diff --git a/instamatic/TEMController/jeol_microscope.py b/src/instamatic/TEMController/jeol_microscope.py similarity index 99% rename from instamatic/TEMController/jeol_microscope.py rename to src/instamatic/TEMController/jeol_microscope.py index e1a4b7aa..d7773bd5 100644 --- a/instamatic/TEMController/jeol_microscope.py +++ b/src/instamatic/TEMController/jeol_microscope.py @@ -106,7 +106,7 @@ def __init__(self, name: str = 'jeol'): raise TEMCommunicationError('Cannot establish microscope connection (timeout).') logger.info('Microscope connection established') - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) self._x_direction = 0 self._y_direction = 0 @@ -427,7 +427,7 @@ def getDiffShift(self) -> Tuple[int, int]: def setDiffShift(self, x: int, y: int): self.def3.SetPLA(x, y) - def releaseConnection(self): + def release_connection(self): comtypes.CoUninitialize() logger.info('Connection to microscope released') diff --git a/instamatic/TEMController/lenses.py b/src/instamatic/TEMController/lenses.py similarity index 100% rename from instamatic/TEMController/lenses.py rename to src/instamatic/TEMController/lenses.py diff --git a/instamatic/TEMController/microscope.py b/src/instamatic/TEMController/microscope.py similarity index 100% rename from instamatic/TEMController/microscope.py rename to src/instamatic/TEMController/microscope.py diff --git a/instamatic/TEMController/microscope_client.py b/src/instamatic/TEMController/microscope_client.py similarity index 100% rename from instamatic/TEMController/microscope_client.py rename to src/instamatic/TEMController/microscope_client.py diff --git a/instamatic/TEMController/simu_microscope.py b/src/instamatic/TEMController/simu_microscope.py similarity index 99% rename from instamatic/TEMController/simu_microscope.py rename to src/instamatic/TEMController/simu_microscope.py index 1516590b..a66ff8fb 100644 --- a/instamatic/TEMController/simu_microscope.py +++ b/src/instamatic/TEMController/simu_microscope.py @@ -475,7 +475,7 @@ def setDiffShift(self, x: int, y: int): self.DiffractionShift_x = x self.DiffractionShift_y = y - def releaseConnection(self): + def release_connection(self): print('Connection to microscope released') def isBeamBlanked(self) -> bool: diff --git a/instamatic/TEMController/stage.py b/src/instamatic/TEMController/stage.py similarity index 100% rename from instamatic/TEMController/stage.py rename to src/instamatic/TEMController/stage.py diff --git a/instamatic/TEMController/states.py b/src/instamatic/TEMController/states.py similarity index 100% rename from instamatic/TEMController/states.py rename to src/instamatic/TEMController/states.py diff --git a/instamatic/__init__.py b/src/instamatic/__init__.py similarity index 98% rename from instamatic/__init__.py rename to src/instamatic/__init__.py index 841eb321..ca6faba7 100644 --- a/instamatic/__init__.py +++ b/src/instamatic/__init__.py @@ -9,7 +9,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # """ -__version__ = '1.10.0' +__version__ = '2.0.0' __title__ = 'instamatic' __long_title__ = f'{__title__} v{__version__}' __author__ = 'Stef Smeets' diff --git a/instamatic/acquire_at_items.py b/src/instamatic/acquire_at_items.py similarity index 100% rename from instamatic/acquire_at_items.py rename to src/instamatic/acquire_at_items.py diff --git a/instamatic/admin.py b/src/instamatic/admin.py similarity index 100% rename from instamatic/admin.py rename to src/instamatic/admin.py diff --git a/instamatic/banner.py b/src/instamatic/banner.py similarity index 100% rename from instamatic/banner.py rename to src/instamatic/banner.py diff --git a/instamatic/browser.py b/src/instamatic/browser.py similarity index 100% rename from instamatic/browser.py rename to src/instamatic/browser.py diff --git a/instamatic/calibrate/__init__.py b/src/instamatic/calibrate/__init__.py similarity index 100% rename from instamatic/calibrate/__init__.py rename to src/instamatic/calibrate/__init__.py diff --git a/instamatic/calibrate/calibrate_beamshift.py b/src/instamatic/calibrate/calibrate_beamshift.py similarity index 99% rename from instamatic/calibrate/calibrate_beamshift.py rename to src/instamatic/calibrate/calibrate_beamshift.py index ac8e41d6..de72e28e 100644 --- a/instamatic/calibrate/calibrate_beamshift.py +++ b/src/instamatic/calibrate/calibrate_beamshift.py @@ -105,7 +105,7 @@ def plot(self, to_file=None, outdir=''): def center(self, ctrl): """Return beamshift values to center the beam in the frame.""" - pixel_center = [val / 2.0 for val in ctrl.cam.getImageDimensions()] + pixel_center = [val / 2.0 for val in ctrl.cam.get_image_dimensions()] beamshift = self.pixelcoord_to_beamshift(pixel_center) if ctrl: diff --git a/instamatic/calibrate/calibrate_brightness.py b/src/instamatic/calibrate/calibrate_brightness.py similarity index 100% rename from instamatic/calibrate/calibrate_brightness.py rename to src/instamatic/calibrate/calibrate_brightness.py diff --git a/instamatic/calibrate/calibrate_directbeam.py b/src/instamatic/calibrate/calibrate_directbeam.py similarity index 100% rename from instamatic/calibrate/calibrate_directbeam.py rename to src/instamatic/calibrate/calibrate_directbeam.py diff --git a/instamatic/calibrate/calibrate_imageshift12.py b/src/instamatic/calibrate/calibrate_imageshift12.py similarity index 100% rename from instamatic/calibrate/calibrate_imageshift12.py rename to src/instamatic/calibrate/calibrate_imageshift12.py diff --git a/instamatic/calibrate/calibrate_stage_lowmag.py b/src/instamatic/calibrate/calibrate_stage_lowmag.py similarity index 100% rename from instamatic/calibrate/calibrate_stage_lowmag.py rename to src/instamatic/calibrate/calibrate_stage_lowmag.py diff --git a/instamatic/calibrate/calibrate_stage_mag1.py b/src/instamatic/calibrate/calibrate_stage_mag1.py similarity index 100% rename from instamatic/calibrate/calibrate_stage_mag1.py rename to src/instamatic/calibrate/calibrate_stage_mag1.py diff --git a/instamatic/calibrate/calibrate_stagematrix.py b/src/instamatic/calibrate/calibrate_stagematrix.py similarity index 99% rename from instamatic/calibrate/calibrate_stagematrix.py rename to src/instamatic/calibrate/calibrate_stagematrix.py index 5766d84c..01abc311 100644 --- a/instamatic/calibrate/calibrate_stagematrix.py +++ b/src/instamatic/calibrate/calibrate_stagematrix.py @@ -158,7 +158,7 @@ def calibrate_stage_from_stageshifts(ctrl, mag = ctrl.magnification.value mode = ctrl.mode.get() - binning = ctrl.cam.getBinning() + binning = ctrl.cam.get_binning() pairs = [] @@ -293,7 +293,7 @@ def calibrate_stage(ctrl, print(f'\nCalibrating stagematrix mode=`{mode}` mag={mag}\n') - camera_shape = ctrl.cam.getCameraDimensions() + camera_shape = ctrl.cam.get_camera_dimensions() pixelsize = config.calibration[mode]['pixelsize'][mag] if pixelsize == 1.0 or pixelsize == 0.0: diff --git a/instamatic/calibrate/center_z.py b/src/instamatic/calibrate/center_z.py similarity index 100% rename from instamatic/calibrate/center_z.py rename to src/instamatic/calibrate/center_z.py diff --git a/instamatic/calibrate/filenames.py b/src/instamatic/calibrate/filenames.py similarity index 100% rename from instamatic/calibrate/filenames.py rename to src/instamatic/calibrate/filenames.py diff --git a/instamatic/calibrate/fit.py b/src/instamatic/calibrate/fit.py similarity index 100% rename from instamatic/calibrate/fit.py rename to src/instamatic/calibrate/fit.py diff --git a/instamatic/camera/CCDCOM.h b/src/instamatic/camera/CCDCOM.h similarity index 100% rename from instamatic/camera/CCDCOM.h rename to src/instamatic/camera/CCDCOM.h diff --git a/instamatic/camera/CCDCOM2_x64_gatan.dll b/src/instamatic/camera/CCDCOM2_x64_gatan.dll similarity index 100% rename from instamatic/camera/CCDCOM2_x64_gatan.dll rename to src/instamatic/camera/CCDCOM2_x64_gatan.dll diff --git a/instamatic/camera/CCDCOM2_x64_simulation.dll b/src/instamatic/camera/CCDCOM2_x64_simulation.dll similarity index 100% rename from instamatic/camera/CCDCOM2_x64_simulation.dll rename to src/instamatic/camera/CCDCOM2_x64_simulation.dll diff --git a/instamatic/camera/CCDCOM2_x86_gatan.dll b/src/instamatic/camera/CCDCOM2_x86_gatan.dll similarity index 100% rename from instamatic/camera/CCDCOM2_x86_gatan.dll rename to src/instamatic/camera/CCDCOM2_x86_gatan.dll diff --git a/instamatic/camera/CCDCOM2_x86_simulation.dll b/src/instamatic/camera/CCDCOM2_x86_simulation.dll similarity index 100% rename from instamatic/camera/CCDCOM2_x86_simulation.dll rename to src/instamatic/camera/CCDCOM2_x86_simulation.dll diff --git a/instamatic/camera/EMCameraObj.dll b/src/instamatic/camera/EMCameraObj.dll similarity index 100% rename from instamatic/camera/EMCameraObj.dll rename to src/instamatic/camera/EMCameraObj.dll diff --git a/instamatic/camera/__init__.py b/src/instamatic/camera/__init__.py similarity index 100% rename from instamatic/camera/__init__.py rename to src/instamatic/camera/__init__.py diff --git a/instamatic/camera/camera.py b/src/instamatic/camera/camera.py similarity index 99% rename from instamatic/camera/camera.py rename to src/instamatic/camera/camera.py index 4b56a0a6..0e811700 100644 --- a/instamatic/camera/camera.py +++ b/src/instamatic/camera/camera.py @@ -192,7 +192,7 @@ def main_entry(): if __name__ == '__main__': # main_entry() cam = Camera(use_server=True) - arr = cam.getImage(exposure=0.1) + arr = cam.get_image(exposure=0.1) print(arr) print(arr.shape) diff --git a/instamatic/camera/camera_client.py b/src/instamatic/camera/camera_client.py similarity index 95% rename from instamatic/camera/camera_client.py rename to src/instamatic/camera/camera_client.py index a75b0f78..dbe39570 100644 --- a/instamatic/camera/camera_client.py +++ b/src/instamatic/camera/camera_client.py @@ -83,7 +83,7 @@ def __init__( atexit.register(self.s.close) - xres, yres = self.getImageDimensions() + xres, yres = self.get_image_dimensions() bitdepth = 4 self._imagebufsize = bitdepth * xres * yres + self._bufsize @@ -119,7 +119,11 @@ def _eval_dct(self, dct): """Takes approximately 0.2-0.3 ms per call if HOST=='localhost'.""" self.s.send(dumper(dct)) - acquiring_image = dct['attr_name'] == 'getImage' + acquiring_image = dct['attr_name'] == 'get_image' + acquiring_movie = dct['attr_name'] == 'get_movie' + + if acquiring_movie: + raise NotImplementedError('Acquiring movies over a socket is not supported.') if acquiring_image and not self.use_shared_memory: response = self.s.recv(self._imagebufsize) diff --git a/instamatic/camera/camera_emmenu.py b/src/instamatic/camera/camera_emmenu.py similarity index 87% rename from instamatic/camera/camera_emmenu.py rename to src/instamatic/camera/camera_emmenu.py index fd2d7ffc..85284022 100644 --- a/instamatic/camera/camera_emmenu.py +++ b/src/instamatic/camera/camera_emmenu.py @@ -104,7 +104,7 @@ def __init__( # check if exists if not self._immgr.DirectoryExist(self.top_drc_index, drc_name): - if self.getEMMenuVersion().startswith('4.'): + if self.get_emmenu_version().startswith('4.'): self._immgr.CreateNewSubDirectory(self.top_drc_index, drc_name, 2, 2) else: # creating new subdirectories is bugged in EMMENU 5.0.9.0/5.0.10.0 @@ -118,11 +118,11 @@ def __init__( self.load_defaults() - msg = f'Camera `{self.getCameraName()}` ({self.name}) initialized' + msg = f'Camera `{self.get_camera_name()}` ({self.name}) initialized' # print(msg) logger.info(msg) - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) def load_defaults(self) -> None: if self.name != config.settings.camera: @@ -132,7 +132,7 @@ def load_defaults(self) -> None: self.streamable = False - def listConfigs(self) -> list: + def list_configs(self) -> list: """List the configs from the Configuration Manager.""" print(f'Configurations for camera {self.name}') current = self._vp.Configuration @@ -147,13 +147,13 @@ def listConfigs(self) -> list: return lst - def getCurrentConfigName(self) -> str: + def get_current_config_name(self) -> str: """Return the name of the currently selected configuration in EMMENU.""" - cfg = self.getCurrentConfig(as_dict=False) + cfg = self.get_current_config(as_dict=False) return cfg.Name - def getCurrentConfig(self, as_dict: bool = True) -> dict: + def get_current_config(self, as_dict: bool = True) -> dict: """Get selected config object currently associated with the viewport.""" vp_cfg_name = self._vp.Configuration @@ -214,15 +214,15 @@ def getCurrentConfig(self, as_dict: bool = True) -> dict: else: return cfg - def selectConfig(self) -> None: + def select_config(self) -> None: """Select config by name.""" - cfgs = self.listConfigs() + cfgs = self.list_configs() if config not in cfgs: raise ValueError(f'No such config: {config} -> must be one of {cfgs}') raise NotImplementedError - def getCurrentCameraInfo(self) -> dict: + def get_current_camera_info(self) -> dict: """Gets the current camera object.""" cam = self._cam @@ -242,12 +242,12 @@ def getCurrentCameraInfo(self) -> dict: d['CamCGroup'] = cam.CamCGroup # int return d - def getCameraType(self) -> str: + def get_camera_type(self) -> str: """Get the name of the camera currently in use.""" - cfg = self.getCurrentConfig(as_dict=False) + cfg = self.get_current_config(as_dict=False) return cfg.CameraType - def getEMMenuVersion(self) -> str: + def get_emmenu_version(self) -> str: """Get the version number of EMMENU.""" return self._obj.EMMENUVersion @@ -265,7 +265,7 @@ def unlock(self) -> None: """Unlock emmenu after it has been locked down with `self.lock`""" self._obj.EnableMainframe(0) - def listDirectories(self) -> dict: + def list_directories(self) -> dict: """List subdirectories of the top directory.""" top_j = self._immgr.TopDirectory top_name = self._immgr.FullDirectoryName(top_j) @@ -285,14 +285,14 @@ def listDirectories(self) -> dict: return d - def getEMVectorByIndex(self, img_index: int, drc_index: int = None) -> dict: + def get_emvector_by_index(self, img_index: int, drc_index: int = None) -> dict: """Returns the EMVector by index as a python dictionary.""" - p = self.getImageByIndex(img_index, drc_index) + p = self.get_image_by_index(img_index, drc_index) v = p.EMVector d = EMVector2dict(v) return d - def deleteAllImages(self) -> None: + def delete_all_images(self) -> None: """Clears all images currently stored in EMMENU buffers.""" for i, p in enumerate(self._emi): try: @@ -301,12 +301,12 @@ def deleteAllImages(self) -> None: # sometimes EMMenu also loses track of image pointers... print(f'Failed to delete buffer {i} ({p})') - def deleteImageByIndex(self, img_index: int, drc_index: int = None) -> int: + def delete_image_by_index(self, img_index: int, drc_index: int = None) -> int: """Delete the image from EMMENU by its index.""" - p = self.getImageByIndex(img_index, drc_index) + p = self.get_image_by_index(img_index, drc_index) self._emi.DeleteImage(p) # alternative: self._emi.Remove(p.ImgHandle) - def getImageByIndex(self, img_index: int, drc_index: int = None) -> int: + def get_image_by_index(self, img_index: int, drc_index: int = None) -> int: """Grab data from the image manager by index. Return image pointer (COM). @@ -319,12 +319,12 @@ def getImageByIndex(self, img_index: int, drc_index: int = None) -> int: return p - def getImageDataByIndex(self, img_index: int, drc_index: int = None) -> 'np.array': + def get_image_data_by_index(self, img_index: int, drc_index: int = None) -> 'np.array': """Grab data from the image manager by index. Return numpy 2D array """ - p = self.getImageByIndex(img_index, drc_index) + p = self.get_image_by_index(img_index, drc_index) tpe = p.DataType method = type_dict[tpe] @@ -334,49 +334,49 @@ def getImageDataByIndex(self, img_index: int, drc_index: int = None) -> 'np.arra return np.array(arr) - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): """Get the maximum dimensions reported by the camera.""" - # cfg = self.getCurrentConfig() + # cfg = self.get_current_config() # return cfg.DimensionX, cfg.DimensionY return self._cam.RealSizeX, self._cam.RealSizeY # return self._cam.MaximumSizeX, self._cam.MaximumSizeY - def getImageDimensions(self) -> (int, int): + def get_image_dimensions(self) -> (int, int): """Get the dimensions of the image.""" - binning = self.getBinning() + binning = self.get_binning() return int(self._cam.RealSizeX / binning), int(self._cam.RealSizeY / binning) - def getPhysicalPixelsize(self) -> (int, int): + def get_physical_pixelsize(self) -> (int, int): """Returns the physical pixel size of the camera nanometers.""" return self._cam.PixelSizeX, self._cam.PixelSizeY - def getBinning(self) -> int: + def get_binning(self) -> int: """Returns the binning corresponding to the currently selected camera config.""" - cfg = self.getCurrentConfig(as_dict=False) + cfg = self.get_current_config(as_dict=False) bin_x = cfg.BinningX bin_y = cfg.BinningY assert bin_x == bin_y, 'Binnings differ in X and Y direction! (X: {bin_x} | Y: {bin_y})' return bin_x - def getCameraName(self) -> str: + def get_camera_name(self) -> str: """Get the name reported by the camera.""" return self._cam.name - def writeTiffFromPointer(self, image_pointer, filename: str) -> None: + def write_tiff_from_pointer(self, image_pointer, filename: str) -> None: """Write tiff file using the EMMENU machinery `image_pointer` is the memory address returned by `getImageIndex()`""" self._emf.WriteTiff(image_pointer, filename) - def writeTiff(self, image_index, filename: str) -> None: + def write_tiff(self, image_index, filename: str) -> None: """Write tiff file using the EMMENU machinery `image_index` is the index in the current directory of the image to be written.""" drc_index = self.drc_index - p = self.getImageByIndex(image_index, drc_index) + p = self.get_image_by_index(image_index, drc_index) - self.writeTiffFromPointer(p, filename) + self.write_tiff_from_pointer(p, filename) - def writeTiffs(self, start_index: int, stop_index: int, path: str, clear_buffer: bool = False) -> None: + def write_tiffs(self, start_index: int, stop_index: int, path: str, clear_buffer: bool = False) -> None: """Write a series of data in tiff format and writes them to the given `path` using EMMENU machinery.""" path = Path(path) @@ -386,7 +386,7 @@ def writeTiffs(self, start_index: int, stop_index: int, path: str, clear_buffer: raise IndexError(f'`stop_index`: {stop_index} >= `start_index`: {start_index}') for i, image_index in enumerate(range(start_index, stop_index + 1)): - p = self.getImageByIndex(image_index, drc_index) + p = self.get_image_by_index(image_index, drc_index) fn = str(path / f'{i:04d}.tiff') print(f'Image #{image_index} -> {fn}') @@ -394,7 +394,7 @@ def writeTiffs(self, start_index: int, stop_index: int, path: str, clear_buffer: # TODO: wrap writeTiff in try/except # writeTiff causes vague error if image does not exist - self.writeTiffFromPointer(p, fn) + self.write_tiff_from_pointer(p, fn) if clear_buffer: # self._immgr.DeleteImageBuffer(drc_index, image_index) # does not work on 3200 @@ -402,13 +402,13 @@ def writeTiffs(self, start_index: int, stop_index: int, path: str, clear_buffer: print(f'Wrote {i+1} images to {path}') - def getImage(self, **kwargs) -> 'np.array': + def get_image(self, **kwargs) -> 'np.array': """Acquire image through EMMENU and return data as np array.""" self._vp.AcquireAndDisplayImage() i = self.get_image_index() - return self.getImageDataByIndex(i) + return self.get_image_data_by_index(i) - def acquireImage(self, **kwargs) -> int: + def acquire_image(self, **kwargs) -> int: """Acquire image through EMMENU and store in the Image Manager Returns the image index.""" self._vp.AcquireAndDisplayImage() @@ -486,12 +486,12 @@ def get_timestamps(self, start_index: int, end_index: int) -> list: drc_index = self.drc_index timestamps = [] for i, image_index in enumerate(range(start_index, end_index + 1)): - p = self.getImageByIndex(image_index, drc_index) + p = self.get_image_by_index(image_index, drc_index) t = p.EMVector.lImgCreationTime timestamps.append(t) return timestamps - def releaseConnection(self) -> None: + def release_connection(self) -> None: """Release the connection to the camera.""" self.stop_liveview() @@ -500,7 +500,7 @@ def releaseConnection(self) -> None: self.set_image_index(0) # self._immgr.DeleteDirectory(self.drc_index) # bugged in EMMENU 5.0.9.0/5.0.10.0, FIXME later - msg = f'Connection to camera `{self.getCameraName()}` ({self.name}) released' + msg = f'Connection to camera `{self.get_camera_name()}` ({self.name}) released' # print(msg) logger.info(msg) diff --git a/instamatic/camera/camera_gatan.py b/src/instamatic/camera/camera_gatan.py similarity index 92% rename from instamatic/camera/camera_gatan.py rename to src/instamatic/camera/camera_gatan.py index ac35bdc4..3b8ddddb 100644 --- a/instamatic/camera/camera_gatan.py +++ b/src/instamatic/camera/camera_gatan.py @@ -128,18 +128,18 @@ def __init__(self, name: str = 'gatan'): self._releaseCCDCOM = getattr(lib, symbols['releaseCCDCOM']) - self.establishConnection() + self.establish_connection() self.load_defaults() - msg = f'Camera {self.getName()} initialized' + msg = f'Camera {self.get_name()} initialized' logger.info(msg) - # dim_x, dim_y = self.getImageDimensions() + # dim_x, dim_y = self.get_image_dimensions() # print(f"Dimensions {dim_x}x{dim_y}") - # print(f"Info {self.isCameraInfoAvailable()} | Count {self.getCameraCount()}") + # print(f"Info {self.is_camera_info_available()} | Count {self.getCameraCount()}") - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) def load_defaults(self): if self.name != config.settings.camera: @@ -149,7 +149,7 @@ def load_defaults(self): self.streamable = False - def getImage(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: + def get_image(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: """Image acquisition routine. exposure: exposure time in seconds @@ -195,32 +195,32 @@ def getImage(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: return arr - def isCameraInfoAvailable(self) -> bool: + def is_camera_info_available(self) -> bool: """Return the status of the camera.""" return self._isCameraInfoAvailable() - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): """Return the dimensions reported by the camera.""" pnWidth = c_int(0) pnHeight = c_int(0) self._cameraDimensions(byref(pnWidth), byref(pnHeight)) return pnWidth.value, pnHeight.value - def getName(self) -> str: + def get_name(self) -> str: """Return the name reported by the camera.""" buf = create_unicode_buffer(20) self._cameraName(buf, 20) return buf.value - def establishConnection(self) -> None: + def establish_connection(self) -> None: """Establish connection to the camera.""" res = self._initCCDCOM(20120101) if res != 1: raise RuntimeError(f'Could not establish camera connection to {self.name}') - def releaseConnection(self) -> None: + def release_connection(self) -> None: """Release the connection to the camera.""" - name = self.getName() + name = self.get_name() self._releaseCCDCOM() msg = f'Connection to camera {name} released' logger.info(msg) diff --git a/instamatic/camera/camera_gatan2.py b/src/instamatic/camera/camera_gatan2.py similarity index 77% rename from instamatic/camera/camera_gatan2.py rename to src/instamatic/camera/camera_gatan2.py index e757a612..cdefc84d 100644 --- a/instamatic/camera/camera_gatan2.py +++ b/src/instamatic/camera/camera_gatan2.py @@ -27,11 +27,11 @@ def __init__(self, name: str = 'gatan2'): self.load_defaults() - msg = f'Camera `{self.getCameraName()}` ({self.name}) initialized' + msg = f'Camera `{self.get_camera_name()}` ({self.name}) initialized' # print(msg) logger.info(msg) - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) def load_defaults(self) -> None: if self.name != config.settings.camera: @@ -41,42 +41,42 @@ def load_defaults(self) -> None: self.streamable = False - def getCameraType(self) -> str: + def get_camera_type(self) -> str: """Get the name of the camera currently in use.""" raise NotImplementedError - def getDMVersion(self) -> str: + def get_dm_version(self) -> str: """Get the version number of DM.""" return self.g.GetDMVersion() - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): """Get the maximum dimensions reported by the camera.""" raise NotImplementedError - def getImageDimensions(self) -> (int, int): + def get_image_dimensions(self) -> (int, int): """Get the dimensions of the image.""" - binning = self.getBinning() - dim_x, dim_y = self.getCameraDimensions() + binning = self.get_binning() + dim_x, dim_y = self.get_camera_dimensions() return int(dim_x / binning), int(dim_y / binning) - def getPhysicalPixelsize(self) -> (int, int): + def get_physical_pixelsize(self) -> (int, int): """Returns the physical pixel size of the camera nanometers.""" raise NotImplementedError - def getBinning(self) -> int: + def get_binning(self) -> int: """Returns the binning corresponding to the currently selected camera config.""" raise NotImplementedError - def getCameraName(self) -> str: + def get_camera_name(self) -> str: """Get the name reported by the camera.""" return self.name - def writeTiff(self, filename: str) -> None: + def write_tiff(self, filename: str) -> None: """Write tiff file using the DM machinery.""" raise NotImplementedError - def writeTiffs(self) -> None: + def write_tiffs(self) -> None: """Write a series of data in tiff format and writes them to the given `path`""" raise NotImplementedError @@ -86,11 +86,11 @@ def writeTiffs(self) -> None: print(f'Wrote {i+1} images to {path}') - def getImage(self, - exposure=0.400, - binning=1, - processing='gain normalized', - ) -> 'np.array': + def get_image(self, + exposure=0.400, + binning=1, + processing='gain normalized', + ) -> 'np.array': """Acquire image through DM and return data as np array.""" width, height = self.dimensions @@ -99,23 +99,23 @@ def getImage(self, bottom = height right = width - arr = self.g.getImage(processing=processing, - height=height, - width=width, - binning=binning, - top=top, - left=left, - bottom=bottom, - right=right, - exposure=exposure, - shutterDelay=0, - ) + arr = self.g.get_image(processing=processing, + height=height, + width=width, + binning=binning, + top=top, + left=left, + bottom=bottom, + right=right, + exposure=exposure, + shutterDelay=0, + ) return arr - def acquireImage(self, **kwargs) -> 'np.array': + def acquire_image(self, **kwargs) -> 'np.array': """Acquire image through DM.""" - return self.getImage(**kwargs) + return self.get_image(**kwargs) def get_ready_for_record(self) -> None: self.reset_record_vars() @@ -157,9 +157,9 @@ def get_exposure(self) -> int: """Return exposure time in ms.""" raise NotImplementedError - def releaseConnection(self) -> None: + def release_connection(self) -> None: """Release the connection to the camera.""" - msg = f'Connection to camera `{self.getCameraName()}` ({self.name}) released' + msg = f'Connection to camera `{self.get_camera_name()}` ({self.name}) released' # print(msg) logger.info(msg) diff --git a/instamatic/camera/camera_merlin.py b/src/instamatic/camera/camera_merlin.py similarity index 89% rename from instamatic/camera/camera_merlin.py rename to src/instamatic/camera/camera_merlin.py index 9fe93c74..89a56b81 100644 --- a/instamatic/camera/camera_merlin.py +++ b/src/instamatic/camera/camera_merlin.py @@ -1,3 +1,28 @@ +"""Camera module for connecting with the Merlin EM detector. + +The module communicates over TCP/IP with the camera. + +Example usage: + +``` +# initialize +cam = CameraMerlin() + +# get values +cam.merlin_get('DETECTORSTATUS') + +# set continuous read/write mode +cam.merlin_set('CONTINUOUSRW', 1) +cam.merlin_set('COUNTERDEPTH', 12) + +# acquire single frame (uses soft trigger) +frame = cam.get_image(exposure=0.1) + +# acquire multiple frames with gapless acquisition +frames = cam.get_movie(n_frames=10, exposure=0.1) +``` +""" + import atexit import logging import socket @@ -61,13 +86,13 @@ def __init__(self, name='merlin'): self.load_defaults() - self.establishConnection() - self.establishDataConnection() + self.establish_connection() + self.establish_data_connection() - msg = f'Camera {self.getName()} initialized' + msg = f'Camera {self.get_name()} initialized' logger.info(msg) - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) def load_defaults(self): if self.name != config.settings.camera: @@ -134,7 +159,18 @@ def merlin_get(self, key: str) -> str: return value def merlin_cmd(self, key: str): - """Send Merlin command through command socket.""" + """Send Merlin command through command socket. + + Parameters + ---------- + key : str + Name of the command + + Raises + ------ + ValueError + If the command failed + """ self.s_cmd.sendall(MPX_CMD('CMD', key)) response = self.s_cmd.recv(1024).decode() logger.debug(response) @@ -183,7 +219,7 @@ def teardown_soft_trigger(self): self._soft_trigger_mode = False self._soft_trigger_exposure = None - def getImage(self, exposure: float = None, **kwargs) -> np.ndarray: + def get_image(self, exposure: float = None, **kwargs) -> np.ndarray: """Image acquisition routine. If the exposure is not given, the default value is read from the config file. @@ -235,7 +271,7 @@ def getImage(self, exposure: float = None, **kwargs) -> np.ndarray: return data - def getMovie(self, n_frames: int, exposure: float = None, **kwargs) -> List[np.ndarray]: + def get_movie(self, n_frames: int, exposure: float = None, **kwargs) -> List[np.ndarray]: """Gapless movie acquisition routine. If the exposure is not given, the default value is read from the config file. @@ -302,29 +338,25 @@ def getMovie(self, n_frames: int, exposure: float = None, **kwargs) -> List[np.n return data - def isCameraInfoAvailable(self) -> bool: - """Check if the camera is available.""" - return True - - def getImageDimensions(self) -> (int, int): + def get_image_dimensions(self) -> (int, int): """Get the binned dimensions reported by the camera.""" - binning = self.getBinning() - dim_x, dim_y = self.getCameraDimensions() + binning = self.get_binning() + dim_x, dim_y = self.get_camera_dimensions() dim_x = int(dim_x / binning) dim_y = int(dim_y / binning) return dim_x, dim_y - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): """Get the dimensions reported by the camera.""" return self.dimensions - def getName(self) -> str: + def get_name(self) -> str: """Get the name reported by the camera.""" return self.name - def establishConnection(self) -> None: + def establish_connection(self) -> None: """Establish connection to command port of the merlin software.""" # Create command socket self.s_cmd = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -353,7 +385,7 @@ def establishConnection(self) -> None: for key, value in self.detector_config.items(): self.merlin_set(key, value) - def establishDataConnection(self) -> None: + def establish_data_connection(self) -> None: """Establish connection to the dataport of the merlin software.""" # Create command socket s_data = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -367,7 +399,7 @@ def establishDataConnection(self) -> None: self.s_data = s_data - def releaseConnection(self) -> None: + def release_connection(self) -> None: """Release the connection to the camera.""" if self._soft_trigger_mode: logger.info('Stopping acquisition') @@ -377,7 +409,7 @@ def releaseConnection(self) -> None: self.s_data.close() - name = self.getName() + name = self.get_name() msg = f"Connection to camera '{name}' released" logger.info(msg) @@ -390,7 +422,7 @@ def test_movie(cam): t0 = time.perf_counter() - frames = cam.getMovie(n_frames, exposure=exposure) + frames = cam.get_movie(n_frames, exposure=exposure) t1 = time.perf_counter() @@ -413,7 +445,7 @@ def test_single_frame(cam): t0 = time.perf_counter() for i in range(n_frames): - frame = cam.getImage() + frame = cam.get_image() assert frame.shape == (512, 512) t1 = time.perf_counter() @@ -426,7 +458,7 @@ def test_single_frame(cam): def test_plot_single_image(cam): - arr = cam.getImage(exposure=0.1) + arr = cam.get_image(exposure=0.1) import numpy as np diff --git a/instamatic/camera/camera_serval.py b/src/instamatic/camera/camera_serval.py similarity index 88% rename from instamatic/camera/camera_serval.py rename to src/instamatic/camera/camera_serval.py index 7e3a26d1..75fb9d5b 100644 --- a/instamatic/camera/camera_serval.py +++ b/src/instamatic/camera/camera_serval.py @@ -26,12 +26,12 @@ def __init__(self, name='serval'): self.load_defaults() - self.establishConnection() + self.establish_connection() - msg = f'Camera {self.getName()} initialized' + msg = f'Camera {self.get_name()} initialized' logger.info(msg) - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) def load_defaults(self): if self.name != config.settings.camera: @@ -41,7 +41,7 @@ def load_defaults(self): self.__dict__.update(config.camera.mapping) - def getImage(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: + def get_image(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: """Image acquisition routine. If the exposure and binsize are not given, the default values are read from the config file. @@ -72,7 +72,7 @@ def getImage(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: arr = np.array(img) return arr - def getMovie(self, n_frames, exposure=None, binsize=None, **kwargs): + def get_movie(self, n_frames, exposure=None, binsize=None, **kwargs): """Movie acquisition routine. If the exposure and binsize are not given, the default values are read from the config file. @@ -98,25 +98,25 @@ def getMovie(self, n_frames, exposure=None, binsize=None, **kwargs): return arr - def getImageDimensions(self) -> (int, int): + def get_image_dimensions(self) -> (int, int): """Get the binned dimensions reported by the camera.""" - binning = self.getBinning() - dim_x, dim_y = self.getCameraDimensions() + binning = self.get_binning() + dim_x, dim_y = self.get_camera_dimensions() dim_x = int(dim_x / binning) dim_y = int(dim_y / binning) return dim_x, dim_y - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): """Get the dimensions reported by the camera.""" return self.dimensions - def getName(self) -> str: + def get_name(self) -> str: """Get the name reported by the camera.""" return self.name - def establishConnection(self) -> None: + def establish_connection(self) -> None: """Establish connection to the camera.""" self.conn = ServalCamera() self.conn.connect(self.url) @@ -144,10 +144,10 @@ def establishConnection(self) -> None: }], } - def releaseConnection(self) -> None: + def release_connection(self) -> None: """Release the connection to the camera.""" self.conn.measurement_stop() - name = self.getName() + name = self.get_name() msg = f"Connection to camera '{name}' released" logger.info(msg) diff --git a/instamatic/camera/camera_simu.py b/src/instamatic/camera/camera_simu.py similarity index 68% rename from instamatic/camera/camera_simu.py rename to src/instamatic/camera/camera_simu.py index 6dc72573..eada7bc9 100644 --- a/instamatic/camera/camera_simu.py +++ b/src/instamatic/camera/camera_simu.py @@ -19,14 +19,14 @@ def __init__(self, name='simulate'): self.name = name - self.establishConnection() + self.establish_connection() self.load_defaults() - msg = f'Camera {self.getName()} initialized' + msg = f'Camera {self.get_name()} initialized' logger.info(msg) - atexit.register(self.releaseConnection) + atexit.register(self.release_connection) # EMMENU variables self._image_index = 0 @@ -42,22 +42,27 @@ def load_defaults(self): self.__dict__.update(config.camera.mapping) - def getImage(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: + def get_image(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: """Image acquisition routine. If the exposure and binsize are not given, the default values are read from the config file. - exposure: + Parameters + ---------- + exposure : float Exposure time in seconds. - binsize: + binsize : int Which binning to use. - """ + Returns + ------- + arr : np.ndarray + """ if exposure is None: exposure = self.default_exposure if not binsize: binsize = self.default_binsize - dim_x, dim_y = self.getCameraDimensions() + dim_x, dim_y = self.get_camera_dimensions() dim_x = int(dim_x / binsize) dim_y = int(dim_y / binsize) @@ -68,53 +73,72 @@ def getImage(self, exposure=None, binsize=None, **kwargs) -> np.ndarray: return arr - def acquireImage(self) -> int: + def get_movie(self, n_frames, *, exposure: float = None, binsize: int = None, **kwargs): + """"Movie acquisition routine. If the exposure and binsize are not + given, the default values are read from the config file. + + Parameters + ---------- + n_frames : int + Number of frames to collect + exposure : float + Exposure time in seconds. + binsize : int + Which binning to use. + + Returns + ------- + stack : List[np.ndarray] + """ + return [self.get_image(exposure=exposure, binsize=binsize) for _ in range(n_frames)] + + def acquire_image(self) -> int: """For TVIPS compatibility.""" return 1 - def isCameraInfoAvailable(self) -> bool: + def is_camera_info_available(self) -> bool: """Check if the camera is available.""" return True - def getImageDimensions(self) -> (int, int): + def get_image_dimensions(self) -> (int, int): """Get the binned dimensions reported by the camera.""" - binning = self.getBinning() - dim_x, dim_y = self.getCameraDimensions() + binning = self.get_binning() + dim_x, dim_y = self.get_camera_dimensions() dim_x = int(dim_x / binning) dim_y = int(dim_y / binning) return dim_x, dim_y - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): """Get the dimensions reported by the camera.""" return self.dimensions - def getName(self) -> str: + def get_name(self) -> str: """Get the name reported by the camera.""" return self.name - def establishConnection(self) -> None: + def establish_connection(self) -> None: """Establish connection to the camera.""" res = 1 if res != 1: raise RuntimeError(f'Could not establish camera connection to {self.name}') - def releaseConnection(self) -> None: + def release_connection(self) -> None: """Release the connection to the camera.""" - name = self.getName() + name = self.get_name() msg = f"Connection to camera '{name}' released" logger.info(msg) # Mimic EMMENU API - def getEMMenuVersion(self) -> str: + def get_emmenu_version(self) -> str: return 'simu' - def getCameraType(self) -> str: + def get_camera_type(self) -> str: return 'SimuType' - def getCurrentConfigName(self) -> str: + def get_current_config_name(self) -> str: return 'SimuCfg' def set_autoincrement(self, value): @@ -161,8 +185,8 @@ def get_exposure(self) -> int: def get_timestamps(self, start_index, end_index): return list(range(20)) - def getBinning(self): + def get_binning(self): return self.default_binsize - def writeTiffs(self, start_index: int, stop_index: int, path: str, clear_buffer=True) -> None: + def write_tiffs(self, start_index: int, stop_index: int, path: str, clear_buffer=True) -> None: pass diff --git a/instamatic/camera/camera_timepix.py b/src/instamatic/camera/camera_timepix.py similarity index 85% rename from instamatic/camera/camera_timepix.py rename to src/instamatic/camera/camera_timepix.py index c8e4e87d..ae01ef52 100644 --- a/instamatic/camera/camera_timepix.py +++ b/src/instamatic/camera/camera_timepix.py @@ -23,7 +23,7 @@ class LockingError(RuntimeError): pass -def arrangeData(raw, out=None): +def arrange_data(raw, out=None): """10000 loops, best of 3: 81.3 s per loop.""" s = 256 * 256 q1 = raw[0:s].reshape(256, 256) @@ -41,7 +41,7 @@ def arrangeData(raw, out=None): return out -def correctCross(raw, factor=2.15): +def correct_cross(raw, factor=2.15): """100000 loops, best of 3: 18 us per loop.""" raw[255:258] = raw[255] / factor raw[:, 255:258] = raw[:, 255:256] / factor @@ -73,7 +73,7 @@ def __init__(self, name='pytimepix'): atexit.register(self.disconnect) self.is_connected = None - self.name = self.getName() + self.name = self.get_name() self.load_defaults() def acquire_lock(self): @@ -118,10 +118,10 @@ def disconnect(self): print('Camera disconnect failed...') return ret - def getFrameSize(self): + def get_frame_size(self): return self.lib.EMCameraObj_getFrameSize(self.obj) - def readRealDacs(self, filename): + def read_real_dacs(self, filename): """std::string filename.""" if not os.path.exists(filename): raise OSError(f'Cannot find `RealDacs` file: {filename}') @@ -137,7 +137,7 @@ def readRealDacs(self, filename): self.disconnect() sys.exit() - def readHwDacs(self, filename): + def read_hw_dacs(self, filename): """std::string filename.""" if not os.path.exists(filename): raise OSError(f'Cannot find `HwDacs` file: {filename}') @@ -153,7 +153,7 @@ def readHwDacs(self, filename): self.disconnect() sys.exit() - def readPixelsCfg(self, filename): + def read_pixels_cfg(self, filename): """std::string filename.""" 'int mode = TPX_MODE_DONT_SET -> set in header file' if not os.path.exists(filename): @@ -170,7 +170,7 @@ def readPixelsCfg(self, filename): self.disconnect() sys.exit() - def processRealDac(self, chipnr=None, index=None, key=None, value=None): + def process_real_dac(self, chipnr=None, index=None, key=None, value=None): """int *chipnr.""" 'int *index' 'std::string *key' @@ -183,7 +183,7 @@ def processRealDac(self, chipnr=None, index=None, key=None, value=None): self.lib.EMCameraObj_processRealDac(self.obj, byref(chipnr), byref(index), key, value) - def processHwDac(self, key, value): + def process_hw_dac(self, key, value): """std::string *key.""" 'std::string *value' @@ -191,15 +191,15 @@ def processHwDac(self, key, value): value = create_unicode_buffer(20) self.lib.EMCameraObj_processHwDac(self.obj, byref(key), byref(value)) - def startAcquisition(self): - """Equivalent to openShutteR?""" + def start_acquisition(self): + """Equivalent to openShutter?""" self.lib.EMCameraObj_startAcquisition(self.obj) - def stopAcquisition(self): - """Equivalent to closeShutter?""" + def stop_acquisition(self): + """Equivalent to close_shutter?""" self.lib.EMCameraObj_stopAcquisition(self.obj) - def openShutter(self): + def open_shutter(self): """Opens the Relaxd shutter under software control. Note that opening and closing the shutter under software control @@ -209,11 +209,11 @@ def openShutter(self): """ self.lib.EMCameraObj_openShutter(self.obj) - def closeShutter(self): + def close_shutter(self): """Closes shutter under software control.""" self.lib.EMCameraObj_closeShutter(self.obj) - def readMatrix(self, arr=None, sz=512 * 512): + def read_matrix(self, arr=None, sz=512 * 512): """Reads a frame from all connected devices, decodes the data and stores the pixel counts in array data. @@ -231,7 +231,7 @@ def readMatrix(self, arr=None, sz=512 * 512): return arr - def enableTimer(self, enable, us): + def enable_timer(self, enable, us): """Disables (enable is false) or enables the timer and sets the timer time-out to us microseconds. Note that the timer resolution is 10 us. After the Relaxd shutter opens (either explicitly by software or by an @@ -245,55 +245,55 @@ def enableTimer(self, enable, us): self.lib.EMCameraObj_enableTimer(self.obj, enable, us) - def resetMatrix(self): + def reset_matrix(self): self.lib.EMCameraObj_resetMatrix(self.obj) - def timerExpired(self): + def timer_expired(self): return self.lib.EMCameraObj_timerExpired(self.obj) - def setAcqPars(self, pars): + def set_acq_pars(self, pars): """AcqParams *pars.""" raise NotImplementedError pars = AcqParams self.lib.EMCameraObj_setAcqPars(self.obj, byref(pars)) - def isBusy(self, busy): + def is_busy(self, busy): """bool *busy.""" busy = c_bool(busy) self.lib.EMCameraObj_isBusy(self.obj, byref(busy)) - def acquireData(self, exposure=0.001): + def acquire_data(self, exposure=0.001): microseconds = int(exposure * 1e6) # seconds to microseconds - self.enableTimer(True, microseconds) + self.enable_timer(True, microseconds) - self.openShutter() + self.open_shutter() # sleep here to avoid burning cycles # only sleep if exposure is longer than Windows timer resolution, i.e. 1 ms if exposure > 0.001: time.sleep(exposure - 0.001) - while not self.timerExpired(): + while not self.timer_expired(): pass - # self.closeShutter() + # self.close_shutter() - arr = self.readMatrix() + arr = self.read_matrix() - out = arrangeData(arr) - correctCross(out, factor=self.correction_ratio) + out = arrange_data(arr) + correct_cross(out, factor=self.correction_ratio) out = np.rot90(out, k=3) return out - def getImage(self, exposure): - return self.acquireData(exposure=exposure) + def get_image(self, exposure): + return self.acquire_data(exposure=exposure) - def getName(self): + def get_name(self): return 'timepix' - def getCameraDimensions(self) -> (int, int): + def get_camera_dimensions(self) -> (int, int): return self.dimensions def load_defaults(self): @@ -328,11 +328,11 @@ def initialize(config, name='pytimepix'): cam.init() - cam.readHwDacs(hwDacs) - cam.readPixelsCfg(pixelsCfg) - cam.readRealDacs(realDacs) + cam.read_hw_dacs(hwDacs) + cam.read_pixels_cfg(pixelsCfg) + cam.read_real_dacs(realDacs) - print(f'Camera {cam.getName()} initialized (resolution: {cam.getCameraDimensions()})') + print(f'Camera {cam.get_name()} initialized (resolution: {cam.get_camera_dimensions()})') return cam @@ -359,11 +359,11 @@ def initialize(config, name='pytimepix'): t = 0.01 n = 100 - arr = cam.acquireData(t) + arr = cam.acquire_data(t) print(f'[ py hardware timer] -> shape: {arr.shape}') t0 = time.perf_counter() for x in range(n): - cam.acquireData(t) + cam.acquire_data(t) dt = time.perf_counter() - t0 print(f'Total time: {dt:.1f} s, acquisition time: {1000*(dt/n):.2f} ms, overhead: {1000*(dt/n - t):.2f} ms') diff --git a/instamatic/camera/fakevideostream.py b/src/instamatic/camera/fakevideostream.py similarity index 94% rename from instamatic/camera/fakevideostream.py rename to src/instamatic/camera/fakevideostream.py index bbc0a632..e58c885e 100644 --- a/instamatic/camera/fakevideostream.py +++ b/src/instamatic/camera/fakevideostream.py @@ -46,8 +46,8 @@ def __getattr__(self, attrname): except AttributeError: raise reraise_on_fail - def getImage(self, exposure=None, binsize=None): - frame = self.cam.getImage(exposure=exposure, binsize=binsize) + def get_image(self, exposure=None, binsize=None): + frame = self.cam.get_image(exposure=exposure, binsize=binsize) self.frame, scale = autoscale(frame, maxdim=self.display_dim) @@ -87,7 +87,7 @@ def continuous_collection(self, exposure=0.1, n=100, callback=None): while go_on: i += 1 - img = self.getImage(exposure=exposure) + img = self.get_image(exposure=exposure) if callback: go_on = callback(img) diff --git a/instamatic/camera/gatansocket3.md b/src/instamatic/camera/gatansocket3.md similarity index 100% rename from instamatic/camera/gatansocket3.md rename to src/instamatic/camera/gatansocket3.md diff --git a/instamatic/camera/gatansocket3.py b/src/instamatic/camera/gatansocket3.py similarity index 100% rename from instamatic/camera/gatansocket3.py rename to src/instamatic/camera/gatansocket3.py diff --git a/instamatic/camera/merlin_io.py b/src/instamatic/camera/merlin_io.py similarity index 100% rename from instamatic/camera/merlin_io.py rename to src/instamatic/camera/merlin_io.py diff --git a/instamatic/camera/mpxhwrelaxd.dll b/src/instamatic/camera/mpxhwrelaxd.dll similarity index 100% rename from instamatic/camera/mpxhwrelaxd.dll rename to src/instamatic/camera/mpxhwrelaxd.dll diff --git a/instamatic/camera/timepix.lockfile b/src/instamatic/camera/timepix.lockfile similarity index 100% rename from instamatic/camera/timepix.lockfile rename to src/instamatic/camera/timepix.lockfile diff --git a/instamatic/camera/tpx/171207_with_flatfield.bpc b/src/instamatic/camera/tpx/171207_with_flatfield.bpc similarity index 100% rename from instamatic/camera/tpx/171207_with_flatfield.bpc rename to src/instamatic/camera/tpx/171207_with_flatfield.bpc diff --git a/instamatic/camera/tpx/171207_with_flatfield.bpc.dacs b/src/instamatic/camera/tpx/171207_with_flatfield.bpc.dacs similarity index 100% rename from instamatic/camera/tpx/171207_with_flatfield.bpc.dacs rename to src/instamatic/camera/tpx/171207_with_flatfield.bpc.dacs diff --git a/instamatic/camera/tpx/HW.dacs b/src/instamatic/camera/tpx/HW.dacs similarity index 100% rename from instamatic/camera/tpx/HW.dacs rename to src/instamatic/camera/tpx/HW.dacs diff --git a/instamatic/camera/tpx/config.txt b/src/instamatic/camera/tpx/config.txt similarity index 100% rename from instamatic/camera/tpx/config.txt rename to src/instamatic/camera/tpx/config.txt diff --git a/instamatic/camera/videostream.py b/src/instamatic/camera/videostream.py similarity index 95% rename from instamatic/camera/videostream.py rename to src/instamatic/camera/videostream.py index 98c322b4..4ed978a1 100644 --- a/instamatic/camera/videostream.py +++ b/src/instamatic/camera/videostream.py @@ -49,11 +49,11 @@ def run(self): if self.acquireInitiateEvent.is_set(): self.acquireInitiateEvent.clear() - frame = self.cam.getImage(exposure=self.exposure, binsize=self.binsize) + frame = self.cam.get_image(exposure=self.exposure, binsize=self.binsize) self.callback(frame, acquire=True) elif not self.continuousCollectionEvent.is_set(): - frame = self.cam.getImage(exposure=self.frametime, binsize=self.binsize) + frame = self.cam.get_image(exposure=self.frametime, binsize=self.binsize) self.callback(frame) def start_loop(self): @@ -122,7 +122,7 @@ def setup_grabber(self): atexit.register(grabber.stop) return grabber - def getImage(self, exposure=None, binsize=None): + def get_image(self, exposure=None, binsize=None): current_frametime = self.grabber.frametime # set to 0 to prevent it lagging data acquisition @@ -179,7 +179,7 @@ def continuous_collection(self, exposure=0.1, n=100, callback=None): while go_on: i += 1 - img = self.getImage(exposure=exposure) + img = self.get_image(exposure=exposure) if callback: go_on = callback(img) diff --git a/instamatic/config/__init__.py b/src/instamatic/config/__init__.py similarity index 100% rename from instamatic/config/__init__.py rename to src/instamatic/config/__init__.py diff --git a/instamatic/config/alignments/neutral.yaml b/src/instamatic/config/alignments/neutral.yaml similarity index 100% rename from instamatic/config/alignments/neutral.yaml rename to src/instamatic/config/alignments/neutral.yaml diff --git a/instamatic/config/autoconfig.py b/src/instamatic/config/autoconfig.py similarity index 97% rename from instamatic/config/autoconfig.py rename to src/instamatic/config/autoconfig.py index 907d57d6..101a402c 100644 --- a/instamatic/config/autoconfig.py +++ b/src/instamatic/config/autoconfig.py @@ -14,17 +14,17 @@ def get_tvips_calibs(ctrl, rng: list, mode: str, wavelength: float) -> dict: calib_range = {} - binning = ctrl.cam.getBinning() + binning = ctrl.cam.get_binning() ctrl.mode.set(mode) for i, mag in enumerate(rng): ctrl.magnification.index = i - d = ctrl.cam.getCurrentCameraInfo() + d = ctrl.cam.get_current_camera_info() img = ctrl.get_image(exposure=10) # set to minimum allowed value index = ctrl.cam.get_image_index() - v = ctrl.cam.getEMVectorByIndex(index) + v = ctrl.cam.get_emvector_by_index(index) PixelSizeX = v['fImgDistX'] PixelSizeY = v['fImgDistY'] diff --git a/instamatic/config/calibration/orius.yaml b/src/instamatic/config/calibration/orius.yaml similarity index 100% rename from instamatic/config/calibration/orius.yaml rename to src/instamatic/config/calibration/orius.yaml diff --git a/instamatic/config/calibration/simulate.yaml b/src/instamatic/config/calibration/simulate.yaml similarity index 100% rename from instamatic/config/calibration/simulate.yaml rename to src/instamatic/config/calibration/simulate.yaml diff --git a/instamatic/config/calibration/timepix.yaml b/src/instamatic/config/calibration/timepix.yaml similarity index 100% rename from instamatic/config/calibration/timepix.yaml rename to src/instamatic/config/calibration/timepix.yaml diff --git a/instamatic/config/calibration/tvips-f416.yaml b/src/instamatic/config/calibration/tvips-f416.yaml similarity index 100% rename from instamatic/config/calibration/tvips-f416.yaml rename to src/instamatic/config/calibration/tvips-f416.yaml diff --git a/instamatic/config/camera/merlin.yaml b/src/instamatic/config/camera/merlin.yaml similarity index 88% rename from instamatic/config/camera/merlin.yaml rename to src/instamatic/config/camera/merlin.yaml index 47270e8f..5721c4c8 100644 --- a/instamatic/config/camera/merlin.yaml +++ b/src/instamatic/config/camera/merlin.yaml @@ -9,11 +9,10 @@ possible_binsizes: [1] stretch_amplitude: 0.0 stretch_azimuth: 0.0 detector_config: - THRESHOLD0: 120 - THRESHOLD1: 40 - HVBIAS: 511 + CONTINUOUSRW: 1 COUNTERDEPTH: 12 FILEENABLE: 0 + RUNHEADLESS: 1 # server hostname or IP address and port used to send commands host: '127.0.0.1' commandport: 6341 diff --git a/instamatic/config/camera/orius.yaml b/src/instamatic/config/camera/orius.yaml similarity index 100% rename from instamatic/config/camera/orius.yaml rename to src/instamatic/config/camera/orius.yaml diff --git a/instamatic/config/camera/serval.yaml b/src/instamatic/config/camera/serval.yaml similarity index 100% rename from instamatic/config/camera/serval.yaml rename to src/instamatic/config/camera/serval.yaml diff --git a/instamatic/config/camera/simulate.yaml b/src/instamatic/config/camera/simulate.yaml similarity index 100% rename from instamatic/config/camera/simulate.yaml rename to src/instamatic/config/camera/simulate.yaml diff --git a/instamatic/config/camera/simulateDLL.yaml b/src/instamatic/config/camera/simulateDLL.yaml similarity index 100% rename from instamatic/config/camera/simulateDLL.yaml rename to src/instamatic/config/camera/simulateDLL.yaml diff --git a/instamatic/config/camera/timepix.yaml b/src/instamatic/config/camera/timepix.yaml similarity index 100% rename from instamatic/config/camera/timepix.yaml rename to src/instamatic/config/camera/timepix.yaml diff --git a/instamatic/config/camera/tvips-f416.yaml b/src/instamatic/config/camera/tvips-f416.yaml similarity index 100% rename from instamatic/config/camera/tvips-f416.yaml rename to src/instamatic/config/camera/tvips-f416.yaml diff --git a/instamatic/config/camera/tvips-xf416.yaml b/src/instamatic/config/camera/tvips-xf416.yaml similarity index 100% rename from instamatic/config/camera/tvips-xf416.yaml rename to src/instamatic/config/camera/tvips-xf416.yaml diff --git a/instamatic/config/config_updater.py b/src/instamatic/config/config_updater.py similarity index 100% rename from instamatic/config/config_updater.py rename to src/instamatic/config/config_updater.py diff --git a/instamatic/config/defaults.yaml b/src/instamatic/config/defaults.yaml similarity index 100% rename from instamatic/config/defaults.yaml rename to src/instamatic/config/defaults.yaml diff --git a/instamatic/config/microscope/fei_simu.yaml b/src/instamatic/config/microscope/fei_simu.yaml similarity index 100% rename from instamatic/config/microscope/fei_simu.yaml rename to src/instamatic/config/microscope/fei_simu.yaml diff --git a/instamatic/config/microscope/fei_themisZ.yaml b/src/instamatic/config/microscope/fei_themisZ.yaml similarity index 100% rename from instamatic/config/microscope/fei_themisZ.yaml rename to src/instamatic/config/microscope/fei_themisZ.yaml diff --git a/instamatic/config/microscope/jeol-1400.yaml b/src/instamatic/config/microscope/jeol-1400.yaml similarity index 100% rename from instamatic/config/microscope/jeol-1400.yaml rename to src/instamatic/config/microscope/jeol-1400.yaml diff --git a/instamatic/config/microscope/jeol.yaml b/src/instamatic/config/microscope/jeol.yaml similarity index 100% rename from instamatic/config/microscope/jeol.yaml rename to src/instamatic/config/microscope/jeol.yaml diff --git a/instamatic/config/microscope/simulate.yaml b/src/instamatic/config/microscope/simulate.yaml similarity index 100% rename from instamatic/config/microscope/simulate.yaml rename to src/instamatic/config/microscope/simulate.yaml diff --git a/instamatic/config/scripts/close_down.py b/src/instamatic/config/scripts/close_down.py similarity index 100% rename from instamatic/config/scripts/close_down.py rename to src/instamatic/config/scripts/close_down.py diff --git a/instamatic/config/scripts/focus_mode.py b/src/instamatic/config/scripts/focus_mode.py similarity index 100% rename from instamatic/config/scripts/focus_mode.py rename to src/instamatic/config/scripts/focus_mode.py diff --git a/instamatic/config/scripts/hello_world.py b/src/instamatic/config/scripts/hello_world.py similarity index 100% rename from instamatic/config/scripts/hello_world.py rename to src/instamatic/config/scripts/hello_world.py diff --git a/instamatic/config/scripts/readme.md b/src/instamatic/config/scripts/readme.md similarity index 100% rename from instamatic/config/scripts/readme.md rename to src/instamatic/config/scripts/readme.md diff --git a/instamatic/config/scripts/search_mode.py b/src/instamatic/config/scripts/search_mode.py similarity index 100% rename from instamatic/config/scripts/search_mode.py rename to src/instamatic/config/scripts/search_mode.py diff --git a/instamatic/config/settings.yaml b/src/instamatic/config/settings.yaml similarity index 100% rename from instamatic/config/settings.yaml rename to src/instamatic/config/settings.yaml diff --git a/instamatic/config/utils.py b/src/instamatic/config/utils.py similarity index 100% rename from instamatic/config/utils.py rename to src/instamatic/config/utils.py diff --git a/instamatic/exceptions.py b/src/instamatic/exceptions.py similarity index 100% rename from instamatic/exceptions.py rename to src/instamatic/exceptions.py diff --git a/instamatic/experiments/__init__.py b/src/instamatic/experiments/__init__.py similarity index 100% rename from instamatic/experiments/__init__.py rename to src/instamatic/experiments/__init__.py diff --git a/instamatic/experiments/autocred/__init__.py b/src/instamatic/experiments/autocred/__init__.py similarity index 100% rename from instamatic/experiments/autocred/__init__.py rename to src/instamatic/experiments/autocred/__init__.py diff --git a/instamatic/experiments/autocred/experiment.py b/src/instamatic/experiments/autocred/experiment.py similarity index 99% rename from instamatic/experiments/autocred/experiment.py rename to src/instamatic/experiments/autocred/experiment.py index 72bef4dd..745b3ff9 100644 --- a/instamatic/experiments/autocred/experiment.py +++ b/src/instamatic/experiments/autocred/experiment.py @@ -992,7 +992,7 @@ def update_referencepoint_bs(self, bs, br): def raster_scan(self): from instamatic.experiments.serialed.experiment import get_offsets_in_scan_area pixelsize_mag1 = config.calibration['mag1']['pixelsize'][self.magnification] / 1000 # nm -> um - xdim, ydim = self.ctrl.getCameraDimensions() + xdim, ydim = self.ctrl.cam.get_camera_dimensions() box_x, box_y = self.pixelsize_mag1 * xdim, self.pixelsize_mag1 * ydim # Make negative to reflect config change 2019-07-03 to make omega more in line with other software diff --git a/instamatic/experiments/cred/__init__.py b/src/instamatic/experiments/cred/__init__.py similarity index 100% rename from instamatic/experiments/cred/__init__.py rename to src/instamatic/experiments/cred/__init__.py diff --git a/instamatic/experiments/cred/experiment.py b/src/instamatic/experiments/cred/experiment.py similarity index 100% rename from instamatic/experiments/cred/experiment.py rename to src/instamatic/experiments/cred/experiment.py diff --git a/instamatic/experiments/cred_gatan/__init__.py b/src/instamatic/experiments/cred_gatan/__init__.py similarity index 100% rename from instamatic/experiments/cred_gatan/__init__.py rename to src/instamatic/experiments/cred_gatan/__init__.py diff --git a/instamatic/experiments/cred_gatan/experiment.py b/src/instamatic/experiments/cred_gatan/experiment.py similarity index 99% rename from instamatic/experiments/cred_gatan/experiment.py rename to src/instamatic/experiments/cred_gatan/experiment.py index 11c83bcc..b9b2dc8d 100644 --- a/instamatic/experiments/cred_gatan/experiment.py +++ b/src/instamatic/experiments/cred_gatan/experiment.py @@ -332,10 +332,10 @@ def log_end_status(self): print(f'Rotation speed: {self.rotation_speed:.3f} degrees/s') with open(self.path / 'cRED_log.txt', 'w') as f: - print(f'Program: {instamatic.__long_title__} + GMS {self.cam.getDMVersion()}', file=f) + print(f'Program: {instamatic.__long_title__} + GMS {self.cam.get_dm_version()}', file=f) print(f'Camera: {config.camera.name}', file=f) print(f'Microscope: {config.microscope.name}', file=f) - # print(f"Camera type: {self.cam.getCameraType()}", file=f) + # print(f"Camera type: {self.cam.get_camera_type()}", file=f) print(f'Mode: {self.mode}', file=f) print(f'Data Collection Time: {self.now}', file=f) print(f'Time Period Start: {self.t_start}', file=f) diff --git a/instamatic/experiments/cred_tvips/__init__.py b/src/instamatic/experiments/cred_tvips/__init__.py similarity index 100% rename from instamatic/experiments/cred_tvips/__init__.py rename to src/instamatic/experiments/cred_tvips/__init__.py diff --git a/instamatic/experiments/cred_tvips/experiment.py b/src/instamatic/experiments/cred_tvips/experiment.py similarity index 98% rename from instamatic/experiments/cred_tvips/experiment.py rename to src/instamatic/experiments/cred_tvips/experiment.py index 5e4d51f9..7fd95a8c 100644 --- a/instamatic/experiments/cred_tvips/experiment.py +++ b/src/instamatic/experiments/cred_tvips/experiment.py @@ -430,7 +430,7 @@ def start_collection(self, target_angle: float, start_angle: float = None, manua path_data = self.path / 'tiff' path_data.mkdir(exist_ok=True, parents=True) - self.emmenu.writeTiffs(start_index, end_index, path=path_data) + self.emmenu.write_tiffs(start_index, end_index, path=path_data) if self.track: # Center crystal position @@ -463,9 +463,9 @@ def log_end_status(self): physical_pixelsize = config.camera.physical_pixelsize # mm - binning = self.emmenu.getBinning() - image_dimensions_x, image_dimensions_y = self.emmenu.getImageDimensions() - camera_dimensions_x, camera_dimensions_y = self.emmenu.getCameraDimensions() + binning = self.emmenu.get_binning() + image_dimensions_x, image_dimensions_y = self.emmenu.get_image_dimensions() + camera_dimensions_x, camera_dimensions_y = self.emmenu.get_camera_dimensions() pixelsize *= binning physical_pixelsize *= binning @@ -478,11 +478,11 @@ def log_end_status(self): print(f'Rotation speed: {self.rotation_speed:.3f} degrees/s') with open(self.path / 'cRED_log.txt', 'w') as f: - print(f'Program: {instamatic.__long_title__} + EMMenu {self.emmenu.getEMMenuVersion()}', file=f) + print(f'Program: {instamatic.__long_title__} + EMMenu {self.emmenu.get_emmenu_version()}', file=f) print(f'Camera: {config.camera.name}', file=f) print(f'Microscope: {config.microscope.name}', file=f) - print(f'Camera type: {self.emmenu.getCameraType()}', file=f) - print(f'Camera config: {self.emmenu.getCurrentConfigName()}', file=f) + print(f'Camera type: {self.emmenu.get_camera_type()}', file=f) + print(f'Camera config: {self.emmenu.get_current_config_name()}', file=f) print(f'Mode: {self.mode}', file=f) print(f'Data Collection Time: {self.now}', file=f) print(f'Time Period Start: {self.t_start}', file=f) diff --git a/instamatic/experiments/red/__init__.py b/src/instamatic/experiments/red/__init__.py similarity index 100% rename from instamatic/experiments/red/__init__.py rename to src/instamatic/experiments/red/__init__.py diff --git a/instamatic/experiments/red/experiment.py b/src/instamatic/experiments/red/experiment.py similarity index 100% rename from instamatic/experiments/red/experiment.py rename to src/instamatic/experiments/red/experiment.py diff --git a/instamatic/experiments/serialed/__init__.py b/src/instamatic/experiments/serialed/__init__.py similarity index 100% rename from instamatic/experiments/serialed/__init__.py rename to src/instamatic/experiments/serialed/__init__.py diff --git a/instamatic/experiments/serialed/experiment.py b/src/instamatic/experiments/serialed/experiment.py similarity index 99% rename from instamatic/experiments/serialed/experiment.py rename to src/instamatic/experiments/serialed/experiment.py index e52b8acb..6ccd3a63 100644 --- a/instamatic/experiments/serialed/experiment.py +++ b/src/instamatic/experiments/serialed/experiment.py @@ -213,7 +213,7 @@ def load_calibration(self, **kwargs): self.log.info('Brightness=%s', self.ctrl.brightness) self.pixelsize_mag1 = config.calibration['mag1']['pixelsize'][self.magnification] / 1000 # nm -> um - xdim, ydim = self.ctrl.cam.getCameraDimensions() + xdim, ydim = self.ctrl.cam.get_camera_dimensions() self.image_dimensions = self.pixelsize_mag1 * xdim, self.pixelsize_mag1 * ydim self.log.info('Image dimensions %s', self.image_dimensions) diff --git a/instamatic/formats/__init__.py b/src/instamatic/formats/__init__.py similarity index 100% rename from instamatic/formats/__init__.py rename to src/instamatic/formats/__init__.py diff --git a/instamatic/formats/adscimage.py b/src/instamatic/formats/adscimage.py similarity index 100% rename from instamatic/formats/adscimage.py rename to src/instamatic/formats/adscimage.py diff --git a/instamatic/formats/csvIO.py b/src/instamatic/formats/csvIO.py similarity index 100% rename from instamatic/formats/csvIO.py rename to src/instamatic/formats/csvIO.py diff --git a/instamatic/formats/mrc.py b/src/instamatic/formats/mrc.py similarity index 100% rename from instamatic/formats/mrc.py rename to src/instamatic/formats/mrc.py diff --git a/instamatic/formats/util.py b/src/instamatic/formats/util.py similarity index 100% rename from instamatic/formats/util.py rename to src/instamatic/formats/util.py diff --git a/instamatic/formats/xdscbf.py b/src/instamatic/formats/xdscbf.py similarity index 100% rename from instamatic/formats/xdscbf.py rename to src/instamatic/formats/xdscbf.py diff --git a/instamatic/goniotool.py b/src/instamatic/goniotool.py similarity index 100% rename from instamatic/goniotool.py rename to src/instamatic/goniotool.py diff --git a/instamatic/gridmontage.py b/src/instamatic/gridmontage.py similarity index 98% rename from instamatic/gridmontage.py rename to src/instamatic/gridmontage.py index 03b02e88..9fe40937 100644 --- a/instamatic/gridmontage.py +++ b/src/instamatic/gridmontage.py @@ -57,9 +57,9 @@ def setup(self, self.overlap = overlap if not binning: - binning = self.ctrl.cam.getBinning() + binning = self.ctrl.cam.get_binning() - res_x, res_y = self.ctrl.cam.getImageDimensions() + res_x, res_y = self.ctrl.cam.get_image_dimensions() overlap_x = int(res_x * overlap) overlap_y = int(res_y * overlap) diff --git a/instamatic/gui/__init__.py b/src/instamatic/gui/__init__.py similarity index 100% rename from instamatic/gui/__init__.py rename to src/instamatic/gui/__init__.py diff --git a/instamatic/gui/about_frame.py b/src/instamatic/gui/about_frame.py similarity index 100% rename from instamatic/gui/about_frame.py rename to src/instamatic/gui/about_frame.py diff --git a/instamatic/gui/autocred_frame.py b/src/instamatic/gui/autocred_frame.py similarity index 100% rename from instamatic/gui/autocred_frame.py rename to src/instamatic/gui/autocred_frame.py diff --git a/instamatic/gui/base_module.py b/src/instamatic/gui/base_module.py similarity index 100% rename from instamatic/gui/base_module.py rename to src/instamatic/gui/base_module.py diff --git a/instamatic/gui/console_frame.py b/src/instamatic/gui/console_frame.py similarity index 100% rename from instamatic/gui/console_frame.py rename to src/instamatic/gui/console_frame.py diff --git a/instamatic/gui/cred_fei_frame.py b/src/instamatic/gui/cred_fei_frame.py similarity index 100% rename from instamatic/gui/cred_fei_frame.py rename to src/instamatic/gui/cred_fei_frame.py diff --git a/instamatic/gui/cred_frame.py b/src/instamatic/gui/cred_frame.py similarity index 100% rename from instamatic/gui/cred_frame.py rename to src/instamatic/gui/cred_frame.py diff --git a/instamatic/gui/cred_tvips_frame.py b/src/instamatic/gui/cred_tvips_frame.py similarity index 99% rename from instamatic/gui/cred_tvips_frame.py rename to src/instamatic/gui/cred_tvips_frame.py index fb51d4a1..863ef315 100644 --- a/instamatic/gui/cred_tvips_frame.py +++ b/src/instamatic/gui/cred_tvips_frame.py @@ -296,7 +296,7 @@ def focus(self): self.ctrl.run_script('focus_mode.py') def get_image(self): - self.ctrl.cam.acquireImage() + self.ctrl.cam.acquire_image() def acquire_data_CRED_TVIPS(controller, **kwargs): diff --git a/instamatic/gui/ctrl_frame.py b/src/instamatic/gui/ctrl_frame.py similarity index 100% rename from instamatic/gui/ctrl_frame.py rename to src/instamatic/gui/ctrl_frame.py diff --git a/instamatic/gui/debug_frame.py b/src/instamatic/gui/debug_frame.py similarity index 100% rename from instamatic/gui/debug_frame.py rename to src/instamatic/gui/debug_frame.py diff --git a/instamatic/gui/defocus_button.py b/src/instamatic/gui/defocus_button.py similarity index 100% rename from instamatic/gui/defocus_button.py rename to src/instamatic/gui/defocus_button.py diff --git a/instamatic/gui/gui.py b/src/instamatic/gui/gui.py similarity index 100% rename from instamatic/gui/gui.py rename to src/instamatic/gui/gui.py diff --git a/instamatic/gui/io_frame.py b/src/instamatic/gui/io_frame.py similarity index 100% rename from instamatic/gui/io_frame.py rename to src/instamatic/gui/io_frame.py diff --git a/instamatic/gui/jobs.py b/src/instamatic/gui/jobs.py similarity index 100% rename from instamatic/gui/jobs.py rename to src/instamatic/gui/jobs.py diff --git a/instamatic/gui/machine_learning_frame.py b/src/instamatic/gui/machine_learning_frame.py similarity index 100% rename from instamatic/gui/machine_learning_frame.py rename to src/instamatic/gui/machine_learning_frame.py diff --git a/instamatic/gui/modules.py b/src/instamatic/gui/modules.py similarity index 100% rename from instamatic/gui/modules.py rename to src/instamatic/gui/modules.py diff --git a/instamatic/gui/mpl_frame.py b/src/instamatic/gui/mpl_frame.py similarity index 100% rename from instamatic/gui/mpl_frame.py rename to src/instamatic/gui/mpl_frame.py diff --git a/instamatic/gui/red_frame.py b/src/instamatic/gui/red_frame.py similarity index 100% rename from instamatic/gui/red_frame.py rename to src/instamatic/gui/red_frame.py diff --git a/instamatic/gui/sed_frame.py b/src/instamatic/gui/sed_frame.py similarity index 100% rename from instamatic/gui/sed_frame.py rename to src/instamatic/gui/sed_frame.py diff --git a/instamatic/gui/videostream_frame.py b/src/instamatic/gui/videostream_frame.py similarity index 100% rename from instamatic/gui/videostream_frame.py rename to src/instamatic/gui/videostream_frame.py diff --git a/instamatic/image_utils.py b/src/instamatic/image_utils.py similarity index 100% rename from instamatic/image_utils.py rename to src/instamatic/image_utils.py diff --git a/instamatic/imreg.py b/src/instamatic/imreg.py similarity index 100% rename from instamatic/imreg.py rename to src/instamatic/imreg.py diff --git a/instamatic/io.py b/src/instamatic/io.py similarity index 100% rename from instamatic/io.py rename to src/instamatic/io.py diff --git a/instamatic/main.py b/src/instamatic/main.py similarity index 100% rename from instamatic/main.py rename to src/instamatic/main.py diff --git a/instamatic/montage.py b/src/instamatic/montage.py similarity index 100% rename from instamatic/montage.py rename to src/instamatic/montage.py diff --git a/instamatic/neural_network/__init__.py b/src/instamatic/neural_network/__init__.py similarity index 100% rename from instamatic/neural_network/__init__.py rename to src/instamatic/neural_network/__init__.py diff --git a/instamatic/neural_network/neural_network.py b/src/instamatic/neural_network/neural_network.py similarity index 100% rename from instamatic/neural_network/neural_network.py rename to src/instamatic/neural_network/neural_network.py diff --git a/instamatic/neural_network/preprocess.py b/src/instamatic/neural_network/preprocess.py similarity index 100% rename from instamatic/neural_network/preprocess.py rename to src/instamatic/neural_network/preprocess.py diff --git a/instamatic/neural_network/preprocess_SerialRED.py b/src/instamatic/neural_network/preprocess_SerialRED.py similarity index 100% rename from instamatic/neural_network/preprocess_SerialRED.py rename to src/instamatic/neural_network/preprocess_SerialRED.py diff --git a/instamatic/neural_network/weights-py2.p b/src/instamatic/neural_network/weights-py2.p similarity index 100% rename from instamatic/neural_network/weights-py2.p rename to src/instamatic/neural_network/weights-py2.p diff --git a/instamatic/neural_network/weights-py3.p b/src/instamatic/neural_network/weights-py3.p similarity index 100% rename from instamatic/neural_network/weights-py3.p rename to src/instamatic/neural_network/weights-py3.p diff --git a/instamatic/processing/ImgConversion.py b/src/instamatic/processing/ImgConversion.py similarity index 100% rename from instamatic/processing/ImgConversion.py rename to src/instamatic/processing/ImgConversion.py diff --git a/instamatic/processing/ImgConversionDM.py b/src/instamatic/processing/ImgConversionDM.py similarity index 100% rename from instamatic/processing/ImgConversionDM.py rename to src/instamatic/processing/ImgConversionDM.py diff --git a/instamatic/processing/ImgConversionTPX.py b/src/instamatic/processing/ImgConversionTPX.py similarity index 100% rename from instamatic/processing/ImgConversionTPX.py rename to src/instamatic/processing/ImgConversionTPX.py diff --git a/instamatic/processing/ImgConversionTVIPS.py b/src/instamatic/processing/ImgConversionTVIPS.py similarity index 100% rename from instamatic/processing/ImgConversionTVIPS.py rename to src/instamatic/processing/ImgConversionTVIPS.py diff --git a/instamatic/processing/XDS_template.py b/src/instamatic/processing/XDS_template.py similarity index 100% rename from instamatic/processing/XDS_template.py rename to src/instamatic/processing/XDS_template.py diff --git a/instamatic/processing/XDS_templateDM.py b/src/instamatic/processing/XDS_templateDM.py similarity index 100% rename from instamatic/processing/XDS_templateDM.py rename to src/instamatic/processing/XDS_templateDM.py diff --git a/instamatic/processing/XDS_templateTPX.py b/src/instamatic/processing/XDS_templateTPX.py similarity index 100% rename from instamatic/processing/XDS_templateTPX.py rename to src/instamatic/processing/XDS_templateTPX.py diff --git a/instamatic/processing/XDS_templateTVIPS.py b/src/instamatic/processing/XDS_templateTVIPS.py similarity index 100% rename from instamatic/processing/XDS_templateTVIPS.py rename to src/instamatic/processing/XDS_templateTVIPS.py diff --git a/instamatic/processing/__init__.py b/src/instamatic/processing/__init__.py similarity index 100% rename from instamatic/processing/__init__.py rename to src/instamatic/processing/__init__.py diff --git a/instamatic/processing/find_crystals.py b/src/instamatic/processing/find_crystals.py similarity index 100% rename from instamatic/processing/find_crystals.py rename to src/instamatic/processing/find_crystals.py diff --git a/instamatic/processing/find_crystals_ilastik.py b/src/instamatic/processing/find_crystals_ilastik.py similarity index 100% rename from instamatic/processing/find_crystals_ilastik.py rename to src/instamatic/processing/find_crystals_ilastik.py diff --git a/instamatic/processing/find_holes.py b/src/instamatic/processing/find_holes.py similarity index 100% rename from instamatic/processing/find_holes.py rename to src/instamatic/processing/find_holes.py diff --git a/instamatic/processing/flatfield.py b/src/instamatic/processing/flatfield.py similarity index 100% rename from instamatic/processing/flatfield.py rename to src/instamatic/processing/flatfield.py diff --git a/instamatic/processing/stretch_correction.py b/src/instamatic/processing/stretch_correction.py similarity index 100% rename from instamatic/processing/stretch_correction.py rename to src/instamatic/processing/stretch_correction.py diff --git a/instamatic/server/TEMServer_FEI.py b/src/instamatic/server/TEMServer_FEI.py similarity index 93% rename from instamatic/server/TEMServer_FEI.py rename to src/instamatic/server/TEMServer_FEI.py index 96bfbb5b..e3499239 100644 --- a/instamatic/server/TEMServer_FEI.py +++ b/src/instamatic/server/TEMServer_FEI.py @@ -1,5 +1,5 @@ """Utility script to enable rotation control from a dmscript See -`https://github.com/instamatic-dev/instamatic/tree/master/dmscript` for +`https://github.com/instamatic-dev/InsteaDMatic` for usage.""" import datetime import logging @@ -46,7 +46,7 @@ def main(): import argparse description = """ -Utility script to enable rotation control from a dmscript. See [https://github.com/instamatic-dev/instamatic/tree/master/dmscript] for usage. +Utility script to enable rotation control from a dmscript. See [https://github.com/instamatic-dev/InsteaDMatic] for usage. """ parser = argparse.ArgumentParser( diff --git a/instamatic/server/__init__.py b/src/instamatic/server/__init__.py similarity index 100% rename from instamatic/server/__init__.py rename to src/instamatic/server/__init__.py diff --git a/instamatic/server/cam_client.py b/src/instamatic/server/cam_client.py similarity index 100% rename from instamatic/server/cam_client.py rename to src/instamatic/server/cam_client.py diff --git a/instamatic/server/cam_server.py b/src/instamatic/server/cam_server.py similarity index 99% rename from instamatic/server/cam_server.py rename to src/instamatic/server/cam_server.py index 06971153..cc11d529 100644 --- a/instamatic/server/cam_server.py +++ b/src/instamatic/server/cam_server.py @@ -105,7 +105,7 @@ def run(self): status = 500 else: if self.use_shared_memory: - if attr_name == 'getImage': + if attr_name == 'get_image': self.copy_data_to_shared_buffer(ret) ret = { 'shape': ret.shape, diff --git a/instamatic/server/dials_server.py b/src/instamatic/server/dials_server.py similarity index 100% rename from instamatic/server/dials_server.py rename to src/instamatic/server/dials_server.py diff --git a/instamatic/server/goniotool_server.py b/src/instamatic/server/goniotool_server.py similarity index 100% rename from instamatic/server/goniotool_server.py rename to src/instamatic/server/goniotool_server.py diff --git a/instamatic/server/serializer.py b/src/instamatic/server/serializer.py similarity index 100% rename from instamatic/server/serializer.py rename to src/instamatic/server/serializer.py diff --git a/instamatic/server/tem_client.py b/src/instamatic/server/tem_client.py similarity index 100% rename from instamatic/server/tem_client.py rename to src/instamatic/server/tem_client.py diff --git a/instamatic/server/tem_server.py b/src/instamatic/server/tem_server.py similarity index 100% rename from instamatic/server/tem_server.py rename to src/instamatic/server/tem_server.py diff --git a/instamatic/server/vm_ubuntu_server.py b/src/instamatic/server/vm_ubuntu_server.py similarity index 100% rename from instamatic/server/vm_ubuntu_server.py rename to src/instamatic/server/vm_ubuntu_server.py diff --git a/instamatic/server/xds_server.py b/src/instamatic/server/xds_server.py similarity index 100% rename from instamatic/server/xds_server.py rename to src/instamatic/server/xds_server.py diff --git a/instamatic/tools.py b/src/instamatic/tools.py similarity index 100% rename from instamatic/tools.py rename to src/instamatic/tools.py diff --git a/instamatic/utils/__init__.py b/src/instamatic/utils/__init__.py similarity index 100% rename from instamatic/utils/__init__.py rename to src/instamatic/utils/__init__.py diff --git a/instamatic/utils/beamstop.py b/src/instamatic/utils/beamstop.py similarity index 100% rename from instamatic/utils/beamstop.py rename to src/instamatic/utils/beamstop.py diff --git a/instamatic/utils/high_precision_timers.py b/src/instamatic/utils/high_precision_timers.py similarity index 100% rename from instamatic/utils/high_precision_timers.py rename to src/instamatic/utils/high_precision_timers.py diff --git a/instamatic/utils/progress.py b/src/instamatic/utils/progress.py similarity index 100% rename from instamatic/utils/progress.py rename to src/instamatic/utils/progress.py diff --git a/instamatic/utils/singleton.py b/src/instamatic/utils/singleton.py similarity index 100% rename from instamatic/utils/singleton.py rename to src/instamatic/utils/singleton.py diff --git a/instamatic/utils/spinbox.py b/src/instamatic/utils/spinbox.py similarity index 100% rename from instamatic/utils/spinbox.py rename to src/instamatic/utils/spinbox.py diff --git a/instamatic/utils/xds_parser.py b/src/instamatic/utils/xds_parser.py similarity index 100% rename from instamatic/utils/xds_parser.py rename to src/instamatic/utils/xds_parser.py diff --git a/tests/test_camera.py b/tests/test_camera.py index e0bf6c0a..e3fde796 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -19,6 +19,6 @@ def test_get_image(ctrl): def test_functions(ctrl): - dims = ctrl.cam.getImageDimensions() + dims = ctrl.cam.get_image_dimensions() assert isinstance(dims, tuple) assert len(dims) == 2