<jupyter_start><jupyter_text>Reference - http://pen.envr.tsukuba.ac.jp/~torarimon/?GDAL_python - https://gis-oer.github.io/gitbook/book/materials/python/07/07.html  Setting path<jupyter_code># original file 
orgdir = 'orgdata/ALAV2A200132900-OORIRFU-D071P3-20091027-001/'<jupyter_output><empty_output><jupyter_text>Clip<jupyter_code>import glob
fs = glob.glob(orgdir + 'IMG*')
fs
from osgeo import gdal
import os

clip = 'clip.geojson'
for f in fs:
    fout = os.path.dirname(f) + '/clip-' + os.path.basename(f)
    d = gdal.Warp(fout, f, dstSRS="EPSG:6676", xRes=10.0, yRes=10.0, cutlineDSName=clip, cropToCutline=True, dstNodata="0")
    d = None<jupyter_output><empty_output><jupyter_text>Overlay<jupyter_code>import glob
fs = glob.glob(orgdir + 'clip*')
fs.sort()
fs
# make new file from original file profile
ds = gdal.Open(fs[0], gdal.GA_ReadOnly)
arr = ds.GetRasterBand(1).ReadAsArray()
h, w = arr.shape
dst_ds = gdal.GetDriverByName('GTiff').Create("tenryurivmouth.tif", w, h, 4, gdal.GDT_Byte)
d = dst_ds.SetGeoTransform(ds.GetGeoTransform())
d = dst_ds.SetProjection(ds.GetProjection())

# overlay band data
for i, f in enumerate(fs):
    ds = gdal.Open(f, gdal.GA_ReadOnly)
    x = ds.ReadAsArray()
    d = dst_ds.GetRasterBand(i+1).WriteArray(x)

# post
ds.FlushCache()    
dst_ds = None<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15349887133182843, 'fraction_numerical': 0.03310759969902182, 'mean_word_length': 5.333333333333333, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '651786', 'license': 'MIT', 'n_tokens_mistral': 587, 'n_tokens_neox': 559, 'n_words': 91, 'path': 'preClipAndOverlay.ipynb', 'repo_name': 'computational-sediment-hyd/ProcessingSatelliteData-on-JupyterNotebook', 'size': '1329'}