Skip to content

Commit

Permalink
Remove pygeotools dependency for computing difference map #26
Browse files Browse the repository at this point in the history
Previously, pygeotools was used for computing difference maps for two DEMs (i.e. ASP output vs. COP30 reference DEM). Now this is handled by the geoutils package.

A memory leak error was also resolved by removing the pygeotools dependencies here.
  • Loading branch information
bpurinton committed Jul 8, 2024
1 parent e93aa60 commit b368b5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 6 additions & 13 deletions asp_plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import rasterio as rio
from rasterio.windows import Window
from osgeo import gdal
from pygeotools.lib import iolib, warplib
import geoutils as gu
import matplotlib.pyplot as plt
import matplotlib.colors
import matplotlib.image as mpimg
Expand Down Expand Up @@ -148,8 +148,7 @@ def hillshade(self):
hillshade = np.ma.masked_equal(hs_ds.ReadAsArray(), 0)
return hillshade

def compute_difference(self, second_fn, outdir=None):
print(f"Computing difference map between:\n\n{self.fn}\n\nand\n\n{second_fn}")
def compute_difference(self, second_fn):
fn_list = [self.fn, second_fn]
outdir = os.path.dirname(os.path.abspath(self.fn))

Expand All @@ -159,17 +158,11 @@ def compute_difference(self, second_fn, outdir=None):
+ os.path.splitext(os.path.split(second_fn)[1])[0]
)

ds_list = warplib.memwarp_multi_fn(
fn_list, extent="intersection", res="max", t_srs="first", r="cubic"
)
r1_ds = ds_list[0]
r2_ds = ds_list[1]
r1 = iolib.ds_getma(r1_ds, 1)
r2 = iolib.ds_getma(r2_ds, 1)
diff = r2 - r1
rasters = gu.raster.load_multiple_rasters(fn_list, ref_grid=1)
diff = rasters[1] - rasters[0]
dst_fn = os.path.join(outdir, outprefix + "_diff.tif")
iolib.writeGTiff(diff, dst_fn, r1_ds, ndv=-9999)
return diff
diff.save(dst_fn)
return diff.data


class Plotter:
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ dependencies:
- contextily
- matplotlib-scalebar
- click
- geoutils
- xdem
- pip:
- markdown-pdf

0 comments on commit b368b5c

Please sign in to comment.