@@ -225,6 +225,8 @@ def plot_radial_var_norm(
225225
226226def calculate_pair_dist_function (
227227 self ,
228+ RxRy = None ,
229+ hxwy = None ,
228230 k_min = 0.05 ,
229231 k_max = None ,
230232 k_width = 0.25 ,
@@ -275,6 +277,13 @@ def calculate_pair_dist_function(
275277
276278 Parameters
277279 ----------
280+ RxRy : None or 2-tuple
281+ None calculates on the whole radial average for dataset
282+ A 2-tuple calculates on the radial profile for one scan pixel defined by Rx and Ry
283+ or gives the top left corner of a box to average with widths defined by hxwy
284+ hxwy : None or 2-tuple
285+ A 2-tuple gives the height and width of a box to average anchored at Rx, Ry
286+ hx and wy need to be larger than 1
278287 k_min : number
279288 Minimum scattering vector to include in the calculation
280289 k_max : number or None
@@ -322,13 +331,20 @@ def calculate_pair_dist_function(
322331 k = self .qq
323332 dk = k [1 ] - k [0 ]
324333 k2 = k ** 2
325- Ik = self .radial_mean
334+ if RxRy == None :
335+ Ik = self .radial_mean
336+ elif RxRy != None and hxwy == None :
337+ Ik = self .radial_all [RxRy [0 ], RxRy [1 ]]
338+ elif RxRy != None and hxwy != None :
339+ Ik = self .radial_all [
340+ RxRy [0 ] : RxRy [0 ] + hxwy [0 ], RxRy [1 ] : RxRy [1 ] + hxwy [1 ]
341+ ].mean (axis = (0 , 1 ))
326342 int_mean = np .mean (Ik )
327343 sub_fit = k >= k_min
328344
329345 # initial guesses for background coefs
330- const_bg = np .min (self . radial_mean ) / int_mean
331- int0 = np .median (self . radial_mean ) / int_mean - const_bg
346+ const_bg = np .min (Ik ) / int_mean
347+ int0 = np .median (Ik ) / int_mean - const_bg
332348 sigma0 = np .mean (k )
333349 coefs = [const_bg , int0 , sigma0 , int0 , sigma0 ]
334350 lb = [0 , 0 , 0 , 0 , 0 ]
@@ -453,7 +469,7 @@ def calculate_pair_dist_function(
453469
454470 # Plots
455471 if plot_background_fits :
456- fig , ax = self .plot_background_fits (figsize = figsize , returnfig = True )
472+ fig , ax = self .plot_background_fits (Ik = Ik , figsize = figsize , returnfig = True )
457473 if returnfig :
458474 ans .append ((fig , ax ))
459475
@@ -478,16 +494,24 @@ def calculate_pair_dist_function(
478494
479495def plot_background_fits (
480496 self ,
497+ Ik = None ,
481498 figsize = (8 , 4 ),
482499 returnfig = False ,
483500):
484501 """
485502 TODO
503+ Ik : numpy array
504+ Ik calculated in calculate_pair_dist_function. Defaults to self.radial_mean for a pdf calculated
505+ over whole dataset, but correctly calculated for sub areas, if defined
486506 """
507+ if isinstance (Ik , np .ndarray ):
508+ pass
509+ else :
510+ Ik = self .radial_mean
487511 fig , ax = plt .subplots (figsize = figsize )
488512 ax .plot (
489513 self .qq ,
490- self . radial_mean ,
514+ Ik ,
491515 color = "k" ,
492516 )
493517 ax .plot (
@@ -502,8 +526,8 @@ def plot_background_fits(
502526 ax .set_ylabel ("I(k) and Background Fit Estimates" )
503527 ax .set_ylim (
504528 (
505- np .min (self . radial_mean [ self . radial_mean > 0 ]) * 0.8 ,
506- np .max (self . radial_mean * self .Sk_mask ) * 1.25 ,
529+ np .min (Ik [ Ik > 0 ]) * 0.8 ,
530+ np .max (Ik * self .Sk_mask ) * 1.25 ,
507531 )
508532 )
509533 ax .set_yscale ("log" )
0 commit comments