7
7
from warnings import warn
8
8
9
9
import h5py
10
+ import npstreams as ns
10
11
import numpy as np
11
12
from scipy .ndimage import gaussian_filter
12
-
13
- import npstreams as ns
14
- from skued import (
15
- __version__ ,
16
- nfold ,
17
- autocenter ,
18
- ArbitrarySelection ,
19
- Selection ,
20
- )
13
+ from skued import ArbitrarySelection , Selection , __version__ , autocenter , nfold
21
14
22
15
from .meta import HDF5ExperimentalParameter , MetaHDF5Dataset
23
16
@@ -44,9 +37,7 @@ def write_access_needed(f):
44
37
@wraps (f )
45
38
def newf (self , * args , ** kwargs ):
46
39
if self .mode != "r+" :
47
- raise PermissionError (
48
- f"The dataset { self .filename } has not been opened with write access."
49
- )
40
+ raise PermissionError (f"The dataset { self .filename } has not been opened with write access." )
50
41
return f (self , * args , ** kwargs )
51
42
52
43
return newf
@@ -91,26 +82,14 @@ class DiffractionDataset(h5py.File, metaclass=MetaHDF5Dataset):
91
82
"acquisition_date" , str , default = ""
92
83
) # Acquisition date, no specific format
93
84
energy = HDF5ExperimentalParameter ("energy" , float , default = 90 ) # keV
94
- pump_wavelength = HDF5ExperimentalParameter (
95
- "pump_wavelength" , int , default = 800
96
- ) # nanometers
97
- fluence = HDF5ExperimentalParameter (
98
- "fluence" , float , default = 0
99
- ) # milliJoules / centimeters ^ 2
100
- time_zero_shift = HDF5ExperimentalParameter (
101
- "time_zero_shift" , float , default = 0
102
- ) # picoseconds
103
- temperature = HDF5ExperimentalParameter (
104
- "temperature" , float , default = 293
105
- ) # kelvins
85
+ pump_wavelength = HDF5ExperimentalParameter ("pump_wavelength" , int , default = 800 ) # nanometers
86
+ fluence = HDF5ExperimentalParameter ("fluence" , float , default = 0 ) # milliJoules / centimeters ^ 2
87
+ time_zero_shift = HDF5ExperimentalParameter ("time_zero_shift" , float , default = 0 ) # picoseconds
88
+ temperature = HDF5ExperimentalParameter ("temperature" , float , default = 293 ) # kelvins
106
89
exposure = HDF5ExperimentalParameter ("exposure" , float , default = 1 ) # seconds
107
90
scans = HDF5ExperimentalParameter ("scans" , tuple , default = (1 ,))
108
- camera_length = HDF5ExperimentalParameter (
109
- "camera_length" , float , default = 0.23
110
- ) # meters
111
- pixel_width = HDF5ExperimentalParameter (
112
- "pixel_width" , float , default = 14e-6
113
- ) # meters
91
+ camera_length = HDF5ExperimentalParameter ("camera_length" , float , default = 0.23 ) # meters
92
+ pixel_width = HDF5ExperimentalParameter ("pixel_width" , float , default = 14e-6 ) # meters
114
93
aligned = HDF5ExperimentalParameter ("aligned" , bool , default = False )
115
94
normalized = HDF5ExperimentalParameter ("normalized" , bool , default = False )
116
95
notes = HDF5ExperimentalParameter ("notes" , str , default = "" )
@@ -234,9 +213,7 @@ def from_collection(
234
213
235
214
if ckwargs is None :
236
215
ckwargs = {"compression" : "lzf" , "shuffle" : True , "fletcher32" : True }
237
- ckwargs [
238
- "chunks"
239
- ] = True # For some reason, if no chunking, writing to disk is SLOW
216
+ ckwargs ["chunks" ] = True # For some reason, if no chunking, writing to disk is SLOW
240
217
241
218
first , patterns = ns .peek (patterns )
242
219
if dtype is None :
@@ -498,16 +475,12 @@ def mask_apply(self, func):
498
475
if r .dtype != bool :
499
476
raise TypeError (f"Diffraction pattern masks must be boolean, not { r .dtype } " )
500
477
if r .shape != old_mask .shape :
501
- raise ValueError (
502
- f"Expected diffraction pattern mask with shape { old_mask .shape } , but got { r .shape } "
503
- )
478
+ raise ValueError (f"Expected diffraction pattern mask with shape { old_mask .shape } , but got { r .shape } " )
504
479
self .experimental_parameters_group ["valid_mask" ][:] = func (self .valid_mask )
505
480
506
481
@write_access_needed
507
482
@update_equilibrium_pattern
508
- def symmetrize (
509
- self , mod , center = None , kernel_size = None , callback = None , processes = 1
510
- ):
483
+ def symmetrize (self , mod , center = None , kernel_size = None , callback = None , processes = 1 ):
511
484
"""
512
485
Symmetrize diffraction images based on n-fold rotational symmetry.
513
486
@@ -610,9 +583,7 @@ def shift_time_zero(self, shift):
610
583
"""
611
584
differential = shift - self .time_zero_shift
612
585
self .time_zero_shift = shift
613
- self .experimental_parameters_group ["time_points" ][:] = (
614
- self .time_points + differential
615
- )
586
+ self .experimental_parameters_group ["time_points" ][:] = self .time_points + differential
616
587
617
588
def _get_time_index (self , timedelay ):
618
589
"""
@@ -632,9 +603,7 @@ def _get_time_index(self, timedelay):
632
603
time_index = np .argmin (np .abs (self .time_points - timedelay ))
633
604
actual_timedelay = self .time_points [time_index ]
634
605
if actual_timedelay != timedelay :
635
- warn (
636
- f"Time-delay { timedelay } ps not available. Using closest-timedelay { actual_timedelay } ps instead"
637
- )
606
+ warn (f"Time-delay { timedelay } ps not available. Using closest-timedelay { actual_timedelay } ps instead" )
638
607
return time_index
639
608
640
609
def diff_eq (self ):
@@ -691,9 +660,7 @@ def _recompute_diff_eq(self):
691
660
else :
692
661
diff_eq = ns .average ((intensity [:, :, i ] for i in range (t0_index )), axis = 2 )
693
662
694
- eq_dset = self .diffraction_group .require_dataset (
695
- name = "equilibrium" , shape = diff_eq .shape , dtype = float
696
- )
663
+ eq_dset = self .diffraction_group .require_dataset (name = "equilibrium" , shape = diff_eq .shape , dtype = float )
697
664
eq_dset [:] = diff_eq
698
665
699
666
def diff_data (self , timedelay , relative = False , out = None ):
@@ -866,7 +833,7 @@ def _autocenter(self):
866
833
# diffraction center rather than fail the autocenter routine.
867
834
# See #26.
868
835
if np .allclose (image * self .valid_mask , 0 ):
869
- r , c = image .shape [0 ]// 2 , image .shape [1 ]// 2
836
+ r , c = image .shape [0 ] // 2 , image .shape [1 ] // 2
870
837
else :
871
838
r , c = autocenter (im = image , mask = self .valid_mask )
872
839
0 commit comments