From 35c81f85cd11bafc0b6b5a981d7b1844ea540f1b Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 16:50:01 +0100 Subject: [PATCH 01/13] Move isort,black,flake8 to ruff --- .azure-pipelines/azure-pipelines.yml | 4 +- ...lake8-validation.py => lint-validation.py} | 3 +- .pre-commit-config.yaml | 38 ++--------- pyproject.toml | 65 +++++++++++++++++-- setup.cfg | 17 ----- 5 files changed, 69 insertions(+), 58 deletions(-) rename .azure-pipelines/{flake8-validation.py => lint-validation.py} (96%) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 8cb10339d..fb5f86cdd 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -35,9 +35,9 @@ stages: - bash: | set -eux - pip install flake8 + pip install ruff cd repository - python .azure-pipelines/flake8-validation.py + python .azure-pipelines/lint-validation.py displayName: Flake8 validation # Set up constants for further build steps diff --git a/.azure-pipelines/flake8-validation.py b/.azure-pipelines/lint-validation.py similarity index 96% rename from .azure-pipelines/flake8-validation.py rename to .azure-pipelines/lint-validation.py index 4b6b02738..4cfbad234 100644 --- a/.azure-pipelines/flake8-validation.py +++ b/.azure-pipelines/lint-validation.py @@ -7,7 +7,8 @@ try: flake8 = subprocess.run( [ - "flake8", + "ruff", + "check", "--exit-zero", ], capture_output=True, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cbb44f922..605e444cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,41 +14,17 @@ repos: - id: no-commit-to-branch name: "Don't commit to 'main' directly" -# Automatically sort imports -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: isort - args: [ - '-a', 'from __future__ import annotations', # 3.7-3.11 - '--rm', 'from __future__ import absolute_import', # -3.0 - '--rm', 'from __future__ import division', # -3.0 - '--rm', 'from __future__ import generator_stop', # -3.7 - '--rm', 'from __future__ import generators', # -2.3 - '--rm', 'from __future__ import nested_scopes', # -2.2 - '--rm', 'from __future__ import print_function', # -3.0 - '--rm', 'from __future__ import unicode_literals', # -3.0 - '--rm', 'from __future__ import with_statement', # -2.6 - ] - -# Automatic source code formatting -- repo: https://github.com/psf/black - rev: 22.12.0 - hooks: - - id: black - args: [--safe, --quiet] - files: \.pyi?$|SConscript$|^libtbx_config$ - types: [file] + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + files: \.pyi?$|SConscript$|^libtbx_config$ + types: [file] - repo: https://github.com/pre-commit/mirrors-clang-format rev: v14.0.6 hooks: - id: clang-format files: \.c(c|pp|xx)?$|\.h(pp)?$ - -# Linting -- repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - additional_dependencies: ['flake8-comprehensions==3.8.0'] diff --git a/pyproject.toml b/pyproject.toml index 5903259e3..2f5bf55a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.black] -include='\.pyi?$|/SConscript$|/libtbx_config$' +include = '\.pyi?$|/SConscript$|/libtbx_config$' [tool.towncrier] package = "dxtbx" @@ -7,12 +7,63 @@ package_dir = ".." filename = "CHANGELOG.rst" issue_format = "`#{issue} `_" -[tool.isort] -sections="FUTURE,STDLIB,THIRDPARTY,CCTBX,DIALS,FIRSTPARTY,LOCALFOLDER" -known_firstparty="dxtbx_*,dxtbx" -known_cctbx="boost,boost_adaptbx,cbflib_adaptbx,cctbx,chiltbx,clipper_adaptbx,cma_es,cootbx,crys3d,cudatbx,fable,fast_linalg,fftw3tbx,gltbx,iota,iotbx,libtbx,mmtbx,omptbx,prime,rstbx,scitbx,simtbx,smtbx,spotfinder,tbxx,ucif,wxtbx,xfel" -known_dials="dials" -profile="black" + +[tool.ruff.lint] +select = ["E", "F", "W", "C4", "I"] +unfixable = ["F841"] +# E501 line too long (handled by formatter) +# E741 Ambiguous variable name (We have lots of meaningful I, L, l) +ignore = ["E501", "E741"] + +[tool.ruff.lint.per-file-ignores] +"installer/**.py" = ["I"] +"**/__init__.py" = ["F401"] + +[tool.ruff.lint.isort] +known-first-party = ["dxtbx_*", "dxtbx"] +required-imports = ["from __future__ import annotations"] +section-order = [ + "future", + "standard-library", + "third-party", + "cctbx", + "first-party", + "local-folder", +] + +[tool.ruff.lint.isort.sections] +"cctbx" = [ + "boost", + "boost_adaptbx", + "cbflib_adaptbx", + "cctbx", + "chiltbx", + "clipper_adaptbx", + "cma_es", + "cootbx", + "crys3d", + "cudatbx", + "fable", + "fast_linalg", + "fftw3tbx", + "gltbx", + "iota", + "iotbx", + "libtbx", + "mmtbx", + "omptbx", + "prime", + "rstbx", + "scitbx", + "serialtbx", + "simtbx", + "smtbx", + "spotfinder", + "tbxx", + "ucif", + "wxtbx", + "xfel", +] [tool.mypy] no_implicit_optional = true diff --git a/setup.cfg b/setup.cfg index 3a93e3ec8..ae760f5f5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,20 +11,3 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 - -[flake8] -# Black disagrees with flake8 on a few points. Ignore those. -ignore = E203, E266, E501, W503 -# E203 whitespace before ':' -# E266 too many leading '#' for block comment -# E501 line too long -# W503 line break before binary operator - -max-line-length = 88 - -select = - E401,E711,E712,E713,E714,E721,E722,E901, - F401,F402,F403,F405,F541,F631,F632,F633,F811,F812,F821,F822,F841,F901, - W191,W291,W292,W293,W602,W603,W604,W605,W606, - # flake8-comprehensions, https://github.com/adamchainz/flake8-comprehensions - C4, From 9d475630b58f0b9424a69d02e9e016928dfe1e19 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 16:51:25 +0100 Subject: [PATCH 02/13] Run latest black formatting --- SConscript | 6 +++- .../PILATUS_300K_S_N_3_0104_Diamond.py | 6 ++-- src/dxtbx/example/resolution_corners.py | 1 - src/dxtbx/filecache.py | 1 - src/dxtbx/filecache_controller.py | 1 - src/dxtbx/format/FormatCBFCspad.py | 4 +-- src/dxtbx/format/FormatCBFFull.py | 1 - src/dxtbx/format/FormatCBFFullPilatus.py | 1 - src/dxtbx/format/FormatCBFMini.py | 1 - src/dxtbx/format/FormatCBFMiniADSCHF4M.py | 1 - src/dxtbx/format/FormatCBFMiniEiger.py | 1 - .../format/FormatCBFMiniEigerPetraP14.py | 1 - .../format/FormatCBFMiniEigerPhotonFactory.py | 1 - src/dxtbx/format/FormatCBFMiniPilatus.py | 1 - .../format/FormatCBFMiniPilatusDESY6MSN115.py | 1 - .../format/FormatCBFMiniPilatusDLS12M.py | 1 - .../format/FormatCBFMiniPilatusDLS6MSN100.py | 1 - .../FormatCBFMiniPilatusDLS6MSN114DMM.py | 1 - .../format/FormatCBFMiniPilatusDLS6MSN119.py | 1 - .../format/FormatCBFMiniPilatusDLS6MSN126.py | 1 - .../format/FormatCBFMiniPilatusHelpers.py | 1 - .../FormatCBFMiniPilatusSOLEILPX16MSN106.py | 1 - src/dxtbx/format/FormatCBFMiniPilatusXXX.py | 1 - src/dxtbx/format/FormatCBFMultiTile.py | 1 - src/dxtbx/format/FormatEDFALS733.py | 1 - src/dxtbx/format/FormatHDF5Lambda.py | 1 - src/dxtbx/format/FormatISISSXD.py | 2 -- src/dxtbx/format/FormatMANDI.py | 6 ---- src/dxtbx/format/FormatMRC.py | 1 - src/dxtbx/format/FormatMarIP.py | 1 - src/dxtbx/format/FormatNXmxED.py | 1 - src/dxtbx/format/FormatPY.py | 1 - src/dxtbx/format/FormatSER.py | 7 ++--- src/dxtbx/format/FormatSMV.py | 1 - src/dxtbx/format/FormatSMVADSC.py | 1 - src/dxtbx/format/FormatSMVADSCSN442.py | 1 - src/dxtbx/format/FormatSMVADSCSN445.py | 1 - src/dxtbx/format/FormatSMVADSCSN457.py | 1 - src/dxtbx/format/FormatSMVADSCSN905.py | 1 - src/dxtbx/format/FormatSMVCMOS1.py | 1 - src/dxtbx/format/FormatSMVJHSim.py | 1 - src/dxtbx/format/FormatSMVNOIR.py | 1 - src/dxtbx/format/FormatSMVTimePix_SU.py | 1 - src/dxtbx/format/FormatTIFF.py | 1 - src/dxtbx/format/FormatTIFFBruker.py | 1 - src/dxtbx/format/FormatTIFFRayonix.py | 1 - src/dxtbx/format/FormatTIFFRayonixXPP.py | 1 - src/dxtbx/format/FormatXDS.py | 1 - src/dxtbx/format/FormatXTCCspad.py | 8 +++-- src/dxtbx/format/Registry.py | 1 + src/dxtbx/format/TemplatePYCXI31.py | 1 - src/dxtbx/format/TemplatePYCXI32.py | 1 - src/dxtbx/format/TemplatePYCXI41.py | 1 - src/dxtbx/format/TemplatePYCXI51.py | 1 - src/dxtbx/format/TemplatePYCXI61.py | 1 - src/dxtbx/format/TemplatePYCXI71.py | 1 - src/dxtbx/format/TemplatePYCXI7d.py | 1 - src/dxtbx/format/cbf_writer.py | 17 +++++++---- src/dxtbx/model/__init__.py | 12 ++++---- src/dxtbx/model/detector.py | 2 +- src/dxtbx/model/detector_helpers.py | 2 -- src/dxtbx/model/scan.py | 2 -- src/dxtbx/model/tof_helpers.py | 2 -- src/dxtbx/nexus/__init__.py | 20 ++++++++----- tests/conftest.py | 12 ++++---- tests/nexus/test_build_dxtbx_models.py | 30 +++++++++---------- 66 files changed, 70 insertions(+), 118 deletions(-) diff --git a/SConscript b/SConscript index aaafe78f4..47c27e746 100644 --- a/SConscript +++ b/SConscript @@ -119,7 +119,11 @@ if not env_etc.no_boost_python and hasattr(env_etc, "boost_adaptbx_include"): env = env_no_includes_boost_python_ext.Clone() # Don't surface warnings from system or cctbx_project headers - system_includes = [x for x in env_etc.conda_cpppath if x] if libtbx.env.build_options.use_conda else [] + system_includes = ( + [x for x in env_etc.conda_cpppath if x] + if libtbx.env.build_options.use_conda + else [] + ) system_includes.append(str(Path(env_etc.scitbx_dist).parent)) env.Append(CXXFLAGS=[f"-isystem{x}" for x in system_includes]) env.Append(SHCXXFLAGS=[f"-isystem{x}" for x in system_includes]) diff --git a/src/dxtbx/data/beamline_defs/PILATUS_300K_S_N_3_0104_Diamond.py b/src/dxtbx/data/beamline_defs/PILATUS_300K_S_N_3_0104_Diamond.py index f7d9262c3..c488b2529 100644 --- a/src/dxtbx/data/beamline_defs/PILATUS_300K_S_N_3_0104_Diamond.py +++ b/src/dxtbx/data/beamline_defs/PILATUS_300K_S_N_3_0104_Diamond.py @@ -45,9 +45,9 @@ def _at_I19(self, mmcif=False): b[lookup("df.rad.mono")] = "Silicon 111" b[lookup("df.src.details")] = "Nowell et al. (2012)" b[lookup("df.src.type")] = "Diamond Light Source Beamline I19-2" - b[ - lookup("references") - ] = "Nowell, H. et al. (2012) J. Synchrotron Rad. 19, 435-441." + b[lookup("references")] = ( + "Nowell, H. et al. (2012) J. Synchrotron Rad. 19, 435-441." + ) b[lookup("sw.collection")] = "GDA - generic data acquisition software" return b diff --git a/src/dxtbx/example/resolution_corners.py b/src/dxtbx/example/resolution_corners.py index 230690fdd..7383d41ff 100644 --- a/src/dxtbx/example/resolution_corners.py +++ b/src/dxtbx/example/resolution_corners.py @@ -1,6 +1,5 @@ """Print out the resolution (two-theta) of the corners of the detector""" - from __future__ import annotations import math diff --git a/src/dxtbx/filecache.py b/src/dxtbx/filecache.py index 31714e3c7..0bb3e27c8 100644 --- a/src/dxtbx/filecache.py +++ b/src/dxtbx/filecache.py @@ -36,7 +36,6 @@ Any further access attempts will then result in an exception. """ - from __future__ import annotations import io diff --git a/src/dxtbx/filecache_controller.py b/src/dxtbx/filecache_controller.py index d975e967d..b55124a33 100644 --- a/src/dxtbx/filecache_controller.py +++ b/src/dxtbx/filecache_controller.py @@ -1,6 +1,5 @@ """A simple cache controller. Caching only one file at a time.""" - from __future__ import annotations import os diff --git a/src/dxtbx/format/FormatCBFCspad.py b/src/dxtbx/format/FormatCBFCspad.py index ee1dd5814..012ddc426 100644 --- a/src/dxtbx/format/FormatCBFCspad.py +++ b/src/dxtbx/format/FormatCBFCspad.py @@ -1,6 +1,5 @@ """Methods specific to interacting with CSPAD images""" - from __future__ import annotations import pycbf @@ -61,7 +60,8 @@ def _detector(self): def sync_detector_to_cbf(self, detector=None): """If the detector object has been changed, due to refinement or manual repositioning - in a gui, call this function to synchronize these changes to the underlying CBF handle""" + in a gui, call this function to synchronize these changes to the underlying CBF handle + """ def recursive_sync(cbf, group, cbf_detectors=None, root=False): """Walks the hierarchy and synchronizes the dxtbx matrices to the CBF axes.""" diff --git a/src/dxtbx/format/FormatCBFFull.py b/src/dxtbx/format/FormatCBFFull.py index b2666deff..d7fea13be 100644 --- a/src/dxtbx/format/FormatCBFFull.py +++ b/src/dxtbx/format/FormatCBFFull.py @@ -4,7 +4,6 @@ but will allow for extension for specific implementations of CBF. """ - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatCBFFullPilatus.py b/src/dxtbx/format/FormatCBFFullPilatus.py index 551a8cfe4..91a84f6b5 100644 --- a/src/dxtbx/format/FormatCBFFullPilatus.py +++ b/src/dxtbx/format/FormatCBFFullPilatus.py @@ -1,6 +1,5 @@ """Pilatus implementation of fullCBF format, for use with Dectris detectors.""" - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMini.py b/src/dxtbx/format/FormatCBFMini.py index 39060f84a..8e24f1808 100644 --- a/src/dxtbx/format/FormatCBFMini.py +++ b/src/dxtbx/format/FormatCBFMini.py @@ -4,7 +4,6 @@ pairs. """ - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMiniADSCHF4M.py b/src/dxtbx/format/FormatCBFMiniADSCHF4M.py index 9fbe07337..57ddac48b 100644 --- a/src/dxtbx/format/FormatCBFMiniADSCHF4M.py +++ b/src/dxtbx/format/FormatCBFMiniADSCHF4M.py @@ -4,7 +4,6 @@ Located in dxtbx/format """ - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMiniEiger.py b/src/dxtbx/format/FormatCBFMiniEiger.py index 648b3ac6c..fd20b2638 100644 --- a/src/dxtbx/format/FormatCBFMiniEiger.py +++ b/src/dxtbx/format/FormatCBFMiniEiger.py @@ -1,6 +1,5 @@ """An implementation of the CBF image reader for Eiger images""" - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py b/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py index 36b5cce91..9b3e401a8 100644 --- a/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py +++ b/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py @@ -1,6 +1,5 @@ """An implementation of the CBF image reader for Eiger images""" - from __future__ import annotations import datetime diff --git a/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py b/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py index 5a972c28b..df729e46f 100644 --- a/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py +++ b/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py @@ -1,6 +1,5 @@ """An implementation of the CBF image reader for Eiger images""" - from __future__ import annotations import os diff --git a/src/dxtbx/format/FormatCBFMiniPilatus.py b/src/dxtbx/format/FormatCBFMiniPilatus.py index 7fd832923..f3fe5b49f 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatus.py +++ b/src/dxtbx/format/FormatCBFMiniPilatus.py @@ -1,6 +1,5 @@ """An implementation of the CBF image reader for Pilatus images""" - from __future__ import annotations import os diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDESY6MSN115.py b/src/dxtbx/format/FormatCBFMiniPilatusDESY6MSN115.py index 63cc524b0..553d7d0cf 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDESY6MSN115.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDESY6MSN115.py @@ -3,7 +3,6 @@ detector at PETRA III beamline P14, which has a vertical goniometer. """ - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py b/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py index a64b551b8..38066e47f 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py @@ -1,6 +1,5 @@ """An implementation of the CBF image reader for Pilatus images, for the P12M-DLS""" - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN100.py b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN100.py index 7108c9a8e..1b02746b8 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN100.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN100.py @@ -3,7 +3,6 @@ 6M SN 100 currently on Diamond I04. """ - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN114DMM.py b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN114DMM.py index 5c73d7cfd..c8fa13f53 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN114DMM.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN114DMM.py @@ -3,7 +3,6 @@ 6M SN 100 currently on Diamond I04. """ - from __future__ import annotations import os diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN119.py b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN119.py index 390bafd22..12b949b4e 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN119.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN119.py @@ -3,7 +3,6 @@ 6M SN 119 currently on Diamond I24. """ - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN126.py b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN126.py index e5c916e42..9b30592fc 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN126.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDLS6MSN126.py @@ -3,7 +3,6 @@ 6M SN 100 currently on Diamond I03. """ - from __future__ import annotations import binascii diff --git a/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py b/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py index c5cec3f4d..3d68bfcab 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py @@ -1,6 +1,5 @@ """Helpers for FormatCBFMiniPilatus...""" - from __future__ import annotations import calendar diff --git a/src/dxtbx/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py b/src/dxtbx/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py index e1a41528c..935847796 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusSOLEILPX16MSN106.py @@ -1,6 +1,5 @@ """Set up for Soleil PX1, with full kappa goniometer""" - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatCBFMiniPilatusXXX.py b/src/dxtbx/format/FormatCBFMiniPilatusXXX.py index 1fb64ee5a..42382bb7a 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusXXX.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusXXX.py @@ -3,7 +3,6 @@ 6M SN 100 currently on Diamond I04. """ - from __future__ import annotations from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus diff --git a/src/dxtbx/format/FormatCBFMultiTile.py b/src/dxtbx/format/FormatCBFMultiTile.py index 89dfe26c2..91e519532 100644 --- a/src/dxtbx/format/FormatCBFMultiTile.py +++ b/src/dxtbx/format/FormatCBFMultiTile.py @@ -1,6 +1,5 @@ """Reads a multi-tile CBF image, discovering its detector geometry automatically""" - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatEDFALS733.py b/src/dxtbx/format/FormatEDFALS733.py index 6c405f0e8..93b119c2b 100644 --- a/src/dxtbx/format/FormatEDFALS733.py +++ b/src/dxtbx/format/FormatEDFALS733.py @@ -1,6 +1,5 @@ """Implementation of an ImageFormat class to read MarIP-format image""" - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatHDF5Lambda.py b/src/dxtbx/format/FormatHDF5Lambda.py index d7f1f8226..b536fc2d9 100644 --- a/src/dxtbx/format/FormatHDF5Lambda.py +++ b/src/dxtbx/format/FormatHDF5Lambda.py @@ -3,7 +3,6 @@ http://www.x-spectrum.de/ """ - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatISISSXD.py b/src/dxtbx/format/FormatISISSXD.py index 9d5889c67..aea0d7166 100644 --- a/src/dxtbx/format/FormatISISSXD.py +++ b/src/dxtbx/format/FormatISISSXD.py @@ -15,7 +15,6 @@ class FormatISISSXD(FormatHDF5): - """ Class to read image files from ISIS SXD (https://www.isis.stfc.ac.uk/Pages/sxd.aspx) @@ -195,7 +194,6 @@ def _get_panel_fast_axes(self) -> Tuple[Tuple[float, float, float]]: ) def _get_panel_projections_2d(self) -> dict: - """ Returns a projection of the detector flattened around the bottom panel (11) diff --git a/src/dxtbx/format/FormatMANDI.py b/src/dxtbx/format/FormatMANDI.py index a928e9de4..cfb7f62af 100644 --- a/src/dxtbx/format/FormatMANDI.py +++ b/src/dxtbx/format/FormatMANDI.py @@ -20,7 +20,6 @@ class FormatMANDI(FormatHDF5): - """ Class to read NXTOFRAW from MaNDi (https://neutrons.ornl.gov/mandi) @@ -404,7 +403,6 @@ def write_histogram_data( write_tof_bins: bool = True, nproc: int = 8, ) -> None: - """ Generates histogram spectra for a given detector and writes it to nxs_file """ @@ -460,7 +458,6 @@ def generate_histogram_data_for_panel( panel_name: str, nproc=8, ) -> np.array: - """ Generates histogram data for a given panel """ @@ -503,7 +500,6 @@ def generate_histogram_data_for_panel( def get_time_range_for_panel( nxs_file: h5py.File, panel_size: Tuple[float, float], panel_name: str ) -> Tuple[float, float]: - """ Returns the range of event times for a given panel """ @@ -542,7 +538,6 @@ def event_data_is_valid(event_id, event_time_offset): def get_time_range_for_dataset( nxs_file_path: str, panel_size: Tuple[int, int] ) -> Tuple[float, float]: - """ Iterates over num_panels to find the overall min/max tof event recorded """ @@ -583,7 +578,6 @@ def generate_tof_bins( delta_tof: float = 50, padding: float = 100, ) -> np.ndarray: - """ delta_tof: float (usec) padding: float (usec) diff --git a/src/dxtbx/format/FormatMRC.py b/src/dxtbx/format/FormatMRC.py index ef47c8a3c..52005b236 100644 --- a/src/dxtbx/format/FormatMRC.py +++ b/src/dxtbx/format/FormatMRC.py @@ -2,7 +2,6 @@ standard used in electron microscopy (http://www.ccpem.ac.uk/mrc_format/mrc2014.php)""" - from __future__ import annotations import logging diff --git a/src/dxtbx/format/FormatMarIP.py b/src/dxtbx/format/FormatMarIP.py index fd908a37e..191a7949a 100644 --- a/src/dxtbx/format/FormatMarIP.py +++ b/src/dxtbx/format/FormatMarIP.py @@ -1,6 +1,5 @@ """An ImageFormat class to read MarIP-format image""" - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatNXmxED.py b/src/dxtbx/format/FormatNXmxED.py index ad70a20c8..05309ea98 100644 --- a/src/dxtbx/format/FormatNXmxED.py +++ b/src/dxtbx/format/FormatNXmxED.py @@ -72,7 +72,6 @@ def _beam(self, index=None): class FormatNXmxEDeBIC(FormatNXmxED): - """Set a mask specific for the SINGLA installed at eBIC""" @staticmethod diff --git a/src/dxtbx/format/FormatPY.py b/src/dxtbx/format/FormatPY.py index 5117f6426..63936e291 100644 --- a/src/dxtbx/format/FormatPY.py +++ b/src/dxtbx/format/FormatPY.py @@ -1,6 +1,5 @@ """Implementation of a base class to read a pickled Python dictionary.""" - from __future__ import annotations import pickle diff --git a/src/dxtbx/format/FormatSER.py b/src/dxtbx/format/FormatSER.py index 7265323b6..0ea102d67 100644 --- a/src/dxtbx/format/FormatSER.py +++ b/src/dxtbx/format/FormatSER.py @@ -3,7 +3,6 @@ https://personal.ntu.edu.sg/cbb/info/TIAformat/index.html """ - from __future__ import annotations import os @@ -123,9 +122,9 @@ def read_emi(filename): grp = root.find("ExperimentalDescription/Root") for elem in grp: - _emi[ - "{} [{}]".format(elem.findtext("Label"), elem.findtext("Unit")) - ] = _parseEntry_emi(elem.findtext("Value")) + _emi["{} [{}]".format(elem.findtext("Label"), elem.findtext("Unit"))] = ( + _parseEntry_emi(elem.findtext("Value")) + ) # AcquireInfo grp = root.find("AcquireInfo") diff --git a/src/dxtbx/format/FormatSMV.py b/src/dxtbx/format/FormatSMV.py index 46183b2e8..4f2107ff3 100644 --- a/src/dxtbx/format/FormatSMV.py +++ b/src/dxtbx/format/FormatSMV.py @@ -8,7 +8,6 @@ representations. """ - from __future__ import annotations from boost_adaptbx.boost.python import streambuf diff --git a/src/dxtbx/format/FormatSMVADSC.py b/src/dxtbx/format/FormatSMVADSC.py index 05e45ce76..e56b8e9cb 100644 --- a/src/dxtbx/format/FormatSMVADSC.py +++ b/src/dxtbx/format/FormatSMVADSC.py @@ -1,6 +1,5 @@ """An implementation of the SMV image reader for ADSC images""" - from __future__ import annotations import calendar diff --git a/src/dxtbx/format/FormatSMVADSCSN442.py b/src/dxtbx/format/FormatSMVADSCSN442.py index 64907d97e..01f72811b 100644 --- a/src/dxtbx/format/FormatSMVADSCSN442.py +++ b/src/dxtbx/format/FormatSMVADSCSN442.py @@ -4,7 +4,6 @@ day which had its own way of recording beam centre. """ - from __future__ import annotations import dateutil.parser diff --git a/src/dxtbx/format/FormatSMVADSCSN445.py b/src/dxtbx/format/FormatSMVADSCSN445.py index 8afa660dc..965eae884 100644 --- a/src/dxtbx/format/FormatSMVADSCSN445.py +++ b/src/dxtbx/format/FormatSMVADSCSN445.py @@ -4,7 +4,6 @@ day which had its own way of recording beam centre. """ - from __future__ import annotations from dxtbx.format.FormatSMVADSCSN import FormatSMVADSCSN diff --git a/src/dxtbx/format/FormatSMVADSCSN457.py b/src/dxtbx/format/FormatSMVADSCSN457.py index 869209cda..84af82afa 100644 --- a/src/dxtbx/format/FormatSMVADSCSN457.py +++ b/src/dxtbx/format/FormatSMVADSCSN457.py @@ -4,7 +4,6 @@ which has reversed phi. """ - from __future__ import annotations from dxtbx.format.FormatSMVADSCSN import FormatSMVADSCSN diff --git a/src/dxtbx/format/FormatSMVADSCSN905.py b/src/dxtbx/format/FormatSMVADSCSN905.py index 5d43ab0f5..382443fc3 100644 --- a/src/dxtbx/format/FormatSMVADSCSN905.py +++ b/src/dxtbx/format/FormatSMVADSCSN905.py @@ -4,7 +4,6 @@ day which had its own way of recording beam centre. """ - from __future__ import annotations from dxtbx.format.FormatSMVADSCSN import FormatSMVADSCSN diff --git a/src/dxtbx/format/FormatSMVCMOS1.py b/src/dxtbx/format/FormatSMVCMOS1.py index 54ee44657..70d2c91f3 100644 --- a/src/dxtbx/format/FormatSMVCMOS1.py +++ b/src/dxtbx/format/FormatSMVCMOS1.py @@ -1,6 +1,5 @@ """An implementation of the SMV image reader for CMOS1 images, from ALS 4.2.2""" - from __future__ import annotations import calendar diff --git a/src/dxtbx/format/FormatSMVJHSim.py b/src/dxtbx/format/FormatSMVJHSim.py index 00a3c6213..512e3079a 100644 --- a/src/dxtbx/format/FormatSMVJHSim.py +++ b/src/dxtbx/format/FormatSMVJHSim.py @@ -1,6 +1,5 @@ """An implementation of the SMV image reader for JHSim images.""" - from __future__ import annotations import calendar diff --git a/src/dxtbx/format/FormatSMVNOIR.py b/src/dxtbx/format/FormatSMVNOIR.py index d9c4a072f..9517dfd16 100644 --- a/src/dxtbx/format/FormatSMVNOIR.py +++ b/src/dxtbx/format/FormatSMVNOIR.py @@ -3,7 +3,6 @@ Inherits from FormatSMVRigaku. """ - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatSMVTimePix_SU.py b/src/dxtbx/format/FormatSMVTimePix_SU.py index 054280010..b557ca86b 100644 --- a/src/dxtbx/format/FormatSMVTimePix_SU.py +++ b/src/dxtbx/format/FormatSMVTimePix_SU.py @@ -1,7 +1,6 @@ """Format classes to specifically recognise images from an electron detector with a 2x2 array of Timepix modules, converted to SMV in various ways.""" - from __future__ import annotations import calendar diff --git a/src/dxtbx/format/FormatTIFF.py b/src/dxtbx/format/FormatTIFF.py index 1ce37a07b..4b2dd4a6a 100644 --- a/src/dxtbx/format/FormatTIFF.py +++ b/src/dxtbx/format/FormatTIFF.py @@ -6,7 +6,6 @@ and generate the experimental model representations. """ - from __future__ import annotations from dxtbx import IncorrectFormatError diff --git a/src/dxtbx/format/FormatTIFFBruker.py b/src/dxtbx/format/FormatTIFFBruker.py index 7929e27f7..d045089bd 100644 --- a/src/dxtbx/format/FormatTIFFBruker.py +++ b/src/dxtbx/format/FormatTIFFBruker.py @@ -1,6 +1,5 @@ """An implementation of the TIFF image reader for Bruker images""" - from __future__ import annotations import datetime diff --git a/src/dxtbx/format/FormatTIFFRayonix.py b/src/dxtbx/format/FormatTIFFRayonix.py index 00af76ca0..d1ce6422d 100644 --- a/src/dxtbx/format/FormatTIFFRayonix.py +++ b/src/dxtbx/format/FormatTIFFRayonix.py @@ -1,6 +1,5 @@ """An implementation of the TIFF image reader for Rayonix images.""" - from __future__ import annotations import datetime diff --git a/src/dxtbx/format/FormatTIFFRayonixXPP.py b/src/dxtbx/format/FormatTIFFRayonixXPP.py index 5a3977299..f54a7af61 100644 --- a/src/dxtbx/format/FormatTIFFRayonixXPP.py +++ b/src/dxtbx/format/FormatTIFFRayonixXPP.py @@ -6,7 +6,6 @@ least viewed. """ - from __future__ import annotations import re diff --git a/src/dxtbx/format/FormatXDS.py b/src/dxtbx/format/FormatXDS.py index 9e4bf375b..75f6a0179 100644 --- a/src/dxtbx/format/FormatXDS.py +++ b/src/dxtbx/format/FormatXDS.py @@ -1,6 +1,5 @@ """Format object for XDS files""" - from __future__ import annotations import sys diff --git a/src/dxtbx/format/FormatXTCCspad.py b/src/dxtbx/format/FormatXTCCspad.py index 586d393a1..a69a987bf 100644 --- a/src/dxtbx/format/FormatXTCCspad.py +++ b/src/dxtbx/format/FormatXTCCspad.py @@ -90,9 +90,11 @@ def get_raw_data(self, index=None): det, event, use_default=self.params.cspad.use_psana_calib, - dark=self._pedestals[run_number] - if self.params.cspad.dark_correction - else False, + dark=( + self._pedestals[run_number] + if self.params.cspad.dark_correction + else False + ), common_mode=self.params.cspad.common_mode, apply_gain_mask=self.params.cspad.apply_gain_mask, gain_mask_value=None, diff --git a/src/dxtbx/format/Registry.py b/src/dxtbx/format/Registry.py index cebcac37b..2a0e2cc0f 100644 --- a/src/dxtbx/format/Registry.py +++ b/src/dxtbx/format/Registry.py @@ -3,6 +3,7 @@ this is useful for i.e. identifying the best tool to read a given range of image formats. """ + from __future__ import annotations import importlib.metadata diff --git a/src/dxtbx/format/TemplatePYCXI31.py b/src/dxtbx/format/TemplatePYCXI31.py index 474b65cf8..9d0cc041a 100644 --- a/src/dxtbx/format/TemplatePYCXI31.py +++ b/src/dxtbx/format/TemplatePYCXI31.py @@ -6,7 +6,6 @@ class FormatPYCXI31(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 3.1. diff --git a/src/dxtbx/format/TemplatePYCXI32.py b/src/dxtbx/format/TemplatePYCXI32.py index cfc6e0ab2..9cbd18ad2 100644 --- a/src/dxtbx/format/TemplatePYCXI32.py +++ b/src/dxtbx/format/TemplatePYCXI32.py @@ -6,7 +6,6 @@ class FormatPYCXI32(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 3.2. diff --git a/src/dxtbx/format/TemplatePYCXI41.py b/src/dxtbx/format/TemplatePYCXI41.py index fda88e8fc..67787f09c 100644 --- a/src/dxtbx/format/TemplatePYCXI41.py +++ b/src/dxtbx/format/TemplatePYCXI41.py @@ -6,7 +6,6 @@ class FormatPYCXI41(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 4.1. diff --git a/src/dxtbx/format/TemplatePYCXI51.py b/src/dxtbx/format/TemplatePYCXI51.py index b1ad424b1..01973f476 100644 --- a/src/dxtbx/format/TemplatePYCXI51.py +++ b/src/dxtbx/format/TemplatePYCXI51.py @@ -6,7 +6,6 @@ class FormatPYCXI51(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 5.1. diff --git a/src/dxtbx/format/TemplatePYCXI61.py b/src/dxtbx/format/TemplatePYCXI61.py index 7ee2848cd..406002dd9 100644 --- a/src/dxtbx/format/TemplatePYCXI61.py +++ b/src/dxtbx/format/TemplatePYCXI61.py @@ -6,7 +6,6 @@ class FormatPYCXI61(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 6.1. diff --git a/src/dxtbx/format/TemplatePYCXI71.py b/src/dxtbx/format/TemplatePYCXI71.py index f0dd21ccd..4af0326d8 100644 --- a/src/dxtbx/format/TemplatePYCXI71.py +++ b/src/dxtbx/format/TemplatePYCXI71.py @@ -6,7 +6,6 @@ class FormatPYCXI71(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 7.1. diff --git a/src/dxtbx/format/TemplatePYCXI7d.py b/src/dxtbx/format/TemplatePYCXI7d.py index 9c329b673..e51b954d6 100644 --- a/src/dxtbx/format/TemplatePYCXI7d.py +++ b/src/dxtbx/format/TemplatePYCXI7d.py @@ -6,7 +6,6 @@ class FormatPYCXI7d(FormatPYunspecified): - """PREFERENCE FILE. Treats any Pickle-format file lacking a DETECTOR_FORMAT_VERSION key automatically as format CXI 7.d. diff --git a/src/dxtbx/format/cbf_writer.py b/src/dxtbx/format/cbf_writer.py index d200facd3..87fc964a7 100644 --- a/src/dxtbx/format/cbf_writer.py +++ b/src/dxtbx/format/cbf_writer.py @@ -34,7 +34,8 @@ def add_frame_specific_cbf_tables( """Adds tables to cbf handle that won't already exsist if the cbf file is just a header @ param wavelength Wavelength in angstroms @ param timestamp String formatted timestamp for the image - @ param trusted_ranges Array of trusted range tuples (min, max), one for each element""" + @ param trusted_ranges Array of trusted range tuples (min, max), one for each element + """ """Data items in the DIFFRN_RADIATION category describe the radiation used for measuring diffraction intensities, @@ -70,11 +71,15 @@ def add_frame_specific_cbf_tables( diffrn_id, "INJECTION" if is_xfel else "unknown", "0", - "electrospray" - if is_xfel - else "unknown" "crystals injected by electrospray" - if is_xfel - else "unknown", + ( + "electrospray" + if is_xfel + else ( + "unknown" "crystals injected by electrospray" + if is_xfel + else "unknown" + ) + ), ] ) diff --git a/src/dxtbx/model/__init__.py b/src/dxtbx/model/__init__.py index d1e5e384b..c23bf5747 100644 --- a/src/dxtbx/model/__init__.py +++ b/src/dxtbx/model/__init__.py @@ -340,12 +340,12 @@ def to_dict(self): recalculated_unit_cell = self.get_recalculated_unit_cell() if recalculated_unit_cell is not None: xl_dict["recalculated_unit_cell"] = recalculated_unit_cell.parameters() - xl_dict[ - "recalculated_cell_parameter_sd" - ] = self.get_recalculated_cell_parameter_sd() - xl_dict[ - "recalculated_cell_volume_sd" - ] = self.get_recalculated_cell_volume_sd() + xl_dict["recalculated_cell_parameter_sd"] = ( + self.get_recalculated_cell_parameter_sd() + ) + xl_dict["recalculated_cell_volume_sd"] = ( + self.get_recalculated_cell_volume_sd() + ) return xl_dict diff --git a/src/dxtbx/model/detector.py b/src/dxtbx/model/detector.py index c046ca8d9..6c0bb564a 100644 --- a/src/dxtbx/model/detector.py +++ b/src/dxtbx/model/detector.py @@ -216,7 +216,7 @@ def merge_panel_scope_extracts_by_id(panel_params): id_to_params = {} - for (i, params) in enumerate(panel_params): + for i, params in enumerate(panel_params): if params.id not in id_to_params: id_to_params[params.id] = [ i, diff --git a/src/dxtbx/model/detector_helpers.py b/src/dxtbx/model/detector_helpers.py index 5810638d7..d768b72ec 100644 --- a/src/dxtbx/model/detector_helpers.py +++ b/src/dxtbx/model/detector_helpers.py @@ -333,7 +333,6 @@ def set_detector_distance(detector, distance): def get_detector_projection_2d_axes( detector: Detector, ) -> tuple[list[Float2], list[Float2], list[Float2]]: - """ Project panel origins, fast and slow axes onto the best-fitting 2D plane. """ @@ -452,7 +451,6 @@ def get_panel_projection_2d_from_axes( slow_axis_2d: matrix.col, origin_2d: matrix.col, ) -> tuple[Float4, Float2]: - """ Gets translation and rotation required to project image_data from panel, based on axes given. diff --git a/src/dxtbx/model/scan.py b/src/dxtbx/model/scan.py index e63f2b025..0718d269a 100644 --- a/src/dxtbx/model/scan.py +++ b/src/dxtbx/model/scan.py @@ -114,7 +114,6 @@ def from_dict(d, t=None): """ def add_properties_table(scan_dict, num_images): - """ Handles legacy case before Scan had a properties table. Moves oscillation, epochs, and exposure times to a properties @@ -146,7 +145,6 @@ def add_properties_table(scan_dict, num_images): return scan_dict def make_properties_table_consistent(properties, num_images): - """ Handles legacy case before Scan had a properties table. Ensures oscillation, epochs, and exposure times have the same length. diff --git a/src/dxtbx/model/tof_helpers.py b/src/dxtbx/model/tof_helpers.py index 5a7e03e79..0941f6b92 100644 --- a/src/dxtbx/model/tof_helpers.py +++ b/src/dxtbx/model/tof_helpers.py @@ -34,7 +34,6 @@ def tof_from_wavelength( def frame_to_tof_interpolator(frames: List[float], tof: List[float]) -> interp1d: - """ ToF can vary nonlinearly with frame number. A cubic spline is used to better account for these cases. @@ -48,7 +47,6 @@ def frame_to_tof_interpolator(frames: List[float], tof: List[float]) -> interp1d def tof_to_frame_interpolator(tof: List[float], frames: List[float]) -> interp1d: - """ ToF can vary nonlinearly with frame number. A cubic spline is used to better account for these cases. diff --git a/src/dxtbx/nexus/__init__.py b/src/dxtbx/nexus/__init__.py index 10f3cb736..e0fb8717b 100644 --- a/src/dxtbx/nexus/__init__.py +++ b/src/dxtbx/nexus/__init__.py @@ -346,10 +346,12 @@ def equipment_component_key(dependency): origin = MCSTAS_TO_IMGCIF @ ( module.fast_pixel_direction.offset.to("mm").magnitude if module.fast_pixel_direction.offset is not None - else np.array([0.0, 0.0, 0.0]) - + module.slow_pixel_direction.offset.to("mm").magnitude - if module.slow_pixel_direction.offset is not None - else np.array([0.0, 0.0, 0.0]) + else ( + np.array([0.0, 0.0, 0.0]) + + module.slow_pixel_direction.offset.to("mm").magnitude + if module.slow_pixel_direction.offset is not None + else np.array([0.0, 0.0, 0.0]) + ) ) else: # Flat detector model @@ -395,10 +397,12 @@ def equipment_component_key(dependency): ( module.fast_pixel_direction.offset.to("mm").magnitude if module.fast_pixel_direction.offset is not None - else np.array([0.0, 0.0, 0.0]) - + module.slow_pixel_direction.offset.to("mm").magnitude - if module.slow_pixel_direction.offset is not None - else np.array([0.0, 0.0, 0.0]) + else ( + np.array([0.0, 0.0, 0.0]) + + module.slow_pixel_direction.offset.to("mm").magnitude + if module.slow_pixel_direction.offset is not None + else np.array([0.0, 0.0, 0.0]) + ) ) + A[0, :3, 3] ) diff --git a/tests/conftest.py b/tests/conftest.py index 84d2b795f..cc1761ff3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -78,9 +78,9 @@ def nxmx_example(): "fast_pixel_direction", data=7.5e-5 ) fast_pixel_direction.attrs["transformation_type"] = "translation" - fast_pixel_direction.attrs[ - "depends_on" - ] = "/entry/instrument/detector/module/module_offset" + fast_pixel_direction.attrs["depends_on"] = ( + "/entry/instrument/detector/module/module_offset" + ) fast_pixel_direction.attrs["vector"] = np.array([-1.0, 0.0, 0.0]) fast_pixel_direction.attrs["offset"] = np.array([0.0, 0.0, 0.0]) fast_pixel_direction.attrs["offset_units"] = b"m" @@ -90,9 +90,9 @@ def nxmx_example(): "slow_pixel_direction", data=7.5e-5 ) slow_pixel_direction.attrs["transformation_type"] = "translation" - slow_pixel_direction.attrs[ - "depends_on" - ] = "/entry/instrument/detector/module/module_offset" + slow_pixel_direction.attrs["depends_on"] = ( + "/entry/instrument/detector/module/module_offset" + ) slow_pixel_direction.attrs["vector"] = np.array([0.0, -1.0, 0.0]) slow_pixel_direction.attrs["offset"] = np.array([0.0, 0.0, 0.0]) slow_pixel_direction.attrs["offset_units"] = b"m" diff --git a/tests/nexus/test_build_dxtbx_models.py b/tests/nexus/test_build_dxtbx_models.py index 82c33ca86..c310d9569 100644 --- a/tests/nexus/test_build_dxtbx_models.py +++ b/tests/nexus/test_build_dxtbx_models.py @@ -295,9 +295,9 @@ def test_get_dxtbx_detector(nxmx_example): def test_get_dxtbx_detector_beam_center_fallback(nxmx_example): - nxmx_example["/entry/instrument/detector/module/module_offset"].attrs[ - "offset" - ] = np.array((0, 0, 0)) + nxmx_example["/entry/instrument/detector/module/module_offset"].attrs["offset"] = ( + np.array((0, 0, 0)) + ) instrument = nxmx.NXmx(nxmx_example).entries[0].instruments[0] wavelength = instrument.beams[0].incident_wavelength.to("angstrom").magnitude detector = dxtbx.nexus.get_dxtbx_detector(instrument.detectors[0], wavelength) @@ -431,9 +431,9 @@ def detector_with_two_theta(): "fast_pixel_direction", data=7.5e-5 ) fast_pixel_direction.attrs["transformation_type"] = "translation" - fast_pixel_direction.attrs[ - "depends_on" - ] = "/entry/instrument/detector/module/module_offset" + fast_pixel_direction.attrs["depends_on"] = ( + "/entry/instrument/detector/module/module_offset" + ) fast_pixel_direction.attrs["vector"] = np.array([-1.0, 0.0, 0.0]) fast_pixel_direction.attrs["units"] = "m" @@ -441,25 +441,25 @@ def detector_with_two_theta(): "slow_pixel_direction", data=7.5e-5 ) slow_pixel_direction.attrs["transformation_type"] = "translation" - slow_pixel_direction.attrs[ - "depends_on" - ] = "/entry/instrument/detector/module/module_offset" + slow_pixel_direction.attrs["depends_on"] = ( + "/entry/instrument/detector/module/module_offset" + ) slow_pixel_direction.attrs["vector"] = np.array([0, -1.0, 0.0]) slow_pixel_direction.attrs["units"] = "m" module_offset = module.create_dataset("module_offset", data=112.19250476301882) module_offset.attrs["transformation_type"] = "translation" - module_offset.attrs[ - "depends_on" - ] = "/entry/instrument/detector/transformations/det_z" + module_offset.attrs["depends_on"] = ( + "/entry/instrument/detector/transformations/det_z" + ) module_offset.attrs["vector"] = np.array([0.72264186, 0.69122265, 0.0]) module_offset.attrs["units"] = b"mm" transformations = detector.create_group("transformations") det_z = transformations.create_dataset("det_z", data=120.0) - det_z.attrs[ - "depends_on" - ] = b"/entry/instrument/detector/transformations/two_theta" + det_z.attrs["depends_on"] = ( + b"/entry/instrument/detector/transformations/two_theta" + ) det_z.attrs["transformation_type"] = b"translation" det_z.attrs["units"] = b"mm" det_z.attrs["vector"] = np.array([0.0, 0.0, 1.0]) From 9a1b6f9f115b7a1fa0bb9f4446fe3678107ab939 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 16:54:11 +0100 Subject: [PATCH 03/13] Fix visibly --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 605e444cf..55a1b5f0b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: rev: v0.3.4 hooks: - id: ruff - args: [--fix, --exit-non-zero-on-fix] + args: [--fix, --exit-non-zero-on-fix, --show-fixes] - id: ruff-format files: \.pyi?$|SConscript$|^libtbx_config$ types: [file] From 997d8aabd3abdab954e1256c0c0ddb4047497ad5 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 16:54:42 +0100 Subject: [PATCH 04/13] Run ruff format --- .azure-pipelines/bootstrap.py | 4 +--- src/dxtbx/command_line/detector_superpose.py | 7 +++--- .../command_line/plot_detector_models.py | 2 -- src/dxtbx/command_line/read_sequence.py | 1 - src/dxtbx/dxtbx_imageset_ext.pyi | 2 -- src/dxtbx/example/to_xds.py | 2 -- src/dxtbx/format/Format.py | 3 --- src/dxtbx/format/FormatBruker.py | 1 - src/dxtbx/format/FormatBrukerED1.py | 3 --- src/dxtbx/format/FormatBrukerFixedChi.py | 2 -- src/dxtbx/format/FormatBrukerPhoton.py | 3 --- src/dxtbx/format/FormatCBFMiniADSCHF4M.py | 3 --- .../format/FormatCBFMiniEigerPhotonFactory.py | 2 -- .../format/FormatCBFMiniEigerQuadroED1.py | 1 - .../format/FormatCBFMiniPilatusDLS12M.py | 1 - .../format/FormatCBFMiniPilatusHelpers.py | 1 - .../format/FormatCBFMultiTileHierarchy.py | 4 +++- src/dxtbx/format/FormatGatanDM4.py | 7 ------ src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py | 1 - src/dxtbx/format/FormatHDF5SaclaMPCCD.py | 1 - src/dxtbx/format/FormatISISSXD.py | 2 -- src/dxtbx/format/FormatMANDI.py | 5 +--- src/dxtbx/format/FormatMRC.py | 3 --- src/dxtbx/format/FormatMultiImage.py | 3 --- src/dxtbx/format/FormatMultiImageLazy.py | 1 - src/dxtbx/format/FormatNXmxDLS.py | 1 - src/dxtbx/format/FormatNexus.py | 2 -- src/dxtbx/format/FormatNexusJungfrauHack.py | 1 - src/dxtbx/format/FormatPYunspecified.py | 2 -- src/dxtbx/format/FormatROD.py | 13 +++-------- src/dxtbx/format/FormatSER.py | 3 --- src/dxtbx/format/FormatSMVADSCNoDateStamp.py | 1 - src/dxtbx/format/FormatSMVADSCSN.py | 1 - src/dxtbx/format/FormatSMVHamamatsu.py | 1 - .../format/FormatSMVHamamatsuSPring8BL32XU.py | 2 -- src/dxtbx/format/FormatSMVTimePix_SU.py | 3 --- src/dxtbx/format/FormatTIFFRayonixESRF.py | 7 ++++-- src/dxtbx/format/FormatXTCJungfrau.py | 1 - src/dxtbx/format/TemplatePYCXI31.py | 1 - src/dxtbx/format/TemplatePYCXI32.py | 1 - src/dxtbx/format/TemplatePYCXI41.py | 1 - src/dxtbx/format/TemplatePYCXI51.py | 1 - src/dxtbx/format/TemplatePYCXI61.py | 1 - src/dxtbx/format/TemplatePYCXI71.py | 1 - src/dxtbx/format/TemplatePYCXI7d.py | 1 - src/dxtbx/format/cbf_writer.py | 6 ++--- src/dxtbx/format/nexus.py | 19 ++++++++------- src/dxtbx/format/nxmx_writer.py | 23 ++++++++++--------- src/dxtbx/imageset.py | 1 - src/dxtbx/model/detector.py | 1 - src/dxtbx/model/experiment_list.py | 1 - src/dxtbx/model/scan.py | 1 - src/dxtbx/model/scan_helpers.py | 1 - src/dxtbx/nexus/__init__.py | 1 - src/dxtbx/serialize/xds.py | 2 -- tests/model/crystal_model_old.py | 5 ---- tests/model/test_beam.py | 1 - tests/model/test_crystal_model.py | 1 - tests/model/test_detector.py | 4 ---- tests/model/test_detector2.py | 4 +++- tests/model/test_experiment_list.py | 1 - tests/model/test_ray_intersection.py | 1 - tests/model/test_scan.py | 4 ---- tests/model/test_scan_data.py | 1 - tests/model/test_scan_helpers.py | 2 -- tests/model/test_spectrum.py | 1 - tests/nexus/test_build_dxtbx_models.py | 2 -- tests/serialize/test_serialize.py | 1 - tests/serialize/test_xds.py | 4 +--- tests/test_imageset.py | 1 - 70 files changed, 46 insertions(+), 153 deletions(-) diff --git a/.azure-pipelines/bootstrap.py b/.azure-pipelines/bootstrap.py index 46878a35b..661e3b25d 100644 --- a/.azure-pipelines/bootstrap.py +++ b/.azure-pipelines/bootstrap.py @@ -122,9 +122,7 @@ def install_micromamba(python): There was a failure in constructing the conda environment. Attempt {retry} of 5 will start {retry} minute(s) from {t}. ******************************************************************************* -""".format( - retry=retry, t=time.asctime() - ) +""".format(retry=retry, t=time.asctime()) ) time.sleep(retry * 60) else: diff --git a/src/dxtbx/command_line/detector_superpose.py b/src/dxtbx/command_line/detector_superpose.py index b67273910..67eee579c 100644 --- a/src/dxtbx/command_line/detector_superpose.py +++ b/src/dxtbx/command_line/detector_superpose.py @@ -92,10 +92,9 @@ def run(args=None): "Reference detector must be at least %d panels long given the panel list" % (max_p_id + 1) ) - assert max_p_id < len( - moving - ), "Moving detector must be at least %d panels long given the panel list" % ( - max_p_id + 1 + assert max_p_id < len(moving), ( + "Moving detector must be at least %d panels long given the panel list" + % (max_p_id + 1) ) panel_ids = params.panel_list diff --git a/src/dxtbx/command_line/plot_detector_models.py b/src/dxtbx/command_line/plot_detector_models.py index b9f228280..e99105fa0 100644 --- a/src/dxtbx/command_line/plot_detector_models.py +++ b/src/dxtbx/command_line/plot_detector_models.py @@ -125,7 +125,6 @@ def plot_group( def plot_image_plane_projection(detector, color, ax, panel_numbers=True): - origin_2d, fast_2d, slow_2d = get_detector_projection_2d_axes(detector) for panel, origin, fast, slow in zip(detector, origin_2d, fast_2d, slow_2d): @@ -182,7 +181,6 @@ def run(args=None): min_z = max_z = None ax = None for file_name, color in zip(files, colors): - # read the data and get the detector models try: experiments = ExperimentListFactory.from_json_file( diff --git a/src/dxtbx/command_line/read_sequence.py b/src/dxtbx/command_line/read_sequence.py index 96a31f79b..8bef785c2 100644 --- a/src/dxtbx/command_line/read_sequence.py +++ b/src/dxtbx/command_line/read_sequence.py @@ -12,7 +12,6 @@ def read_sequence(images: list[str]): - sequences = ImageSetFactory.new(images) for sequence in sequences: diff --git a/src/dxtbx/dxtbx_imageset_ext.pyi b/src/dxtbx/dxtbx_imageset_ext.pyi index d876a7c23..8335d3c1a 100644 --- a/src/dxtbx/dxtbx_imageset_ext.pyi +++ b/src/dxtbx/dxtbx_imageset_ext.pyi @@ -21,14 +21,12 @@ class ExternalLookup: def pedestal(self) -> Any: ... class ExternalLookupItemBool: - data: Any filename: Any def __init__(self, *args, **kwargs) -> None: ... def __reduce__(self) -> Any: ... class ExternalLookupItemDouble: - data: Any filename: Any def __init__(self, *args, **kwargs) -> None: ... diff --git a/src/dxtbx/example/to_xds.py b/src/dxtbx/example/to_xds.py index 61f778d3c..4b9646a7d 100644 --- a/src/dxtbx/example/to_xds.py +++ b/src/dxtbx/example/to_xds.py @@ -5,7 +5,6 @@ classes. """ - from __future__ import annotations import math @@ -57,7 +56,6 @@ def get_scan(self): return self._scan def XDS(self): - sensor = self.get_detector().get_type() fast, slow = map(int, self.get_detector().get_image_size()) f, s = self.get_detector().get_pixel_size() diff --git a/src/dxtbx/format/Format.py b/src/dxtbx/format/Format.py index 4054c7fc1..7e9f46635 100644 --- a/src/dxtbx/format/Format.py +++ b/src/dxtbx/format/Format.py @@ -377,7 +377,6 @@ def get_imageset( # Create an imageset or sequence if not is_sequence: - # Create the imageset iset = ImageSet( ImageSetData( @@ -391,7 +390,6 @@ def get_imageset( # If any are None then read from format if [beam, detector, goniometer, scan].count(None) != 0: - # Get list of models beam = [] detector = [] @@ -412,7 +410,6 @@ def get_imageset( iset.set_scan(scan[i], i) else: - # Get the template if template is None: template = template_regex(filenames[0])[0] diff --git a/src/dxtbx/format/FormatBruker.py b/src/dxtbx/format/FormatBruker.py index 5d83ec1b5..a54732068 100644 --- a/src/dxtbx/format/FormatBruker.py +++ b/src/dxtbx/format/FormatBruker.py @@ -33,7 +33,6 @@ def read_header_lines(image_path, max_bytes=512 * 50): max_bytes = (max_bytes // 80) * 80 with FormatBruker.open_file(image_path, "rb") as f: while True: - # read a line and look for HDRBLKS line = f.read(80) if not line: diff --git a/src/dxtbx/format/FormatBrukerED1.py b/src/dxtbx/format/FormatBrukerED1.py index b08bee4fe..fc2a5e31a 100644 --- a/src/dxtbx/format/FormatBrukerED1.py +++ b/src/dxtbx/format/FormatBrukerED1.py @@ -21,7 +21,6 @@ class FormatBrukerED1(FormatBruker): @staticmethod def understand(image_file): - try: header_lines = FormatBruker.read_header_lines(image_file) except OSError: @@ -45,7 +44,6 @@ def understand(image_file): return True def _start(self): - try: header_lines = FormatBruker.read_header_lines(self._image_file) except OSError: @@ -175,7 +173,6 @@ def _beam(self): ) def _scan(self): - start = float(self.header_dict["START"].split()[0]) incr = float(self.header_dict["INCREME"].split()[0]) if incr < 0: diff --git a/src/dxtbx/format/FormatBrukerFixedChi.py b/src/dxtbx/format/FormatBrukerFixedChi.py index 854011eca..3ea48ccfe 100644 --- a/src/dxtbx/format/FormatBrukerFixedChi.py +++ b/src/dxtbx/format/FormatBrukerFixedChi.py @@ -11,7 +11,6 @@ class FormatBrukerFixedChi(FormatBruker): @staticmethod def understand(image_file): - hdr = FormatBruker.read_header_lines(image_file) hdr_dic = FormatBruker.parse_header(hdr) @@ -105,7 +104,6 @@ def _beam(self): return self._beam_factory.simple(wavelength) def _scan(self): - start = float(self.header_dict["START"][0]) incr = float(self.header_dict["INCREME"][0]) if incr < 0: diff --git a/src/dxtbx/format/FormatBrukerPhoton.py b/src/dxtbx/format/FormatBrukerPhoton.py index 7ccb2b4e7..1ae34b5e3 100644 --- a/src/dxtbx/format/FormatBrukerPhoton.py +++ b/src/dxtbx/format/FormatBrukerPhoton.py @@ -21,7 +21,6 @@ class FormatBrukerPhoton(FormatBruker): @staticmethod def understand(image_file): - try: header_lines = FormatBruker.read_header_lines(image_file) except OSError: @@ -39,7 +38,6 @@ def understand(image_file): return True def _start(self): - try: header_lines = FormatBruker.read_header_lines(self._image_file) except OSError: @@ -145,7 +143,6 @@ def _beam(self): ) def _scan(self): - start = float(self.header_dict["START"].split()[0]) incr = float(self.header_dict["INCREME"].split()[0]) if incr < 0: diff --git a/src/dxtbx/format/FormatCBFMiniADSCHF4M.py b/src/dxtbx/format/FormatCBFMiniADSCHF4M.py index 57ddac48b..33863d284 100644 --- a/src/dxtbx/format/FormatCBFMiniADSCHF4M.py +++ b/src/dxtbx/format/FormatCBFMiniADSCHF4M.py @@ -25,7 +25,6 @@ def get_adsc_timestamp(timestamp): timestamp = re.sub("_+", "_", timestamp) for format in ["%a_%b_%d_%H:%M:%S_%Y"]: - try: struct_time = time.strptime(timestamp, format) return calendar.timegm(struct_time) @@ -41,7 +40,6 @@ class FormatCBFMiniADSCHF4M(FormatCBFMini): @staticmethod def understand(image_file): - header = FormatCBFMini.get_cbf_header(image_file) for record in header.split("\n"): @@ -151,7 +149,6 @@ def _scan(self): ) def detectorbase_start(self): - self.detectorbase = ADSCHF4MImage(self._image_file) self.detectorbase.readHeader() diff --git a/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py b/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py index df729e46f..41d279be0 100644 --- a/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py +++ b/src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py @@ -37,7 +37,6 @@ def _goniometer(self): ) def _detector(self): - max_trusted_value = 1e7 if "_lower_" in self._image_file: @@ -118,7 +117,6 @@ def _scan(self): ) def detectorbase_start(self): - self.detectorbase = PilatusImage(self._image_file) self.detectorbase.readHeader() diff --git a/src/dxtbx/format/FormatCBFMiniEigerQuadroED1.py b/src/dxtbx/format/FormatCBFMiniEigerQuadroED1.py index c19c86d04..fa9f8ae74 100644 --- a/src/dxtbx/format/FormatCBFMiniEigerQuadroED1.py +++ b/src/dxtbx/format/FormatCBFMiniEigerQuadroED1.py @@ -11,7 +11,6 @@ class FormatCBFMiniEigerQuadroED1(FormatCBFMiniEiger): @staticmethod def understand(image_file): - header = FormatCBFMiniEiger.get_cbf_header(image_file) for record in header.split("\n"): diff --git a/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py b/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py index 38066e47f..e05be5ea6 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py @@ -57,7 +57,6 @@ def __init__(self, image_file, **kwargs): super().__init__(image_file, **kwargs) def _detector(self): - # module positions from detector blueprints - modelling at the moment as # 24 modules, each consisting of 5 sensors (the latter is ignored) x = matrix.col((-1, 0, 0)) diff --git a/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py b/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py index 3d68bfcab..f6d657d12 100644 --- a/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py +++ b/src/dxtbx/format/FormatCBFMiniPilatusHelpers.py @@ -14,7 +14,6 @@ def get_pilatus_timestamp(timestamp_string): milliseconds = "000" for format in ["%Y-%b-%dT%H:%M:%S", "%Y-%m-%dT%H:%M:%S", "%Y/%b/%d %H:%M:%S"]: - try: struct_time = time.strptime(timestamp, format) return calendar.timegm(struct_time) + float("0." + milliseconds) diff --git a/src/dxtbx/format/FormatCBFMultiTileHierarchy.py b/src/dxtbx/format/FormatCBFMultiTileHierarchy.py index 211942f15..9a929cca1 100644 --- a/src/dxtbx/format/FormatCBFMultiTileHierarchy.py +++ b/src/dxtbx/format/FormatCBFMultiTileHierarchy.py @@ -162,7 +162,9 @@ def _add_panel_group(self, group_id, d): except RuntimeError as e: assert "DXTBX_ASSERT(D_)" in str(e) else: - assert False # shouldn't be reached. Detector should be initialized only once. + assert ( + False + ) # shouldn't be reached. Detector should be initialized only once. else: parent_pg = self._add_panel_group(parent, d) pg = parent_pg.add_group() diff --git a/src/dxtbx/format/FormatGatanDM4.py b/src/dxtbx/format/FormatGatanDM4.py index acb93f1ef..18c671162 100644 --- a/src/dxtbx/format/FormatGatanDM4.py +++ b/src/dxtbx/format/FormatGatanDM4.py @@ -126,7 +126,6 @@ def search_tag_hierarchy(name, tag_list): def extract_image_data(image_file, offset, ntags, byteord): # read tags with FormatGatanDM4.open_file(image_file, "rb") as f: - f.seek(offset) root = [] @@ -230,7 +229,6 @@ class FormatGatanDM4(Format): @staticmethod def understand(image_file): - try: header = FormatGatanDM4._read_header(image_file) except struct.error: @@ -255,7 +253,6 @@ def _read_header(image_file): hd = {} with FormatGatanDM4.open_file(image_file, "rb") as f: - hd["version"] = struct.unpack(">I", f.read(4))[0] if hd["version"] == 3: @@ -414,13 +411,11 @@ def understand(image_file): return extract_num_images(image_file) == 1 def __init__(self, image_file, **kwargs): - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatGatanDM4.__init__(self, image_file, **kwargs) def get_raw_data(self): - with FormatGatanDM4.open_file(self._image_file, "rb") as f: f.seek(self._data_offset) return self._read_raw_data(f) @@ -432,14 +427,12 @@ def understand(image_file): return extract_num_images(image_file) > 1 def __init__(self, image_file, **kwargs): - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatMultiImage.__init__(self, **kwargs) FormatGatanDM4.__init__(self, image_file, **kwargs) def get_raw_data(self, index): - with FormatGatanDM4.open_file(self._image_file, "rb") as f: f.seek(self._data_offset) diff --git a/src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py b/src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py index cca49cf26..a5d401759 100644 --- a/src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py +++ b/src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py @@ -11,7 +11,6 @@ class FormatHDF5ESRFJungfrau4M(FormatHDF5): - # A class to understand still-shot images from ESRF collected on a Jungfrau 4M. _cached_mask = None diff --git a/src/dxtbx/format/FormatHDF5SaclaMPCCD.py b/src/dxtbx/format/FormatHDF5SaclaMPCCD.py index 53e958232..44d55f1d3 100644 --- a/src/dxtbx/format/FormatHDF5SaclaMPCCD.py +++ b/src/dxtbx/format/FormatHDF5SaclaMPCCD.py @@ -255,7 +255,6 @@ def get_raw_data(self, index=None): self.set_index(index) if self._raw_data is None: - if self.RECONST_MODE: self._raw_data = flex.int(self.reconst_image()) diff --git a/src/dxtbx/format/FormatISISSXD.py b/src/dxtbx/format/FormatISISSXD.py index aea0d7166..00299d515 100644 --- a/src/dxtbx/format/FormatISISSXD.py +++ b/src/dxtbx/format/FormatISISSXD.py @@ -75,7 +75,6 @@ def get_goniometer(self, idx: int = None) -> Goniometer: return goniometer def get_detector(self, index: int = None) -> Detector: - num_panels = self._get_num_panels() panel_names = self._get_panel_names() panel_type = self._get_panel_type() @@ -282,7 +281,6 @@ def _load_raw_data(self): self._raw_data = tuple(raw_data) def get_raw_data(self, index: int, use_loaded_data=True) -> Tuple[flex.int]: - raw_data = [] if use_loaded_data: diff --git a/src/dxtbx/format/FormatMANDI.py b/src/dxtbx/format/FormatMANDI.py index cfb7f62af..3d7473046 100644 --- a/src/dxtbx/format/FormatMANDI.py +++ b/src/dxtbx/format/FormatMANDI.py @@ -65,7 +65,6 @@ def get_name(image_file: str) -> str: return get_name(image_file) == "MANDI" def get_raw_data(self, index: int) -> Tuple[flex.int]: - raw_data = [] panel_size = self._get_image_size() for panel_name in self._get_panel_names(): @@ -80,7 +79,6 @@ def get_raw_data(self, index: int) -> Tuple[flex.int]: return tuple(raw_data) def get_detector(self) -> Detector: - num_panels = self._get_num_panels() panel_names = self._get_panel_names() panel_type = self._get_panel_type() @@ -377,7 +375,6 @@ def add_histogram_data_to_nxs_file( panel_size: Tuple[int, int] = (256, 256), # (px) nproc: int = 8, ) -> None: - tof_bins = FormatMANDI.generate_tof_bins( nxs_file=nxs_file_path, panel_size=panel_size, @@ -442,7 +439,7 @@ def delete_event_data(nxs_file, base_dir, panel_name): @staticmethod def compute_event_histogram( - args: Tuple[int, np.array, np.array, np.array] + args: Tuple[int, np.array, np.array, np.array], ) -> np.array: pixel_idx, event_time_offset, corrected_event_id, tof_bins = args h, _ = np.histogram( diff --git a/src/dxtbx/format/FormatMRC.py b/src/dxtbx/format/FormatMRC.py index 52005b236..4b84858a5 100644 --- a/src/dxtbx/format/FormatMRC.py +++ b/src/dxtbx/format/FormatMRC.py @@ -70,7 +70,6 @@ def _unpack_header(header): return hd def _extend_header(self, xh): - # Extensions from FEI headers only if not self._header_dictionary["exttyp"].startswith(b"FEI"): return @@ -271,7 +270,6 @@ def _scan(self): return ScanFactory.make_scan((index, index), exposure, oscillation, {index: 0}) def get_raw_data(self): - with mrcfile.open(self._image_file) as mrc: image = flex.double(mrc.data.astype("double")) @@ -315,7 +313,6 @@ def get_image_file(self, index=None): return Format.get_image_file(self) def get_raw_data(self, index): - # Note MRC files use z, y, x ordering with mrcfile.mmap(self._image_file) as mrc: image = flex.double(mrc.data[index, ...].astype("double")) diff --git a/src/dxtbx/format/FormatMultiImage.py b/src/dxtbx/format/FormatMultiImage.py index 2dc123033..ee64d9ab3 100644 --- a/src/dxtbx/format/FormatMultiImage.py +++ b/src/dxtbx/format/FormatMultiImage.py @@ -222,7 +222,6 @@ def get_imageset( # Create an imageset or sequence if not is_sequence: - # Use imagesetlazy # Setup ImageSetLazy and just return it. No models are set. if lazy: @@ -251,7 +250,6 @@ def get_imageset( # If any are None then read from format if not all((beam, detector, goniometer, scan)): - # Get list of models num_images = format_instance.get_num_images() beam = [None] * num_images @@ -272,7 +270,6 @@ def get_imageset( iset.set_scan(scan[index], i) else: - # Get the template template = filenames[0] diff --git a/src/dxtbx/format/FormatMultiImageLazy.py b/src/dxtbx/format/FormatMultiImageLazy.py index 4ed83666e..2c00b126c 100644 --- a/src/dxtbx/format/FormatMultiImageLazy.py +++ b/src/dxtbx/format/FormatMultiImageLazy.py @@ -28,7 +28,6 @@ def get_imageset( check_format=True, lazy=True, ): - return super().get_imageset( filenames=filenames, beam=beam, diff --git a/src/dxtbx/format/FormatNXmxDLS.py b/src/dxtbx/format/FormatNXmxDLS.py index 9070463ed..3343ac9bc 100644 --- a/src/dxtbx/format/FormatNXmxDLS.py +++ b/src/dxtbx/format/FormatNXmxDLS.py @@ -75,7 +75,6 @@ def _local_visit(name) -> Path | None: class FormatNXmxDLS(FormatNXmx): - _cached_file_handle = None @staticmethod diff --git a/src/dxtbx/format/FormatNexus.py b/src/dxtbx/format/FormatNexus.py index c4fb92281..f4ed4a1a8 100644 --- a/src/dxtbx/format/FormatNexus.py +++ b/src/dxtbx/format/FormatNexus.py @@ -18,7 +18,6 @@ def understand(image_file): return False def _start(self): - # Read the file structure self._reader = reader = nexus.NXmxReader(self._image_file) @@ -180,7 +179,6 @@ def get_num_images(self): if __name__ == "__main__": for arg in sys.argv[1:]: if FormatNexus.understand(arg): - format_instance = FormatNexus(arg) beam = format_instance.get_beam() diff --git a/src/dxtbx/format/FormatNexusJungfrauHack.py b/src/dxtbx/format/FormatNexusJungfrauHack.py index a1a9a029a..e43892c6f 100644 --- a/src/dxtbx/format/FormatNexusJungfrauHack.py +++ b/src/dxtbx/format/FormatNexusJungfrauHack.py @@ -38,7 +38,6 @@ def understand(image_file): return False def _start(self): - # Read the file structure self._reader = reader = NXmxReader(self._image_file) diff --git a/src/dxtbx/format/FormatPYunspecified.py b/src/dxtbx/format/FormatPYunspecified.py index 82f7f64a6..1da479994 100644 --- a/src/dxtbx/format/FormatPYunspecified.py +++ b/src/dxtbx/format/FormatPYunspecified.py @@ -65,7 +65,6 @@ def _start(self): ) def start_helper(self, version_token): - is_file = isinstance(self._image_file, str) and os.path.isfile(self._image_file) if is_file: @@ -97,7 +96,6 @@ def start_helper(self, version_token): self.detectorbase = image def _goniometer(self): - return self._goniometer_factory.single_axis() def _detector(self): diff --git a/src/dxtbx/format/FormatROD.py b/src/dxtbx/format/FormatROD.py index e755d504b..fa031c0a1 100644 --- a/src/dxtbx/format/FormatROD.py +++ b/src/dxtbx/format/FormatROD.py @@ -284,7 +284,6 @@ def get_beam(self, index=None): return Format.get_beam(self) def _beam(self): - wavelength = self._bin_header["alpha1_wavelength"] if wavelength <= 0.05: probe = Probe.electron @@ -311,19 +310,13 @@ def _detector(self): # Note that XDS.INP's directions of Y and Z are opposite from ours. rot_e1 = np.array( r3_rotation_axis_and_angle_as_matrix([0, 0, 1], detector_rotns_rad[0]) - ).reshape( - 3, 3 - ) # clockwise along e1 = Z + ).reshape(3, 3) # clockwise along e1 = Z rot_e2 = np.array( r3_rotation_axis_and_angle_as_matrix([-1, 0, 0], detector_rotns_rad[1]) - ).reshape( - 3, 3 - ) # ANTI-clockwise along e2 = X + ).reshape(3, 3) # ANTI-clockwise along e2 = X rot_theta = np.array( r3_rotation_axis_and_angle_as_matrix([0, -1, 0], theta_rad) - ).reshape( - 3, 3 - ) # ANTI-clockwise along e3 = Y + ).reshape(3, 3) # ANTI-clockwise along e3 = Y detector_axes = rot_theta.dot(rot_e2.dot(rot_e1)) pixel_size_x = self._bin_header["real_px_size_x"] diff --git a/src/dxtbx/format/FormatSER.py b/src/dxtbx/format/FormatSER.py index 0ea102d67..acf5ccc21 100644 --- a/src/dxtbx/format/FormatSER.py +++ b/src/dxtbx/format/FormatSER.py @@ -389,7 +389,6 @@ def _get_raw_data(self, index): class FormatSERimages(FormatSER): @staticmethod def understand(image_file): - with FormatSER.open_file(image_file, "rb") as fh: fh.seek(18) nimages = struct.unpack(" 1 def __init__(self, image_file, **kwargs): - if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatMultiImage.__init__(self, **kwargs) diff --git a/src/dxtbx/format/FormatSMVADSCNoDateStamp.py b/src/dxtbx/format/FormatSMVADSCNoDateStamp.py index db3502b3c..5b0961b95 100644 --- a/src/dxtbx/format/FormatSMVADSCNoDateStamp.py +++ b/src/dxtbx/format/FormatSMVADSCNoDateStamp.py @@ -13,7 +13,6 @@ class FormatSMVADSCNoDateStamp(FormatSMVADSC): @staticmethod def understand(image_file): - # assert for this that the image file has to be a file not a URL if not os.path.exists(image_file): return False diff --git a/src/dxtbx/format/FormatSMVADSCSN.py b/src/dxtbx/format/FormatSMVADSCSN.py index 21b554536..30b667ca7 100644 --- a/src/dxtbx/format/FormatSMVADSCSN.py +++ b/src/dxtbx/format/FormatSMVADSCSN.py @@ -74,7 +74,6 @@ def _adsc_module_gain(self, model=None): return super()._adsc_module_gain(model=model) def detectorbase_start(self): - self.detectorbase = ADSCImage(self._image_file) self.detectorbase.open_file = self.open_file self.detectorbase.readHeader() diff --git a/src/dxtbx/format/FormatSMVHamamatsu.py b/src/dxtbx/format/FormatSMVHamamatsu.py index b96acb729..725191cdc 100644 --- a/src/dxtbx/format/FormatSMVHamamatsu.py +++ b/src/dxtbx/format/FormatSMVHamamatsu.py @@ -8,7 +8,6 @@ class FormatSMVHamamatsu(FormatSMVADSC): @staticmethod def understand(image_file): - size, header = FormatSMVHamamatsu.get_smv_header(image_file) wanted_header_items = ["DETECTOR_NAME"] diff --git a/src/dxtbx/format/FormatSMVHamamatsuSPring8BL32XU.py b/src/dxtbx/format/FormatSMVHamamatsuSPring8BL32XU.py index 9cacbd867..7a120d763 100644 --- a/src/dxtbx/format/FormatSMVHamamatsuSPring8BL32XU.py +++ b/src/dxtbx/format/FormatSMVHamamatsuSPring8BL32XU.py @@ -8,7 +8,6 @@ class FormatSMVHamamatsuSPring8BL32XU(FormatSMVHamamatsu): @staticmethod def understand(image_file): - size, header = FormatSMVHamamatsu.get_smv_header(image_file) wanted_header_items = ["DETECTOR_NAME"] @@ -20,7 +19,6 @@ def understand(image_file): return header["DETECTOR_NAME"] == "Hamamatsu C10158DK" def _start(self): - FormatSMVHamamatsu._start(self) def detectorbase_start(self): diff --git a/src/dxtbx/format/FormatSMVTimePix_SU.py b/src/dxtbx/format/FormatSMVTimePix_SU.py index b557ca86b..d7f48fa88 100644 --- a/src/dxtbx/format/FormatSMVTimePix_SU.py +++ b/src/dxtbx/format/FormatSMVTimePix_SU.py @@ -28,7 +28,6 @@ class FormatSMVTimePix_SU(FormatSMV): @staticmethod def understand(image_file): - size, header = FormatSMV.get_smv_header(image_file) # only recognise TimePix_SU @@ -119,7 +118,6 @@ class FormatSMVTimePix_SU_512x512(FormatSMVTimePix_SU): @staticmethod def understand(image_file): - size, header = FormatSMVTimePix_SU.get_smv_header(image_file) # check the pixel size is 55 microns @@ -321,7 +319,6 @@ class FormatSMVTimePix_SU_516x516(FormatSMVTimePix_SU): @staticmethod def understand(image_file): - size, header = FormatSMVTimePix_SU.get_smv_header(image_file) # check there are 516*516 pixels diff --git a/src/dxtbx/format/FormatTIFFRayonixESRF.py b/src/dxtbx/format/FormatTIFFRayonixESRF.py index bea0cba68..8bb87d3f4 100644 --- a/src/dxtbx/format/FormatTIFFRayonixESRF.py +++ b/src/dxtbx/format/FormatTIFFRayonixESRF.py @@ -40,8 +40,11 @@ def understand(image_file): # struct.unpack(format + "ii", bytes[offset + 772 : offset + 780]) # ) - header_beam_center = 0.001 * col( # Rayonix says this should be pixels - struct.unpack(format + "ii", bytes[offset + 644 : offset + 652]) + header_beam_center = ( + 0.001 + * col( # Rayonix says this should be pixels + struct.unpack(format + "ii", bytes[offset + 644 : offset + 652]) + ) ) disagreement = header_beam_center[0] / detector_center_px[0] diff --git a/src/dxtbx/format/FormatXTCJungfrau.py b/src/dxtbx/format/FormatXTCJungfrau.py index 02dee7e24..56f8a8f69 100644 --- a/src/dxtbx/format/FormatXTCJungfrau.py +++ b/src/dxtbx/format/FormatXTCJungfrau.py @@ -77,7 +77,6 @@ def get_raw_data(self, index=None): data = data.astype(np.float64) self._raw_data = [] for module_count, module in enumerate(d.hierarchy()): - if ( self.params.jungfrau.use_big_pixels and os.environ.get("DONT_USE_BIG_PIXELS_JUNGFRAU") is None diff --git a/src/dxtbx/format/TemplatePYCXI31.py b/src/dxtbx/format/TemplatePYCXI31.py index 9d0cc041a..aedef764a 100644 --- a/src/dxtbx/format/TemplatePYCXI31.py +++ b/src/dxtbx/format/TemplatePYCXI31.py @@ -13,7 +13,6 @@ class FormatPYCXI31(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 3.1" ) diff --git a/src/dxtbx/format/TemplatePYCXI32.py b/src/dxtbx/format/TemplatePYCXI32.py index 9cbd18ad2..c751aa5c9 100644 --- a/src/dxtbx/format/TemplatePYCXI32.py +++ b/src/dxtbx/format/TemplatePYCXI32.py @@ -13,7 +13,6 @@ class FormatPYCXI32(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 3.2" ) diff --git a/src/dxtbx/format/TemplatePYCXI41.py b/src/dxtbx/format/TemplatePYCXI41.py index 67787f09c..27b6d27ed 100644 --- a/src/dxtbx/format/TemplatePYCXI41.py +++ b/src/dxtbx/format/TemplatePYCXI41.py @@ -13,7 +13,6 @@ class FormatPYCXI41(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 4.1" ) diff --git a/src/dxtbx/format/TemplatePYCXI51.py b/src/dxtbx/format/TemplatePYCXI51.py index 01973f476..d74b4a619 100644 --- a/src/dxtbx/format/TemplatePYCXI51.py +++ b/src/dxtbx/format/TemplatePYCXI51.py @@ -13,7 +13,6 @@ class FormatPYCXI51(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 5.1" ) diff --git a/src/dxtbx/format/TemplatePYCXI61.py b/src/dxtbx/format/TemplatePYCXI61.py index 406002dd9..d2763ab7e 100644 --- a/src/dxtbx/format/TemplatePYCXI61.py +++ b/src/dxtbx/format/TemplatePYCXI61.py @@ -13,7 +13,6 @@ class FormatPYCXI61(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 6.1" ) diff --git a/src/dxtbx/format/TemplatePYCXI71.py b/src/dxtbx/format/TemplatePYCXI71.py index 4af0326d8..c7ba48c00 100644 --- a/src/dxtbx/format/TemplatePYCXI71.py +++ b/src/dxtbx/format/TemplatePYCXI71.py @@ -13,7 +13,6 @@ class FormatPYCXI71(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 7.1" ) diff --git a/src/dxtbx/format/TemplatePYCXI7d.py b/src/dxtbx/format/TemplatePYCXI7d.py index e51b954d6..44732575d 100644 --- a/src/dxtbx/format/TemplatePYCXI7d.py +++ b/src/dxtbx/format/TemplatePYCXI7d.py @@ -13,7 +13,6 @@ class FormatPYCXI7d(FormatPYunspecified): """ def _start(self): - FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 7.d" ) diff --git a/src/dxtbx/format/cbf_writer.py b/src/dxtbx/format/cbf_writer.py index 87fc964a7..514d1651e 100644 --- a/src/dxtbx/format/cbf_writer.py +++ b/src/dxtbx/format/cbf_writer.py @@ -434,9 +434,9 @@ def recursive_setup_basis_dict(key, parent_name="", panel_id=0): node = panel_group_from_key(key) if node.is_panel(): - axis_settings[-1][ - -2 - ] = "0" # Drop the setting change for leaves as it's encoded below + axis_settings[-1][-2] = ( + "0" # Drop the setting change for leaves as it's encoded below + ) aname = level_string(key) fast = [str(v) for v in node.get_local_fast_axis()] diff --git a/src/dxtbx/format/nexus.py b/src/dxtbx/format/nexus.py index 1d1775fda..f1c4c99b3 100644 --- a/src/dxtbx/format/nexus.py +++ b/src/dxtbx/format/nexus.py @@ -330,9 +330,9 @@ def result(self): # XXX not sure how best to handle this, but probably a still so no scan axis scan_axis = 0 else: - assert ( - self._is_scan_axis.count(True) == 1 - ), "Only one axis can be a scan axis: %s" % list(self._is_scan_axis) + assert self._is_scan_axis.count(True) == 1, ( + "Only one axis can be a scan axis: %s" % list(self._is_scan_axis) + ) scan_axis = flex.first_index(self._is_scan_axis, True) # Rotate 180 about up from McStas coordinate system @@ -794,10 +794,13 @@ def __init__(self, instrument, beam, idx=None): expected_detectors = [] root_name = None for i, parent_id in enumerate(group_parent): - assert parent_id in [ - -1, - 1, - ], "Hierarchy of detectors not supported. Hierarchy of module components within detector elements is supported" + assert ( + parent_id + in [ + -1, + 1, + ] + ), "Hierarchy of detectors not supported. Hierarchy of module components within detector elements is supported" if parent_id == -1: assert root_name is None, "Multiple roots not supported" @@ -1466,7 +1469,7 @@ def detectorgroupdatafactory(obj, instrument): if detector_name in mapping: assert ( dataset_name not in mapping[detector_name]["dataset_names"] - ), ("Dataset %s found in > 1 NXdetectors" % dataset_name) + ), "Dataset %s found in > 1 NXdetectors" % dataset_name mapping[detector_name]["dataset_names"].add(dataset_name) mapping[detector_name]["datasets"].append(dataset) else: diff --git a/src/dxtbx/format/nxmx_writer.py b/src/dxtbx/format/nxmx_writer.py index a6d849e11..88d893493 100644 --- a/src/dxtbx/format/nxmx_writer.py +++ b/src/dxtbx/format/nxmx_writer.py @@ -331,17 +331,17 @@ def recursive_setup_basis_dict(key, parent_name="", panel_id=0): source.attrs["NX_class"] = "NXsource" source["name"] = self.params.nexus_details.source_name if self.params.nexus_details.source_short_name: - source["name"].attrs[ - "short_name" - ] = self.params.nexus_details.source_short_name + source["name"].attrs["short_name"] = ( + self.params.nexus_details.source_short_name + ) # --> instrument instrument = entry.create_group("instrument") instrument.attrs["NX_class"] = "NXinstrument" instrument["name"] = self.params.nexus_details.instrument_name if self.params.nexus_details.instrument_short_name: - instrument["name"].attrs[ - "short_name" - ] = self.params.nexus_details.instrument_short_name + instrument["name"].attrs["short_name"] = ( + self.params.nexus_details.instrument_short_name + ) beam = instrument.create_group("beam") beam.attrs["NX_class"] = "NXbeam" if self.params.nexus_details.total_flux: @@ -580,9 +580,9 @@ def add_beams(self, beams=None, spectra=None): dtype=spectra_y.dtype, ) handle["incident_wavelength_1Dspectrum"].attrs["units"] = "angstrom" - handle["incident_wavelength"].attrs[ - "variant" - ] = "incident_wavelength_1Dspectrum" + handle["incident_wavelength"].attrs["variant"] = ( + "incident_wavelength_1Dspectrum" + ) else: if len(beams) > 1: wavelengths = np.array( @@ -787,8 +787,9 @@ def setup_axis(name, vector, main_axis=False): if axis_number == len(gonio.get_axes()) - 1: axis.attrs["depends_on"] = "." else: - axis.attrs["depends_on"] = "/entry/sample/transformations/%s" % ( - gonio.get_names()[axis_number + 1] + axis.attrs["depends_on"] = ( + "/entry/sample/transformations/%s" + % (gonio.get_names()[axis_number + 1]) ) else: setup_axis("omega", gonio.get_rotation_axis(), main_axis=True) diff --git a/src/dxtbx/imageset.py b/src/dxtbx/imageset.py index 9061387fa..9c2291120 100644 --- a/src/dxtbx/imageset.py +++ b/src/dxtbx/imageset.py @@ -371,7 +371,6 @@ def _is_imageset_a_sequence(template, indices): # Label each group as either an imageset or a sequence. file_groups = [] for template, indices in filelist_per_imageset.items(): - # Check if this imageset is a sequence is_sequence = _is_imageset_a_sequence(template, indices) diff --git a/src/dxtbx/model/detector.py b/src/dxtbx/model/detector.py index 6c0bb564a..2141af547 100644 --- a/src/dxtbx/model/detector.py +++ b/src/dxtbx/model/detector.py @@ -214,7 +214,6 @@ def merge_panel_scope_extracts_by_id(panel_params): - id_to_params = {} for i, params in enumerate(panel_params): if params.id not in id_to_params: diff --git a/src/dxtbx/model/experiment_list.py b/src/dxtbx/model/experiment_list.py index 6a5a01923..1720c62e2 100644 --- a/src/dxtbx/model/experiment_list.py +++ b/src/dxtbx/model/experiment_list.py @@ -716,7 +716,6 @@ def from_filenames( # Treat each format as a separate block of data for format_class, records in format_groups.items(): if issubclass(format_class, FormatMultiImage): - if all_tof: _merge_sequence_model_metadata( records, diff --git a/src/dxtbx/model/scan.py b/src/dxtbx/model/scan.py index 0718d269a..83475ecb5 100644 --- a/src/dxtbx/model/scan.py +++ b/src/dxtbx/model/scan.py @@ -281,7 +281,6 @@ def make_scan( @staticmethod def make_scan_from_properties(image_range, properties, batch_offset=0, deg=True): - return Scan(tuple(map(int, image_range)), properties, batch_offset, deg) @staticmethod diff --git a/src/dxtbx/model/scan_helpers.py b/src/dxtbx/model/scan_helpers.py index 56b1ec4e6..7e22209ea 100644 --- a/src/dxtbx/model/scan_helpers.py +++ b/src/dxtbx/model/scan_helpers.py @@ -69,7 +69,6 @@ def _image2template_directory(filename): directory = os.path.dirname(filename) if not directory: - # then it should be the current working directory directory = os.getcwd() diff --git a/src/dxtbx/nexus/__init__.py b/src/dxtbx/nexus/__init__.py index e0fb8717b..e506e3aca 100644 --- a/src/dxtbx/nexus/__init__.py +++ b/src/dxtbx/nexus/__init__.py @@ -262,7 +262,6 @@ def get_dxtbx_detector( root = detector for module in nxdetector.modules: - if len(nxdetector.modules) > 1: # Set up the detector hierarchy if module.fast_pixel_direction.depends_on is not None: diff --git a/src/dxtbx/serialize/xds.py b/src/dxtbx/serialize/xds.py index 5e96662cb..e79ef1c9c 100644 --- a/src/dxtbx/serialize/xds.py +++ b/src/dxtbx/serialize/xds.py @@ -216,7 +216,6 @@ def __init__(self, sequence): self.panel_normal = [] for panel_id, panel in enumerate(self.get_detector()): - f = Rd * matrix.col(panel.get_fast_axis()) s = Rd * matrix.col(panel.get_slow_axis()) n = f.cross(s) @@ -389,7 +388,6 @@ def XDS_INP( if len(self.panel_x_axis) > 1: for panel_id, panel_x_axis in enumerate(self.panel_x_axis): - result.append("") result.append("!") result.append("! SEGMENT %d" % (panel_id + 1)) diff --git a/tests/model/crystal_model_old.py b/tests/model/crystal_model_old.py index 467668869..dc94b36c3 100644 --- a/tests/model/crystal_model_old.py +++ b/tests/model/crystal_model_old.py @@ -42,7 +42,6 @@ def __init__( mosaicity=None, deg=True, ): - # Set the space group assert [space_group_symbol, space_group].count(None) == 1 if space_group_symbol: @@ -183,7 +182,6 @@ def _update_B(self): self._B = matrix.sqr(self._uc.fractionalization_matrix()).transpose() def set_U(self, U): - # check U is a rotation matrix. assert U.is_r3_rotation_matrix() self._U = U @@ -198,7 +196,6 @@ def get_B(self): return self._B def set_B(self, B): - # also set the unit cell co = crystal_orientation(B, True) self._uc = co.unit_cell() @@ -220,7 +217,6 @@ def get_B_covariance(self): return self._cov_B def set_B_covariance(self, cov): - cov = matrix.sqr(cov) # check cov is of the right size. No other checks made @@ -231,7 +227,6 @@ def set_B_covariance(self, cov): return def _calc_cell_parameter_sd(self): - # self._cov_B is the covariance matrix of elements of the B matrix. We # need to construct the covariance matrix of elements of the # transpose of B. The vector of elements of B is related to the diff --git a/tests/model/test_beam.py b/tests/model/test_beam.py index f6f72eb38..92ff32c05 100644 --- a/tests/model/test_beam.py +++ b/tests/model/test_beam.py @@ -234,7 +234,6 @@ def test_polychromatic_beam_from_dict(): def test_make_polychromatic_beam(): - direction = (0.0, 0.0, 1.0) divergence = 0.2 sigma_divergence = 0.3 diff --git a/tests/model/test_crystal_model.py b/tests/model/test_crystal_model.py index 5a9c592be..c694f181d 100644 --- a/tests/model/test_crystal_model.py +++ b/tests/model/test_crystal_model.py @@ -548,7 +548,6 @@ def test_check_old_vs_new(): "crystal_class", [Crystal, MosaicCrystalKabsch2010, MosaicCrystalSauter2014] ) def test_set_scan_varying_B_covariance(crystal_class): - xl = crystal_class( real_space_a=(10, 0, 0), real_space_b=(0, 11, 0), diff --git a/tests/model/test_detector.py b/tests/model/test_detector.py index 714f08e8b..e7cd24418 100644 --- a/tests/model/test_detector.py +++ b/tests/model/test_detector.py @@ -325,7 +325,6 @@ def test_get_detector_projection_2d_axes(): def test_get_panel_projection_2d_from_axes(dials_data): - # Get test data pytest.importorskip("h5py") filename = dials_data("image_examples", pathlib=True) / "dectris_eiger_master.h5" @@ -365,7 +364,6 @@ def test_get_panel_projection_2d_from_axes(dials_data): def test_panel_get_projection_2d(): - detector = create_detector(offset=0) panel = detector[0] @@ -387,7 +385,6 @@ def test_panel_get_projection_2d(): def test_detector_has_projection_2d(): - # Valid rotation value rotation = (1, 0, 0, 1) @@ -428,7 +425,6 @@ def test_detector_has_projection_2d(): def test_pickle_suite(): - rotation = (1, 0, 0, 1) ## Test single panel detector without 2d projection diff --git a/tests/model/test_detector2.py b/tests/model/test_detector2.py index fcd23194e..010bba2ef 100644 --- a/tests/model/test_detector2.py +++ b/tests/model/test_detector2.py @@ -140,7 +140,9 @@ def test_get_valid_D_matrix(detector): """Setup the hierarchy of frames and check it's all consistent.""" # Set a valid frame for the top level detector detector.hierarchy().set_local_frame( - (1, 0, 0), (0, 1, 0), (0, 0, 100) # Fast axis # Slow axis + (1, 0, 0), + (0, 1, 0), + (0, 0, 100), # Fast axis # Slow axis ) # Origin # Check that all sub groups have the same frame and that we can get diff --git a/tests/model/test_experiment_list.py b/tests/model/test_experiment_list.py index 0e9643c22..47c324e29 100644 --- a/tests/model/test_experiment_list.py +++ b/tests/model/test_experiment_list.py @@ -401,7 +401,6 @@ def experiment_list(): def test_experimentlist_factory_from_json(monkeypatch, dials_regression): - # Get all the filenames filename1 = os.path.join( dials_regression, "experiment_test_data", "experiment_1.json" diff --git a/tests/model/test_ray_intersection.py b/tests/model/test_ray_intersection.py index 04c7a68da..5db414d76 100644 --- a/tests/model/test_ray_intersection.py +++ b/tests/model/test_ray_intersection.py @@ -176,7 +176,6 @@ def random_xy(): # Loop a number of times num = 1000 for i in range(num): - # Create a detector coordinate xy = matrix.col(random_xy()) diff --git a/tests/model/test_scan.py b/tests/model/test_scan.py index ed517b6f2..1f8f3d23d 100644 --- a/tests/model/test_scan.py +++ b/tests/model/test_scan.py @@ -60,7 +60,6 @@ def test_make_scan_from_properties(): def test_set_get_properties(): - image_range = (1, 10) scan = ScanFactory.make_scan_from_properties(image_range=image_range, properties={}) @@ -245,7 +244,6 @@ def test_scan_properties_to_dict(): def test_scan_properties_equivalence(): - int_diff = 1 double_diff = 1e-6 @@ -384,7 +382,6 @@ def test_scan_properties_equivalence(): def test_scan_constant_oscillation_width(): - image_range = (1, 10) scan = ScanFactory.make_scan_from_properties(image_range=image_range, properties={}) @@ -414,7 +411,6 @@ def test_scan_constant_oscillation_width(): def test_print_scan(): - image_range = (1, 10) scan = ScanFactory.make_scan_from_properties(image_range=image_range, properties={}) diff --git a/tests/model/test_scan_data.py b/tests/model/test_scan_data.py index 10fd4e806..05b1d3207 100644 --- a/tests/model/test_scan_data.py +++ b/tests/model/test_scan_data.py @@ -179,7 +179,6 @@ def test_from_phil(): def test_scan_factory_from_dict(scan): - empty_scan = Scan() empty_scan_from_dict = ScanFactory.from_dict(empty_scan.to_dict()) diff --git a/tests/model/test_scan_helpers.py b/tests/model/test_scan_helpers.py index b6f3d2e69..cc4155271 100644 --- a/tests/model/test_scan_helpers.py +++ b/tests/model/test_scan_helpers.py @@ -21,7 +21,6 @@ def test_is_angle_in_random_range(): # If A < B or A > B if angular_range[0] < angular_range[1]: - # Check that the following are true # angle in range 0 -> A = False # angle in range A -> B = True @@ -33,7 +32,6 @@ def test_is_angle_in_random_range(): for angle in range(angular_range[1] + 1, 360): assert is_angle_in_range(angular_range, angle, True) is False else: - # Check that the following are true # angle in range 0 -> B = True # angle in range B -> A = False diff --git a/tests/model/test_spectrum.py b/tests/model/test_spectrum.py index a58694842..13ae807f9 100644 --- a/tests/model/test_spectrum.py +++ b/tests/model/test_spectrum.py @@ -41,7 +41,6 @@ def test_spectrum_bandwidth(): def test_spectrum_weighted_mean_variance(): - p = 11900.0 h = 10000.0 w = 5.0 diff --git a/tests/nexus/test_build_dxtbx_models.py b/tests/nexus/test_build_dxtbx_models.py index c310d9569..4f4591ca7 100644 --- a/tests/nexus/test_build_dxtbx_models.py +++ b/tests/nexus/test_build_dxtbx_models.py @@ -308,9 +308,7 @@ def test_get_dxtbx_detector_beam_center_fallback(nxmx_example): @pytest.fixture def detector_with_multiple_modules(): - with h5py.File(" ", "w", **pytest.h5_in_memory) as f: - detector = f.create_group("/entry/instrument/detector") detector.attrs["NX_class"] = "NXdetector" detector["beam_center_x"] = 2079.79727597266 diff --git a/tests/serialize/test_serialize.py b/tests/serialize/test_serialize.py index 22917baf5..02b6f7a84 100644 --- a/tests/serialize/test_serialize.py +++ b/tests/serialize/test_serialize.py @@ -98,7 +98,6 @@ def test_goniometer_with_scan_points(): ) for g1 in [simple_g, multi_ax_g]: - S_static = matrix.sqr(g1.get_setting_rotation()) g1.set_setting_rotation_at_scan_points([S_static] * 5) d = g1.to_dict() diff --git a/tests/serialize/test_xds.py b/tests/serialize/test_xds.py index d32192b12..41edb1c3e 100644 --- a/tests/serialize/test_xds.py +++ b/tests/serialize/test_xds.py @@ -51,9 +51,7 @@ def test_to_xds(dials_data, tmpdir): UNTRUSTED_RECTANGLE= 0 2464 2315 2333 DATA_RANGE= 1 9 JOB=XYCORR INIT COLSPOT IDXREF DEFPIX INTEGRATE CORRECT\ -""" % ( - dials_data("centroid_test_data", pathlib=True) / "centroid_????.cbf" - ) +""" % (dials_data("centroid_test_data", pathlib=True) / "centroid_????.cbf") # universe changed once, so be flexible expected = [expected_f % a for a in ["3.960382", "3.960386"]] diff --git a/tests/test_imageset.py b/tests/test_imageset.py index 7ac51b0ee..311b7b2d4 100644 --- a/tests/test_imageset.py +++ b/tests/test_imageset.py @@ -76,7 +76,6 @@ def test_format(dials_regression, image): @pytest.fixture(scope="session") def image_examples(dials_data): - return [ str(dials_data("image_examples", pathlib=True) / e) for e in [ From 29a140dbd5d4a7fdfd81d5b4500c5f70bfc5a588 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 17:02:05 +0100 Subject: [PATCH 05/13] Manual fixes for lint violations --- src/dxtbx/format/FormatXTC.py | 4 ++-- src/dxtbx/format/nexus.py | 2 +- src/dxtbx/imageset.py | 4 ++-- src/dxtbx/util/dlsnxs2cbf.py | 2 +- tests/nexus/test_nxmx_writer.py | 3 +-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/dxtbx/format/FormatXTC.py b/src/dxtbx/format/FormatXTC.py index cb70f7448..b73a4da17 100644 --- a/src/dxtbx/format/FormatXTC.py +++ b/src/dxtbx/format/FormatXTC.py @@ -6,9 +6,9 @@ from itertools import groupby import numpy as np + import serialtbx.detector.xtc import serialtbx.util - from libtbx.phil import parse from scitbx.array_family import flex @@ -174,7 +174,7 @@ def _load_hit_indices(self): assert self.params.mode == "idx" hits = np.loadtxt(self.params.hits_file, int) hits = list(map(tuple, hits)) - key = lambda x: x[0] + key = lambda x: x[0] # noqa: E731 gb = groupby(sorted(hits, key=key), key=key) # dictionary where key is run number, and vals are indices of hits self._hit_inds = {r: [ind for _, ind in group] for r, group in gb} diff --git a/src/dxtbx/format/nexus.py b/src/dxtbx/format/nexus.py index f1c4c99b3..35dfefaab 100644 --- a/src/dxtbx/format/nexus.py +++ b/src/dxtbx/format/nexus.py @@ -7,7 +7,7 @@ from typing import Iterable, Union import h5py -import hdf5plugin # noqa; F401 +import hdf5plugin # noqa: F401 import numpy import cctbx.uctbx diff --git a/src/dxtbx/imageset.py b/src/dxtbx/imageset.py index 9c2291120..20351bcae 100644 --- a/src/dxtbx/imageset.py +++ b/src/dxtbx/imageset.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import Iterable + import natsort import boost_adaptbx.boost.python @@ -31,8 +33,6 @@ ext = boost_adaptbx.boost.python.import_ext("dxtbx_ext") -from typing import Iterable - __all__ = ( "ExternalLookup", "ExternalLookupItemBool", diff --git a/src/dxtbx/util/dlsnxs2cbf.py b/src/dxtbx/util/dlsnxs2cbf.py index 011afe42d..2d45fcf85 100644 --- a/src/dxtbx/util/dlsnxs2cbf.py +++ b/src/dxtbx/util/dlsnxs2cbf.py @@ -5,7 +5,7 @@ from pathlib import Path import h5py -import hdf5plugin # noqa; F401 +import hdf5plugin # noqa: F401 import numpy as np import nxmx import pint diff --git a/tests/nexus/test_nxmx_writer.py b/tests/nexus/test_nxmx_writer.py index aa5538f86..a86d28e8a 100644 --- a/tests/nexus/test_nxmx_writer.py +++ b/tests/nexus/test_nxmx_writer.py @@ -9,12 +9,11 @@ from libtbx.test_utils import approx_equal from dxtbx.format.nexus import h5str +from dxtbx.format.nxmx_writer import NXmxWriter, phil_scope from dxtbx.model.experiment_list import ExperimentListFactory pytest.importorskip("dials") -from dxtbx.format.nxmx_writer import NXmxWriter, phil_scope - def test_writer_jf16M(dials_data, tmpdir): h5path = ( From 1f5e462997772865d9b82b1c57b91328cbd224ce Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 17:04:00 +0100 Subject: [PATCH 06/13] Run import sort --- src/dxtbx/command_line/detector_superpose.py | 7 +++---- src/dxtbx/command_line/image2pickle.py | 4 ++-- src/dxtbx/dxtbx_model_ext.pyi | 6 ++++-- src/dxtbx/format/FormatNexusJungfrauExt.py | 2 +- src/dxtbx/format/FormatPYmultitile.py | 3 +-- src/dxtbx/format/FormatXTCCspad.py | 6 +++--- src/dxtbx/format/FormatXTCEpix.py | 1 + src/dxtbx/format/FormatXTCJungfrau.py | 1 + src/dxtbx/format/FormatXTCRayonix.py | 3 +-- src/dxtbx/format/cbf_writer.py | 2 +- src/dxtbx/format/nxmx_writer.py | 5 ++--- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/dxtbx/command_line/detector_superpose.py b/src/dxtbx/command_line/detector_superpose.py index 67eee579c..e2e6f4ccd 100644 --- a/src/dxtbx/command_line/detector_superpose.py +++ b/src/dxtbx/command_line/detector_superpose.py @@ -3,16 +3,15 @@ import math import sys -from serialtbx.detector import iterate_detector_at_level +import dials.util +from dials.util.options import OptionParser from libtbx.phil import parse from libtbx.test_utils import approx_equal from scitbx.array_family import flex from scitbx.math.superpose import least_squares_fit from scitbx.matrix import col - -import dials.util -from dials.util.options import OptionParser +from serialtbx.detector import iterate_detector_at_level import dxtbx.util from dxtbx.model.experiment_list import ExperimentListFactory diff --git a/src/dxtbx/command_line/image2pickle.py b/src/dxtbx/command_line/image2pickle.py index c3d6d6a38..62838ca42 100644 --- a/src/dxtbx/command_line/image2pickle.py +++ b/src/dxtbx/command_line/image2pickle.py @@ -12,10 +12,10 @@ import sys import numpy as np -import serialtbx.detector.cspad -import serialtbx.util import libtbx.option_parser +import serialtbx.detector.cspad +import serialtbx.util from libtbx import easy_pickle from libtbx.utils import Usage from scitbx.array_family import flex diff --git a/src/dxtbx/dxtbx_model_ext.pyi b/src/dxtbx/dxtbx_model_ext.pyi index b7f7010e8..fac8393b7 100644 --- a/src/dxtbx/dxtbx_model_ext.pyi +++ b/src/dxtbx/dxtbx_model_ext.pyi @@ -22,8 +22,10 @@ from scitbx.array_family import shared as flex_shared # Attempt to use the stub typing for flex-inheritance from scitbx.array_family.flex import FlexPlain -from dxtbx_model_ext import Probe # type: ignore -from dxtbx_model_ext import ExperimentType +from dxtbx_model_ext import ( + ExperimentType, + Probe, # type: ignore +) # TypeVar for the set of Experiment models that can be joint-accepted # - profile, imageset and scalingmodel are handled as 'object' diff --git a/src/dxtbx/format/FormatNexusJungfrauExt.py b/src/dxtbx/format/FormatNexusJungfrauExt.py index a9b2e82d1..55d90e60e 100644 --- a/src/dxtbx/format/FormatNexusJungfrauExt.py +++ b/src/dxtbx/format/FormatNexusJungfrauExt.py @@ -4,9 +4,9 @@ import h5py import numpy as np -from serialtbx.detector.jungfrau import pad_stacked_format from scitbx.array_family import flex +from serialtbx.detector.jungfrau import pad_stacked_format from dxtbx.format.FormatNexus import FormatNexus from dxtbx.format.nexus import h5str diff --git a/src/dxtbx/format/FormatPYmultitile.py b/src/dxtbx/format/FormatPYmultitile.py index fb19e4623..3ff8153d8 100644 --- a/src/dxtbx/format/FormatPYmultitile.py +++ b/src/dxtbx/format/FormatPYmultitile.py @@ -5,10 +5,9 @@ from calendar import timegm from time import strptime -from serialtbx.detector.legacy_metrology.cspad_detector import CSPadDetector - from iotbx.detectors.npy import image_dict_to_unicode from scitbx.matrix import col +from serialtbx.detector.legacy_metrology.cspad_detector import CSPadDetector from dxtbx.format.FormatPY import FormatPY from dxtbx.model import Detector diff --git a/src/dxtbx/format/FormatXTCCspad.py b/src/dxtbx/format/FormatXTCCspad.py index a69a987bf..cb72009f4 100644 --- a/src/dxtbx/format/FormatXTCCspad.py +++ b/src/dxtbx/format/FormatXTCCspad.py @@ -3,14 +3,14 @@ import sys import numpy as np -import serialtbx.detector.cspad -from serialtbx.detector import cspad -from serialtbx.detector.xtc import env_distance +import serialtbx.detector.cspad from cctbx.eltbx import attenuation_coefficient from libtbx.phil import parse from scitbx.array_family import flex from scitbx.matrix import col +from serialtbx.detector import cspad +from serialtbx.detector.xtc import env_distance from dxtbx.format.FormatXTC import FormatXTC, locator_str from dxtbx.model import Detector, ParallaxCorrectedPxMmStrategy diff --git a/src/dxtbx/format/FormatXTCEpix.py b/src/dxtbx/format/FormatXTCEpix.py index f3cae2a10..bea3bcf44 100644 --- a/src/dxtbx/format/FormatXTCEpix.py +++ b/src/dxtbx/format/FormatXTCEpix.py @@ -62,6 +62,7 @@ def get_detector(self, index=None): def _detector(self, index=None): from PSCalib.SegGeometryStore import sgs + from serialtbx.detector.xtc import basis_from_geo run = self.get_run_from_index(index) diff --git a/src/dxtbx/format/FormatXTCJungfrau.py b/src/dxtbx/format/FormatXTCJungfrau.py index 56f8a8f69..7956f57ef 100644 --- a/src/dxtbx/format/FormatXTCJungfrau.py +++ b/src/dxtbx/format/FormatXTCJungfrau.py @@ -102,6 +102,7 @@ def get_detector(self, index=None): def _detector(self, index=None): from PSCalib.SegGeometryStore import sgs + from serialtbx.detector.xtc import basis_from_geo run = self.get_run_from_index(index) diff --git a/src/dxtbx/format/FormatXTCRayonix.py b/src/dxtbx/format/FormatXTCRayonix.py index a85578f37..b2426ffa9 100644 --- a/src/dxtbx/format/FormatXTCRayonix.py +++ b/src/dxtbx/format/FormatXTCRayonix.py @@ -15,10 +15,9 @@ raise psana = None -from serialtbx.detector import rayonix - from libtbx.phil import parse from scitbx.array_family import flex +from serialtbx.detector import rayonix from dxtbx.format.FormatXTC import FormatXTC, locator_str diff --git a/src/dxtbx/format/cbf_writer.py b/src/dxtbx/format/cbf_writer.py index 514d1651e..595538ecd 100644 --- a/src/dxtbx/format/cbf_writer.py +++ b/src/dxtbx/format/cbf_writer.py @@ -13,9 +13,9 @@ import sys import pycbf -from serialtbx.detector import basis from scitbx.array_family import flex +from serialtbx.detector import basis import dxtbx.format.Registry from dxtbx.format.FormatCBFMultiTile import cbf_wrapper diff --git a/src/dxtbx/format/nxmx_writer.py b/src/dxtbx/format/nxmx_writer.py index 88d893493..fa82fedf6 100644 --- a/src/dxtbx/format/nxmx_writer.py +++ b/src/dxtbx/format/nxmx_writer.py @@ -12,7 +12,7 @@ import h5py import numpy as np -from serialtbx.detector import basis +from dials.util.options import ArgumentParser, flatten_experiments from cctbx import factor_ev_angstrom from libtbx import easy_pickle @@ -20,8 +20,7 @@ from libtbx.utils import Sorry from scitbx import matrix from scitbx.array_family import flex - -from dials.util.options import ArgumentParser, flatten_experiments +from serialtbx.detector import basis from dxtbx import flumpy from dxtbx.format.FormatCBFMultiTile import angle_and_axis From 49fdb2511270a51fc30f6376b8b9bad78b6ef4ca Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 17:05:06 +0100 Subject: [PATCH 07/13] Run all ruff fixes (including unsafe, manually checked) --- src/dxtbx/format/Format.py | 2 +- src/dxtbx/format/FormatXTC.py | 4 ++-- src/dxtbx/format/FormatXTCEpix.py | 2 +- src/dxtbx/format/FormatXTCJungfrau.py | 2 +- src/dxtbx/format/FormatXTCMultipleDetectors.py | 6 +++--- src/dxtbx/format/FormatXTCRayonix.py | 2 +- src/dxtbx/format/nxmx_writer.py | 8 ++++---- tests/test_flumpy.py | 2 +- tests/test_regression_images.py | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/dxtbx/format/Format.py b/src/dxtbx/format/Format.py index 7e9f46635..dea10c004 100644 --- a/src/dxtbx/format/Format.py +++ b/src/dxtbx/format/Format.py @@ -148,7 +148,7 @@ def __init__(self, image_file, **kwargs): # Don't allow abstract instantion # - except for Format, which is used as a placeholder in many # places (e.g. still, check_format=False) so needs to be allowed. - if self.is_abstract() and not type(self) is Format: + if self.is_abstract() and type(self) is not Format: raise TypeError( f"Cannot instantiate: Format class '{type(self).__name__}' is marked abstract" ) diff --git a/src/dxtbx/format/FormatXTC.py b/src/dxtbx/format/FormatXTC.py index b73a4da17..624978e8d 100644 --- a/src/dxtbx/format/FormatXTC.py +++ b/src/dxtbx/format/FormatXTC.py @@ -312,11 +312,11 @@ def filter_event(self, evt): codes = self._evr.eventCodes(evt) if self.params.filter.required_present_codes and not all( - [c in codes for c in self.params.filter.required_present_codes] + c in codes for c in self.params.filter.required_present_codes ): return False if self.params.filter.required_absent_codes and any( - [c in codes for c in self.params.filter.required_absent_codes] + c in codes for c in self.params.filter.required_absent_codes ): return False return True diff --git a/src/dxtbx/format/FormatXTCEpix.py b/src/dxtbx/format/FormatXTCEpix.py index bea3bcf44..e5b05af1c 100644 --- a/src/dxtbx/format/FormatXTCEpix.py +++ b/src/dxtbx/format/FormatXTCEpix.py @@ -30,7 +30,7 @@ def understand(image_file): params = FormatXTC.params_from_phil(epix_locator_scope, image_file) except Exception: return False - return any(["epix" in src.lower() for src in params.detector_address]) + return any("epix" in src.lower() for src in params.detector_address) def get_raw_data(self, index=None): if index is None: diff --git a/src/dxtbx/format/FormatXTCJungfrau.py b/src/dxtbx/format/FormatXTCJungfrau.py index 7956f57ef..458502dd0 100644 --- a/src/dxtbx/format/FormatXTCJungfrau.py +++ b/src/dxtbx/format/FormatXTCJungfrau.py @@ -61,7 +61,7 @@ def understand(image_file): params = FormatXTC.params_from_phil(jungfrau_locator_scope, image_file) except Exception: return False - return any(["jungfrau" in src.lower() for src in params.detector_address]) + return any("jungfrau" in src.lower() for src in params.detector_address) def get_raw_data(self, index=None): from serialtbx.detector.util import jungfrau diff --git a/src/dxtbx/format/FormatXTCMultipleDetectors.py b/src/dxtbx/format/FormatXTCMultipleDetectors.py index 9a74c31ae..6f0cc1fb4 100644 --- a/src/dxtbx/format/FormatXTCMultipleDetectors.py +++ b/src/dxtbx/format/FormatXTCMultipleDetectors.py @@ -18,11 +18,11 @@ class FormatXTCMultipleDetectors(FormatXTCRayonix, FormatXTCCspad, FormatXTCJungfrau): def __init__(self, image_file, **kwargs): - if any(["rayonix" in src.lower() for src in self.params.detector_address]): + if any("rayonix" in src.lower() for src in self.params.detector_address): FormatXTCRayonix.__init__(self, image_file, **kwargs) - if any(["cspad" in src.lower() for src in self.params.detector_address]): + if any("cspad" in src.lower() for src in self.params.detector_address): FormatXTCCspad.__init__(self, image_file, **kwargs) - if any(["jungfrau" in src.lower() for src in self.params.detector_address]): + if any("jungfrau" in src.lower() for src in self.params.detector_address): FormatXTCJungfrau.__init__(self, image_file, **kwargs) FormatXTC.__init__( self, image_file, locator_scope=multiple_locator_scope, **kwargs diff --git a/src/dxtbx/format/FormatXTCRayonix.py b/src/dxtbx/format/FormatXTCRayonix.py index b2426ffa9..230aa21e7 100644 --- a/src/dxtbx/format/FormatXTCRayonix.py +++ b/src/dxtbx/format/FormatXTCRayonix.py @@ -67,7 +67,7 @@ def understand(image_file): params = FormatXTC.params_from_phil(rayonix_locator_scope, image_file) except Exception: return False - return any(["rayonix" in src.lower() for src in params.detector_address]) + return any("rayonix" in src.lower() for src in params.detector_address) def get_raw_data(self, index=None): if index is None: diff --git a/src/dxtbx/format/nxmx_writer.py b/src/dxtbx/format/nxmx_writer.py index fa82fedf6..0c1768b77 100644 --- a/src/dxtbx/format/nxmx_writer.py +++ b/src/dxtbx/format/nxmx_writer.py @@ -363,8 +363,8 @@ def recursive_setup_basis_dict(key, parent_name="", panel_id=0): det["description"] = "Detector converted from DIALS models" det["depends_on"] = "/entry/instrument/detector/transformations/AXIS_RAIL" det["gain_setting"] = "auto" - assert len(set([p.get_material() for p in detector])) == 1 - assert len(set([p.get_thickness() for p in detector])) == 1 + assert len({p.get_material() for p in detector}) == 1 + assert len({p.get_thickness() for p in detector}) == 1 det["sensor_material"] = detector[0].get_material() self._create_scalar( det, "sensor_thickness", "f", detector[0].get_thickness() * 1000 @@ -395,7 +395,7 @@ def recursive_setup_basis_dict(key, parent_name="", panel_id=0): transformations.attrs["NX_class"] = "NXtransformations" if self.params.trusted_range is None: - assert len(set([p.get_trusted_range() for p in detector])) == 1 + assert len({p.get_trusted_range() for p in detector}) == 1 trusted_min, trusted_max = detector[0].get_trusted_range() else: trusted_min, trusted_max = self.params.trusted_range @@ -666,7 +666,7 @@ def append_frame(self, index=None, data=None): data = (data,) if len(data) > 1: - assert len(set([d.focus() for d in data])) == 1 + assert len({d.focus() for d in data}) == 1 shape = len(data), data[0].focus()[0], data[0].focus()[1] else: shape = data[0].focus()[0], data[0].focus()[1] diff --git a/tests/test_flumpy.py b/tests/test_flumpy.py index 88ef9f8cc..a8d996519 100644 --- a/tests/test_flumpy.py +++ b/tests/test_flumpy.py @@ -338,7 +338,7 @@ def test_flex_looping_vecs(): # Don't be dumb when casting flex_nonvec = flex.double((9, 3)) - assert not flumpy.vec_from_numpy(flumpy.to_numpy(flex_nonvec)) is flex_nonvec + assert flumpy.vec_from_numpy(flumpy.to_numpy(flex_nonvec)) is not flex_nonvec # mat3 fo = flex.mat3_double(5) diff --git a/tests/test_regression_images.py b/tests/test_regression_images.py index 40e560af8..dbf5634e2 100644 --- a/tests/test_regression_images.py +++ b/tests/test_regression_images.py @@ -270,7 +270,7 @@ def recurse(parentformat, filename, level=0): multiple_formats = False for subformat in dag.get(parentformat, []): format_class = dxtbx.format.Registry.get_format_class_for(subformat) - if not get_url_scheme(filename) in format_class.schemes: + if get_url_scheme(filename) not in format_class.schemes: print("Not matching ", filename, "to", format_class) continue understood = format_class.understand(filename) From 0a623811e2f489ef89305a2801fdcf4c8ab91427 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 17:08:04 +0100 Subject: [PATCH 08/13] News --- newsfragments/XXX.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/XXX.misc diff --git a/newsfragments/XXX.misc b/newsfragments/XXX.misc new file mode 100644 index 000000000..b9cf26fa1 --- /dev/null +++ b/newsfragments/XXX.misc @@ -0,0 +1 @@ +Switch linting/formatting to ruff. From fc68b6ed8b2daade1eb8ca4a83542443ca3a70b0 Mon Sep 17 00:00:00 2001 From: DiamondLightSource-build-server Date: Thu, 6 Jun 2024 16:08:29 +0000 Subject: [PATCH 09/13] Rename newsfragments/XXX.misc to newsfragments/738.misc --- newsfragments/{XXX.misc => 738.misc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename newsfragments/{XXX.misc => 738.misc} (100%) diff --git a/newsfragments/XXX.misc b/newsfragments/738.misc similarity index 100% rename from newsfragments/XXX.misc rename to newsfragments/738.misc From 39032fb132a9c5070ce335bf19fabd3d6f31ea59 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 17:23:28 +0100 Subject: [PATCH 10/13] Autoupdate pre-commits Except clang-format, will do separately. --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55a1b5f0b..2024e7323 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: # Syntax validation and some basic sanity checks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-merge-conflict - id: check-ast @@ -15,7 +15,7 @@ repos: name: "Don't commit to 'main' directly" - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.3.4 + rev: v0.4.8 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] From 211a2ba237860f3ce4f7bf8182e686f68f0bf2df Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 6 Jun 2024 17:29:11 +0100 Subject: [PATCH 11/13] Eliminate remaining mentions --- .azure-pipelines/azure-pipelines.yml | 2 +- CONTRIBUTING.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index fb5f86cdd..b10f478af 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -38,7 +38,7 @@ stages: pip install ruff cd repository python .azure-pipelines/lint-validation.py - displayName: Flake8 validation + displayName: Ruff validation # Set up constants for further build steps - bash: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 960a7ade1..e4f078401 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,7 +96,7 @@ message that the code in question is special and care should be taken. - **Please install the pre-commit hooks**. (`libtbx.precommit install` if using the libtbx ecosystem). These use the [pre-commit] library and ensure that various sanity checks are run before commit, including formatting, syntax - compatibility, basic flake8 checks, lack of conflict markers and file size + compatibility, basic Ruff checks, lack of conflict markers and file size limits. Basically, most of the essential rules will be checked automatically by this. - **We format python code with [black]**. This means that while writing code @@ -106,13 +106,13 @@ message that the code in question is special and care should be taken. you can't, the whole codebase is auto-cleaned once a week. Most IDEs and editors have support for running formatters like black frequently or automatically. -- **Avoid introducing new pre-commit flake8 warnings** - if you feel that it's +- **Avoid introducing new pre-commit Ruff warnings** - if you feel that it's appropriate to violate a warning, mark it up explicitly with a [noqa] comment. Probably the most common cause of this are "F401 - module imported or unused", which happens when importing packages to collect into a single namespace for other imports (though declaring `__all__` avoids this issue). The pre-commit hooks will pick up the most important of these, but please try - to resolve any other valid warnings shown with a normal run of flake8. The + to resolve any other valid warnings shown with a normal run of Ruff. The configuration in the repository turns off any that disagree with black's interpretation of the rules or standard practice in our repositories. - **We format C++ code with [clang-format]**. We use a configuration for style @@ -125,7 +125,7 @@ message that the code in question is special and care should be taken. [pre-commit]: https://github.com/pre-commit/pre-commit [black]: https://github.com/python/black [clang-format]: https://clang.llvm.org/docs/ClangFormat.html -[noqa]: http://flake8.pycqa.org/en/3.7.7/user/violations.html#in-line-ignoring-errors +[noqa]: http://Ruff.pycqa.org/en/3.7.7/user/violations.html#in-line-ignoring-errors [PEP8]: https://www.python.org/dev/peps/pep-0008 [Google-style]: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html [Zen of Python]: https://www.python.org/dev/peps/pep-0020/#the-zen-of-python From 13cc8314f6634516c8fabfd96012e96ff68181bc Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Fri, 7 Jun 2024 08:41:23 +0100 Subject: [PATCH 12/13] Fix remaining flake8 references --- .azure-pipelines/lint-validation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.azure-pipelines/lint-validation.py b/.azure-pipelines/lint-validation.py index 4cfbad234..ad57bc75b 100644 --- a/.azure-pipelines/lint-validation.py +++ b/.azure-pipelines/lint-validation.py @@ -5,7 +5,7 @@ failures = 0 try: - flake8 = subprocess.run( + process = subprocess.run( [ "ruff", "check", @@ -18,14 +18,14 @@ ) except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e: print( - "##vso[task.logissue type=error;]flake8 validation failed with", + "##vso[task.logissue type=error;]Ruff validation failed with", str(e.__class__.__name__), ) print(e.stdout) print(e.stderr) - print("##vso[task.complete result=Failed;]flake8 validation failed") + print("##vso[task.complete result=Failed;]Ruff validation failed") exit() -for line in flake8.stdout.split("\n"): +for line in process.stdout.split("\n"): if ":" not in line: continue filename, lineno, column, error = line.split(":", maxsplit=3) @@ -38,5 +38,5 @@ ) if failures: - print(f"##vso[task.logissue type=warning]Found {failures} flake8 violation(s)") - print(f"##vso[task.complete result=Failed;]Found {failures} flake8 violation(s)") + print(f"##vso[task.logissue type=warning]Found {failures} Ruff violation(s)") + print(f"##vso[task.complete result=Failed;]Found {failures} Ruff violation(s)") From a261b394bfd8493a9ba73a9c2fa7c3b1903eabfc Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Fri, 7 Jun 2024 10:24:17 +0100 Subject: [PATCH 13/13] Fix importorskip before the dials-importing dependency --- tests/nexus/test_nxmx_writer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/nexus/test_nxmx_writer.py b/tests/nexus/test_nxmx_writer.py index a86d28e8a..c70adf223 100644 --- a/tests/nexus/test_nxmx_writer.py +++ b/tests/nexus/test_nxmx_writer.py @@ -9,11 +9,12 @@ from libtbx.test_utils import approx_equal from dxtbx.format.nexus import h5str -from dxtbx.format.nxmx_writer import NXmxWriter, phil_scope from dxtbx.model.experiment_list import ExperimentListFactory pytest.importorskip("dials") +from dxtbx.format.nxmx_writer import NXmxWriter, phil_scope # noqa: E402 + def test_writer_jf16M(dials_data, tmpdir): h5path = (