Пример #1
0
    def fix_dtype(self):
        if not hasattr(self, 'dtype'):
            self.dtype = self.infer_dtype()

        if self.multi_output:
            # Convert to a dict of numpy dtypes
            if (not hasattr(self, 'data_kind')
                    or not isinstance(self.data_kind, (dict, immutabledict))):
                raise ValueError(
                    f"{self.__class__.__name__} has multiple outputs and "
                    "must declare its data kind as a dict: "
                    "{dtypename: data kind}.")
            if not isinstance(self.dtype, dict):
                raise ValueError(
                    f"{self.__class__.__name__} has multiple outputs, so its "
                    "dtype must be specified as a dict: {output: dtype}.")
            self.dtype = {
                k: strax.to_numpy_dtype(dt)
                for k, dt in self.dtype.items()
            }
        else:
            # Convert to a numpy dtype
            self.dtype = strax.to_numpy_dtype(self.dtype)

        # Check required time information is present
        for d in self.provides:
            fieldnames = self.dtype_for(d).names
            ok = 'time' in fieldnames and (
                ('dt' in fieldnames and 'length' in fieldnames)
                or 'endtime' in fieldnames)
            if not ok:
                raise ValueError(
                    f"Missing time and endtime information for {d}")
Пример #2
0
        def get_plugin(d):
            nonlocal plugins

            if d not in self._plugin_class_registry:
                raise KeyError(f"No plugin class registered that provides {d}")

            p = self._plugin_class_registry[d]()
            for d in p.provides:
                plugins[d] = p

            p.run_id = run_id

            # The plugin may not get all the required options here
            # but we don't know if we need the plugin yet
            self._set_plugin_config(p, run_id, tolerant=True)

            p.deps = {d: get_plugin(d) for d in p.depends_on}

            p.lineage = {
                d: (p.__class__.__name__, p.version(run_id), {
                    q: v
                    for q, v in p.config.items() if p.takes_config[q].track
                })
            }
            for d in p.depends_on:
                p.lineage.update(p.deps[d].lineage)

            if not hasattr(p, 'data_kind') and not p.multi_output:
                if len(p.depends_on):
                    # Assume data kind is the same as the first dependency
                    p.data_kind = p.deps[p.depends_on[0]].data_kind
                else:
                    # No dependencies: assume provided data kind and
                    # data type are synonymous
                    p.data_kind = p.provides[0]

            if not hasattr(p, 'dtype'):
                p.dtype = p.infer_dtype()

            if p.multi_output:
                if (not hasattr(p, 'data_kind')
                        or not isinstance(p.data_kind, dict)):
                    raise ValueError(
                        f"{p.__class__.__name__} has multiple outputs and "
                        "must declare its data kind as a dict: "
                        "{dtypename: data kind}.")
                if not isinstance(p.dtype, dict):
                    raise ValueError(
                        f"{p.__class__.__name__} has multiple outputs, so its "
                        "dtype must be specified as a dict: {output: dtype}.")
                p.dtype = {
                    k: strax.to_numpy_dtype(dt)
                    for k, dt in p.dtype.items()
                }
            else:
                p.dtype = strax.to_numpy_dtype(p.dtype)

            return p