-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.py
56 lines (40 loc) · 1.28 KB
/
merge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import geopandas as gpd
import pandas as pd
import numpy as np
import os
import shutil
import pathlib
import rasterio
from glob import glob
from rasterio.merge import merge
def makeMosaic(q, out_fp ):
src_files_to_mosaic = []
dem_fps = glob(q)
for fp in dem_fps:
src = rasterio.open(fp)
src_files_to_mosaic.append(src)
mosaic, out_trans = merge(src_files_to_mosaic)
out_meta = src.meta.copy()
# Update the metadata
out_meta.update({"driver": "GTiff",
"height": mosaic.shape[1],
"width": mosaic.shape[2],
"transform": out_trans,
"compress": 'lzw'
}
)
with rasterio.open(out_fp, "w", **out_meta, tiled=True, blockxsize=256, blockysize=256, BIGTIFF='YES') as dest:
dest.write(mosaic)
"""
q = "/scratch/PI/gdaily/Jeff/worldBank/mayData/Results2_December/*/modifiedESA_mar6.tif"
out_fp = "/scratch/PI/gdaily/Jeff/worldBank/modifiedESA_mar6.tif"
makeMosaic(q, out_fp)
"""
q = "/scratch/PI/gdaily/Jeff/worldBank/mayData/Results2_December/*/modifiedBiomass_mar6.tif"
out_fp = "/scratch/PI/gdaily/Jeff/worldBank/modifiedBiomass_mar6.tif"
makeMosaic(q, out_fp)
"""
q = "/scratch/PI/gdaily/Jeff/worldBank/mayData/Results2_December/*/plantation_map_mar6.tif"
out_fp = "/scratch/PI/gdaily/Jeff/worldBank/plantation_map_mar6.tif"
makeMosaic(q, out_fp)
"""