Ejemplo n.º 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')
Ejemplo n.º 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()
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
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.
     """
     with self.sphere.sphere_lock:
         self.sphere.bai_2d = int_2d_data()
     for arch in self.sphere.arches:
         arch.integrate_2d(**self.sphere.bai_2d_args,
                           global_mask=self.sphere.global_mask)
         # self.sphere.arches[arch.idx] = arch
         self.sphere._update_bai_2d(arch)
         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')
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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