Beispiel #1
0
    def test_get_geospatial_meta(self):
        meta = utils.get_geographic_attributes(self.geo)

        assert meta == {
            'variables': {
                'y': {
                    'attributes': {
                        'actual_min': 1,
                        'actual_max': 4,
                    }
                },
                'x': {
                    'attributes': {
                        'actual_min': -4,
                        'actual_max': -1,
                    }
                },
            },
            'attributes': {
                'geospatial_lat_min': 1.0,
                'geospatial_lat_max': 4.0,
                'geospatial_lon_min': -4.0,
                'geospatial_lon_max': -1.0,
                'geospatial_bbox': 'POLYGON ((-1 1, -1 4, -4 4, -4 1, -1 1))',
                'geospatial_bounds': 'LINESTRING (-1 1, -4 4)',
                'geospatial_bounds_crs': 'EPSG:4326',
            }
        }
Beispiel #2
0
    def test_wrap_small_coords(self):

        geo = pd.DataFrame({'x': [-1, -2], 'y': [1, 2]})

        meta = utils.get_geographic_attributes(geo)

        assert meta == {
            'variables': {
                'y': {
                    'attributes': {
                        'actual_min': 1,
                        'actual_max': 2,
                    }
                },
                'x': {
                    'attributes': {
                        'actual_min': -2,
                        'actual_max': -1,
                    }
                },
            },
            'attributes': {
                'geospatial_lat_min': 1,
                'geospatial_lat_max': 2,
                'geospatial_lon_min': -2,
                'geospatial_lon_max': -1,
                'geospatial_bbox': 'POLYGON ((-1 1, -1 2, -2 2, -2 1, -1 1))',
                'geospatial_bounds': 'LINESTRING (-1 1, -2 2)',
                'geospatial_bounds_crs': 'EPSG:4326',
            }
        }
Beispiel #3
0
    def test_wrap_same_coords(self):

        geo = pd.DataFrame({'x': [-1, -1, -1], 'y': [1, 1, 1]})

        meta = utils.get_geographic_attributes(geo)

        assert meta == {
            'variables': {
                'y': {
                    'attributes': {
                        'actual_min': 1,
                        'actual_max': 1,
                    }
                },
                'x': {
                    'attributes': {
                        'actual_min': -1,
                        'actual_max': -1,
                    }
                },
            },
            'attributes': {
                'geospatial_lat_min': 1,
                'geospatial_lat_max': 1,
                'geospatial_lon_min': -1,
                'geospatial_lon_max': -1,
                'geospatial_bbox': 'POLYGON ((-1 1, -1 1, -1 1, -1 1))',
                'geospatial_bounds': 'POINT (-1 1)',
                'geospatial_bounds_crs': 'EPSG:4326',
            }
        }
Beispiel #4
0
    def test_wrap_dateline(self):
        ncfile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                              "resources/wrapping_dateline.nc")

        with CFDataset.load(ncfile) as ncd:
            axes = {
                't': 'time',
                'z': 'z',
                'x': 'lon',
                'y': 'lat',
            }
            df = ncd.to_dataframe(axes=axes)

            meta = utils.get_geographic_attributes(df, axes=axes)

            assert meta == {
                "variables": {
                    "lat": {
                        "attributes": {
                            "actual_min": 61.777,
                            "actual_max": 67.068
                        }
                    },
                    "lon": {
                        "attributes": {
                            "actual_min": -179.966,
                            "actual_max": 179.858
                        }
                    }
                },
                "attributes": {
                    "geospatial_lat_min": 61.777,
                    "geospatial_lat_max": 67.068,
                    "geospatial_lon_min": -179.966,
                    "geospatial_lon_max": 179.858,
                    "geospatial_bbox":
                    "POLYGON ((198.669 61.777, 198.669 67.068, 174.792 67.068, 174.792 61.777, 198.669 61.777))",
                    'geospatial_bounds':
                    "POLYGON ((174.792 61.777, 174.926 62.206, 178.838667737 64.055605136, 178.916 64.084, 179.858 64.311, 192.86 67.029, 196.86 67.068, 198.669 66.861, 187.753767857 64.334204193, 179.195 62.395, 176.169 61.862, 174.792 61.777))",
                    "geospatial_bounds_crs": "EPSG:4326"
                }
            }