Skip to content

Commit

Permalink
Run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
ndevenish committed Jun 6, 2024
1 parent 9a1b6f9 commit 997d8aa
Show file tree
Hide file tree
Showing 70 changed files with 46 additions and 153 deletions.
4 changes: 1 addition & 3 deletions .azure-pipelines/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions src/dxtbx/command_line/detector_superpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/dxtbx/command_line/plot_detector_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/command_line/read_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


def read_sequence(images: list[str]):

sequences = ImageSetFactory.new(images)

for sequence in sequences:
Expand Down
2 changes: 0 additions & 2 deletions src/dxtbx/dxtbx_imageset_ext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
2 changes: 0 additions & 2 deletions src/dxtbx/example/to_xds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
classes.
"""


from __future__ import annotations

import math
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions src/dxtbx/format/Format.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ def get_imageset(

# Create an imageset or sequence
if not is_sequence:

# Create the imageset
iset = ImageSet(
ImageSetData(
Expand All @@ -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 = []
Expand All @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatBruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions src/dxtbx/format/FormatBrukerED1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class FormatBrukerED1(FormatBruker):
@staticmethod
def understand(image_file):

try:
header_lines = FormatBruker.read_header_lines(image_file)
except OSError:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions src/dxtbx/format/FormatBrukerFixedChi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions src/dxtbx/format/FormatBrukerPhoton.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class FormatBrukerPhoton(FormatBruker):
@staticmethod
def understand(image_file):

try:
header_lines = FormatBruker.read_header_lines(image_file)
except OSError:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions src/dxtbx/format/FormatCBFMiniADSCHF4M.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"):
Expand Down Expand Up @@ -151,7 +149,6 @@ def _scan(self):
)

def detectorbase_start(self):

self.detectorbase = ADSCHF4MImage(self._image_file)
self.detectorbase.readHeader()

Expand Down
2 changes: 0 additions & 2 deletions src/dxtbx/format/FormatCBFMiniEigerPhotonFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def _goniometer(self):
)

def _detector(self):

max_trusted_value = 1e7

if "_lower_" in self._image_file:
Expand Down Expand Up @@ -118,7 +117,6 @@ def _scan(self):
)

def detectorbase_start(self):

self.detectorbase = PilatusImage(self._image_file)
self.detectorbase.readHeader()

Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatCBFMiniEigerQuadroED1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatCBFMiniPilatusDLS12M.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatCBFMiniPilatusHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/dxtbx/format/FormatCBFMultiTileHierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions src/dxtbx/format/FormatGatanDM4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -230,7 +229,6 @@ class FormatGatanDM4(Format):

@staticmethod
def understand(image_file):

try:
header = FormatGatanDM4._read_header(image_file)
except struct.error:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class FormatHDF5ESRFJungfrau4M(FormatHDF5):

# A class to understand still-shot images from ESRF collected on a Jungfrau 4M.

_cached_mask = None
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatHDF5SaclaMPCCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 0 additions & 2 deletions src/dxtbx/format/FormatISISSXD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions src/dxtbx/format/FormatMANDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions src/dxtbx/format/FormatMRC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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"))
Expand Down
Loading

0 comments on commit 997d8aa

Please sign in to comment.