コード例 #1
0
    def issubset(self, other):
        """Report whether other coordinates contains these coordinates.

        Arguments
        ---------
        other : Coordinates, Coordinates1d
            Other coordinates to check

        Returns
        -------
        issubset : bool
            True if these coordinates are a subset of the other coordinates.

        Notes
        -----
        This overrides the Coordinates1d.issubset method with optimizations for uniform coordinates.
        """

        from podpac.core.coordinates import Coordinates

        if isinstance(other, Coordinates):
            if self.name not in other.dims:
                return False
            other = other[self.name]

        # use Coordinates1d implementation when the other coordinates are not uniform
        if not other.is_uniform:
            return super(UniformCoordinates1d, self).issubset(other)

        # use Coordinates1d implementation when the steps cannot be compared (e.g. months and days)
        try:
            self.step / other.step
        except TypeError:
            return super(UniformCoordinates1d, self).issubset(other)

        # short-cuts that don't require checking coordinates
        if self.dtype != other.dtype:
            return False

        if self.bounds[0] < other.bounds[0] or self.bounds[1] > other.bounds[1]:
            return False

        # check start and step
        if self.start not in other:
            return False

        if self.size == 1:
            return True

        if self.dtype == np.datetime64:
            return timedelta_divisible(self.step, other.step)
        else:
            return self.step % other.step == 0
コード例 #2
0
    def __contains__(self, item):
        # overrides the Coordinates1d.__contains__ method with optimizations for uniform coordinates.

        try:
            item = make_coord_value(item)
        except:
            return False

        if type(item) != self.dtype:
            return False

        if item < self.bounds[0] or item > self.bounds[1]:
            return False

        if self.dtype == np.datetime64:
            return timedelta_divisible(item - self.start, self.step)
        else:
            return (item - self.start) % self.step == 0
コード例 #3
0
def test_timedelta_divisible():
    assert timedelta_divisible(np.timedelta64(1, "D"), np.timedelta64(1, "D"))
    assert timedelta_divisible(np.timedelta64(4, "D"), np.timedelta64(2, "D"))
    assert timedelta_divisible(np.timedelta64(1, "D"), np.timedelta64(6, "h"))
    assert timedelta_divisible(np.timedelta64(1, "D"), np.timedelta64(6, "m"))
    assert timedelta_divisible(np.timedelta64(1, "D"), np.timedelta64(6, "s"))
    assert timedelta_divisible(np.timedelta64(1, "Y"), np.timedelta64(2, "M"))

    assert not timedelta_divisible(np.timedelta64(4, "D"),
                                   np.timedelta64(3, "D"))
    assert not timedelta_divisible(np.timedelta64(1, "D"),
                                   np.timedelta64(2, "D"))
    assert not timedelta_divisible(np.timedelta64(6, "h"),
                                   np.timedelta64(1, "D"))
    assert not timedelta_divisible(np.timedelta64(1, "D"),
                                   np.timedelta64(5, "h"))

    assert not timedelta_divisible(np.timedelta64(1, "M"),
                                   np.timedelta64(1, "D"))