def test_dense_stream(lazy): arr = np.random.randint(0, 65535, size=(2, 3, 4, 5)).astype("uint16") stream = array_to_stream(arr) if lazy: arrs = stream_to_sparse_COO_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) arrs = arrs.compute() assert (arrs == arr).all() else: arrs = stream_to_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert (arrs == arr).all()
def test_empty_stream(lazy): arr = np.zeros((2, 3, 4, 5), dtype="uint16") stream = array_to_stream(arr) if lazy: arrs = stream_to_sparse_COO_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) arrs = arrs.compute() assert not arrs.any() else: arrs = stream_to_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert not arrs.any()
def test_empty_stream(lazy): arr = np.zeros((2, 3, 4, 5), dtype="uint16") stream = array_to_stream(arr) if lazy: arrs = da.from_array(stream_to_sparse_COO_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2), chunks=(1, 1, 2, 5)) arrs = arrs.compute() assert not arrs.any() else: arrs = stream_to_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert not arrs.any()
def test_dense_stream(lazy): arr = np.random.randint(0, 65535, size=(2, 3, 4, 5)).astype("uint16") stream = array_to_stream(arr) if lazy: arrs = da.from_array(stream_to_sparse_COO_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2), chunks=(1, 1, 2, 5)) arrs = arrs.compute() assert (arrs == arr).all() else: arrs = stream_to_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert (arrs == arr).all()
def test_sparse_stream(lazy): arr = np.zeros((2, 3, 4, 5), dtype="uint16") arr[0, 0, 0, 0] = 1 arr[-1, -1, -1, -1] = 2 arr[1, 1, 3, 3] = 3 stream = array_to_stream(arr) if lazy: arrs = stream_to_sparse_COO_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) arrs = arrs.compute() assert (arrs == arr).all() else: arrs = stream_to_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert (arrs == arr).all()
def test_sparse_stream(lazy): arr = np.zeros((2, 3, 4, 5), dtype="uint16") arr[0, 0, 0, 0] = 1 arr[-1, -1, -1, -1] = 2 arr[1, 1, 3, 3] = 3 stream = array_to_stream(arr) if lazy: arrs = da.from_array(stream_to_sparse_COO_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2), chunks=(1, 1, 2, 5)) arrs = arrs.compute() assert (arrs == arr).all() else: arrs = stream_to_array( stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert (arrs == arr).all()
def test_empty_stream(lazy): arr = np.zeros((2, 3, 4, 5), dtype="uint16") stream = array_to_stream(arr) if lazy: if not sparse_installed: pytest.skip("The sparse package is not installed") arrs = da.from_array(stream_to_sparse_COO_array(stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2), chunks=(1, 1, 2, 5)) arrs = arrs.compute() assert not arrs.any() else: arrs = stream_to_array(stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert not arrs.any()
def test_dense_stream(lazy): arr = np.random.randint(0, 65535, size=(2, 3, 4, 5)).astype("uint16") stream = array_to_stream(arr) if lazy: if not sparse_installed: pytest.skip("The sparse package is not installed") arrs = da.from_array(stream_to_sparse_COO_array(stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2), chunks=(1, 1, 2, 5)) arrs = arrs.compute() assert (arrs == arr).all() else: arrs = stream_to_array(stream, spatial_shape=(3, 4), sum_frames=False, channels=5, last_frame=2) assert (arrs == arr).all()
def stream_to_array(self, stream_data, spectrum_image=None): """Convert stream to array. Parameters ---------- stream_data: array spectrum_image: array or None If array, the data from the stream are added to the array. Otherwise it creates a new array and returns it. """ spectrum_image = stream_readers.stream_to_array( stream=stream_data, spatial_shape=self.reader.spatial_shape, channels=self.bin_count, first_frame=self.reader.first_frame, last_frame=self.reader.last_frame, rebin_energy=self.reader.rebin_energy, sum_frames=self.reader.sum_frames, spectrum_image=spectrum_image, dtype=self.reader.SI_data_dtype, ) return spectrum_image