creare-com / podpac

Pipeline for Observational Data Processing Analysis and Collaboration
https://podpac.org
Apache License 2.0
45 stars 6 forks source link

ENH: Node get_bounds method. #486

Closed jmilloy closed 3 years ago

jmilloy commented 3 years ago

Any node

    def test_get_bounds(self):
        class MyNode(Node):
            def find_coordinates(self):
                return [
                    podpac.Coordinates([[0, 1, 2], [0, 10, 20]], dims=["lat", "lon"], crs="EPSG:2193"),
                    podpac.Coordinates([[3, 4], [30, 40]], dims=["lat", "lon"], crs="EPSG:2193"),
                ]

        node = MyNode()

        with podpac.settings:
            podpac.settings["DEFAULT_CRS"] = "EPSG:4326"

            # specify crs
            bounds, crs = node.get_bounds(crs="EPSG:2193")
            assert bounds == {"lat": (0, 4), "lon": (0, 40)}
            assert crs == "EPSG:2193"

            # default crs
            bounds, crs = node.get_bounds()
            assert bounds == {
                "lat": (-75.81397534013118, -75.81362774074242),
                "lon": (82.92787904584206, 82.9280189659297),
            }
            assert crs == "EPSG:4326"

Special case for Datasources

    def test_get_bounds(self):
        node = podpac.data.Array(
            source=np.ones((3, 4)),
            coordinates=podpac.Coordinates([range(3), range(4)], ["lat", "lon"], crs="EPSG:2193"),
        )

        with podpac.settings:
            podpac.settings["DEFAULT_CRS"] = "EPSG:4326"

            # specify crs
            bounds, crs = node.get_bounds(crs="EPSG:3857")
            assert bounds == {
                "lat": (-13291827.558247399, -13291815.707967814),
                "lon": (9231489.26794932, 9231497.142754894),
            }
            assert crs == "EPSG:3857"

            # native/source crs
            bounds, crs = node.get_bounds(crs="source")
            assert bounds == {"lat": (0, 2), "lon": (0, 3)}
            assert crs == "EPSG:2193"

            # default crs
            bounds, crs = node.get_bounds()
            assert bounds == {
                "lat": (-75.81365382984804, -75.81362774074242),
                "lon": (82.92787904584206, 82.92794978642414),
            }
            assert crs == "EPSG:4326"

closes #467