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

[POC]: delete richdem from source #558

Open
10 tasks
adebardo opened this issue Aug 2, 2024 · 0 comments
Open
10 tasks

[POC]: delete richdem from source #558

adebardo opened this issue Aug 2, 2024 · 0 comments
Labels
[POC] Conception To review Tickets needs approval about it conception

Comments

@adebardo
Copy link

adebardo commented Aug 2, 2024

Context

The purpose of this ticket is to remove the dependency richdem in the source files to ensure its license does not alter the license of xdem.

Indeed, the GNU GPL v3.0 free license is strongly copyleft. In other words, it applies to:

  • The original Richdem project
  • Any derivative work (i.e., any modified version of Richdem)
  • Any combined work (i.e., any software linked binary to Richdem)

The xDEM project falls into the third category, as it uses the Richdem API and imports the symbols exposed by this package (i.e., this library).

Code

  • In the setup.cfg, move the richdem dependency to test and remove it from opt
  • Remove the calls to richdem and modify the APIs in the files:
    • terrain.py
    • dem.py
      Example on the maximum_curvature function:
@overload  
def maximum_curvature(  
    dem: RasterType,  
    resolution: float | tuple[float, float] | None = None,  
- use_richdem: bool = False,  
) -> RasterType:  
    ...
  • delete _get_terrainattr_richdem (maybe use in tests)

Test

The use of richdem in the tests does not impact the xdem license. Therefore, it is possible to keep the ground truth generated by xdem.

Two Solutions are Possible:

1 - Keep richdem

However, it is necessary to remove the tests that verify the outputs of richdem in certain APIs. Thus, we will no longer be able to generate the terrain ground truth as follows:

# Functions for RichDEM wrapper methods  
functions_richdem = {  
-    "slope_Horn": lambda dem: xdem.terrain.slope(dem, degrees=True, use_richdem=True),  
-    "aspect_Horn": lambda dem: xdem.terrain.aspect(dem, degrees=True, use_richdem=True),  
-    "hillshade_Horn": lambda dem: xdem.terrain.hillshade(dem, use_richdem=True),  
-    "curvature": lambda dem: xdem.terrain.curvature(dem, use_richdem=True),  
-    "profile_curvature": lambda dem: xdem.terrain.profile_curvature(dem, use_richdem=True),  
-    "planform_curvature": lambda dem: xdem.terrain.planform_curvature(dem, use_richdem=True),  
}

We will need to directly obtain their implementation.

Example for aspect:

def _get_terrainattr_richdem(rst: RasterType, attribute: str = "slope_radians") -> NDArrayf:  
    """  
 Derive terrain attribute for DEM opened with rasterio. One of "slope_degrees", "slope_percentage", "aspect", "profile_curvature", "planform_curvature", "curvature" and others (see RichDEM documentation). :param rst: DEM as raster :param attribute: RichDEM terrain attribute :return: """  
 rda = _raster_to_rda(rst)  
 terrattr = rd.TerrainAttribute(rda, attrib=attribute)  
 terrattr[terrattr == terrattr.no_data] = np.nan  
  
    return np.array(terrattr)
# The aspect of RichDEM is returned in degrees, we convert to radians to match the others  
terrain_attributes["aspect"] = np.deg2rad(_get_terrainattr_richdem(dem, attribute="aspect"))  
# For flat slopes, RichDEM returns a 90° aspect by default, while GDAL return a 180° aspect  
# We stay consistent with GDAL  
slope_tmp = _get_terrainattr_richdem(dem, attribute="slope_radians")  
terrain_attributes["aspect"][slope_tmp == 0] = np.pi

2 - Generate Terrain Truths

  • In a notebook (or script), retrieve the terrain truths and save them in the test folder.
  • In the tests, open these truths and compare the outputs with those of xdem.

Documentation

README(.md|.rst|.txt)

  • add "The RichDEM tool, distributed under the GNU GPL v3.0 license, is used solely for testing purposes and is not required for the operation of xDEM. The xDEM tool itself is distributed under the MIT license."

Contribution Guide

  • add "RichDEM should only be used for testing purposes within the xDEM project. The functionality of xDEM must not depend on RichDEM."

Estimation

2 days

@adebardo adebardo added the [POC] Conception To review Tickets needs approval about it conception label Aug 2, 2024
@adebardo adebardo mentioned this issue Aug 2, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[POC] Conception To review Tickets needs approval about it conception
Projects
None yet
Development

No branches or pull requests

1 participant