示例#1
0
    def bai_2d_all(self):
        """Integrates all arches 2d. Note, does not call sphere method
        directly, handles same functions but broken up for updates
        after each image.
        """
        self.data_2d.clear()
        with self.sphere.sphere_lock:
            if self.sphere.static:
                self.sphere.bai_2d = int_2d_data_static()
            else:
                self.sphere.bai_2d = int_2d_data()
        for arch in self.sphere.arches:
            if self.sphere.static:
                arch.static = True
            if self.sphere.gi:
                arch.gi = True
            arch.integrate_2d(**self.sphere.bai_2d_args)
            self.sphere.arches[arch.idx] = arch
            self.sphere._update_bai_2d(arch)

            self.data_2d[int(arch.idx)] = {
                'map_raw': arch.map_raw,
                'mask': arch.mask,
                'int_2d': arch.int_2d
            }
            self.update.emit(arch.idx)
        with self.file_lock:
            with catch(self.sphere.data_file, 'a') as file:
                ut.dict_to_h5(self.sphere.bai_2d_args, file, 'bai_2d_args')
示例#2
0
    def __init__(
            self,
            idx=None,
            map_raw=None,
            poni=None,
            mask=None,
            scan_info={},
            ai_args={},
            file_lock=Condition(),
            # poni_file=None, static=False, poni_dict=None,
            static=False,
            poni_dict=None,
            gi=False,
            th_mtr='th',
            tilt_angle=0):
        # pylint: disable=too-many-arguments
        """idx: int, name of the arch.
        map_raw: numpy array, raw image data
        poni: PONI object, calibration data
        mask: None or numpy array, indices of pixels to mask
        scan_info: dict, metadata about scan
        ai_args: dict, args to be fed to azimuthalIntegrator constructor
        file_lock: Condition, lock for file access.
        """
        super(EwaldArch, self).__init__()
        self.idx = idx
        self.map_raw = map_raw
        if poni is None:
            self.poni = PONI()
        else:
            self.poni = poni
        # self.poni_file = poni_file
        self.poni_dict = poni_dict
        if mask is None and map_raw is not None:
            self.mask = np.arange(map_raw.size)[map_raw.flatten() < 0]
        else:
            self.mask = mask
        self.scan_info = scan_info
        self.ai_args = ai_args
        self.file_lock = file_lock

        self.static = static
        self.gi = gi
        self.th_mtr = th_mtr
        self.tilt_angle = tilt_angle

        self.integrator = self.setup_integrator()

        self.arch_lock = Condition()
        self.map_norm = 1

        if self.static:
            self.int_1d = int_1d_data_static()
            self.int_2d = int_2d_data_static()
        else:
            self.int_1d = int_1d_data()
            self.int_2d = int_2d_data()
示例#3
0
 def reset(self):
     """Clears all data, resets to a default EwaldArch.
     """
     self.idx = None
     self.map_raw = None
     self.poni = PONI()
     # self.poni_file = None
     self.poni_dict = None
     self.mask = None
     self.scan_info = {}
     self.integrator = self.setup_integrator()
     self.map_norm = 1
     if self.static:
         self.int_1d = int_1d_data_static()
         self.int_2d = int_2d_data_static()
     else:
         self.int_1d = int_1d_data()
         self.int_2d = int_2d_data()
示例#4
0
文件: sphere.py 项目: rwalroth/xdart
 def reset(self):
     """Resets all held data objects to blank state, called when all
     new data is going to be loaded or when a sphere needs to be
     purged of old data.
     """
     with self.sphere_lock:
         self.scan_data = pd.DataFrame()
         self.mgi_1d = int_1d_data()
         self.mgi_2d = int_2d_data()
         self.arches = ArchSeries(self.data_file,
                                  self.file_lock,
                                  static=self.static,
                                  gi=self.gi)
         self.global_mask = None
         if self.static:
             self.bai_1d = int_1d_data_static()
             self.bai_2d = int_2d_data_static()
         else:
             self.bai_1d = int_1d_data()
             self.bai_2d = int_2d_data()
         self.overall_raw = 0
示例#5
0
文件: sphere.py 项目: rwalroth/xdart
    def by_arch_integrate_2d(self, **args):
        """Integrates all arches individually, then sums the results for
        the overall integration result.

        args: see EwaldArch.integrate_2d. If any args are passed, the
            bai_2d_args dictionary is also updated with the new args.
            If no args are passed, uses bai_2d_args attribute.
        """
        if not args:
            args = self.bai_2d_args
        else:
            self.bai_2d_args = args.copy()
        with self.sphere_lock:
            if self.static:
                self.bai_2d = int_2d_data_static()
            else:
                self.bai_2d = int_2d_data()

            for arch in self.arches:
                arch.integrate_2d(global_mask=self.global_mask, **args)
                self.arches[arch.idx] = arch
                self._update_bai_2d(arch)
