Exemplo n.º 1
0
    def _fix_output(self, result, start, end, _dtype=None):
        if self.multi_output and _dtype is None:
            if not isinstance(result, dict):
                raise ValueError(
                    f"{self.__class__.__name__} is multi-output and should "
                    "provide a dict output {dtypename: result}")
            return {
                d: self._fix_output(result[d], start, end, _dtype=d)
                for d in self.provides
            }

        if _dtype is None:
            assert not self.multi_output
            _dtype = self.provides[0]

        if not isinstance(result, strax.Chunk):
            if start is None:
                assert len(self.depends_on) == 0
                raise ValueError(
                    "Plugins without dependencies must return full strax "
                    f"Chunks, but {self.__class__.__name__} produced a "
                    f"{type(result)}!")

            result = strax.dict_to_rec(result, dtype=self.dtype_for(_dtype))
            self._check_dtype(result, _dtype)
            result = self.chunk(start=start,
                                end=end,
                                data_type=_dtype,
                                data=result)
        return result
Exemplo n.º 2
0
 def _artificial_dead_time(self, start, end, dt):
     return strax.dict_to_rec(
         dict(time=[start],
              length=[(end - start) // dt],
              dt=[dt],
              channel=[ARTIFICIAL_DEADTIME_CHANNEL]),
         self.dtype_for('raw_records'))
Exemplo n.º 3
0
    def _fix_output(self, result, start, end, _dtype=None):
        if self.multi_output and _dtype is None:
            if not isinstance(result, dict):
                raise ValueError(
                    f"{self.__class__.__name__} is multi-output and should "
                    "provide a dict output {dtypename: result}")
            return {
                d: self._fix_output(result[d], start, end, _dtype=d)
                for d in self.provides
            }

        if _dtype is None:
            assert not self.multi_output
            _dtype = self.provides[0]

        if not isinstance(result, strax.Chunk):
            if start is None:
                assert len(self.depends_on) == 0
                raise ValueError(
                    "Plugins without dependencies must return full strax "
                    f"Chunks, but {self.__class__.__name__} produced a "
                    f"{type(result)}!")
            if isinstance(result, dict) and len(result) == 1:
                raise ValueError(
                    f'Ran into single key results dict with key: '
                    f'{list(result.keys())}, cannot convert this to array of '
                    f'dtype {self.dtype_for(_dtype)}.\nSee '
                    f'github.com/AxFoundation/strax/issues/238 for more info')
            result = strax.dict_to_rec(result, dtype=self.dtype_for(_dtype))
            self._check_dtype(result, _dtype)
            result = self.chunk(start=start,
                                end=end,
                                data_type=_dtype,
                                data=result)
        return result
Exemplo n.º 4
0
    def compute(self, aqmon_hits):
        hits = aqmon_hits

        # Make a dict to populate later
        res_temp = dict()

        for i, veto in enumerate(self.veto_names):
            veto_hits = channel_select(hits, self.channel_map[veto + 'stop'],
                                       self.channel_map[veto + 'start'])
            vetos = self.merge_vetos(veto_hits, gap=self.config['min_veto_gap'], \
                                     dtype=strax.time_fields, t=0)

            # Check that we found a veto interval and update the resulting dict
            if len(vetos):
                res_temp.setdefault("time", []).extend(vetos['time'])
                res_temp.setdefault("endtime", []).extend(vetos['endtime'])
                res_temp.setdefault("veto_interval", []).extend(
                    (vetos['endtime'] - vetos['time']))
                res_temp.setdefault("veto_type",
                                    []).extend([veto + 'veto'] * len(vetos))

        res = strax.dict_to_rec(res_temp, dtype=self.dtype)
        res.sort(order='time')

        return res
Exemplo n.º 5
0
    def _fix_output(self, result):
        if self.multi_output:
            if not isinstance(result, dict):
                raise ValueError(
                    f"{self.__class__.__name__} is multi-output and should "
                    "provide a dict output {dtypename: array}")
            r2 = dict()
            for d in self.provides:
                if d not in result:
                    raise ValueError(f"Data type {d} missing from output of "
                                     f"{p.__class__.__name__}!")
                r2[d] = strax.dict_to_rec(result[d], self.dtype_for(d))
                self._check_dtype(r2[d], d)
            return r2

        result = strax.dict_to_rec(result, dtype=self.dtype)
        self._check_dtype(result)
        return result