예제 #1
0
파일: __init__.py 프로젝트: goodsonr/satpy
def filter_keys_by_dataset_id(did, key_container):
    """Filer provided key iterable by the provided `DatasetID`.

    Note: The `modifiers` attribute of `did` should be `None` to allow for
          **any** modifier in the results.

    Args:
        did (DatasetID): Query parameters to match in the `key_container`.
        key_container (iterable): Set, list, tuple, or dict of `DatasetID`
                                  keys.

    Returns (list): List of keys matching the provided parameters in no
                    specific order.

    """
    keys = iter(key_container)

    for key in DATASET_KEYS:
        if getattr(did, key) is not None:
            if key == "wavelength":
                keys = [k for k in keys
                        if (getattr(k, key) is not None and
                            DatasetID.wavelength_match(getattr(k, key),
                                                       getattr(did, key)))]
            else:
                keys = [k for k in keys
                        if getattr(k, key) is not None and getattr(k, key)
                        == getattr(did, key)]

    return keys
예제 #2
0
def filter_keys_by_dataset_id(did, key_container):
    """Filer provided key iterable by the provided `DatasetID`.

    Note: The `modifiers` attribute of `did` should be `None` to allow for
          **any** modifier in the results.

    Args:
        did (DatasetID): Query parameters to match in the `key_container`.
        key_container (iterable): Set, list, tuple, or dict of `DatasetID`
                                  keys.

    Returns (list): List of keys matching the provided parameters in no
                    specific order.

    """
    keys = iter(key_container)

    for key in DATASET_KEYS:
        if getattr(did, key) is not None:
            if key == "wavelength":
                keys = [k for k in keys
                        if (getattr(k, key) is not None and
                            DatasetID.wavelength_match(getattr(k, key),
                                                       getattr(did, key)))]
            else:
                keys = [k for k in keys
                        if getattr(k, key) is not None and getattr(k, key)
                        == getattr(did, key)]

    return keys
예제 #3
0
    def get_keys(self,
                 name_or_wl,
                 resolution=None,
                 polarization=None,
                 calibration=None,
                 modifiers=None):
        # Get things that match at least the name_or_wl
        if isinstance(name_or_wl, numbers.Number):
            keys = [
                k for k in self.keys()
                if DatasetID.wavelength_match(k.wavelength, name_or_wl)
            ]
        elif isinstance(name_or_wl, (str, six.text_type)):
            keys = [
                k for k in self.keys()
                if DatasetID.name_match(k.name, name_or_wl)
            ]
        else:
            raise TypeError("First argument must be a wavelength or name")

        if resolution is not None:
            if not isinstance(resolution, (list, tuple)):
                resolution = (resolution, )
            keys = [
                k for k in keys
                if k.resolution is not None and k.resolution in resolution
            ]
        if polarization is not None:
            if not isinstance(polarization, (list, tuple)):
                polarization = (polarization, )
            keys = [
                k for k in keys if k.polarization is not None
                and k.polarization in polarization
            ]
        if calibration is not None:
            if not isinstance(calibration, (list, tuple)):
                calibration = (calibration, )
            keys = [
                k for k in keys
                if k.calibration is not None and k.calibration in calibration
            ]
        if modifiers is not None:
            keys = [
                k for k in keys
                if k.modifiers is not None and k.modifiers == modifiers
            ]

        return keys
예제 #4
0
    def get_keys_by_datasetid(self, did):
        keys = self.keys()
        for key in DATASET_KEYS:
            if getattr(did, key) is not None:
                if key == "wavelength":
                    keys = [
                        k for k in keys
                        if (getattr(k, key) is not None
                            and DatasetID.wavelength_match(
                                getattr(k, key), getattr(did, key)))
                    ]
                else:
                    keys = [
                        k for k in keys if getattr(k, key) is not None
                        and getattr(k, key) == getattr(did, key)
                    ]

        return keys
예제 #5
0
    def get_key(self, key):
        if isinstance(key, DatasetID):
            res = self.get_keys_by_datasetid(key)
            if not res:
                return None
            elif len(res) == 1:
                return res[0]

            # more than one dataset matched
            res = self.get_best_choice(key, res)
            if len(res) != 1:
                raise KeyError("No unique dataset matching " + str(key))
            return res[0]
        # get by wavelength
        elif isinstance(key, numbers.Number):
            for k in self.keys():
                if k.wavelength is not None and \
                        DatasetID.wavelength_match(k.wavelength, key):
                    return k
        # get by name
        else:
            for k in self.keys():
                if DatasetID.name_match(k.name, key):
                    return k