58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
# \file dfc_lfaps.py
|
|
# \brief TODO
|
|
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
|
# \version 0.1
|
|
# \date 27 août 2018
|
|
#
|
|
# TODO details
|
|
|
|
import numpy as np
|
|
|
|
import sys
|
|
sys.path.append('..')
|
|
import ld2dap
|
|
|
|
# TODO: Add param percentile?
|
|
|
|
dispatcher = {
|
|
'mean': np.mean, # Arithmetic mean
|
|
'median': np.median, # Median
|
|
'average': np.average, # Weighted average (=mean ?)
|
|
'std': np.std, # Standard deviation
|
|
'var': np.var, # Variance
|
|
'amax': np.amax, # Maximum
|
|
'amin': np.amin, # Minimum
|
|
'ptp': np.ptp, # Range of values (max - min)
|
|
}
|
|
|
|
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None, features=['mean'], patch_size=3):
|
|
# Parse parameters type
|
|
treshold = float(treshold)
|
|
areas = None if areas is None else np.array(areas).astype(np.float).astype(np.int)
|
|
sd = None if sd is None else np.array(sd).astype(np.float)
|
|
moi = None if moi is None else np.array(moi).astype(np.float)
|
|
patch_size = int(patch_size)
|
|
features = [dispatcher[x] for x in features]
|
|
|
|
# Pipelines
|
|
loader = ld2dap.LoadTIFF(rasters)
|
|
dfc_filter = ld2dap.Treshold(treshold)
|
|
dfc_filter.input = loader
|
|
aps = ld2dap.AttributeProfiles(area=areas, sd=sd, moi=moi)
|
|
aps.input = dfc_filter
|
|
local_features = ld2dap.LocalFeatures(features, patch_size)
|
|
local_features.input = aps
|
|
out_vectors = ld2dap.RawOutput()
|
|
out_vectors.input = local_features
|
|
|
|
# Compute vectors
|
|
out_vectors.run()
|
|
|
|
return out_vectors.data
|
|
|
|
def version():
|
|
return 'v0.0'
|
|
|