ld2daps/ld2dap/Treshold.py

48 lines
1.5 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
# \file Treshold.py
# \brief TODO
# \author Florent Guiotte <florent.guiotte@gmail.com>
# \version 0.1
# \date 09 avril 2018
#
# TODO details
from ld2dap.core import Filter
import numpy as np
class Treshold(Filter):
def __init__(self, treshold, max_value=None):
super().__init__(self.__class__.__name__)
self.treshold = treshold
self.max_value = max_value # if max_value is not None else treshold
def _process(self, data, metadata):
# TODO: UPGRADE STACK DEPENDANCE
# TODO: Verify if the previous TODO is up to date
# TODO: It comes to mind that the hesitations expressed in the previous TODO are probably unfounded, as the previous previous TODO clearly states stacks, and no independants rasters
# This filter each raster independently
self.logger.info('Filtering')
treshold_filter = data > self.treshold
repeat_count = treshold_filter.sum(axis=(0, 1))
data[treshold_filter] = np.nan
if self.max_value is None:
self.max_value = np.nanmax(data, axis=(0, 1))
data = np.rollaxis(data, 2)
treshold_filter = np.rollaxis(treshold_filter, 2)
data[treshold_filter] = np.repeat(self.max_value, repeat_count)
data = np.rollaxis(data, 0, 3)
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))
return data, metadata