Example #1
0
    def test_outputs(self):
        # standard single-output
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
        assert node.outputs is None

        # even if the sources have multiple outputs, the default here is outputs
        node = BaseCompositor(sources=[MULTI_0_XY, MULTI_1_XY])
        assert node.outputs is None
Example #2
0
 def test_iteroutputs_empty(self):
     node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
     outputs = node.iteroutputs(
         podpac.Coordinates([-1, -1, -1], dims=["lat", "lon", "time"]))
     np.testing.assert_array_equal(next(outputs), [[[np.nan]]])
     np.testing.assert_array_equal(next(outputs), [[[np.nan]]])
     np.testing.assert_array_equal(next(outputs), [[[np.nan]]])
     with pytest.raises(StopIteration):
         next(outputs)
Example #3
0
    def test_select_sources_default(self):
        node = BaseCompositor(
            sources=[DataSource(),
                     DataSource(),
                     podpac.algorithm.Arange()])
        sources = node.select_sources(podpac.Coordinates([[0, 10]], ["time"]))

        assert isinstance(sources, list)
        assert len(sources) == 3
Example #4
0
    def test_iteroutputs_singlethreaded(self):
        with podpac.settings:
            podpac.settings["MULTITHREADING"] = False

            node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
            outputs = node.iteroutputs(COORDS)
            np.testing.assert_array_equal(next(outputs), LAT)
            np.testing.assert_array_equal(next(outputs), LON)
            np.testing.assert_array_equal(next(outputs), TIME)
            with pytest.raises(StopIteration):
                next(outputs)
            assert node._multi_threaded == False
Example #5
0
    def test_iteroutputs_n_threads_1(self):
        with podpac.settings:
            podpac.settings["MULTITHREADING"] = True
            podpac.settings["N_THREADS"] = 1

            n_threads_before = podpac.core.managers.multi_threading.thread_manager._n_threads_used
            node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
            outputs = node.iteroutputs(COORDS)
            np.testing.assert_array_equal(next(outputs), LAT)
            np.testing.assert_array_equal(next(outputs), LON)
            np.testing.assert_array_equal(next(outputs), TIME)
            with pytest.raises(StopIteration):
                next(outputs)
            assert node._multi_threaded == False
            assert podpac.core.managers.multi_threading.thread_manager._n_threads_used == n_threads_before
Example #6
0
    def test_auto_outputs(self):
        # autodetect single-output
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME],
                              auto_outputs=True)
        assert node.outputs is None

        # autodetect multi-output
        node = BaseCompositor(sources=[MULTI_0_XY, MULTI_1_XY],
                              auto_outputs=True)
        assert node.outputs == ["x", "y"]

        node = BaseCompositor(sources=[MULTI_0_XY, MULTI_3_Z],
                              auto_outputs=True)
        assert node.outputs == ["x", "y", "z"]

        node = BaseCompositor(sources=[MULTI_3_Z, MULTI_0_XY],
                              auto_outputs=True)
        assert node.outputs == ["z", "x", "y"]

        node = BaseCompositor(sources=[MULTI_0_XY, MULTI_4_YX],
                              auto_outputs=True)
        assert node.outputs == ["x", "y"]

        # mixed
        with pytest.raises(
                ValueError,
                match=
                "Cannot composite standard sources with multi-output sources."
        ):
            node = BaseCompositor(sources=[MULTI_2_X, ARRAY_LAT],
                                  auto_outputs=True)

        # no sources
        node = BaseCompositor(sources=[], auto_outputs=True)
        assert node.outputs is None
