Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujun98 committed Feb 28, 2020
1 parent 8fc8be8 commit 2497629
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
12 changes: 7 additions & 5 deletions extra_foam/pipeline/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..config import config, AnalysisType, PumpProbeMode

from extra_foam.algorithms import (
intersection, movingAvgImageData, mask_image_data, nanmean_image_data
intersection, movingAvgImageData, image_with_mask, nanmean_image_data
)


Expand Down Expand Up @@ -520,10 +520,12 @@ def from_array(cls, arr, *,
instance.poi_indices = poi_indices

instance.masked_mean = instance.mean.copy()
mask_image_data(instance.masked_mean,
image_mask=image_mask,
threshold_mask=threshold_mask,
keep_nan=True)
if image_mask is None:
image_mask = np.zeros(arr.shape[-2:], dtype=np.bool)
mask = image_mask.copy()
image_with_mask(instance.masked_mean, mask,
threshold_mask=threshold_mask)
instance.mask = mask
instance.image_mask = image_mask
instance.threshold_mask = threshold_mask

Expand Down
2 changes: 1 addition & 1 deletion extra_foam/pipeline/processors/azimuthal_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ def process(self, data):
mean_ret = integ1d(processed.image.masked_mean, integ_points, mask=mask)

momentum = mean_ret.radial
print(momentum)
intensity = self._normalize_fom(
processed, mean_ret.intensity, self._normalizer,
x=momentum, auc_range=self._auc_range)

self._intensity_ma = intensity

fom = slice_curve(self._intensity_ma, momentum, *self._fom_integ_range)[0]
Expand Down
67 changes: 34 additions & 33 deletions extra_foam/pipeline/processors/tests/test_azimuthal_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def setUp(self):
proc = AzimuthalIntegProcessorTrain()

proc._sample_dist = 0.2
proc._pixel1 = 1e-4
proc._pixel2 = 1e-4
proc._poni1 = 10
proc._poni2 = 10
proc._wavelength = 1e-10
proc._pixel1 = 2e-4
proc._pixel2 = 2e-4
proc._poni1 = 0
proc._poni2 = 0
proc._wavelength = 5e-10

proc._integ_method = 'BBox'
proc._integ_range = (-np.inf, np.inf)
proc._integ_points = 128
proc._integ_points = 64

proc._fom_integ_range = (-np.inf, np.inf)

Expand All @@ -35,40 +35,41 @@ def testAzimuthalIntegration(self, method):
proc = self._proc
proc._integ_method = method

shape = (4, 20, 20)
shape = (4, 128, 64)
image_mask = np.zeros(shape[-2:], dtype=np.bool)
image_mask[1, 1] = True
# image_mask[:, ::2] = True
data, processed = self.data_with_assembled(1001, shape, image_mask=image_mask)

with patch.object(proc._meta, 'has_analysis',
side_effect=lambda x: True if x == AnalysisType.AZIMUTHAL_INTEG else False):
proc.process(data)

ai = processed.ai
assert len(ai.x) == proc._integ_points
assert len(ai.y) == proc._integ_points
assert not all([v is None for v in ai.y])
assert ai.fom is not None
assert shape[-2:] == ai.q_map.shape

def testAzimuthalIntegrationPp(self):
proc = self._proc

shape = (4, 20, 20)
image_mask = np.zeros(shape[-2:], dtype=np.bool)
image_mask[1, 1] = True
data, processed = self.data_with_assembled(1001, shape, image_mask=image_mask)

pp = processed.pp
pp.analysis_type = AnalysisType.AZIMUTHAL_INTEG
processed.pp.image_on = data['assembled']['sliced'][::2, ...]
processed.pp.image_off = data['assembled']['sliced'][::2, ...]

with patch.object(proc._meta, 'has_analysis',
side_effect=lambda x: True if x == AnalysisType.AZIMUTHAL_INTEG else False):
proc.process(data)

assert len(pp.y_on) == proc._integ_points
assert len(pp.y_off) == proc._integ_points
assert len(pp.x) == proc._integ_points
assert len(pp.y) == proc._integ_points
assert pp.fom is not None
print(ai.fom)
# assert shape[-2:] == ai.q_map.shape

# def testAzimuthalIntegrationPp(self):
# proc = self._proc
#
# shape = (4, 20, 20)
# image_mask = np.zeros(shape[-2:], dtype=np.bool)
# image_mask[1, 1] = True
# data, processed = self.data_with_assembled(1001, shape, image_mask=image_mask)
#
# pp = processed.pp
# pp.analysis_type = AnalysisType.AZIMUTHAL_INTEG
# processed.pp.image_on = data['assembled']['sliced'][::2, ...]
# processed.pp.image_off = data['assembled']['sliced'][::2, ...]
#
# with patch.object(proc._meta, 'has_analysis',
# side_effect=lambda x: True if x == AnalysisType.AZIMUTHAL_INTEG else False):
# proc.process(data)
#
# assert len(pp.y_on) == proc._integ_points
# assert len(pp.y_off) == proc._integ_points
# assert len(pp.x) == proc._integ_points
# assert len(pp.y) == proc._integ_points
# assert pp.fom is not None

0 comments on commit 2497629

Please sign in to comment.