Exemple #1
0
    def split(self, t: ty.Union[int, None], allow_early_split=False):
        """Return (chunk_left, chunk_right) split at time t.

        :param t: Time at which to split the data.
        All data in the left chunk will have their (exclusive) end <= t,
        all data in the right chunk will have (inclusive) start >=t.
        :param allow_early_split:
          If False, raise CannotSplit if the requirements above cannot be met.
          If True, split at the closest possible time before t.
        """
        t = max(min(t, self.end), self.start)
        if t == self.end:
            data1, data2 = self.data, self.data[:0]
        elif t == self.start:
            data1, data2 = self.data[:0], self.data
        else:
            data1, data2, t = split_array(data=self.data,
                                          t=t,
                                          allow_early_split=allow_early_split)

        common_kwargs = dict(run_id=self.run_id,
                             dtype=self.dtype,
                             data_type=self.data_type,
                             data_kind=self.data_kind,
                             target_size_mb=self.target_size_mb)

        c1 = strax.Chunk(start=self.start,
                         end=max(self.start, t),
                         data=data1,
                         **common_kwargs)
        c2 = strax.Chunk(start=max(self.start, t),
                         end=max(t, self.end),
                         data=data2,
                         **common_kwargs)
        return c1, c2
Exemple #2
0
    def _read_and_format_chunk(self, *, backend_key, dtype, metadata,
                               chunk_info, time_range,
                               chunk_construction_kwargs) -> strax.Chunk:

        if chunk_info['n'] == 0:
            # No data, no need to load
            data = np.empty(0, dtype=dtype)
        else:
            data = self._read_chunk(backend_key,
                                    chunk_info=chunk_info,
                                    dtype=dtype,
                                    compressor=metadata['compressor'])

        result = strax.Chunk(start=chunk_info['start'],
                             end=chunk_info['end'],
                             run_id=chunk_info['run_id'],
                             data=data,
                             **chunk_construction_kwargs)

        if time_range:
            if result.start < time_range[0]:
                _, result = result.split(t=time_range[0],
                                         allow_early_split=True)
            if result.end > time_range[1]:
                try:
                    result, _ = result.split(t=time_range[1],
                                             allow_early_split=False)
                except strax.CannotSplit:
                    pass

        return result
Exemple #3
0
 def chunk(self, *, start, end, data, data_type=None, run_id=None):
     if data_type is None:
         if self.multi_output:
             raise ValueError("Must give data_type when making chunks from "
                              "a multi-output plugin")
         data_type = self.provides[0]
     if run_id is None:
         run_id = self.run_id
     return strax.Chunk(start=start,
                        end=end,
                        run_id=run_id,
                        data_kind=self.data_kind_for(data_type),
                        data_type=data_type,
                        dtype=self.dtype_for(data_type),
                        data=data,
                        target_size_mb=self.chunk_target_size_mb)