def _get_empty_sdata(self, use_fine_bins: bool = False, max_order: Optional[int] = None) -> SData: """ Initialise an appropriate SData object for this calculation """ bin_centres = self._fine_bin_centres if use_fine_bins else self._bin_centres if max_order is None: max_order = self._quantum_order_num return SData.get_empty(frequencies=bin_centres, atom_keys=list(self._abins_data.get_atoms_data().extract().keys()), order_keys=[f'order_{n}' for n in range(1, max_order + 1)], temperature=self._temperature, sample_form=self._sample_form)
def test_s_data_get_empty(self): from itertools import product sdata = SData.get_empty(frequencies=np.linspace(1., 5., 10), atom_keys=['atom_2', 'atom_3'], order_keys=['order_2', 'order_3'], temperature=101., sample_form='etherial') with self.assertRaises(IndexError): sdata[1] with self.assertRaises(KeyError): sdata[2]['order_1'] for atom, order in product([2, 3], ['order_2', 'order_3']): assert_almost_equal(sdata[atom][order], np.zeros(10)) assert_almost_equal(sdata.get_temperature(), 101.) self.assertEqual(sdata.get_sample_form(), 'etherial')
def _get_empty_sdata(self, use_fine_bins: bool = False, max_order: Optional[int] = None, shape=None) -> SData: """ Initialise an appropriate SData object for this calculation Args: shape: '1d', '2d', or None. If '1d', spectra are 1-D (corresponding to energy). If '2d', spectra have rows corresponding to q bin centres. If None, detect dimensions based on presence of self._q_bin_centres. """ bin_centres = self._fine_bin_centres if use_fine_bins else self._bin_centres if max_order is None: max_order = self._quantum_order_num if (shape and shape.lower() == '1d') or (shape is None and self._q_bin_centres is None): n_rows = None q_bins = None else: n_rows = len(self._q_bin_centres) q_bins = self._q_bins return SData.get_empty( frequencies=bin_centres, atom_keys=list(self._abins_data.get_atoms_data().extract().keys()), order_keys=[f'order_{n}' for n in range(1, max_order + 1)], n_rows=n_rows, temperature=self._temperature, sample_form=self._sample_form, q_bins=q_bins)