Skip to content

Commit

Permalink
Run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Dec 6, 2023
1 parent 29dc13d commit 84885bd
Show file tree
Hide file tree
Showing 34 changed files with 180 additions and 109 deletions.
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import os
import sys

import sphinx_rtd_theme # noqa; F401 - install theme

import nexgen

sys.path.insert(0, os.path.abspath(".."))
Expand Down
12 changes: 7 additions & 5 deletions src/nexgen/beamlines/ED_singla_nxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
from ..nxs_utils.ScanUtils import calculate_scan_points
from ..nxs_write.NXmxWriter import EDNXmxFileWriter
from ..nxs_write.write_utils import find_number_of_images
from ..tools.ED_tools import (extract_detector_info_from_master,
extract_exposure_time_from_master,
extract_start_time_from_master, find_beam_centre)
from ..utils import (coerce_to_path, find_in_dict, get_iso_timestamp,
get_nexus_filename)
from ..tools.ED_tools import (
extract_detector_info_from_master,
extract_exposure_time_from_master,
extract_start_time_from_master,
find_beam_centre,
)
from ..utils import coerce_to_path, find_in_dict, get_iso_timestamp, get_nexus_filename
from .ED_params import ED_coord_system, EDSingla, EDSource

logger = logging.getLogger("nexgen.EDNeXusWriter")
Expand Down
4 changes: 2 additions & 2 deletions src/nexgen/beamlines/GDAtools/GDAjson2params.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_goniometer_axes_from_file(self) -> List[Axis]:
"""Read the axes information from the GDA-supplied json file."""
axes_list = []
for v in self.params.values():
if type(v) is dict and v["location"] == "sample":
if isinstance(v, dict) and v["location"] == "sample":
ax_depends = self._find_axis_depends_on(v["depends_on"])
ax_type = (
TransformationType.ROTATION
Expand All @@ -54,7 +54,7 @@ def get_detector_axes_from_file(self) -> List[Axis]:
"""Read the detector axes information from the GDA-supplied json file."""
axes_list = []
for v in self.params.values():
if type(v) is dict and v["location"] == "detector":
if isinstance(v, dict) and v["location"] == "detector":
ax_type = (
TransformationType.ROTATION
if v["type"] == "rotation"
Expand Down
19 changes: 14 additions & 5 deletions src/nexgen/beamlines/I19_2_gda_nxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
from numpy.typing import DTypeLike

from .. import log
from ..nxs_utils import (Attenuator, Beam, Detector, EigerDetector, Goniometer,
Source, TristanDetector)
from ..nxs_utils import (
Attenuator,
Beam,
Detector,
EigerDetector,
Goniometer,
Source,
TristanDetector,
)
from ..nxs_utils.Detector import DetectorType, UnknownDetectorTypeError
from ..nxs_utils.ScanUtils import calculate_scan_points
from ..nxs_write.NXmxWriter import EventNXmxFileWriter, NXmxFileWriter
from ..utils import get_iso_timestamp, get_nexus_filename
from .beamline_utils import BeamlineAxes, collection_summary_log
from .GDAtools.ExtendedRequest import (ExtendedRequestIO,
read_det_position_from_xml,
read_scan_from_xml)
from .GDAtools.ExtendedRequest import (
ExtendedRequestIO,
read_det_position_from_xml,
read_scan_from_xml,
)
from .GDAtools.GDAjson2params import JSONParamsIO

# Define a logger object and a formatter
Expand Down
11 changes: 9 additions & 2 deletions src/nexgen/beamlines/I19_2_nxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
import numpy as np

from .. import log
from ..nxs_utils import (Attenuator, Beam, Detector, EigerDetector, Goniometer,
Source, TristanDetector)
from ..nxs_utils import (
Attenuator,
Beam,
Detector,
EigerDetector,
Goniometer,
Source,
TristanDetector,
)
from ..nxs_utils.ScanUtils import calculate_scan_points, identify_osc_axis
from ..nxs_write.NXmxWriter import EventNXmxFileWriter, NXmxFileWriter
from ..tools.Metafile import DectrisMetafile
Expand Down
3 changes: 1 addition & 2 deletions src/nexgen/beamlines/SSX_Eiger_nxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import h5py

from .. import log
from ..nxs_utils import (Attenuator, Beam, Detector, EigerDetector, Goniometer,
Source)
from ..nxs_utils import Attenuator, Beam, Detector, EigerDetector, Goniometer, Source
from ..nxs_write.NXmxWriter import NXmxFileWriter
from ..tools.Metafile import DectrisMetafile
from ..tools.MetaReader import define_vds_data_type, update_axes_from_meta
Expand Down
3 changes: 1 addition & 2 deletions src/nexgen/beamlines/SSX_Tristan_nxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from pathlib import Path

from .. import log
from ..nxs_utils import (Attenuator, Beam, Detector, Goniometer, Source,
TristanDetector)
from ..nxs_utils import Attenuator, Beam, Detector, Goniometer, Source, TristanDetector
from ..nxs_write.NXmxWriter import EventNXmxFileWriter
from ..utils import Point3D, find_in_dict, get_iso_timestamp
from .beamline_utils import collection_summary_log
Expand Down
3 changes: 1 addition & 2 deletions src/nexgen/beamlines/SSX_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"""
from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Dict, List, Tuple

from dataclasses import dataclass, field

from ..nxs_utils.ScanUtils import ScanDirection

# I24 chip tools
Expand Down
8 changes: 6 additions & 2 deletions src/nexgen/beamlines/SSX_expt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
from ..nxs_utils import Axis, TransformationType
from ..nxs_utils.ScanUtils import calculate_scan_points
from .beamline_utils import PumpProbe
from .SSX_chip import (Chip, compute_goniometer, fullchip_blocks_conversion,
read_chip_map)
from .SSX_chip import (
Chip,
compute_goniometer,
fullchip_blocks_conversion,
read_chip_map,
)

__all__ = ["run_extruder", "run_fixed_target", "run_3D_grid_scan"]

Expand Down
6 changes: 3 additions & 3 deletions src/nexgen/beamlines/beamline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from __future__ import annotations

import logging
from dataclasses import dataclass
from typing import List, Optional, Tuple

from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin
from nexgen.nxs_utils import (Attenuator, Axis, Beam, Detector, Goniometer,
Source)

from nexgen.nxs_utils import Attenuator, Axis, Beam, Detector, Goniometer, Source
from nexgen.utils import Point3D


Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/command_line/ED_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

import freephil

from . import config_parser, nexus_parser, version_parser
from .. import log
from ..beamlines.ED_params import ED_coord_system
from ..beamlines.ED_singla_nxs import singla_nexus_writer
from ..nxs_utils import Axis, TransformationType
from . import config_parser, nexus_parser, version_parser

logger = logging.getLogger("nexgen.EDNeXusGeneratorCLI")

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 @@ -8,8 +8,8 @@
from collections import namedtuple
from datetime import datetime

from . import version_parser
from .. import log
from . import version_parser

logger = logging.getLogger("nexgen.I19-2_NeXus_cli")

Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/command_line/SSX_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from pathlib import Path
from typing import Tuple

from . import version_parser
from .. import log
from ..beamlines.SSX_chip import CHIP_DICT_DEFAULT
from ..utils import P
from . import version_parser

logger = logging.getLogger("nexgen.SSX_cli")

Expand Down
29 changes: 17 additions & 12 deletions src/nexgen/command_line/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
from scanspec.core import Path as ScanPath
from scanspec.specs import Line

from ..nxs_write.NXclassWriters import (write_NXdata, write_NXdatetime,
write_NXdetector,
write_NXdetector_module, write_NXentry,
write_NXinstrument, write_NXnote,
write_NXsample, write_NXsource)
from ..nxs_write.NXclassWriters import (
write_NXdata,
write_NXdatetime,
write_NXdetector,
write_NXdetector_module,
write_NXentry,
write_NXinstrument,
write_NXnote,
write_NXsample,
write_NXsource,
)
from ..nxs_write.write_utils import find_number_of_images
from ..tools.DataWriter import generate_event_files, generate_image_files
from ..tools.MetaReader import overwrite_beam, overwrite_detector
from ..tools.VDS_tools import image_vds_writer, vds_file_writer
from ..utils import (coord2mcstas, get_filename_template, imgcif2mcstas,
units_of_time)
from ..utils import coord2mcstas, get_filename_template, imgcif2mcstas, units_of_time


def split_arrays(axes_names: List, array: List) -> Dict[str, Tuple]:
Expand Down Expand Up @@ -280,9 +285,9 @@ def calculate_scan_range(
Dict[str, ArrayLike]: A dictionary of ("axis_name": axis_range) key-value pairs.
"""
if (
type(axes_names) is not list
or type(axes_starts) is not list
or type(axes_ends) is not list
not isinstance(axes_names, list)
or not isinstance(axes_starts, list)
or not isinstance(axes_ends, list)
):
raise TypeError("Input values for axes must be passed as lists.")

Expand Down Expand Up @@ -411,7 +416,7 @@ def ScanReader(
transl_start = [goniometer["starts"][i] for i in transl_idx]
transl_end = [goniometer["ends"][i] for i in transl_idx]
transl_increment = [goniometer["increments"][i] for i in transl_idx]
if n_images and type(n_images) is int:
if n_images and isinstance(n_images, int):
TRANSL = calculate_scan_range(
transl_axes,
transl_start,
Expand Down Expand Up @@ -545,7 +550,7 @@ def call_writers(
datafiles = [Path(f).expanduser().resolve() for f in datafiles]

if metafile:
if type(metafile) is str:
if isinstance(metafile, str):
metafile = Path(metafile).expanduser().resolve()

# NXdata: entry/data
Expand Down
3 changes: 1 addition & 2 deletions src/nexgen/command_line/copy_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import freephil

from . import (config_parser, full_copy_parser, tristan_copy_parser,
version_parser)
from .. import log
from ..nxs_copy import CopyNexus, CopyTristanNexus
from . import config_parser, full_copy_parser, tristan_copy_parser, version_parser

# Define a logger object and a formatter
logger = logging.getLogger("nexgen.CopyNeXus")
Expand Down
28 changes: 20 additions & 8 deletions src/nexgen/command_line/nexus_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@
import h5py
import numpy as np

from . import (add_tristan_spec, config_parser, demo_parser,
detectormode_parser, nexus_parser, phil2dict, version_parser)
from .. import log
from ..nxs_write.NXclassWriters import (write_NXdatetime, write_NXentry,
write_NXnote)
from ..nxs_write.NXclassWriters import write_NXdatetime, write_NXentry, write_NXnote
from ..tools.DataWriter import generate_event_files, generate_image_files
from ..tools.MetaReader import overwrite_beam, overwrite_detector
from ..tools.VDS_tools import image_vds_writer, vds_file_writer
from ..utils import (get_filename_template, get_iso_timestamp,
get_nexus_filename, units_of_time)
from .cli_utils import ScanReader # write_nexus_demo, write_nexus
from .cli_utils import call_writers
from ..utils import (
get_filename_template,
get_iso_timestamp,
get_nexus_filename,
units_of_time,
)
from . import (
add_tristan_spec,
config_parser,
demo_parser,
detectormode_parser,
nexus_parser,
phil2dict,
version_parser,
)
from .cli_utils import (
ScanReader, # write_nexus_demo, write_nexus
call_writers,
)

# Define a logger object
logger = logging.getLogger("nexgen.NeXusGenerator")
Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/command_line/phil_files_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import freephil

from . import config_parser, nexus_parser, version_parser
from .. import log, templates
from . import config_parser, nexus_parser, version_parser

try:
from importlib.resources import files
Expand Down
10 changes: 7 additions & 3 deletions src/nexgen/nxs_copy/CopyTristanNexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@

from ..nxs_write.NXclassWriters import write_NXnote
from ..nxs_write.write_utils import create_attributes
from .copy_utils import (check_and_fix_det_axis, compute_ssx_axes,
convert_scan_axis, get_nexus_tree,
identify_tristan_scan_axis)
from .copy_utils import (
check_and_fix_det_axis,
compute_ssx_axes,
convert_scan_axis,
get_nexus_tree,
identify_tristan_scan_axis,
)

tristan_logger = logging.getLogger("nexgen.CopyTristanNeXus")

Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/nxs_copy/copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def convert_scan_axis(nxsample: h5py.Group, nxdata: h5py.Group, ax: str):
def check_and_fix_det_axis(nxs_in: h5py.File):
det_z_grp = nxs_in["/entry/instrument/detector/transformations/detector_z"]
det_z = det_z_grp["det_z"]
if type(det_z[()]) is bytes or type(det_z[()]) is str:
if isinstance(det_z[()], bytes) or isinstance(det_z[()], str):
det_z_attrs = {}
for k, v in det_z.attrs.items():
det_z_attrs[k] = v
Expand Down
3 changes: 1 addition & 2 deletions src/nexgen/nxs_utils/Axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"""
from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Tuple

from dataclasses import dataclass

from ..utils import Point3D


Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/nxs_utils/Detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Dict, List, Literal, Tuple, Union

from dataclasses import dataclass, field
from dataclasses_json import DataClassJsonMixin

from ..utils import Point3D
Expand Down
9 changes: 7 additions & 2 deletions src/nexgen/nxs_utils/Goniometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
from numpy.typing import ArrayLike

from .Axes import Axis
from .ScanUtils import (GridScanOptions, ScanDirection, calculate_scan_points,
identify_grid_scan_axes, identify_osc_axis)
from .ScanUtils import (
GridScanOptions,
ScanDirection,
calculate_scan_points,
identify_grid_scan_axes,
identify_osc_axis,
)


class Goniometer:
Expand Down
1 change: 1 addition & 0 deletions src/nexgen/nxs_utils/Sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

from dataclasses import dataclass

from dataclasses_json import DataClassJsonMixin


Expand Down
2 changes: 1 addition & 1 deletion src/nexgen/nxs_utils/Source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from __future__ import annotations

from collections import namedtuple

from dataclasses import dataclass

from dataclasses_json import DataClassJsonMixin

# Describe facility
Expand Down
Loading

0 comments on commit 84885bd

Please sign in to comment.