def test_missing_spectra_and_nums_frequency(self, ids, shifts, tol): """Test that an error is raised if both, spectra and nums_frequency are missing.""" with pytest.raises(ValueError, match="Either nums_frequency or spectra"): _prepare_jobs(ids, nums_frequency=None, spectra=None, shifts=shifts, atol=tol)
def test_with_nums_frequency(self, ids, spectra, nums_frequency, tol): """Test the prepared jobs when using nums_frequency.""" """Test ``_prepare_jobs`` with a large variety of test cases (cheap).""" ids_, recon_fn, jobs, need_f0 = _prepare_jobs( ids, nums_frequency, None, None, atol=tol, ) # Check ids if ids is None: assert self.nested_dict_ids_match(nums_frequency, ids_) else: assert self.ids_match(ids, ids_) # Check function to use for 1D reconstructions assert recon_fn == _reconstruct_equ # Check reconstruction jobs to be run assert self.nested_dict_ids_match(jobs, ids_) for _id, _jobs in jobs.items(): for idx, job in _jobs.items(): if nums_frequency[_id][idx] == 0: assert job is None continue assert list(job.keys()) == ["num_frequency"] assert job["num_frequency"] == nums_frequency[_id][idx] # always need fun at zero if equidistant reconstruction is performed assert need_f0
def test_with_spectra(self, ids, spectra, tol): """Test the prepared jobs when using spectra and shifts.""" ids_, recon_fn, jobs, need_f0 = _prepare_jobs( ids, nums_frequency=None, spectra=spectra, shifts=None, atol=tol, ) if ids is None: assert self.nested_dict_ids_match(spectra, ids_) else: assert self.ids_match(ids, ids_) # Check function to use for 1D reconstructions assert recon_fn == _reconstruct_gen # Check reconstruction jobs to be run assert self.nested_dict_ids_match(jobs, ids_) # Check all job details for _id, _jobs in jobs.items(): for idx, job in _jobs.items(): if len(spectra[_id][idx]) == 1: assert job is None continue assert list(job.keys()) == ["shifts", "spectrum"] assert job["shifts"] is None assert job["spectrum"] == spectra[_id][idx] assert need_f0
def test_with_spectra_and_shifts(self, ids, spectra, shifts, tol): """Test the prepared jobs when using spectra and shifts.""" ids_, recon_fn, jobs, need_f0 = _prepare_jobs( ids, nums_frequency=None, spectra=spectra, shifts=shifts, atol=tol, ) if ids is None: assert self.nested_dict_ids_match(spectra, ids_) else: assert self.ids_match(ids, ids_) # Check function to use for 1D reconstructions assert recon_fn == _reconstruct_gen # Check reconstruction jobs to be run assert self.nested_dict_ids_match(jobs, ids_) # Check all job details for _id, _jobs in jobs.items(): for idx, job in _jobs.items(): if len(spectra[_id][idx]) == 1: assert job is None continue assert list(job.keys()) == ["shifts", "spectrum"] assert job["shifts"] == shifts[_id][idx] assert job["spectrum"] == spectra[_id][idx] # sometimes need fun at zero if general reconstruction is performed _all_shifts = chain.from_iterable( [ sum( [ __shifts for par_idx, __shifts in _shifts.items() if id_ in ids_ and par_idx in ids_[id_] ], [], ) for id_, _shifts in shifts.items() ], ) assert need_f0 == any(np.isclose(_shift, 0.0, atol=tol, rtol=0) for _shift in _all_shifts)