diff --git a/Dockerfile b/Dockerfile index 906432bd..44c6c1fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,7 +74,6 @@ RUN pip install -U \ scipy \ shapely \ xmltodict \ - https://github.com/OpenDroneMap/gippy/archive/numpyfix.zip \ rasterio \ attrs==19.1.0 diff --git a/configure.sh b/configure.sh index e5e7e320..870ee8cc 100755 --- a/configure.sh +++ b/configure.sh @@ -91,7 +91,7 @@ install() { libboost-log-dev echo "Installing split-merge Dependencies" - pip install -U scipy numpy==1.15.4 shapely pyproj https://github.com/OpenDroneMap/gippy/archive/numpyfix.zip psutil + pip install -U scipy numpy==1.15.4 shapely pyproj psutil echo "Compiling SuperBuild" cd ${RUNPATH}/SuperBuild diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index 2f2a7b10..cc84305c 100644 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -1,6 +1,6 @@ import os import sys -import gippy +import rasterio import numpy import math import time @@ -236,35 +236,33 @@ def post_process(geotiff_path, output_path, smoothing_iterations=1): log.ODM_INFO('Starting post processing (smoothing)...') - img = gippy.GeoImage(geotiff_path) - nodata = img[0].nodata() - arr = img[0].read() + with rasterio.open(geotiff_path) as img: + nodata = img.nodatavals[0] + dtype = img.dtypes[0] + arr = img.read()[0] - # Median filter (careful, changing the value 5 might require tweaking) - # the lines below. There's another numpy function that takes care of - # these edge cases, but it's slower. - for i in range(smoothing_iterations): - log.ODM_INFO("Smoothing iteration %s" % str(i + 1)) - arr = signal.medfilt(arr, 5) + # Median filter (careful, changing the value 5 might require tweaking) + # the lines below. There's another numpy function that takes care of + # these edge cases, but it's slower. + for i in range(smoothing_iterations): + log.ODM_INFO("Smoothing iteration %s" % str(i + 1)) + arr = signal.medfilt(arr, 5) + + # Fill corner points with nearest value + if arr.shape >= (4, 4): + arr[0][:2] = arr[1][0] = arr[1][1] + arr[0][-2:] = arr[1][-1] = arr[2][-1] + arr[-1][:2] = arr[-2][0] = arr[-2][1] + arr[-1][-2:] = arr[-2][-1] = arr[-2][-2] + + # Median filter leaves a bunch of zeros in nodata areas + locs = numpy.where(arr == 0.0) + arr[locs] = nodata + + # write output + with rasterio.open(output_path, 'w', **img.profile) as imgout: + imgout.write(arr.astype(dtype), 1) - # Fill corner points with nearest value - if arr.shape >= (4, 4): - arr[0][:2] = arr[1][0] = arr[1][1] - arr[0][-2:] = arr[1][-1] = arr[2][-1] - arr[-1][:2] = arr[-2][0] = arr[-2][1] - arr[-1][-2:] = arr[-2][-1] = arr[-2][-2] - - # Median filter leaves a bunch of zeros in nodata areas - locs = numpy.where(arr == 0.0) - arr[locs] = nodata - - # write output - imgout = gippy.GeoImage.create_from(img, output_path) - imgout.set_nodata(nodata) - imgout[0].write(arr) - output_path = imgout.filename() - imgout = None - log.ODM_INFO('Completed post processing to create %s in %s' % (os.path.relpath(output_path), datetime.now() - start)) return output_path \ No newline at end of file diff --git a/opendm/dem/merge.py b/opendm/dem/merge.py index 44741930..6161afb3 100644 --- a/opendm/dem/merge.py +++ b/opendm/dem/merge.py @@ -41,10 +41,7 @@ def euclidean_merge_dems(input_dems, output_dem, creation_options={}): logging.disable(logging.DEBUG) with rasterio.open(existing_dems[0]) as first: - src_nodata = 0 - nodatavals = first.get_nodatavals() - if len(nodatavals) > 0: - src_nodata = nodatavals[0] + src_nodata = first.nodatavals[0] res = first.res dtype = first.dtypes[0] profile = first.profile @@ -148,10 +145,7 @@ def euclidean_merge_dems(input_dems, output_dem, creation_options={}): # With rio merge this just adds an extra row, but when the # imprecision occurs at each block, you get artifacts - nodata = 0 - nodatavals = src_d.get_nodatavals() - if len(nodatavals) > 0: - nodata = nodatavals[0] + nodata = src_d.nodatavals[0] # Alternative, custom get_window using rounding src_window = tuple(zip(rowcol( diff --git a/opendm/mesh.py b/opendm/mesh.py index 703ce434..7c9e34e9 100644 --- a/opendm/mesh.py +++ b/opendm/mesh.py @@ -1,6 +1,5 @@ from __future__ import absolute_import import os, shutil, sys, struct, random, math -from gippy import GeoImage from opendm.dem import commands from opendm import system from opendm import log diff --git a/portable.Dockerfile b/portable.Dockerfile index 30228ea0..4142b152 100644 --- a/portable.Dockerfile +++ b/portable.Dockerfile @@ -74,7 +74,6 @@ RUN pip install -U \ scipy \ shapely \ xmltodict \ - https://github.com/OpenDroneMap/gippy/archive/numpyfix.zip \ rasterio \ attrs==19.1.0