Note

This page was generated from a Jupyter notebook. You can download it here: notebooks/Example_ERA5.ipynb

[2]:
from solweig_gpu import thermal_comfort
[3]:
thermal_comfort(
    base_path='/Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters',
    selected_date_str='2020-08-13',
    building_dsm_filename='Building_DSM.tif',
    dem_filename='DEM.tif',
    trees_filename='Trees.tif',
    landcover_filename='Landcover.tif',
    tile_size=1000,
    overlap=100,
    use_own_met=False,
    start_time='2020-08-13 00:00:00',
    end_time='2020-08-14 23:00:00',
    data_source_type='ERA5',
    data_folder='/Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Forcing_data/ERA5',
    save_svf=True,
)
Creating tiles for Building_DSM...
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_0_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_0_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_0_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_0_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_1000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_1000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_1000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_1000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_2000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_2000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_2000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_2000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_3000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_3000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_3000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Building_DSM/Building_DSM_3000_3000.tif
Creating tiles for DEM...
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_0_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_0_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_0_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_0_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_1000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_1000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_1000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_1000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_2000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_2000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_2000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_2000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_3000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_3000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_3000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/DEM/DEM_3000_3000.tif
Creating tiles for Trees...
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_0_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_0_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_0_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_0_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_1000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_1000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_1000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_1000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_2000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_2000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_2000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_2000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_3000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_3000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_3000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Trees/Trees_3000_3000.tif
Creating tiles for Landcover...
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_0_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_0_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_0_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_0_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_1000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_1000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_1000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_1000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_2000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_2000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_2000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_2000_3000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_3000_0.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_3000_1000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_3000_2000.tif
Created tile: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Landcover/Landcover_3000_3000.tif
ERA5 forcing file created: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Outfile.nc  (48 steps from 2020-08-13 00:00:00 to 2020-08-14 23:00:00 UTC)
Processing 24 time steps for metfile_0_0
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_0_0_2020-08-13.txt
Processing 24 time steps for metfile_3000_3000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_3000_3000_2020-08-13.txt
Processing 24 time steps for metfile_0_2000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_0_2000_2020-08-13.txt
Processing 24 time steps for metfile_2000_2000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_2000_2000_2020-08-13.txt
Processing 24 time steps for metfile_3000_1000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_3000_1000_2020-08-13.txt
Processing 24 time steps for metfile_1000_0
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_1000_0_2020-08-13.txt
Processing 24 time steps for metfile_1000_2000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_1000_2000_2020-08-13.txt
Processing 24 time steps for metfile_2000_1000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_2000_1000_2020-08-13.txt
Processing 24 time steps for metfile_0_3000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_0_3000_2020-08-13.txt
Processing 24 time steps for metfile_3000_2000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_3000_2000_2020-08-13.txt
Processing 24 time steps for metfile_0_1000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_0_1000_2020-08-13.txt
Processing 24 time steps for metfile_2000_3000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_2000_3000_2020-08-13.txt
Processing 24 time steps for metfile_1000_3000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_1000_3000_2020-08-13.txt
Processing 24 time steps for metfile_2000_0
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_2000_0_2020-08-13.txt
Processing 24 time steps for metfile_3000_0
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_3000_0_2020-08-13.txt
Processing 24 time steps for metfile_1000_1000
Metfile saved: /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles/metfile_1000_1000_2020-08-13.txt
All raster extents processed and metfiles saved in /Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/metfiles
Using 12 parallel workers
Computing Wall Height and Aspect: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 16/16 [01:42<00:00,  6.42s/it]
Running Solweig ...
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 0_0: 911.22 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 0_1000: 721.32 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 0_2000: 1085.35 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 0_3000: 328.70 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 1000_0: 789.68 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 1000_1000: 813.88 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 1000_2000: 729.81 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 1000_3000: 280.17 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 2000_0: 500.53 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 2000_1000: 486.68 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 2000_2000: 455.75 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 2000_3000: 222.58 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 3000_0: 398.38 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 3000_1000: 405.14 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 3000_2000: 385.00 seconds
Attention! The land cover grid includes values (deciduous and/or conifer) not appropriate for the SOLWEIG-formatted land cover grid (should not include 3 or 4). Land cover under the vegetation is required. Setting the invalid landcover types to grass.
[INFO] Timezone: America/Chicago, UTC offset: -5.0 hours
Time taken to execute tile 3000_3000: 209.73 seconds
[5]:
import rasterio
import numpy as np
import matplotlib.pyplot as plt

# ---- paths ----
utci_path = "/Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Outputs/0_2000/UTCI_0_2000.tif"
tmrt_path = "/Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Outputs/0_2000/TMRT_0_2000.tif"
svf_path  = "/Users/geo-ns36752/Downloads/SOLWEIG-GPU 2/Input_rasters/Outputs/0_2000/SVF_0_2000.tif"

def read_band(path, preferred_band=15):
    """Read preferred_band if it exists; otherwise fall back to band 1 (useful for single-band rasters like SVF)."""
    with rasterio.open(path) as src:
        band = preferred_band if preferred_band <= src.count else 1
        arr = src.read(band).astype(float)
        # mask NoData
        if src.nodata is not None:
            arr = np.where(arr == src.nodata, np.nan, arr)
        bounds = src.bounds
        extent = (bounds.left, bounds.right, bounds.bottom, bounds.top)
    return arr, extent

# read rasters (UTCI/TMRT often have multiple time bands; SVF is single-band)
utci, utci_extent = read_band(utci_path, preferred_band=15)  # 15 = 3pm if bands are hourly starting at 1
tmrt, tmrt_extent = read_band(tmrt_path, preferred_band=15)
svf,  svf_extent  = read_band(svf_path,  preferred_band=1)   # force band 1 for SVF

# ---- colormaps / norms ----
utci_cmap = "coolwarm"
tmrt_cmap = "coolwarm"
svf_cmap  = "viridis"

# ---- plot ----
fig, axes = plt.subplots(1, 3, figsize=(12, 5), constrained_layout=True)

im0 = axes[0].imshow(utci, extent=utci_extent, origin="upper",
                     cmap=utci_cmap)
axes[0].set_title("UTCI (°C)")
axes[0].axis("off")
cbar0 = fig.colorbar(im0, ax=axes[0], fraction=0.046, pad=0.04)
cbar0.set_label("°C")

im1 = axes[1].imshow(tmrt, extent=tmrt_extent, origin="upper",
                     cmap=tmrt_cmap)
axes[1].set_title("TMRT (°C)")
axes[1].axis("off")
cbar1 = fig.colorbar(im1, ax=axes[1], fraction=0.046, pad=0.04)
cbar1.set_label("°C")

im2 = axes[2].imshow(svf, extent=svf_extent, origin="upper",
                     cmap=svf_cmap, vmin=0, vmax=1)
axes[2].set_title("SVF")
axes[2].axis("off")
cbar2 = fig.colorbar(im2, ax=axes[2], fraction=0.046, pad=0.04)
cbar2.set_label("")

plt.show()
../_images/notebooks_Example_ERA5_2_0.png
[ ]:

[ ]: