|
| 1 | +import warnings |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 |
|
3 | 5 | from hexrd import constants |
@@ -428,3 +430,36 @@ def tth_to_pixel(self, tth): |
428 | 430 | convert two-theta value to pixel value (float) along two-theta axis |
429 | 431 | """ |
430 | 432 | return np.degrees(tth - self.tth_min)/self.tth_pixel_size |
| 433 | + |
| 434 | + |
| 435 | +def bin_polar_view(polar_obj: PolarView, |
| 436 | + pv: np.ndarray, |
| 437 | + azimuthal_interval: float, |
| 438 | + integration_range: float): |
| 439 | + '''bin the polar view image into a coarser |
| 440 | + grid by integration around +/- "integration_range" |
| 441 | + every "azimuthal_interval" degree |
| 442 | + ''' |
| 443 | + eta_mi = np.degrees(polar_obj.eta_min) |
| 444 | + eta_ma = np.degrees(polar_obj.eta_max) |
| 445 | + |
| 446 | + nspec = int((eta_ma - eta_mi)/azimuthal_interval)-1 |
| 447 | + |
| 448 | + pv_binned = np.zeros((nspec, pv.shape[1])) |
| 449 | + |
| 450 | + tth_step = polar_obj.tth_pixel_size |
| 451 | + eta_step = polar_obj.eta_pixel_size |
| 452 | + |
| 453 | + for i in range(nspec): |
| 454 | + start = ((i + 1) * azimuthal_interval - integration_range) / eta_step |
| 455 | + stop = ((i + 1) * azimuthal_interval + integration_range) / eta_step |
| 456 | + |
| 457 | + start = int(start) |
| 458 | + stop = int(stop) |
| 459 | + |
| 460 | + # Ignore any warnings about empty slices |
| 461 | + with warnings.catch_warnings(): |
| 462 | + warnings.simplefilter("ignore", category=RuntimeWarning) |
| 463 | + pv_binned[i, :] = np.squeeze(np.nanmean(pv[start:stop, :], axis=0)) |
| 464 | + |
| 465 | + return pv_binned |
0 commit comments