Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
python: ["3.12"]
python: ["3.12", "3.13"]
install: ["-e .[dev]"]
# Make one version be non-editable to test both paths of version code
include:
Expand Down
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
repos:

# Automatic source code formatting
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
args: [--safe, --quiet]


# Linter
- repo: local
hooks:
- id: ruff
name: Run ruff
stages: [pre-commit]
name: lint with ruff
language: system
entry: ruff check --force-exclude --fix
types: [python]
require_serial: true

- id: ruff-format
name: format with ruff
language: system
entry: ruff check
entry: ruff format --force-exclude
types: [python]
require_serial: true


# Other syntax checks
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ classifiers = [
"Natural Language :: English",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
keywords = ["nexus", "NXmx"]
dependencies = [
Expand Down
3 changes: 0 additions & 3 deletions src/nexgen/command_line/ED_mrc_to_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ def overwrite_from_command_line(


def log_dict(logger: Logger, dictionary: dict, skip: list = None) -> None:

if skip is None:
skip = [1]

Expand All @@ -366,7 +365,6 @@ def log_dict(logger: Logger, dictionary: dict, skip: list = None) -> None:


def main():

args = parse_input_arguments()
metadata_template = Metadata(args.input_files)
logger.info("Starting MRC to Nexus conversion.")
Expand Down Expand Up @@ -478,7 +476,6 @@ def main():


def parse_input_arguments():

msg = "Convert electron diffraction data from an MRC format "
msg += "to a NeXus format"
parser = ArgumentParser(description=msg, add_help=True)
Expand Down
3 changes: 1 addition & 2 deletions src/nexgen/command_line/ED_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


def write_from_SINGLA(args):

singla_nexus_writer(
args.master_file,
args.det_distance,
Expand Down Expand Up @@ -60,7 +59,7 @@ def write_from_SINGLA_from_config(args):
)
ED_coord_system["convention"] = params.coord_system.convention
else:
logger.info("The following convention will be applied:\n" f"{ED_coord_system}")
logger.info(f"The following convention will be applied:\n{ED_coord_system}")

if params.coord_system.origin:
logger.info(
Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/command_line/I19_2_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def nexgen_writer(args):
help="Data entry key of dataset in raw .h5 file. Defaults to data.",
)
parser_nex.add_argument(
"-bits" "--bit-depth",
"-bits--bit-depth",
type=int,
choices=[8, 16, 32],
default=32,
Expand Down
3 changes: 2 additions & 1 deletion src/nexgen/command_line/nexus_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ def _parse_cli() -> argparse.ArgumentParser:
help="Data entry key of dataset in raw .h5 file. Defaults to data.",
)
nxmx_parser.add_argument(
"-bits" "--bit-depth",
"-bits",
"--bit-depth",
type=int,
choices=[8, 16, 32],
default=32,
Expand Down
12 changes: 8 additions & 4 deletions src/nexgen/nxs_copy/copy_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def images_nexus(
original_nexus = Path(original_nexus).expanduser().resolve()
nxs_filename = get_nexus_filename(data_file[0], copy=True)
copy_logger.debug(f"New NeXus file name: {nxs_filename}")
with h5py.File(original_nexus, "r") as nxs_in, h5py.File(nxs_filename, "x") as nxs_out:
with (
h5py.File(original_nexus, "r") as nxs_in,
h5py.File(nxs_filename, "x") as nxs_out,
):
if simple_copy is True:
# Copy the whole tree
get_nexus_tree(nxs_in, nxs_out, skip=False)
Expand Down Expand Up @@ -92,9 +95,10 @@ def pseudo_events_nexus(
original_nexus = Path(original_nexus).expanduser().resolve()
nxs_filename = get_nexus_filename(data_file[0], copy=True)
copy_logger.debug(f"New NeXus file name: {nxs_filename}")
with h5py.File(original_nexus, "r") as nxs_in, h5py.File(
nxs_filename, "x"
) as nxs_out:
with (
h5py.File(original_nexus, "r") as nxs_in,
h5py.File(nxs_filename, "x") as nxs_out,
):
nxs_out.attrs["default"] = "entry"
# Copy the whole tree except for nxdata
nxentry = get_nexus_tree(nxs_in, nxs_out)
Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/nxs_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"TransformationType",
"Facility",
"CetaDetector",
"TVIPSDetector"
"TVIPSDetector",
]
3 changes: 1 addition & 2 deletions src/nexgen/nxs_write/write_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def mask_and_flatfield_writer_for_event_data(
)
else:
NXclassUtils_logger.warning(
f"No {dset_name} file found in working directory."
"Writing an ExternalLink."
f"No {dset_name} file found in working directory.Writing an ExternalLink."
)
file_loc = Path(dset_data_file)
image_key = "image" if "tristan" in detector_name.lower() else "/"
Expand Down
18 changes: 7 additions & 11 deletions src/nexgen/tools/data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def build_an_eiger(
for i in range(1, n_modules[0] + 1):
IM[
:,
i * eiger_mod_size[1]
+ (i - 1) * eiger_gap_size[1] : i * (eiger_mod_size[1] + eiger_gap_size[1]),
i * eiger_mod_size[1] + (i - 1) * eiger_gap_size[1] : i
* (eiger_mod_size[1] + eiger_gap_size[1]),
] = 65535
# Vertical modules
for j in range(1, n_modules[1] + 1):
IM[
j * eiger_mod_size[0]
+ (j - 1) * eiger_gap_size[0] : j * (eiger_mod_size[0] + eiger_gap_size[0]),
j * eiger_mod_size[0] + (j - 1) * eiger_gap_size[0] : j
* (eiger_mod_size[0] + eiger_gap_size[0]),
:,
] = 65535

Expand Down Expand Up @@ -104,17 +104,13 @@ def build_a_tristan(
for i in range(1, n_modules[0] + 1):
IM[
:,
i * tristan_mod_size[1]
+ (i - 1)
* tristan_gap_size[1] : i
i * tristan_mod_size[1] + (i - 1) * tristan_gap_size[1] : i
* (tristan_mod_size[1] + tristan_gap_size[1]),
] = 65535
# Vertical modules
for j in range(1, n_modules[1] + 1):
IM[
j * tristan_mod_size[0]
+ (j - 1)
* tristan_gap_size[0] : j
j * tristan_mod_size[0] + (j - 1) * tristan_gap_size[0] : j
* (tristan_mod_size[0] + tristan_gap_size[0]),
:,
] = 65535
Expand Down Expand Up @@ -268,7 +264,7 @@ def generate_event_files(
)
EV_dict[(i, j)] = pseudo_event_list(I, J, exp_time)
t1 = time.process_time()
data_logger.info(f"Time taken to generate pseudo-event list: {t1-t0:.2f} s.")
data_logger.info(f"Time taken to generate pseudo-event list: {t1 - t0:.2f} s.")

# Find total number of events to be written to file
num_events = tristan_chunk * num_chunks
Expand Down
5 changes: 1 addition & 4 deletions src/nexgen/tools/mrc_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Helper functions for the MRC to Nexus converter """
"""Helper functions for the MRC to Nexus converter"""

import logging
import os
Expand Down Expand Up @@ -198,9 +198,7 @@ def to_hdf5_data_file(

# Input is a single MRC file with a stack of images
if (len(data_shape) == 3) and (n == 1):

with h5py.File(out_file, "w") as hdf5_file:

mrc = mrcfile.open(files[0], mode="r")

bs = hdf5plugin.Bitshuffle
Expand Down Expand Up @@ -234,7 +232,6 @@ def to_hdf5_data_file(

# Input is a list of MRC files containing single images
elif (len(data_shape) == 2) and (n >= 1):

with h5py.File(out_file, "w") as hdf5_file:
dataset_shape = (n, data_shape[0], data_shape[1])
dataset = hdf5_file.create_dataset(
Expand Down
4 changes: 0 additions & 4 deletions tests/tools/test_mrc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@


def test_cal_wavelength():

a = 0.025082356047905176
epsilon = 1.0e-15
assert abs(cal_wavelength(200000) - a) < epsilon


def test_get_metadata():

make_mrc_file("images.mrc")
h = get_metadata("images.mrc")
assert isinstance(h, dict)
Expand All @@ -26,7 +24,6 @@ def test_get_metadata():


def test_collect_data():

make_mrc_file("images_00001.mrc")
make_mrc_file("images_00002.mrc")

Expand All @@ -41,7 +38,6 @@ def test_collect_data():


def make_mrc_file(filename):

images = np.zeros((1, 1), dtype=np.int16)

with mrcfile.new(filename, overwrite=True) as mrc:
Expand Down
Loading