Kind of working for once
This commit is contained in:
parent
747491d36d
commit
02657bea40
@ -24,21 +24,81 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"load = ld2dap.LoadTIFF('../Data/phase1_rasters/DEM_C123_TLI/UH17_GEG05_TR.tif')\n",
|
||||
"load = ld2dap.LoadTIFF(('../Data/phase1_rasters/DEM_C123_TLI/UH17_GEG05_TR.tif', '../Data/phase1_rasters/Intensity_C1/UH17_GI1F051_TR.tif')[:])\n",
|
||||
"trsh = ld2dap.Treshold(1e4)\n",
|
||||
"aps = ld2dap.AttributeProfiles(area=[1e6], moi=[.5])\n",
|
||||
"aps = ld2dap.AttributeProfiles(area=[1e4,1e5], moi=[.1,.5,.9])\n",
|
||||
"diff = ld2dap.Differential()\n",
|
||||
"\n",
|
||||
"disp = ld2dap.ShowFig('all')\n",
|
||||
"disp = ld2dap.ShowFig('all', True)\n",
|
||||
"out = ld2dap.RawOutput()\n",
|
||||
"\n",
|
||||
"out.input = aps\n",
|
||||
"disp.input = aps\n",
|
||||
"out2 = ld2dap.RawOutput()\n",
|
||||
"\n",
|
||||
"out2.input = diff\n",
|
||||
"disp.input = diff\n",
|
||||
"\n",
|
||||
"diff.input = aps\n",
|
||||
"\n",
|
||||
"aps.input = trsh\n",
|
||||
"\n",
|
||||
"trsh.input = load\n",
|
||||
"\n",
|
||||
"disp.run()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(out.metadata[1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"out.data.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.imshow(out.data[:,:,10])\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"load = ld2dap.LoadTIFF(('../Data/phase1_rasters/DEM_C123_TLI/UH17_GEG05_TR.tif', '../Data/phase1_rasters/Intensity_C1/UH17_GI1F051_TR.tif')[1])\n",
|
||||
"disp = ld2dap.ShowFig('all')\n",
|
||||
"trsh = ld2dap.Treshold(1e4)\n",
|
||||
"\n",
|
||||
"trsh.input = load\n",
|
||||
"disp.input = trsh\n",
|
||||
"\n",
|
||||
"disp.run()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(out)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@ -54,7 +114,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"out.data.shape"
|
||||
"print(out.metadata[1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -62,7 +122,18 @@
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"disp._showfig(data=out.data, stack=out.metadata[1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"out.data[:,:,5] == out.data[:,:,-1]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
||||
@ -36,6 +36,19 @@ class AttributeProfiles(Filter):
|
||||
|
||||
return att_desc
|
||||
|
||||
def _process_symb(self):
|
||||
att_symb = dict()
|
||||
for att in ['area', 'sd', 'moi']:
|
||||
att_symb[att] = list()
|
||||
if self.__getattribute__(att) is not None:
|
||||
att_symb[att].extend(
|
||||
['\phi^{{{}}}_{{{}}}'.format(att, x) for x in self.__getattribute__(att)[::-1]])
|
||||
att_symb[att].append(None)
|
||||
att_symb[att].extend(
|
||||
['\gamma^{{{}}}_{{{}}}'.format(att, x) for x in self.__getattribute__(att)])
|
||||
|
||||
return att_symb
|
||||
|
||||
def _process_offset(self):
|
||||
att_offset = dict()
|
||||
for att in ['area', 'sd', 'moi']:
|
||||
@ -64,11 +77,15 @@ class AttributeProfiles(Filter):
|
||||
## Create new metadata
|
||||
### Pre-process descriptions
|
||||
att_desc = self._process_desc()
|
||||
att_symb = self._process_symb()
|
||||
|
||||
### Compute stack offsets and att length
|
||||
att_len = self._process_len()
|
||||
att_offset = self._process_offset()
|
||||
stack_offset = sum(att_offset.values())
|
||||
raster_offset = sum(att_len.values())
|
||||
print('DEBUG: att offset: {}, att len: {}'.format(att_offset, att_len))
|
||||
print('DEBUG: stack offset: {}, raster offset: {}'.format(stack_offset, raster_offset))
|
||||
|
||||
### Merge old and new descriptions
|
||||
metadata_new = list()
|
||||
@ -79,14 +96,16 @@ class AttributeProfiles(Filter):
|
||||
raise NotImplementedError('Nested filtering not implemented yet')
|
||||
|
||||
do = dso = 0
|
||||
sb = stack.begin * (raster_offset + 1)
|
||||
for att in ['area', 'sd', 'moi']:
|
||||
if att_offset[att] == 0:
|
||||
continue
|
||||
|
||||
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])
|
||||
raster_list.append(att_min[:,:,sb+do+al:sb+do:-1])
|
||||
raster_list.append(att_min[:,:,sb])
|
||||
print('DEBUG: copying layer {}'.format(sb))
|
||||
raster_list.append(att_max[:,:,sb+do+1:sb+do+al+1])
|
||||
do += al
|
||||
|
||||
stack_new = Stack(dso + stack_offset * stack.begin, att_offset[att],
|
||||
@ -98,6 +117,10 @@ class AttributeProfiles(Filter):
|
||||
print('DESCRIPTION: {} > {}'.format(old_desc, new_desc))
|
||||
old_desc.append(new_desc)
|
||||
|
||||
for old_symb, new_symb in zip(stack_new.symb, att_symb[att]):
|
||||
print('symbRIPTION: {} > {}'.format(old_symb, new_symb))
|
||||
old_symb.append(new_symb)
|
||||
|
||||
metadata_new.append(stack_new)
|
||||
|
||||
|
||||
|
||||
50
ld2dap/Differential.py
Normal file
50
ld2dap/Differential.py
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Differential.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 16 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from ld2dap.core import Filter, Stack
|
||||
import numpy as np
|
||||
|
||||
class Differential(Filter):
|
||||
def __init__(self):
|
||||
super().__init__(self.__class__.__name__)
|
||||
|
||||
def _process(self, data, metadata):
|
||||
raster_list = list()
|
||||
metadata_new = list()
|
||||
|
||||
offset = 0
|
||||
for stack in metadata:
|
||||
print('Differential: {}'.format(stack))
|
||||
raster_list.append(data[:,:,stack.begin+1:stack.end] -
|
||||
data[:,:,stack.begin:stack.end-1])
|
||||
|
||||
size_new = stack.end - stack.begin - 1
|
||||
stack_new = Stack(offset, size_new)
|
||||
|
||||
for i in range(len(stack_new.desc)):
|
||||
desc = stack.desc[i].copy()
|
||||
desc.append(':Differential:')
|
||||
desc.extend(stack.desc[i+1])
|
||||
stack_new.desc[i] = desc
|
||||
metadata_new.append(stack_new)
|
||||
|
||||
for i in range(len(stack_new.symb)):
|
||||
symb = list() #['D(']
|
||||
symb.extend(stack.symb[i])
|
||||
symb.append(' - ')
|
||||
symb.extend(stack.symb[i+1])
|
||||
#symb.append(')')
|
||||
stack_new.symb[i] = symb
|
||||
|
||||
offset += size_new
|
||||
|
||||
data = np.dstack(raster_list)
|
||||
|
||||
return data, metadata_new
|
||||
@ -13,11 +13,12 @@ from ld2dap.core import Output
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
class ShowFig(Output):
|
||||
def __init__(self, stack_id=0, bbox_inches='tight', pad_inches=1):
|
||||
def __init__(self, stack_id=0, symb=False, bbox_inches='tight', pad_inches=1):
|
||||
super().__init__(self.__class__.__name__)
|
||||
self.bbox_inches = bbox_inches
|
||||
self.pad_inches = pad_inches
|
||||
self.stack_id = stack_id
|
||||
self.symb = symb
|
||||
|
||||
def _process(self, data, metadata):
|
||||
if self.stack_id == 'all':
|
||||
@ -37,8 +38,11 @@ class ShowFig(Output):
|
||||
f1 = fig.add_subplot(fig_count, 1, i + 1)
|
||||
img = f1.imshow(data[:,:,di])
|
||||
plt.colorbar(img)
|
||||
f1.set_title(' > '.join(filter(None, stack.desc[i])))
|
||||
if self.symb:
|
||||
plt.rc('text', usetex=True)
|
||||
f1.set_title('${}$'.format(''.join(filter(None, stack.symb[i]))))
|
||||
else:
|
||||
f1.set_title(' > '.join(filter(None, stack.desc[i])))
|
||||
|
||||
plt.show()
|
||||
plt.close(fig)
|
||||
|
||||
|
||||
@ -23,6 +23,6 @@ class Treshold(Filter):
|
||||
for stack in metadata:
|
||||
for d, s in zip(stack.desc, stack.symb):
|
||||
d.append('treshold {}'.format(self.treshold))
|
||||
s.append('T_{{{}}}'.format(self.treshold))
|
||||
#s.append('T_{{{}}}'.format(self.treshold))
|
||||
|
||||
return data * (data < self.treshold) + self.max_value * (data >= self.treshold), metadata
|
||||
|
||||
@ -14,3 +14,4 @@ from .LoadTIFF import LoadTIFF
|
||||
from .SaveFig import SaveFig
|
||||
from .ShowFig import ShowFig
|
||||
from .RawOutput import RawOutput
|
||||
from .Differential import Differential
|
||||
|
||||
@ -16,13 +16,11 @@ class Stack(object):
|
||||
self.desc = list()
|
||||
self.symb = list()
|
||||
|
||||
if desc is not None:
|
||||
for i in range(size):
|
||||
self.desc.append(desc.copy() if isinstance(desc, list) else [desc])
|
||||
for i in range(size):
|
||||
self.desc.append(desc.copy() if isinstance(desc, list) else [desc])
|
||||
|
||||
if symb is not None:
|
||||
for i in range(size):
|
||||
self.symb.append(symb.copy() if isinstance(symb, list) else [symb])
|
||||
for i in range(size):
|
||||
self.symb.append(symb.copy() if isinstance(symb, list) else [symb])
|
||||
|
||||
def __str__(self):
|
||||
return ("Stack: begin: {}, end: {}, desc: {}, symb: {}".format(
|
||||
|
||||
8
test.py
8
test.py
@ -9,7 +9,7 @@
|
||||
# TODO details
|
||||
|
||||
#from core import Input, Output, Filter
|
||||
from ld2dap import LoadTIFF, SaveFig, Treshold, ShowFig
|
||||
from ld2dap import LoadTIFF, SaveFig, Treshold, ShowFig, Differential
|
||||
from ld2dap import AttributeProfiles as APs
|
||||
|
||||
import numpy as np
|
||||
@ -19,12 +19,14 @@ def main():
|
||||
t = Treshold(1e4)
|
||||
ap = APs(np.array([100,1e3,1e4]))
|
||||
o = SaveFig('Res/test.png')
|
||||
s = ShowFig(None)
|
||||
s = ShowFig(0, True)
|
||||
d = Differential()
|
||||
|
||||
t.input = i
|
||||
ap.input = t
|
||||
o.input = ap
|
||||
s.input = ap
|
||||
d.input = ap
|
||||
s.input = d
|
||||
|
||||
i.run()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user