コード例 #1
0
    def simplify(self):
        # NOTE: podpac prefers unstacked UniformCoordinates to AffineCoordinates
        #       if that changes, just return self.copy()
        if self.affine.is_rectilinear:
            tol = 1e-15  # tolerance for deciding when a number is zero
            a = self.affine
            shape = self.shape

            if np.abs(a.e) <= tol and np.abs(a.a) <= tol:
                order = -1
                step = np.array([a.d, a.b])
            else:
                order = 1
                step = np.array([a.e, a.a])

            origin = a.f + step[0] / 2, a.c + step[1] / 2
            end = origin[0] + step[0] * (shape[::order][0] - 1), origin[1] + step[1] * (shape[::order][1] - 1)
            # when the shape == 1, UniformCoordinates1d cannot infer the step from the size
            # we have have to create the UniformCoordinates1d manually
            if shape[::order][0] == 1:
                lat = UniformCoordinates1d(origin[0], end[0], step=step[0], name="lat")
            else:
                lat = clinspace(origin[0], end[0], shape[::order][0], "lat")
            if shape[::order][1] == 1:
                lon = UniformCoordinates1d(origin[1], end[1], step=step[1], name="lon")
            else:
                lon = clinspace(origin[1], end[1], shape[::order][1], "lon")
            return [lat, lon][::order]

        return self.copy()
コード例 #2
0
def test_clinspace_stacked():
    c = clinspace((0, 10, '2018-01-01'), (1, 20, '2018-01-06'), 6)
    assert isinstance(c, StackedCoordinates)

    c1, c2, c3 = c
    assert isinstance(c1, UniformCoordinates1d)
    assert c1.start == 0.0
    assert c1.stop == 1.0
    assert c1.size == 6
    assert isinstance(c2, UniformCoordinates1d)
    assert c2.start == 10.0
    assert c2.stop == 20.0
    assert c2.size == 6
    assert isinstance(c3, UniformCoordinates1d)
    assert c3.start == np.datetime64('2018-01-01')
    assert c3.stop == np.datetime64('2018-01-06')
    assert c3.size == 6

    # named
    c = clinspace((0, 10, '2018-01-01'), (1, 20, '2018-01-06'),
                  6,
                  name='lat_lon_time')
    assert c.name == 'lat_lon_time'

    # size must be an integer
    with pytest.raises(TypeError):
        clinspace((0, 10), (1, 20), (6, 6))

    with pytest.raises(TypeError):
        clinspace((0, 10), (1, 20), 0.2)

    with pytest.raises(TypeError):
        clinspace((0, 10), (1, 20), (0.2, 1.0))
コード例 #3
0
def test_clinspace():
    # numerical
    c = clinspace(0, 1, 6)
    assert isinstance(c, UniformCoordinates1d)
    assert c.start == 0.0
    assert c.stop == 1.0
    assert c.size == 6

    # datetime
    c = clinspace('2018-01-01', '2018-01-05', 5)
    assert isinstance(c, UniformCoordinates1d)
    assert c.start == np.datetime64('2018-01-01')
    assert c.stop == np.datetime64('2018-01-05')
    assert c.size == 5

    # named
    c = clinspace(0, 1, 6, name='lat')
    assert c.name == 'lat'
コード例 #4
0
ファイル: test_cfunctions.py プロジェクト: creare-com/podpac
def test_clinspace():
    # numerical
    c = clinspace(0, 1, 6)
    assert isinstance(c, UniformCoordinates1d)
    assert c.start == 0.0
    assert c.stop == 1.0
    assert c.size == 6

    # datetime
    c = clinspace("2018-01-01", "2018-01-05", 5)
    assert isinstance(c, UniformCoordinates1d)
    assert c.start == np.datetime64("2018-01-01")
    assert c.stop == np.datetime64("2018-01-05")
    assert c.size == 5

    # named
    c = clinspace(0, 1, 6, name="lat")
    assert c.name == "lat"
コード例 #5
0
    def test_definition(self):
        # array radius and theta, plus other checks
        c = PolarCoordinates(center=[1.5, 2.0],
                             radius=[1, 2, 4, 5],
                             theta=[0, 1, 2],
                             dims=["lat", "lon"])
        d = c.definition

        assert isinstance(d, dict)
        json.dumps(d, cls=podpac.core.utils.JSONEncoder)  # test serializable
        c2 = PolarCoordinates.from_definition(d)
        assert c2 == c

        # uniform radius and theta
        c = PolarCoordinates(center=[1.5, 2.0],
                             radius=clinspace(1, 5, 4),
                             theta=clinspace(0, np.pi, 5),
                             dims=["lat", "lon"])
        d = c.definition
        c2 = PolarCoordinates.from_definition(d)
        assert c2 == c
コード例 #6
0
def test_clinspace_shape_mismatch():
    with pytest.raises(
            ValueError,
            match="Size mismatch, 'start' and 'stop' must have the same size"):
        clinspace(0, (0, 10), 6)