示例#6
0
    def data_changed(self, show_all=False):
        """Connected to currentItemChanged signal of listData
        """
        # ic()
        if not show_all:
            self.arch_ids.clear()
            items = self.ui.listData.selectedItems()
            self.arch_ids += sorted([str(item.text()) for item in items])
            idxs = self.arch_ids
        else:
            idxs = self.arch_ids

        # ic(idxs, self.new_scan)

        if (len(idxs) == 0) or ('No data' in idxs):
            time.sleep(0.1)
            return

        # if idxs[0] == 'No data':
        #     self.arch_ids = []
        #     self.sigUpdate.emit()
        #     return

        # if self.new_scan and ('Overall' in idxs) and (len(self.data_1d) == 0):
        # if self.new_scan and ('Overall' in idxs):
        # if self.new_scan:
        #     self.new_scan = False
        #     return

        # ic(idxs, self.new_scan, len(self.data_1d), len(self.data_2d), len(self.sphere.arches.index))

        # Put 'Overall' first in list
        load_2d = self.update_2d
        if 'Overall' in self.arch_ids:
            self.arch_ids.insert(
                0, self.arch_ids.pop(self.arch_ids.index('Overall')))
            idxs = self.sphere.arches.index

        if len(self.sphere.arches.index) > 1:
            if len(idxs) == len(self.sphere.arches.index):
                load_2d = False

        if load_2d:
            idxs_memory = [
                int(idx) for idx in idxs if int(idx) in self.data_2d.keys()
            ]
        else:
            idxs_memory = [
                int(idx) for idx in idxs if int(idx) in self.data_1d.keys()
            ]

        # ic(load_2d, idxs_memory)

        # Remove 2d data from 'Sum' if for unselected keys
        if load_2d:
            if (len(self.arches) == 0) or (len(self.data_2d) == 0):
                self.arches.update({
                    'sum_int_2d': int_2d_data_static(),
                    'sum_map_raw': 0
                })
                self.arches.update({
                    'idxs': [],
                    'add_idxs': [],
                    'sub_idxs': []
                })

            if len(idxs) > 1:
                self.get_arches_sum(idxs, idxs_memory)

            self.arches['idxs'] = [int(idx) for idx in idxs]

        # self.file_thread.arch_ids = [int(idx) for idx in idxs
        #                              if int(idx) not in idxs_memory]
        arch_ids = [int(idx) for idx in idxs if int(idx) not in idxs_memory]

        # ic(arch_ids)
        # if len(self.file_thread.arch_ids) > 0:
        #     self.file_thread.update_2d = load_2d
        #     self.file_thread.queue.put("load_arches")
        if len(arch_ids) > 0:
            self.load_arches_data(arch_ids, load_2d)

        self.sigUpdate.emit()
示例#7
0
文件: sphere.py 项目: rwalroth/xdart
    def __init__(self,
                 name='scan0',
                 arches=[],
                 data_file=None,
                 scan_data=pd.DataFrame(),
                 mg_args={'wavelength': 1e-10},
                 bai_1d_args={},
                 bai_2d_args={},
                 static=False,
                 gi=False,
                 th_mtr='th',
                 overall_raw=0,
                 single_img=False,
                 global_mask=None,
                 poni_dict={}):
        """name: string, name of sphere object.
        arches: list of EwaldArch object, data to intialize with
        data_file: str, path to hdf5 file where data is stored
        scan_data: DataFrame, scan metadata
        mg_args: dict, arguments for Multigeometry. Must include at
            least 'wavelength' attribute in Angstroems
        bai_1d_args: dict, arguments for the integrate1d method of pyFAI
            AzimuthalIntegrator
        bai_2d_args: dict, arguments for the integrate2d method of pyFAI
            AzimuthalIntegrator
        """
        super().__init__()
        self.file_lock = Condition()
        if name is None:
            self.name = os.path.split(data_file)[-1].split('.')[0]
        else:
            self.name = name
        if data_file is None:
            self.data_file = name + ".hdf5"
        else:
            self.data_file = data_file

        self.static = static
        self.gi = gi
        self.th_mtr = th_mtr
        self.single_img = single_img

        if arches:
            self.arches = ArchSeries(self.data_file,
                                     self.file_lock,
                                     arches,
                                     static=self.static,
                                     gi=self.gi)
        else:
            self.arches = ArchSeries(self.data_file,
                                     self.file_lock,
                                     static=self.static,
                                     gi=self.gi)
        self.scan_data = scan_data
        self.mg_args = mg_args
        self.multi_geo = MultiGeometry([a.integrator for a in arches],
                                       **mg_args)
        self.bai_1d_args = bai_1d_args
        self.bai_2d_args = bai_2d_args
        self.mgi_1d = int_1d_data()
        self.mgi_2d = int_2d_data()
        self.sphere_lock = Condition(_PyRLock())

        if self.static:
            self.bai_1d = int_1d_data_static()
            self.bai_2d = int_2d_data_static()
        else:
            self.bai_1d = int_1d_data()
            self.bai_2d = int_2d_data()

        self.overall_raw = overall_raw
        self.global_mask = global_mask
        self.poni_dict = poni_dict