1- from functools import partial
21from pathlib import Path
32
4- import matplotlib .pyplot as plt
5- from matplotlib .colors import Normalize , LogNorm , SymLogNorm
6- import numpy as np
73import typer
84
95from xtl .cli .cliio import Console , epilog
10- from xtl .cli .utils import Timer
11- from xtl .cli .diffraction .cli_utils import get_geometry_from_header , get_radial_units_from_header , ZScale
12- from xtl .exceptions .utils import Catcher
13- from xtl .files .npx import NpxFile
14- from xtl .units .crystallography .radial import RadialUnitType , RadialValue
6+ from xtl .cli .diffraction .cli_utils import ZScale
157
168
179app = typer .Typer ()
@@ -60,12 +52,16 @@ def cli_diffraction_correlate_fft(
6052 cli .print ('Select only one parameter to calculate FFT (--2theta, --q)' , style = 'red' )
6153 raise typer .Abort ()
6254
55+ from xtl .units .crystallography .radial import RadialUnitType , RadialValue
6356 if selection_2theta is not None :
6457 selection = RadialValue (value = selection_2theta , type = RadialUnitType .TWOTHETA_DEG )
6558 else :
6659 selection = RadialValue (value = selection_q , type = RadialUnitType .Q_NM )
6760
6861 # Load CCF data
62+ from xtl .exceptions .utils import Catcher
63+ from xtl .files .npx import NpxFile
64+
6965 with Catcher (echo_func = cli .print , traceback_func = cli .print_traceback ) as catcher :
7066 acc = NpxFile .load (ccf_file )
7167 for key in ['radial' , 'delta' , 'ccf' ]:
@@ -91,6 +87,8 @@ def cli_diffraction_correlate_fft(
9187 raise typer .Abort ()
9288
9389 # Get geometry from CCF file
90+ from xtl .cli .diffraction .cli_utils import get_geometry_from_header , get_radial_units_from_header
91+
9492 with Catcher (echo_func = cli .print , traceback_func = cli .print_traceback ) as catcher :
9593 geometry = get_geometry_from_header (acc .header )
9694 if verbose > 2 :
@@ -127,6 +125,9 @@ def cli_diffraction_correlate_fft(
127125 raise typer .Abort ()
128126
129127 # Get the radial index of the selection
128+ import numpy as np
129+ from xtl .cli .utils import Timer
130+
130131 ccf_i = np .argmin (np .abs (acc .data ['radial' ] - selection .value ))
131132
132133 # Calculate the FFT of the CCF
@@ -154,6 +155,9 @@ def cli_diffraction_correlate_fft(
154155 f'{ d .name .latex } ={ d .value :.2f} { d .units .latex } ' )
155156
156157 # Prepare plots
158+ import matplotlib .pyplot as plt
159+ from matplotlib .colors import Normalize , LogNorm , SymLogNorm
160+
157161 fig = plt .figure ('XCCA overview' , figsize = (16 / 1.2 , 9 / 1.2 ))
158162 fig .suptitle (f'{ ccf_file .name } \n { subtitle } ' )
159163 gs = fig .add_gridspec (2 , 3 , wspace = 0.2 ,)
@@ -196,6 +200,8 @@ def cli_diffraction_correlate_fft(
196200 if zmax is not None :
197201 vmax = zmax
198202
203+ from functools import partial
204+
199205 if zscale == ZScale .LINEAR :
200206 norm = partial (Normalize , clip = False )
201207 elif zscale == ZScale .LOG :
0 commit comments