Example #7
0
    def test_select_sources_intersection(self):
        source_coords = podpac.Coordinates([[0, 10]], ["time"])
        node = BaseCompositor(sources=[DataSource(),
                                       DataSource()],
                              source_coordinates=source_coords)

        # select all
        selected = node.select_sources(source_coords)
        assert len(selected) == 2
        assert selected[0] == node.sources[0]
        assert selected[1] == node.sources[1]

        # select first
        c = podpac.Coordinates(
            [podpac.clinspace(0, 1, 10),
             podpac.clinspace(0, 1, 11), 0], ["lat", "lon", "time"])
        selected = node.select_sources(c)
        assert len(selected) == 1
        assert selected[0] == node.sources[0]

        # select second
        c = podpac.Coordinates(
            [podpac.clinspace(0, 1, 10),
             podpac.clinspace(0, 1, 11), 10], ["lat", "lon", "time"])
        selected = node.select_sources(c)
        assert len(selected) == 1
        assert selected[0] == node.sources[1]

        # select none
        c = podpac.Coordinates(
            [podpac.clinspace(0, 1, 10),
             podpac.clinspace(0, 1, 11), 100], ["lat", "lon", "time"])
        selected = node.select_sources(c)
        assert len(selected) == 0
Example #8
0
    def test_source_coordinates(self):
        # none (default)
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
        assert node.source_coordinates is None

        # unstacked
        node = BaseCompositor(
            sources=[podpac.algorithm.Arange(),
                     podpac.algorithm.SinCoords()],
            source_coordinates=podpac.Coordinates([[0, 1]], dims=["time"]),
        )

        # stacked
        node = BaseCompositor(
            sources=[podpac.algorithm.Arange(),
                     podpac.algorithm.SinCoords()],
            source_coordinates=podpac.Coordinates([[[0, 1], [10, 20]]],
                                                  dims=["time_alt"]),
        )

        # invalid size
        with pytest.raises(
                ValueError,
                match=
                "Invalid source_coordinates, source and source_coordinates size mismatch"
        ):
            node = BaseCompositor(
                sources=[
                    podpac.algorithm.Arange(),
                    podpac.algorithm.SinCoords()
                ],
                source_coordinates=podpac.Coordinates([[0, 1, 2]],
                                                      dims=["time"]),
            )

        with pytest.raises(
                ValueError,
                match=
                "Invalid source_coordinates, source and source_coordinates size mismatch"
        ):
            node = BaseCompositor(
                sources=[
                    podpac.algorithm.Arange(),
                    podpac.algorithm.SinCoords()
                ],
                source_coordinates=podpac.Coordinates([[0, 1, 2]],
                                                      dims=["time"]),
            )

        # invalid ndims
        with pytest.raises(ValueError, match="Invalid source_coordinates"):
            node = BaseCompositor(
                sources=[
                    podpac.algorithm.Arange(),
                    podpac.algorithm.SinCoords()
                ],
                source_coordinates=podpac.Coordinates([[0, 1], [10, 20]],
                                                      dims=["time", "alt"]),
            )
Example #9
0
    def test_eval(self):
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
        with pytest.raises(NotImplementedError):
            node.eval(COORDS)

        node = MockComposite(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
        output = node.eval(COORDS)
        np.testing.assert_array_equal(output, LAT)
Example #10
0
    def test_select_sources_set_interpolation(self):
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME],
                              interpolation="nearest")
        sources = node.select_sources(COORDS)
        assert sources[0].interpolation == "nearest"
        assert sources[1].interpolation == "nearest"
        assert sources[2].interpolation == "nearest"
        assert ARRAY_LAT.interpolation == "bilinear"
        assert ARRAY_LON.interpolation == "bilinear"
        assert ARRAY_TIME.interpolation == "bilinear"

        # if no interpolation is provided, keep the source interpolation values
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
        sources = node.select_sources(COORDS)
        assert node.sources[0].interpolation == "bilinear"
        assert node.sources[1].interpolation == "bilinear"
        assert node.sources[2].interpolation == "bilinear"
Example #11
0
 def test_init(self):
     node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
     repr(node)
Example #12
0
    def test_find_coordinates(self):
        node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])

        coord_list = node.find_coordinates()
        assert isinstance(coord_list, list)
        assert len(coord_list) == 3
Example #13
0
 def test_composite(self):
     node = BaseCompositor(sources=[ARRAY_LAT, ARRAY_LON, ARRAY_TIME])
     with pytest.raises(NotImplementedError):
         node.composite(COORDS, iter(()))