Example #1
0
    def test_s_data(self):
        abins.parameters.sampling['min_wavenumber'] = 100
        abins.parameters.sampling['max_wavenumber'] = 150

        s_data = SData(temperature=10,
                       sample_form='Powder',
                       data=self.sample_data,
                       frequencies=self.frequencies)

        self.assertTrue(
            np.allclose(s_data.extract()['frequencies'], self.frequencies))

        self.assertTrue(
            np.allclose(s_data.extract()['atom_0']['s']['order_1'],
                        self.sample_data['atom_0']['s']['order_1']))
        self.assertTrue(
            np.allclose(s_data.extract()['atom_1']['s']['order_1'],
                        self.sample_data['atom_1']['s']['order_1']))

        with self.assertRaises(AssertionError):
            with self.assertLogs(logger=self.logger, level='WARNING'):
                s_data.check_thresholds(logger=self.logger)

        abins.parameters.sampling['s_absolute_threshold'] = 0.5
        with self.assertLogs(logger=self.logger, level='WARNING'):
            s_data.check_thresholds(logger=self.logger)
Example #2
0
    def test_s_data_apply_dw(self):
        dw = np.random.RandomState(42).rand(2, 5)

        for min_order, max_order, expected in [
            (1, 1, {
                'atom_0': {
                    'order_1': np.linspace(0, 2, 5) * dw[0, :],
                    'order_2': np.linspace(2, 4, 5)
                },
                'atom_1': {
                    'order_1': np.linspace(3, 1, 5) * dw[1, :],
                    'order_2': np.linspace(2, 1, 5)
                }
            }),
            (2, 2, {
                'atom_0': {
                    'order_1': np.linspace(0, 2, 5),
                    'order_2': np.linspace(2, 4, 5) * dw[0, :]
                },
                'atom_1': {
                    'order_1': np.linspace(3, 1, 5),
                    'order_2': np.linspace(2, 1, 5) * dw[1, :]
                }
            }),
            (1, 2, {
                'atom_0': {
                    'order_1': np.linspace(0, 2, 5) * dw[0, :],
                    'order_2': np.linspace(2, 4, 5) * dw[0, :]
                },
                'atom_1': {
                    'order_1': np.linspace(3, 1, 5) * dw[1, :],
                    'order_2': np.linspace(2, 1, 5) * dw[1, :]
                }
            })
        ]:

            sdata = SData(data=deepcopy(self.sample_data_two_orders),
                          frequencies=self.frequencies)
            sdata.apply_dw(dw, min_order=min_order, max_order=max_order)
            for atom_key, atom_data in sdata.extract().items():
                if atom_key == 'frequencies':
                    continue
                for order_key in atom_data['s']:
                    assert_almost_equal(atom_data['s'][order_key],
                                        expected[atom_key][order_key])
Example #3
0
    def _broaden_sdata(self, sdata: SData,
                       broadening_scheme: str = 'auto') -> SData:
        """
        Apply instrumental broadening to scattering data
        """
        sdata_dict = sdata.extract()
        frequencies = sdata_dict['frequencies']
        del sdata_dict['frequencies']

        for atom_key in sdata_dict:
            for order_key in sdata_dict[atom_key]['s']:
                _, sdata_dict[atom_key]['s'][order_key] = (
                    self._instrument.convolve_with_resolution_function(
                        frequencies=frequencies, bins=self._bins,
                        s_dft=sdata_dict[atom_key]['s'][order_key],
                        scheme=broadening_scheme))
        return SData(data=sdata_dict, frequencies=self._bin_centres,
                     temperature = sdata.get_temperature(),
                     sample_form = sdata.get_sample_form())
Example #4
0
    def _broaden_sdata(self,
                       sdata: SData,
                       broadening_scheme: str = 'auto') -> SData:
        """
        Apply instrumental broadening to scattering data

        If the data is 2D, process line-by-line.
        (There is room for improvement, by reworking all the broadening
        implementations to accept 2-D input.)
        """
        sdata_dict = sdata.extract()
        frequencies = sdata_dict['frequencies']
        del sdata_dict['frequencies']
        if 'q_bins' in sdata_dict:
            del sdata_dict['q_bins']

        for atom_key in sdata_dict:
            for order_key, s_dft in sdata_dict[atom_key]['s'].items():
                if len(s_dft.shape) == 1:
                    _, sdata_dict[atom_key]['s'][order_key] = (
                        self._instrument.convolve_with_resolution_function(
                            frequencies=frequencies,
                            bins=self._bins,
                            s_dft=s_dft,
                            scheme=broadening_scheme))
                else:  # 2-D data, broaden one line at a time
                    for q_i, s_dft_row in enumerate(
                            sdata_dict[atom_key]['s'][order_key]):
                        _, sdata_dict[atom_key]['s'][order_key][q_i] = (
                            self._instrument.convolve_with_resolution_function(
                                frequencies=frequencies,
                                bins=self._bins,
                                s_dft=s_dft_row,
                                scheme=broadening_scheme))

        return SData(data=sdata_dict,
                     frequencies=self._bin_centres,
                     temperature=sdata.get_temperature(),
                     sample_form=sdata.get_sample_form(),
                     q_bins=sdata.get_q_bins())