コード例 #1
0
def test_compute_grid(shape_path, metric_path):
    # Load the geometry..
    gdf = geojson_reader(shape_path)
    assert not gdf.empty

    handler = ModisEvi(
        config_filepath=abspath(__file__,
                                "../../src/marapp_metrics/earthengine.yaml"),
        grid=True,
        simplify=True,
        best_effort=False,
    )

    # Compute the metric..
    metric = handler.measure(gdf)
    metric_data = metric._asdict()  # convert namedtuple to dict

    # Load or create precomputed data..
    precomputed_data = json_reader(metric_path, True)
    if precomputed_data is None:
        json_writer(metric_path, metric_data)

    # Compare results with precomputed metrics
    for nested_key, value in traverse_nested(precomputed_data):
        if isinstance(value, float):
            assert deepgetattr(metric_data,
                               nested_key) == pytest.approx(value, abs=1e-2)
        else:
            assert deepgetattr(metric_data, nested_key) == value
コード例 #2
0
def test_create_grid_intersections(shape_path, metric_path):
    base = MetricBase(config_filepath=abspath(
        __file__, "../../src/marapp_metrics/earthengine.yaml"))
    degrees = 0.5

    # Create the geometry (triangle)
    polygon = ee.Geometry.Polygon([[[0, 0], [10, 0], [5, 5], [0, 0]]])
    ee_feature = ee.Feature(polygon, {})
    grids = base._create_grid(ee_feature, degrees)

    # Check that unnecessary grids are dropped
    assert len(grids) < 20 * (20 + 1)
コード例 #3
0
def test_create_grid(shape_path, metric_path):
    degrees = 0.5
    base = MetricBase(config_filepath=abspath(
        __file__, "../../src/marapp_metrics/earthengine.yaml"))

    # Create the geometry.
    polygon = ee.Geometry.Polygon([[[0, 0], [10, 0], [10, 10], [0, 10], [0,
                                                                         0]]])
    ee_feature = ee.Feature(polygon, {})
    grids = base._create_grid(ee_feature, degrees)

    # Check that correct number of grids are made (note the extra 1 is from rounding errors in the bounds method)
    assert len(grids) == 20 * (20 + 1)
コード例 #4
0
def test_throw_area_exception(shape_path, metric_path):
    # Load the geometry..
    gdf = geojson_reader(shape_path)
    assert not gdf.empty

    handler = ModisEvi(
        config_filepath=abspath(__file__,
                                "../../src/marapp_metrics/earthengine.yaml"),
        use_exceeds_limit=True,
    )

    # Large shape should throw an exception
    with pytest.raises(MetricComputeException):
        handler.measure(gdf, area_km2=1e18)