Add TOS and MAXT
This commit is contained in:
parent
a4a4a5a188
commit
b2874a1d85
63
minigrida/descriptors/max_aps.py
Normal file
63
minigrida/descriptors/max_aps.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# file max_aps.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 31 mai 2020
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import sap
|
||||||
|
from joblib import Memory
|
||||||
|
|
||||||
|
memory = Memory(location='cache/', verbose=0)
|
||||||
|
|
||||||
|
|
||||||
|
@memory.cache
|
||||||
|
def _max_attribute_profiles(image, attribute, adjacency=4, image_name=None,
|
||||||
|
filtering_rule='direct'):
|
||||||
|
maxt = sap.MaxTree(image, adjacency, image_name)
|
||||||
|
return sap.create_profiles(maxt, attribute, 'altitude',
|
||||||
|
filtering_rule, 'max attribute profiles')
|
||||||
|
|
||||||
|
|
||||||
|
def run(gt, rasters, coords, remove, attributes, adjacency='4',
|
||||||
|
filtering='direct'):
|
||||||
|
X = []
|
||||||
|
y = []
|
||||||
|
groups = []
|
||||||
|
Xn = None
|
||||||
|
|
||||||
|
for i, (gti, rastersi, coordsi) in enumerate(zip(gt, rasters, coords)):
|
||||||
|
# Compute EAP
|
||||||
|
eap = []
|
||||||
|
for name, raster in rastersi.items():
|
||||||
|
eap += [_max_attribute_profiles(raster, attributes, adjacency, name, filtering)]
|
||||||
|
eap = sap.concatenate(eap)
|
||||||
|
|
||||||
|
Xn = [' '.join((a['tree']['image_name'],
|
||||||
|
a['attribute'],
|
||||||
|
*[str(v) for v in p.values()]))
|
||||||
|
for a in eap.description for p in a['profiles']] if not Xn else Xn
|
||||||
|
|
||||||
|
# Create vectors
|
||||||
|
X_raw = np.moveaxis(np.array(list(eap.vectorize())), 0, -1)
|
||||||
|
y_raw = gti
|
||||||
|
|
||||||
|
# Remove unwanted label X, y
|
||||||
|
lbl = np.ones_like(y_raw, dtype=np.bool)
|
||||||
|
for l in remove if remove else []:
|
||||||
|
lbl &= y_raw != l
|
||||||
|
|
||||||
|
X += [X_raw[lbl]]
|
||||||
|
y += [y_raw[lbl]]
|
||||||
|
groups += [np.repeat(coordsi, lbl.sum())]
|
||||||
|
|
||||||
|
X = np.concatenate(X)
|
||||||
|
y = np.concatenate(y)
|
||||||
|
groups = np.concatenate(groups)
|
||||||
|
Xn = rasters[0].keys()
|
||||||
|
|
||||||
|
return X, y, groups, Xn
|
||||||
59
minigrida/descriptors/sdaps.py
Normal file
59
minigrida/descriptors/sdaps.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# file sdaps.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 31 mai 2020
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import sap
|
||||||
|
from joblib import Memory
|
||||||
|
|
||||||
|
memory = Memory(location='cache/', verbose=0)
|
||||||
|
|
||||||
|
|
||||||
|
@memory.cache
|
||||||
|
def _self_dual_attribute_profiles(*kwargs):
|
||||||
|
return sap.self_dual_attribute_profiles(*kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def run(gt, rasters, coords, remove, attributes, adjacency='4', filtering='direct'):
|
||||||
|
X = []
|
||||||
|
y = []
|
||||||
|
groups = []
|
||||||
|
Xn = None
|
||||||
|
|
||||||
|
for i, (gti, rastersi, coordsi) in enumerate(zip(gt, rasters, coords)):
|
||||||
|
# Compute EAP
|
||||||
|
eap = []
|
||||||
|
for name, raster in rastersi.items():
|
||||||
|
eap += [_self_dual_attribute_profiles(raster, attributes, adjacency, name, filtering)]
|
||||||
|
eap = sap.concatenate(eap)
|
||||||
|
|
||||||
|
Xn = [' '.join((a['tree']['image_name'],
|
||||||
|
a['attribute'],
|
||||||
|
*[str(v) for v in p.values()]))
|
||||||
|
for a in eap.description for p in a['profiles']] if not Xn else Xn
|
||||||
|
|
||||||
|
# Create vectors
|
||||||
|
X_raw = np.moveaxis(np.array(list(eap.vectorize())), 0, -1)
|
||||||
|
y_raw = gti
|
||||||
|
|
||||||
|
# Remove unwanted label X, y
|
||||||
|
lbl = np.ones_like(y_raw, dtype=np.bool)
|
||||||
|
for l in remove if remove else []:
|
||||||
|
lbl &= y_raw != l
|
||||||
|
|
||||||
|
X += [X_raw[lbl]]
|
||||||
|
y += [y_raw[lbl]]
|
||||||
|
groups += [np.repeat(coordsi, lbl.sum())]
|
||||||
|
|
||||||
|
X = np.concatenate(X)
|
||||||
|
y = np.concatenate(y)
|
||||||
|
groups = np.concatenate(groups)
|
||||||
|
Xn = rasters[0].keys()
|
||||||
|
|
||||||
|
return X, y, groups, Xn
|
||||||
Loading…
Reference in New Issue
Block a user