Example #1
0
 def __init__(self,
              waveform_clients=None,
              event_clients=None,
              station_clients=None):
     self.waveform_clients = iterate(waveform_clients)
     self.event_clients = iterate(event_clients)
     self.station_clients = iterate(station_clients)
Example #2
0
    def _load_dataset_entry_point(cls, name=None, load=True):
        """
        Load and cache the dataset entry points.

        Parameters
        ----------
        name
            A string id of the dataset
        load
            If True, load the code associated with the entry point.
        """
        def _load_ep(ep):
            """Load the entry point, ignore removed datasets."""
            # If a plugin was register but no longer exists it can raise.
            with suppress(ModuleNotFoundError):
                ep.load()
                assert name in cls._datasets, "dataset should be registered."

        if name in cls._entry_points:  # entry point has been registered
            if name in cls._datasets:  # and loaded, return
                return
            elif load:  # it has not been loaded, try loading it.
                _load_ep(cls._entry_points[name])
        # it has not been found, iterate entry points and update
        eps = {x.name: x for x in iter_entry_points("obsplus.datasets")}
        cls._entry_points.update(eps)
        # stop if we don't need to load
        if not load:
            return
        # now iterate through all names, or just selected name, and load
        for name in set(iterate(name or eps)) & set(eps):
            _load_ep(eps[name])
Example #3
0
def check_amp_filter_ids(
    event: Event, filter_ids: Optional[Union[str, Collection[str]]] = None
):
    """
    Check that all amplitudes have codes in filter_ids.
    """
    filter_ids = set(str(x) for x in iterate(filter_ids))
    # There is no amplitude specified
    if not filter_ids:
        return
    bad = []
    bad_filters = []
    for amp in event.amplitudes:
        if str(amp.filter_id) not in filter_ids:
            wid = amp.waveform_id
            nslc = (
                f"{wid.network_code}.{wid.station_code}."
                f"{wid.location_code}.{wid.channel_code}"
            )
            bad.append(nslc)
            if amp.filter_id.id not in bad_filters:
                bad_filters.append(amp.filter_id.id)
    assert len(bad) == 0, (
        "Unexpected amplitude filter found:\n"
        f"event_id: {str(event.resource_id)}, "
        f"seed_id/s: {bad}, "
        f"filters_used: {set(bad_filters)}"
    )
Example #4
0
    def _get_sub_tables(
        self, resource_ids: Union[str, Sequence[str]]
    ) -> Dict[str, pd.DataFrame]:
        """return a dict of all"""
        ids = list(iterate(resource_ids))
        import pdb

        pdb.set_trace()

        return {i: v[v._event_id_.isin(ids)] for i, v in self._dfs.items()}
Example #5
0
    def _iter_client(self, clients, method_name, *args, **kwargs):
        """
        Iterate clients, return any values that aren't None.

        Return None if no data is found.
        """
        for cli in iterate(clients):
            try:
                out = getattr(cli, method_name)(*args, **kwargs)
            except AttributeError:  # client doesn't have required method.
                continue
            # if a non-empty object was obtained return it
            if out is not None and len(out):
                return out
Example #6
0
 def _unindexed_iterator(self, paths: Optional[bank_subpaths_type] = None):
     """Return an iterator of potential unindexed files."""
     # get mtime, subtract a bit to avoid odd bugs
     mtime = None
     last_updated = self.last_updated_timestamp  # this needs db so only call once
     if last_updated is not None:
         mtime = last_updated - 0.001
     # get paths to iterate
     bank_path = self.bank_path
     if paths is None:
         paths = self.bank_path
     else:
         paths = [
             f"{self.bank_path}/{x}" if str(bank_path) not in str(x) else str(x)
             for x in iterate(paths)
         ]
     # return file iterator
     return iter_files(paths, ext=self.ext, mtime=mtime)
Example #7
0
 def _wrap(func):
     _decomposer = _VALIDATOR_STATE["decomposer"]
     for cls_ in iterate(cls):
         _decomposer.register(cls_)(func)
     return func