-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added pytests and .lax-File for Netzkater demo data
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import geopandas, pathlib | ||
datadir = pathlib.Path(__file__).parent / '../demo' | ||
|
||
def ensure_netzkater_data(): | ||
import os, wget, zipfile | ||
if not os.path.exists(datadir / 'las_623_5718_1_th_2014-2019.laz'): | ||
if not os.path.exists(datadir / 'data_netzkater.zip'): | ||
print('Downloading file') | ||
wget.download( | ||
'https://geoportal.geoportal-th.de/hoehendaten/LAS/las_2014-2019/las_623_5718_1_th_2014-2019.zip', | ||
str((datadir / 'data_netzkater.zip').absolute())) | ||
print('Unzipping file') | ||
zipfile.ZipFile(str((datadir / 'data_netzkater.zip').absolute())).extractall(str(datadir.absolute())) | ||
|
||
|
||
def test_paper_metrics(): | ||
from pyForMetrix.metricCalculators.publications import MCalc_Hollaus_et_al_2009, MCalc_White_et_al_2015, \ | ||
MCalc_Xu_et_al_2019, MCalc_Woods_et_al_2009 | ||
from pyForMetrix.metrix import PlotMetrics | ||
ensure_netzkater_data() | ||
polys = geopandas.read_file(datadir / 'netzkater_polygons.gpkg') | ||
pm = PlotMetrics([datadir / 'las_623_5718_1_th_2014-2019.laz'], polys) | ||
mcs = [MCalc_Hollaus_et_al_2009(), MCalc_White_et_al_2015(), MCalc_Xu_et_al_2019(), MCalc_Woods_et_al_2009()] | ||
results = pm.calc_custom_metrics(mcs) | ||
assert results.shape == (7,62) | ||
print(results) | ||
|
||
def test_lidRmetrics(): | ||
from pyForMetrix.metricCalculators.types import \ | ||
MCalc_lidRmetrics_lad, \ | ||
MCalc_lidRmetrics_kde, \ | ||
MCalc_lidRmetrics_dispersion, \ | ||
MCalc_lidRmetrics_voxels, \ | ||
MCalc_lidRmetrics_HOME, \ | ||
MCalc_lidRmetrics_percabove, \ | ||
MCalc_lidRmetrics_echo, \ | ||
MCalc_lidRmetrics_basic, \ | ||
MCalc_lidRmetrics_Lmoments, \ | ||
MCalc_lidRmetrics_rumple, \ | ||
MCalc_lidRmetrics_percentiles, \ | ||
MCalc_lidRmetrics_interval, \ | ||
MCalc_lidRmetrics_canopydensity | ||
|
||
from pyForMetrix.metrix import PlotMetrics | ||
ensure_netzkater_data() | ||
polys = geopandas.read_file(datadir / 'netzkater_polygons.gpkg') | ||
pm = PlotMetrics([datadir / 'las_623_5718_1_th_2014-2019.laz'], polys) | ||
mcs = [MCalc_lidRmetrics_lad(), | ||
MCalc_lidRmetrics_kde(), | ||
MCalc_lidRmetrics_dispersion(), | ||
MCalc_lidRmetrics_voxels(), | ||
MCalc_lidRmetrics_HOME(), | ||
MCalc_lidRmetrics_percabove(), | ||
MCalc_lidRmetrics_echo(), | ||
MCalc_lidRmetrics_basic(), | ||
MCalc_lidRmetrics_rumple(), | ||
MCalc_lidRmetrics_percentiles(), | ||
MCalc_lidRmetrics_interval(), | ||
MCalc_lidRmetrics_canopydensity()] | ||
results = pm.calc_custom_metrics(mcs) | ||
assert results.shape == (7,78) | ||
print(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from test_plot_metrics import ensure_netzkater_data, datadir | ||
|
||
|
||
def test_group_metrics(): | ||
from pyForMetrix.metricCalculators.types import MCalc_VisMetrics, MCalc_DensityMetrics, \ | ||
MCalc_HeightMetrics, MCalc_EchoMetrics, MCalc_CoverMetrics, MCalc_VarianceMetrics | ||
from pyForMetrix.metrix import RasterMetrics | ||
from pyForMetrix.normalizer import normalize | ||
ensure_netzkater_data() | ||
import laspy | ||
data = laspy.read(datadir / 'las_623_5718_1_th_2014-2019.laz') | ||
points = { | ||
'points': data.xyz, | ||
'classification': data.classification, | ||
'echo_number': data.return_number, | ||
'scan_angle_rank': data.scan_angle_rank, | ||
'pt_src_id': data.point_source_id | ||
} | ||
normalize(points) | ||
rm = RasterMetrics(points, raster_size=25) | ||
mcs = [MCalc_EchoMetrics(), MCalc_DensityMetrics(), MCalc_CoverMetrics(), | ||
MCalc_VarianceMetrics(), MCalc_HeightMetrics(), MCalc_VisMetrics()] | ||
results = rm.calc_custom_metrics(mcs) | ||
assert results.shape == (40, 40, 35) | ||
assert abs(results.sel({'val':'p100'}).data.max() - 105.63799999) < 0.0001 | ||
|
||
print(results) |