Fix APs and display stack
This commit is contained in:
parent
8e4e6e0ef4
commit
747491d36d
@ -157,7 +157,7 @@
|
|||||||
"sd = np.array([0.5,0.9,0.99,0.999])#,1e4,1e5,5e5])\n",
|
"sd = np.array([0.5,0.9,0.99,0.999])#,1e4,1e5,5e5])\n",
|
||||||
"moi = np.array([0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.99])\n",
|
"moi = np.array([0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.99])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"t = triskele.Triskele(layers_stack[:,:,0], verbose=False)\n",
|
"t = triskele.Triskele(layers_stack[:,:,:2], verbose=False)\n",
|
||||||
"attributes_min = t.filter(tree='min-tree',\n",
|
"attributes_min = t.filter(tree='min-tree',\n",
|
||||||
" area=area,\n",
|
" area=area,\n",
|
||||||
" standard_deviation=sd,\n",
|
" standard_deviation=sd,\n",
|
||||||
|
|||||||
@ -24,15 +24,13 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"load = ld2dap.LoadTIFF(('../Data/test.tiff', '../Data/test2.tiff'))\n",
|
"load = ld2dap.LoadTIFF('../Data/phase1_rasters/DEM_C123_TLI/UH17_GEG05_TR.tif')\n",
|
||||||
"trsh = ld2dap.Treshold(1e4)\n",
|
"trsh = ld2dap.Treshold(1e4)\n",
|
||||||
"aps = ld2dap.AttributeProfiles(area=[100, 1e3, 1e4])\n",
|
"aps = ld2dap.AttributeProfiles(area=[1e6], moi=[.5])\n",
|
||||||
"aps2 = ld2dap.AttributeProfiles(area=[100, 1e3, 1e4])\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"disp = ld2dap.ShowFig(fname=None)\n",
|
"disp = ld2dap.ShowFig('all')\n",
|
||||||
"out = ld2dap.RawOutput()\n",
|
"out = ld2dap.RawOutput()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"aps2.input = aps\n",
|
|
||||||
"out.input = aps\n",
|
"out.input = aps\n",
|
||||||
"disp.input = aps\n",
|
"disp.input = aps\n",
|
||||||
"aps.input = trsh\n",
|
"aps.input = trsh\n",
|
||||||
@ -41,6 +39,15 @@
|
|||||||
"disp.run()"
|
"disp.run()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"' > '.join(x if x is not None else '' for x in out.metadata[0].desc[3])"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@ -50,14 +57,20 @@
|
|||||||
"out.data.shape"
|
"out.data.shape"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"for i, m in enumerate(out.metadata):\n",
|
"print(out.metadata[1])"
|
||||||
" print('{}: {}'.format(i, m))"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -66,7 +79,27 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"load.files"
|
"' > '.join(filter(None, out.metadata[0].desc[3]))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"for x in out.metadata[0].desc:\n",
|
||||||
|
" print (x)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"for i, m in enumerate(out.metadata):\n",
|
||||||
|
" print('{}: {}'.format(i, m))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -43,6 +43,13 @@ class AttributeProfiles(Filter):
|
|||||||
att_offset[att] = len(values) * 2 + 1 if values is not None else 0
|
att_offset[att] = len(values) * 2 + 1 if values is not None else 0
|
||||||
return att_offset
|
return att_offset
|
||||||
|
|
||||||
|
def _process_len(self):
|
||||||
|
att_len = dict()
|
||||||
|
for att in ['area', 'sd', 'moi']:
|
||||||
|
values = self.__getattribute__(att)
|
||||||
|
att_len[att] = len(values) if values is not None else 0
|
||||||
|
return att_len
|
||||||
|
|
||||||
def _process(self, data, metadata):
|
def _process(self, data, metadata):
|
||||||
t = triskele.Triskele(data, verbose=False)
|
t = triskele.Triskele(data, verbose=False)
|
||||||
att_min = t.filter(tree='min-tree', area=self.area,
|
att_min = t.filter(tree='min-tree', area=self.area,
|
||||||
@ -58,23 +65,35 @@ class AttributeProfiles(Filter):
|
|||||||
### Pre-process descriptions
|
### Pre-process descriptions
|
||||||
att_desc = self._process_desc()
|
att_desc = self._process_desc()
|
||||||
|
|
||||||
### Compute stack offsets
|
### Compute stack offsets and att length
|
||||||
|
att_len = self._process_len()
|
||||||
att_offset = self._process_offset()
|
att_offset = self._process_offset()
|
||||||
stack_offset = sum(att_offset.values())
|
stack_offset = sum(att_offset.values())
|
||||||
|
|
||||||
### Merge old and new descriptions
|
### Merge old and new descriptions
|
||||||
metadata_new = list()
|
metadata_new = list()
|
||||||
|
### Re-order to create original APs
|
||||||
|
raster_list = list()
|
||||||
for stack in metadata:
|
for stack in metadata:
|
||||||
if stack.end - stack.begin > 1:
|
if stack.end - stack.begin > 1:
|
||||||
raise NotImplementedError('Nested filtering not implemented yet')
|
raise NotImplementedError('Nested filtering not implemented yet')
|
||||||
|
|
||||||
|
do = dso = 0
|
||||||
for att in ['area', 'sd', 'moi']:
|
for att in ['area', 'sd', 'moi']:
|
||||||
if att_offset[att] == 0:
|
if att_offset[att] == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
stack_new = Stack(stack_offset * stack.begin, att_offset[att],
|
al = att_len[att]
|
||||||
|
raster_list.append(att_min[:,:,do+al:do:-1])
|
||||||
|
raster_list.append(att_min[:,:,0])
|
||||||
|
raster_list.append(att_max[:,:,do+1:do+al+1])
|
||||||
|
do += al
|
||||||
|
|
||||||
|
stack_new = Stack(dso + stack_offset * stack.begin, att_offset[att],
|
||||||
stack.desc[0], stack.symb[0])
|
stack.desc[0], stack.symb[0])
|
||||||
|
|
||||||
|
dso += att_offset[att]
|
||||||
|
|
||||||
for old_desc, new_desc in zip(stack_new.desc, att_desc[att]):
|
for old_desc, new_desc in zip(stack_new.desc, att_desc[att]):
|
||||||
print('DESCRIPTION: {} > {}'.format(old_desc, new_desc))
|
print('DESCRIPTION: {} > {}'.format(old_desc, new_desc))
|
||||||
old_desc.append(new_desc)
|
old_desc.append(new_desc)
|
||||||
@ -82,9 +101,9 @@ class AttributeProfiles(Filter):
|
|||||||
metadata_new.append(stack_new)
|
metadata_new.append(stack_new)
|
||||||
|
|
||||||
|
|
||||||
att = np.dstack((att_min, att_max))
|
data_new = np.dstack(raster_list)
|
||||||
|
|
||||||
return att, metadata_new
|
return data_new, metadata_new
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
area = [10, 100, 1000]
|
area = [10, 100, 1000]
|
||||||
|
|||||||
@ -13,20 +13,32 @@ from ld2dap.core import Output
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
class ShowFig(Output):
|
class ShowFig(Output):
|
||||||
def __init__(self, fname, bbox_inches='tight', pad_inches=1):
|
def __init__(self, stack_id=0, bbox_inches='tight', pad_inches=1):
|
||||||
super().__init__(self.__class__.__name__)
|
super().__init__(self.__class__.__name__)
|
||||||
self.fname = fname
|
|
||||||
self.bbox_inches = bbox_inches
|
self.bbox_inches = bbox_inches
|
||||||
self.pad_inches = pad_inches
|
self.pad_inches = pad_inches
|
||||||
|
self.stack_id = stack_id
|
||||||
|
|
||||||
def _process(self, data, metadata):
|
def _process(self, data, metadata):
|
||||||
|
if self.stack_id == 'all':
|
||||||
|
for stack in metadata:
|
||||||
|
self._showfig(data, stack)
|
||||||
|
else:
|
||||||
|
stack = metadata[self.stack_id]
|
||||||
|
self._showfig(data, stack)
|
||||||
|
|
||||||
|
def _showfig(self, data, stack):
|
||||||
|
fig_count = stack.end - stack.begin
|
||||||
|
|
||||||
im_size = 2
|
im_size = 2
|
||||||
fig = plt.figure(figsize=(16*im_size,3*im_size))
|
fig = plt.figure(figsize=(16*im_size,3*im_size*fig_count))
|
||||||
f1 = fig.add_subplot(111)
|
|
||||||
img = f1.imshow(data[:,:,-1])
|
for i, di in enumerate(range(stack.begin, stack.end)):
|
||||||
plt.colorbar(img)
|
f1 = fig.add_subplot(fig_count, 1, i + 1)
|
||||||
if metadata is not None:
|
img = f1.imshow(data[:,:,di])
|
||||||
print (metadata[0].desc)
|
plt.colorbar(img)
|
||||||
f1.set_title(' > '.join(metadata[0].desc[-1]))
|
f1.set_title(' > '.join(filter(None, stack.desc[i])))
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close(fig)
|
plt.close(fig)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user