Skip to content

Commit

Permalink
Merge branch 'main' into issue9-jenkins-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 24, 2024
2 parents 1fb7b49 + 368d1e5 commit 199df2b
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 61 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
name: "Lint: code quality and formatting checks"
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install isort black ruff
- name: isort
run: python -m isort . --check --diff
# - name: black
# run: python -m black --check --diff .
- name: ruff
run: ruff check .
31 changes: 31 additions & 0 deletions .github/workflows/pytest-collect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pytest-collect

on:
push:
branches: [ main ]
paths:
- 'tests/**'
pull_request:
branches: [ main ]
paths:
- 'tests/**'

jobs:
pytest-collect:
name: "Pytest: check test collection"
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install .[dev]
- name: "pytest: check test collection"
run: pytest --collect-only
19 changes: 17 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"h5netcdf>=1.2.0",
"openeo[localprocessing]",
"cftime",
"pytest-dependency",
"pytest-depends",
"pyarrow",
"fastparquet"
]
Expand All @@ -60,5 +60,20 @@ testpaths = [
"tests",
]
addopts = [
"--import-mode=importlib",
"--import-mode=prepend",
]

[tool.isort]
profile = "black"


[tool.ruff]
# line-length = 100

[tool.ruff.lint]
select = ["E", "F"]
ignore = [
"E501", # Ignore "line-too-long" issues, let black handle that.
]


2 changes: 1 addition & 1 deletion src/openeo_gfmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .backend import Backend, BackendContext
from .metadata import FakeMetadata
from .spatial import SpatialContext, BoundingBoxExtent
from .spatial import BoundingBoxExtent, SpatialContext
from .temporal import TemporalContext

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion src/openeo_gfmap/fetching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"""

from .fetching import CollectionFetcher, FetchType
from .s2 import build_sentinel2_l2a_extractor
from .s1 import build_sentinel1_grd_extractor
from .s2 import build_sentinel2_l2a_extractor

__all__ = [
"build_sentinel2_l2a_extractor", "CollectionFetcher", "FetchType",
Expand Down
7 changes: 3 additions & 4 deletions src/openeo_gfmap/fetching/s1.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
""" Collection fetching of S1 features, supporting different backends.
"""
from typing import Callable
from functools import partial
from typing import Callable

import openeo
from geojson import GeoJSON

from openeo_gfmap.backend import Backend, BackendContext
from openeo_gfmap.spatial import SpatialContext, BoundingBoxExtent
from openeo_gfmap.spatial import SpatialContext
from openeo_gfmap.temporal import TemporalContext

from .fetching import CollectionFetcher, FetchType

from .commons import (
convert_band_names,
load_collection,
rename_bands,
resample_reproject,
)
from .fetching import CollectionFetcher, FetchType

BASE_SENTINEL1_GRD_MAPPING = {
"VH": "S1-VH",
Expand Down
9 changes: 7 additions & 2 deletions src/openeo_gfmap/preprocessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
right after the extraction and the execution of the features UDF.
"""

from openeo_gfmap.preprocessing.cloudmasking import mask_scl_dilation, get_bap_score, bap_masking, get_bap_mask
from openeo_gfmap.preprocessing.cloudmasking import (
bap_masking,
get_bap_mask,
get_bap_score,
mask_scl_dilation,
)
from openeo_gfmap.preprocessing.compositing import mean_compositing, median_compositing
from openeo_gfmap.preprocessing.interpolation import linear_interpolation
from openeo_gfmap.preprocessing.compositing import median_compositing, mean_compositing

