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

Add metrics config unit test #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/danesfield/data/metrics-template-config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Template based on:
# https://github.com/pubgeo/core3d-metrics/blob/a586a44/aoi-example/aoi-example.config
#
# Modifications:
# - CLSMatchValue

[INPUT.REF]
DSMFilename = $ref_prefix-DSM.tif
DTMFilename = $ref_prefix-DTM.tif
CLSFilename = $ref_prefix-CLS.tif
NDXFilename = $ref_prefix-NDX.tif
MTLFilename = $ref_prefix-MTL.tif
#CLSMatchValue = [[6],[17],[6,17],[256]]
CLSMatchValue = 6

[INPUT.TEST]
DSMFilename = $test_dsm
CLSFilename = $test_cls
MTLFilename = $test_mtl
DTMFilename = $test_dtm

[OPTIONS]
QuantizeHeight = false

[PLOTS]
ShowPlots = false
SavePlots = true

[MATERIALS.REF]
MaterialIndices = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
MaterialNames = Unclassified,Asphalt,Concrete/Stone,Glass,Tree,Non-tree vegetation,Metal,Ceramic,Soil,Solar panel,Water,Polymer,Unscored,Indeterminate,Indeterminate asphalt/concrete
MaterialIndicesToIgnore = 0,12,13
32 changes: 32 additions & 0 deletions tests/danesfield/metrics/test_metrics_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
###############################################################################
# Copyright Kitware Inc. and Contributors
# Distributed under the Apache License, 2.0 (apache.org/licenses/LICENSE-2.0)
# See accompanying Copyright.txt and LICENSE files for details
###############################################################################
from danesfield.metrics.config import _current_path, get_filename, get_template, populate_template
from os.path import dirname, join

data_dir = join(dirname(dirname(__file__)), 'data')


def test__current_path():
danesfield_root = dirname(dirname(dirname(data_dir)))
assert _current_path() == join(danesfield_root, 'danesfield', 'metrics')


def test_get_filename():
file1 = 'test_dsm.tif'
file2 = 'test_cls.tif'
assert get_filename(file1, file2) == 'test_dsm__test_cls.config'


def test_get_template():
with open(join(data_dir, 'metrics-template-config.txt'), 'r') as f:
contents = f.read()
assert get_template() == contents


def test_populate_template():
template = '$ref_prefix $test_dsm $test_cls $test_mtl $test_dtm'
populated = populate_template(template, 'prefix', 'dsm', 'cls', 'mtl', 'dtm')
assert populated == 'prefix dsm cls mtl dtm'