Skip to content

Commit dd77aa3

Browse files
authored
Update pre-commit hooks and run formatter on all files (#129)
1 parent 77cf8ca commit dd77aa3

17 files changed

+42
-47
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
# - id: check-json
1818
# - id: check-added-large-files
1919
- repo: https://github.com/stefsmeets/nbcheckorder/
20-
rev: v0.2.0
20+
rev: v0.3.0
2121
hooks:
2222
- id: nbcheckorder
2323
# This notebook is not executed at all, which fails the check
@@ -26,11 +26,11 @@ repos:
2626
docs/examples/montage_processing.ipynb
2727
)$
2828
- repo: https://github.com/myint/docformatter
29-
rev: master # https://github.com/PyCQA/docformatter/issues/293
29+
rev: 'v1.7.7'
3030
hooks:
3131
- id: docformatter
3232
- repo: https://github.com/charliermarsh/ruff-pre-commit
33-
rev: 'v0.7.0'
33+
rev: 'v0.11.10'
3434
hooks:
3535
- id: ruff
3636
args: [--fix]

scripts/process_tvips.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def img_convert(credlog, tiff_path=None, pets_path='PETS', mrc_path='RED', smv_p
140140
print('# TVIPS header')
141141
print(f'Camera: {camera}')
142142
print(f'Acquisition time: {acquisition_time:.3f} s')
143-
print(f'Exposure time: {exposure_time/1000:.3f} s')
143+
print(f'Exposure time: {exposure_time / 1000:.3f} s')
144144
print(f'Overhead time: {overhead:.3f} s')
145145
print(f'Binning (X/Y): {binning_x} {binning_y} px/bin')
146146
print(f'Image resolution (X/Y): {image_res_x_tvips} {image_res_y_tvips} pixels')
@@ -150,15 +150,15 @@ def img_convert(credlog, tiff_path=None, pets_path='PETS', mrc_path='RED', smv_p
150150
print(
151151
f'Physical pixelsize (X/Y): {physical_pixelsize_x_tvips} {physical_pixelsize_y_tvips} μm'
152152
)
153-
print(f'High tension: {high_tension/1000} kV')
153+
print(f'High tension: {high_tension / 1000} kV')
154154
print(f'Wavelength: {wavelength_tvips} Ångstrom')
155155
print(f'Camera length: {camera_length_tvips} mm')
156156

157157
# implement this later if it turns out to be necessary
158158
assert pixelsize_x_tvips == pixelsize_y_tvips, 'Pixelsize is different in X / Y direction'
159-
assert (
160-
physical_pixelsize_x_tvips == physical_pixelsize_y_tvips
161-
), 'Physical pixelsize is different in X / Y direction'
159+
assert physical_pixelsize_x_tvips == physical_pixelsize_y_tvips, (
160+
'Physical pixelsize is different in X / Y direction'
161+
)
162162

163163
buffer = []
164164

@@ -176,9 +176,9 @@ def img_convert(credlog, tiff_path=None, pets_path='PETS', mrc_path='RED', smv_p
176176
if img.min() >= 0 and img.max() < 2**16:
177177
img = img.astype(np.uint16)
178178

179-
assert (
180-
img.dtype.type is np.uint16
181-
), f'Image (#{i}:{fn.stem}) dtype is {img.dtype} (must be np.uint16)'
179+
assert img.dtype.type is np.uint16, (
180+
f'Image (#{i}:{fn.stem}) dtype is {img.dtype} (must be np.uint16)'
181+
)
182182

183183
h = {'ImageGetTime': timestamp, 'ImageExposureTime': exposure_time}
184184

src/instamatic/acquire_at_items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,5 @@ def start(self, start_index: int = 0):
184184

185185
dt = t1 - t0
186186
n_items = i + 1
187-
print(f'Total time taken: {dt:.0f} s for {n_items} items ({dt/n_items:.2f} s/item)')
187+
print(f'Total time taken: {dt:.0f} s for {n_items} items ({dt / n_items:.2f} s/item)')
188188
print('\nAll done!')

src/instamatic/calibrate/calibrate_brightness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def calibrate_brightness_from_image_fn(fns):
174174

175175
def calibrate_brightness(fns=None, ctrl=None, confirm=True):
176176
if not fns:
177-
if confirm and not input("\n >> Go too 2500x mag (type 'go' to start): " '') == 'go':
177+
if confirm and not input("\n >> Go too 2500x mag (type 'go' to start): ") == 'go':
178178
return
179179
else:
180180
calib = calibrate_brightness_live(ctrl, save_images=True)

src/instamatic/calibrate/calibrate_movie_delays.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,15 @@ def _get_movie_times(exposure_=1e-6) -> MovieTimes:
372372
ratio = mte.frame1_times.mean() / mte.exposure
373373
if ratio > 1.1:
374374
msg = (
375-
f'Exposure times exceed expected by {(ratio-1)*100}%. '
375+
f'Exposure times exceed expected by {(ratio - 1) * 100}%. '
376376
f'Consider using longer exposure or smaller header.'
377377
)
378378
warnings.warn(msg, CalibWarning)
379379

380380
ratio = mtr.total_times.mean() / mte.total_times.mean()
381381
if ratio > 0.5:
382382
msg = (
383-
f'Total time is dominated ({ratio*100}%) by header collection. '
383+
f'Total time is dominated ({ratio * 100}%) by header collection. '
384384
f'Consider using longer exposure or smaller header.'
385385
)
386386
warnings.warn(msg, CalibWarning)

src/instamatic/calibrate/calibrate_stage_lowmag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def calibrate_stage_lowmag_live(ctrl, gridsize=5, stepsize=50000, save_images=Fa
278278
i = 0
279279
for dx, dy in np.stack([x_grid, y_grid]).reshape(2, -1).T:
280280
print()
281-
print(f'Position {i+1}/{tot}: x: {x_cent+dx:.0f}, y: {y_cent+dy:.0f}')
281+
print(f'Position {i + 1}/{tot}: x: {x_cent + dx:.0f}, y: {y_cent + dy:.0f}')
282282

283283
ctrl.stage.set(x=x_cent + dx, y=y_cent + dy)
284284
print(ctrl.stage)

src/instamatic/calibrate/calibrate_stage_mag1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def calibrate_mag1_live(
128128
stage = ctrl.stage.get()
129129

130130
print()
131-
print(f'Position {I+1}/{tot}')
131+
print(f'Position {I + 1}/{tot}')
132132
print(stage)
133133

134134
outfile = work_drc / f'calib_{i:04d}' if save_images else None

src/instamatic/calibrate/calibrate_stagematrix.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def main_entry():
467467
dest='overlap',
468468
type=float,
469469
metavar='X',
470-
help=('Specify the approximate overlap between images for cross ' 'correlation.'),
470+
help=('Specify the approximate overlap between images for cross correlation.'),
471471
)
472472

473473
parser.add_argument(
@@ -476,7 +476,7 @@ def main_entry():
476476
dest='stage_length',
477477
type=int,
478478
help=(
479-
'Specify the minimum length (in stage coordinates) the calibration ' 'should cover.'
479+
'Specify the minimum length (in stage coordinates) the calibration should cover.'
480480
),
481481
)
482482

@@ -486,9 +486,7 @@ def main_entry():
486486
dest='min_n_step',
487487
type=int,
488488
metavar='N',
489-
help=(
490-
'Specify the minimum number of steps to take along X and Y for the ' 'calibration.'
491-
),
489+
help=('Specify the minimum number of steps to take along X and Y for the calibration.'),
492490
)
493491

494492
parser.add_argument(

src/instamatic/camera/camera_merlin.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ def get_image(self, exposure: float = None, **kwargs) -> np.ndarray:
237237
self.setup_soft_trigger(exposure=exposure)
238238
elif self._frame_number == self.MAX_NUMFRAMESTOACQUIRE:
239239
logger.debug(
240-
(
241-
'Maximum frame number reached for this acquisition, '
242-
'resetting soft trigger.'
243-
)
240+
('Maximum frame number reached for this acquisition, resetting soft trigger.')
244241
% self.MAX_NUMFRAMESTOACQUIRE
245242
)
246243
self.setup_soft_trigger(exposure=exposure)

src/instamatic/camera/merlin_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def load_mib(buffer: bytes, skip: int = 0):
115115
]
116116
)
117117

118-
assert (
119-
len(buffer) % merlin_frame_dtype.itemsize == 0
120-
), 'buffer size must be a multiple of item size'
118+
assert len(buffer) % merlin_frame_dtype.itemsize == 0, (
119+
'buffer size must be a multiple of item size'
120+
)
121121

122122
data = np.frombuffer(
123123
buffer,

0 commit comments

Comments
 (0)