<jupyter_start><jupyter_text>Reproject Sentinel-2 data to WGS84<jupyter_code>import rasterio
from rasterio.merge import merge
from rasterio.plot import show
from rasterio.warp import calculate_default_transform, reproject, Resampling
import glob
import os
def reproject_raster(in_path, out_path, dst_crs = 'EPSG:4326'):
    # reproject raster to project crs
    with rasterio.open(in_path) as src:
        src_crs = src.crs
        transform, width, height = calculate_default_transform(src_crs, dst_crs, src.width, src.height, *src.bounds)
        kwargs = src.meta.copy()

        kwargs.update({
            'crs': dst_crs,
            'transform': transform,
            'width': width,
            'height': height})

        with rasterio.open(out_path, 'w', **kwargs) as dst:
            for i in range(1, src.count + 1):
                reproject(
                    source=rasterio.band(src, i),
                    destination=rasterio.band(dst, i),
                    src_transform=src.transform,
                    src_crs=src.crs,
                    dst_transform=transform,
                    dst_crs=dst_crs,
                    resampling=Resampling.nearest)
    return(out_path)
# File and folder paths
dirpath = r"data\sentinel2"
search_criteria = "*\R10m\TCI.jp2"
q = os.path.join(dirpath, search_criteria)
print(q)
paths = glob.glob(q)
paths
files_to_mosaic = []
for path_in in paths:
    folders_split = path_in.split('\\')
    filename_split = folders_split[-1].split('.')
    filename_split[0] = 'transformed_tci'
    
    filename_out = '.'.join(filename_split)
    folders_split[-1] = filename_out
    path_out = '\\'.join(folders_split)
    
    reproject_raster(path_in, path_out)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10734787600459242, 'fraction_numerical': 0.009184845005740528, 'mean_word_length': 2.6237006237006235, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '492187', 'license': 'MIT', 'n_tokens_mistral': 598, 'n_tokens_neox': 577, 'n_words': 116, 'path': 'jupyter-notebooks/2 - reproject_sentinel2.ipynb', 'repo_name': 'matt989253/heig-TerraGazer', 'size': '1742'}