Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pygeotools dependency for computing difference map #26

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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