Beispiel #1
0
 def test_negative_input_listmode(self, old_spec_int, new_edges):
     old_edges, old_counts = old_spec_int
     old_counts[0] = -1
     with pytest.raises(bq.RebinError):
         bq.rebin(
             old_counts,
             old_edges,
             new_edges,
             method="listmode",
             zero_pad_warnings=False,
         )
Beispiel #2
0
 def test_overlap_errors(self, old_spec_float):
     old_edges, old_counts = old_spec_float
     new_edges_left = np.linspace(
         old_edges[0] - 10, old_edges[0] - 1, 10, dtype=float
     )
     new_edges_right = np.linspace(
         old_edges[-1] + 1, old_edges[-1] + 10, 10, dtype=float
     )
     with pytest.raises(bq.RebinError):
         bq.rebin(old_counts, old_edges, new_edges_left)
     with pytest.raises(bq.RebinError):
         bq.rebin(old_counts, old_edges, new_edges_right)
Beispiel #3
0
 def test_overlap_warnings(self, old_spec_float):
     old_edges, old_counts = old_spec_float
     new_edges_left = np.linspace(old_edges[0] - 1.0, old_edges[-1], 10)
     new_edges_right = np.linspace(old_edges[0], old_edges[-1] + 1, 10)
     new_edges_both = np.linspace(old_edges[0] - 1.0, old_edges[-1] + 1, 10)
     with pytest.warns(bq.RebinWarning):
         bq.rebin(old_counts, old_edges, new_edges_left, zero_pad_warnings=True)
     with pytest.warns(bq.RebinWarning):
         bq.rebin(old_counts, old_edges, new_edges_right, zero_pad_warnings=True)
     with pytest.warns(bq.RebinWarning):
         bq.rebin(old_counts, old_edges, new_edges_both, zero_pad_warnings=True)
Beispiel #4
0
    def test_uncal_spectrum_counts(self, old_spec_float):
        """Plot the old and new spectrum bins as a sanity check"""

        old_edges, old_counts = old_spec_float
        new_edges = old_edges + 0.3
        new_counts = bq.rebin(old_counts, old_edges, new_edges, zero_pad_warnings=False)
        plt.figure()
        plt.plot(
            *bq.core.plotting.SpectrumPlotter.bin_edges_and_heights_to_steps(
                old_edges, old_counts
            ),
            color="dodgerblue",
            label="original",
        )
        plt.plot(
            *bq.core.plotting.SpectrumPlotter.bin_edges_and_heights_to_steps(
                new_edges, new_counts
            ),
            color="firebrick",
            label="rebinned",
        )
        plt.show()