def test_get_footprint(self): output = utils.get_footprint(size=5) reference = np.array( [ [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], ], dtype="b1", ) self.assertTrue(np.equal(output, reference).all())
def process(data, size=None): if data is None or size is None or "values" not in data: return data radius = int(size // 2) footprint = get_footprint(size)[np.newaxis] # put absolute minimum on no data pixels array = data["values"].copy() minimum = get_dtype_min(array.dtype) no_data_mask = array == data["no_data_value"] array[no_data_mask] = minimum # apply maximum filter filtered = ndimage.maximum_filter(array, footprint=footprint) # replace absolute minimum with original fillvalue filtered[(filtered == minimum) & no_data_mask] = data["no_data_value"] # cut out the result filtered = filtered[:, radius:-radius, radius:-radius] return {"values": filtered, "no_data_value": data["no_data_value"]}