Test Failed
Pull Request — master (#775)
by Nicola
06:18 queued 02:40
created

dials_find_spots   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A DialsFindSpots.process_frames() 0 19 2
A DialsFindSpots.__init__() 0 4 1
A DialsFindSpots.setup() 0 12 1
A DialsFindSpots.nOutput_datasets() 0 2 1
A DialsFindSpots.get_max_frames() 0 2 1
1
# Copyright 2014 Diamond Light Source Ltd.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
15
"""
16
.. module:: dials_find_spots
17
   :platform: Unix
18
   :synopsis: A plugin to integrate azimuthally "symmetric" signals i.e. SAXS,\
19
       WAXS or XRD.Requires a calibration file
20
21
.. moduleauthor:: Aaron D. Parsons <[email protected]>
22
"""
23
24
import logging
25
import numpy as np
26
from savu.plugins.filters.base_filter import BaseFilter
27
from savu.plugins.driver.cpu_plugin import CpuPlugin
28
from savu.plugins.utils import register_plugin
29
from scipy.ndimage import gaussian_filter
30
31
from dials.array_family import flex
32
from dials.algorithms.image.threshold import DispersionThreshold
33
34
35
#@register_plugin
36
class DialsFindSpots(BaseFilter, CpuPlugin):
37
    """
38
    finding the single crystal peaks with dials
39
    :param spotsize: approximate maximum spot size. Default: 45.
40
41
    """
42
43
    def __init__(self):
44
        logging.debug("Starting DialsFindSpots")
45
        super(DialsFindSpots,
46
              self).__init__("DialsFindSpots")
47
48
    def process_frames(self, data):
49
        data = data[0]
50
        lp = gaussian_filter(data, 100)
51
        hp = data - lp # poormans background subtraction
52
        hp -= np.min(hp)
53
        sh = hp.shape
54
        hp = hp.astype('uint32')
55
        hp = flex.int(hp)
56
        
57
        mask = flex.bool(np.ones_like(hp).astype('bool'))
58
        result1 = flex.bool(np.zeros_like(hp).astype('bool'))
59
        spots = np.zeros_like(hp).astype('bool')
60
        
61
        for i in range(3, self.parameters['spotsize'], 5):
62
            algorithm = DispersionThreshold(sh, (i, i), 1, 1, 0, -1)
63
            #print type(hp), type(mask), type(result1)
64
            thing = algorithm(hp, mask, result1)
65
            spots = spots + result1.as_numpy_array()
66
        return [data, spots*data]
67
68
    def setup(self):
69
        in_datasets, out_datasets = self.get_datasets()
70
        in_pData, out_pData = self.get_plugin_datasets()
71
        diffractions = in_datasets[0]
72
        powder = out_datasets[0]
73
        single_crystal = out_datasets[1]
74
        powder.create_dataset(diffractions)
75
        single_crystal.create_dataset(diffractions)
76
        in_pData, out_pData = self.get_plugin_datasets()
77
        in_pData[0].plugin_data_setup('DIFFRACTION', self.get_max_frames())
78
        out_pData[0].plugin_data_setup('DIFFRACTION', self.get_max_frames())
79
        out_pData[1].plugin_data_setup('DIFFRACTION', self.get_max_frames())
80
81
    def get_max_frames(self):
82
        return 'single'
83
84
    def nOutput_datasets(self):
85
        return 2
86