Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Geojson file fields #107

Merged
merged 15 commits into from
Dec 4, 2024
Merged
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: CI
on: [push]
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
miniconda:
Expand Down
33 changes: 33 additions & 0 deletions tests/test_earthspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"""

import glob
import json
import os

import numpy as np
Expand Down Expand Up @@ -332,6 +334,37 @@ def test_sentinelhub_request(self) -> None:
# # check that a Sentinel Hub request was created
assert isinstance(sr2, shb.SentinelHubRequest)

def test_geojson_files(self) -> None:
"""Test fields of GEOJSON files"""

# list all geojson files available in earthspy
geojson_files = glob.glob("./earthspy/data/*")

# check that files were found
assert len(geojson_files) > 0

for file in geojson_files:

with open(file, "r+") as f:
data = json.load(f)

# extract coordinates of geometry nodes
geometry_coordinates = np.array(
data["features"][0]["geometry"]["coordinates"][0]
)

# check if feature is a polygon
assert data["features"][0]["geometry"]["type"] == "Polygon"

# check if coordinates match a 4-point square
assert geometry_coordinates.shape == (5, 2)

# check if the coordinates are valid longitude/latitude coordinates
assert ((geometry_coordinates >= -90) & (geometry_coordinates <= 90)).all()

# check if first coordinate is repeated on the last element
assert geometry_coordinates[0, 0] == geometry_coordinates[-1, 0]

def test_rename_output_files(self) -> None:
"""Test output renaming"""

Expand Down
Loading