__all__ = [
"mask_scl_dilation",
Expand Down
3 changes: 2 additions & 1 deletion src/openeo_gfmap/preprocessing/cloudmasking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Different cloud masking strategies for an OpenEO datacubes."""

from typing import Union
from pathlib import Path
from typing import Union

import openeo
from openeo.processes import if_, is_nan

Expand Down
1 change: 1 addition & 0 deletions src/openeo_gfmap/preprocessing/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import openeo


def linear_interpolation(cube: openeo.DataCube,) -> openeo.DataCube:
"""Perform linear interpolation on the given datacube."""
return cube.apply_dimension(
Expand Down
6 changes: 3 additions & 3 deletions src/openeo_gfmap/preprocessing/udf_rank.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import xarray as xr
from pathlib import Path
import numpy as np

import numpy as np
import xarray as xr
from openeo.udf import XarrayDataCube


def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
"""For a cube having the BAP score, and a given period of list of intervals,
create a binary mask that for each pixel, is True if the BAP score is the
Expand Down
12 changes: 4 additions & 8 deletions src/openeo_gfmap/preprocessing/udf_score.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import math

import numpy as np
import time, math
import xarray as xr
import datetime

from scipy.ndimage import distance_transform_cdt
from skimage.morphology import footprints
from skimage.morphology import binary_erosion, binary_dilation
from openeo.udf import XarrayDataCube
from xarray.ufuncs import isnan as ufuncs_isnan

from scipy.ndimage import distance_transform_cdt
from skimage.morphology import binary_erosion, footprints


def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
Expand Down
1 change: 0 additions & 1 deletion src/openeo_gfmap/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Union

from geojson import GeoJSON
from typing import Dict


@dataclass
Expand Down
2 changes: 0 additions & 2 deletions src/openeo_gfmap/temporal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
""" Definitions of temporal context"""
from dataclasses import dataclass
from typing import Tuple

from datetime import datetime


Expand Down
6 changes: 3 additions & 3 deletions src/openeo_gfmap/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""This sub-module contains utilitary function and tools for OpenEO-GFMap"""

from openeo_gfmap.utils.build_df import load_json
from openeo_gfmap.utils.intervals import quintad_intervals
from openeo_gfmap.utils.tile_processing import (
array_bounds,
arrays_cosine_similarity,
normalize_array,
select_optical_bands,
array_bounds,
select_sar_bands,
arrays_cosine_similarity
)
from openeo_gfmap.utils.intervals import quintad_intervals

__all__ = [
"load_json", "normalize_array", "select_optical_bands", "array_bounds",
Expand Down
1 change: 0 additions & 1 deletion src/openeo_gfmap/utils/build_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
based job. Usefull to collect the output of point based extraction.
"""

from datetime import datetime
from pathlib import Path

import pandas as pd
Expand Down
5 changes: 3 additions & 2 deletions src/openeo_gfmap/utils/catalogue.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Functionalities to interract with product catalogues."""
import requests

from shapely.geometry import shape
from geojson import GeoJSON
from shapely.geometry import shape

from openeo_gfmap import SpatialContext, TemporalContext


def _check_cdse_catalogue(
collection: str,
spatial_extent: SpatialContext,
Expand Down
4 changes: 2 additions & 2 deletions src/openeo_gfmap/utils/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
methods.
"""

from openeo_gfmap import TemporalContext
from datetime import timedelta

from datetime import datetime, timedelta
from openeo_gfmap import TemporalContext


def quintad_intervals(temporal_extent: TemporalContext) -> list:
Expand Down
3 changes: 2 additions & 1 deletion src/openeo_gfmap/utils/tile_processing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Utilitaries to process data tiles."""

import xarray as xr
import numpy as np
import xarray as xr


def normalize_array(
inarr: xr.DataArray,
Expand Down
Empty file.
15 changes: 7 additions & 8 deletions tests/test_openeo_gfmap/test_cloud_masking.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from pathlib import Path

from typing import Union

import pytest

from openeo_gfmap.backend import Backend, BackendContext, BACKEND_CONNECTIONS
from openeo_gfmap.temporal import TemporalContext
from openeo_gfmap.spatial import BoundingBoxExtent
from openeo_gfmap.backend import BACKEND_CONNECTIONS, Backend, BackendContext
from openeo_gfmap.fetching import FetchType, build_sentinel2_l2a_extractor

from openeo_gfmap.preprocessing import (
get_bap_score, bap_masking, median_compositing, get_bap_mask
bap_masking,
get_bap_mask,
get_bap_score,
median_compositing,
)

from openeo_gfmap.spatial import BoundingBoxExtent
from openeo_gfmap.temporal import TemporalContext
from openeo_gfmap.utils import quintad_intervals

backends = [Backend.TERRASCOPE, Backend.CDSE]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_openeo_gfmap/test_intervals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from openeo_gfmap.utils import quintad_intervals
from openeo_gfmap.temporal import TemporalContext
from openeo_gfmap.utils import quintad_intervals


def test_quintad_january():
start_date = "2023-01-01"
Expand Down
33 changes: 19 additions & 14 deletions tests/test_openeo_gfmap/test_s1_fetchers.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
""" Test the data extractors for Sentinel1 data. """
from pathlib import Path

import pytest

import geojson
import openeo
import geopandas as gpd
import xarray as xr
import openeo
import pytest
import rioxarray
import xarray as xr

from openeo_gfmap.backend import BACKEND_CONNECTIONS
from openeo_gfmap import (
SpatialContext, TemporalContext, Backend, BackendContext, BoundingBoxExtent
Backend,
BackendContext,
BoundingBoxExtent,
SpatialContext,
TemporalContext,
)

from openeo_gfmap.backend import BACKEND_CONNECTIONS
from openeo_gfmap.fetching import (
CollectionFetcher, build_sentinel1_grd_extractor, FetchType
CollectionFetcher,
FetchType,
build_sentinel1_grd_extractor,
)

from openeo_gfmap.utils import (
array_bounds, normalize_array, select_sar_bands, arrays_cosine_similarity,
load_json
array_bounds,
arrays_cosine_similarity,
load_json,
normalize_array,
select_sar_bands,
)

# Retrieve the test parameters from the s2 fetcher tests
from .test_s2_fetchers import (
test_configurations, test_backends, POINT_EXTRACTION_DF
)
from .test_s2_fetchers import POINT_EXTRACTION_DF, test_backends, test_configurations


class TestS1Extractors:
"""Build collection extractor for different S1 collections on different
Expand Down
Loading

0 comments on commit 199df2b

Please sign in to comment.