@@ -335,7 +335,8 @@ def orientation_plan(
335335 )
336336 self .orientation_zone_axis_steps = (
337337 np .round (step / self .orientation_refine_ratio ) * self .orientation_refine_ratio
338- ).astype (np .integer )
338+ ).astype (np .int32 )
339+ # ).astype(np.integer)
339340
340341 if self .orientation_fiber and self .orientation_fiber_angles [0 ] == 0 :
341342 self .orientation_num_zones = int (1 )
@@ -370,7 +371,8 @@ def orientation_plan(
370371 (self .orientation_zone_axis_steps + 1 )
371372 * (self .orientation_zone_axis_steps + 2 )
372373 / 2
373- ).astype (np .integer )
374+ ).astype (np .int32 )
375+ # ).astype(np.integer)
374376 self .orientation_vecs = np .zeros ((self .orientation_num_zones , 3 ))
375377 self .orientation_vecs [0 , :] = self .orientation_zone_axis_range [0 , :]
376378 self .orientation_inds = np .zeros ((self .orientation_num_zones , 3 ), dtype = "int" )
@@ -379,7 +381,8 @@ def orientation_plan(
379381 # or circular arc SLERP for fiber texture
380382 for a0 in np .arange (1 , self .orientation_zone_axis_steps + 1 ):
381383 inds = np .arange (a0 * (a0 + 1 ) / 2 , a0 * (a0 + 1 ) / 2 + a0 + 1 ).astype (
382- np .integer
384+ np .int32
385+ # np.integer
383386 )
384387
385388 p0 = pv [a0 , :]
@@ -617,7 +620,8 @@ def orientation_plan(
617620
618621 # Solve for number of angular steps along in-plane rotation direction
619622 self .orientation_in_plane_steps = np .round (360 / angle_step_in_plane ).astype (
620- np .integer
623+ np .int32
624+ # np.integer
621625 )
622626
623627 # Calculate -z angles (Euler angle 3)
@@ -2208,8 +2212,6 @@ def calculate_strain(
22082212 deformation tensor which transforms the simulated diffraction pattern
22092213 into the experimental pattern, for all probe positons.
22102214
2211- TODO: add robust fitting?
2212-
22132215 Parameters
22142216 ----------
22152217 bragg_peaks_array (PointListArray):
@@ -2330,71 +2332,75 @@ def calculate_strain(
23302332 inds_match [a0 ] = ind_min
23312333 keep [a0 ] = True
23322334
2333- # Get all paired peaks
2334- qxy = np .vstack ((p .data ["qx" ][keep ], p .data ["qy" ][keep ])).T
2335- qxy_ref = np .vstack (
2336- (p_ref .data ["qx" ][inds_match [keep ]], p_ref .data ["qy" ][inds_match [keep ]])
2337- ).T
2335+ if np .sum (keep ) >= min_num_peaks :
2336+ # Get all paired peaks
2337+ qxy = np .vstack ((p .data ["qx" ][keep ], p .data ["qy" ][keep ])).T
2338+ qxy_ref = np .vstack (
2339+ (
2340+ p_ref .data ["qx" ][inds_match [keep ]],
2341+ p_ref .data ["qy" ][inds_match [keep ]],
2342+ )
2343+ ).T
23382344
2339- # Fit transformation matrix
2340- # Note - not sure about transpose here
2341- # (though it might not matter if rotation isn't included)
2342- if intensity_weighting :
2343- weights = np .sqrt (p .data ["intensity" ][keep , None ]) * 0 + 1
2344- m = lstsq (
2345- qxy_ref * weights ,
2346- qxy * weights ,
2347- rcond = None ,
2348- )[0 ].T
2349- else :
2350- m = lstsq (
2351- qxy_ref ,
2352- qxy ,
2353- rcond = None ,
2354- )[0 ].T
2355-
2356- # Robust fitting
2357- if robust :
2358- for a0 in range (5 ):
2359- # calculate new weights
2360- qxy_fit = qxy_ref @ m
2361- diff2 = np .sum ((qxy_fit - qxy ) ** 2 , axis = 1 )
2362-
2363- weights = np .exp (
2364- diff2 / ((- 2 * robust_thresh ** 2 ) * np .median (diff2 ))
2365- )[:, None ]
2366- if intensity_weighting :
2367- weights *= np .sqrt (p .data ["intensity" ][keep , None ])
2368-
2369- # calculate new fits
2345+ # Fit transformation matrix
2346+ # Note - not sure about transpose here
2347+ # (though it might not matter if rotation isn't included)
2348+ if intensity_weighting :
2349+ weights = np .sqrt (p .data ["intensity" ][keep , None ]) * 0 + 1
23702350 m = lstsq (
23712351 qxy_ref * weights ,
23722352 qxy * weights ,
23732353 rcond = None ,
23742354 )[0 ].T
2355+ else :
2356+ m = lstsq (
2357+ qxy_ref ,
2358+ qxy ,
2359+ rcond = None ,
2360+ )[0 ].T
23752361
2376- # Set values into the infinitesimal strain matrix
2377- strain_map .get_slice ("e_xx" ).data [rx , ry ] = 1 - m [0 , 0 ]
2378- strain_map .get_slice ("e_yy" ).data [rx , ry ] = 1 - m [1 , 1 ]
2379- strain_map .get_slice ("e_xy" ).data [rx , ry ] = - (m [0 , 1 ] + m [1 , 0 ]) / 2.0
2380- strain_map .get_slice ("theta" ).data [rx , ry ] = (m [0 , 1 ] - m [1 , 0 ]) / 2.0
2381-
2382- # Add finite rotation from ACOM orientation map.
2383- # I am not sure about the relative signs here.
2384- # Also, maybe I need to add in the mirror operator?
2385- if orientation_map .mirror [rx , ry , 0 ]:
2386- strain_map .get_slice ("theta" ).data [rx , ry ] += (
2387- orientation_map .angles [rx , ry , 0 , 0 ]
2388- + orientation_map .angles [rx , ry , 0 , 2 ]
2389- )
2390- else :
2391- strain_map .get_slice ("theta" ).data [rx , ry ] -= (
2392- orientation_map .angles [rx , ry , 0 , 0 ]
2393- + orientation_map .angles [rx , ry , 0 , 2 ]
2394- )
2362+ # Robust fitting
2363+ if robust :
2364+ for a0 in range (5 ):
2365+ # calculate new weights
2366+ qxy_fit = qxy_ref @ m
2367+ diff2 = np .sum ((qxy_fit - qxy ) ** 2 , axis = 1 )
2368+
2369+ weights = np .exp (
2370+ diff2 / ((- 2 * robust_thresh ** 2 ) * np .median (diff2 ))
2371+ )[:, None ]
2372+ if intensity_weighting :
2373+ weights *= np .sqrt (p .data ["intensity" ][keep , None ])
2374+
2375+ # calculate new fits
2376+ m = lstsq (
2377+ qxy_ref * weights ,
2378+ qxy * weights ,
2379+ rcond = None ,
2380+ )[0 ].T
2381+
2382+ # Set values into the infinitesimal strain matrix
2383+ strain_map .get_slice ("e_xx" ).data [rx , ry ] = 1 - m [0 , 0 ]
2384+ strain_map .get_slice ("e_yy" ).data [rx , ry ] = 1 - m [1 , 1 ]
2385+ strain_map .get_slice ("e_xy" ).data [rx , ry ] = - (m [0 , 1 ] + m [1 , 0 ]) / 2.0
2386+ strain_map .get_slice ("theta" ).data [rx , ry ] = (m [0 , 1 ] - m [1 , 0 ]) / 2.0
2387+
2388+ # Add finite rotation from ACOM orientation map.
2389+ # I am not sure about the relative signs here.
2390+ # Also, maybe I need to add in the mirror operator?
2391+ if orientation_map .mirror [rx , ry , 0 ]:
2392+ strain_map .get_slice ("theta" ).data [rx , ry ] += (
2393+ orientation_map .angles [rx , ry , 0 , 0 ]
2394+ + orientation_map .angles [rx , ry , 0 , 2 ]
2395+ )
2396+ else :
2397+ strain_map .get_slice ("theta" ).data [rx , ry ] -= (
2398+ orientation_map .angles [rx , ry , 0 , 0 ]
2399+ + orientation_map .angles [rx , ry , 0 , 2 ]
2400+ )
23952401
2396- else :
2397- strain_map .get_slice ("mask" ).data [rx , ry ] = 0.0
2402+ else :
2403+ strain_map .get_slice ("mask" ).data [rx , ry ] = 0.0
23982404
23992405 if rotation_range is not None :
24002406 strain_map .get_slice ("theta" ).data [:] = np .mod (
0 commit comments