Metadata-Version: 2.4
Name: pet-adjusted
Version: 0.1.5
Summary: PET (pythermalcomfort) with urban-adjusted air temperature and 1.2 m wind speed
Author: Ivan Cardenas
Author-email: Ivan Cardenas <i.l.cardenasleon@utwente.nl>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Requires-Dist: numpy>=2.0
Requires-Dist: pythermalcomfort>=4.7.0
Requires-Dist: scipy>=1.11
Requires-Dist: cupy-cuda13x>=14.2.0 ; extra == 'cuda'
Requires-Dist: solweig-gpu>=2.0.0 ; extra == 'solweig'
Requires-Dist: gdal>=3.13 ; extra == 'solweig'
Requires-Dist: torch>=2.9 ; extra == 'solweig'
Requires-Python: >=3.12
Project-URL: Repository, https://github.com/ivan-cardenas/PET-Adjusted
Project-URL: Documentation, https://github.com/ivan-cardenas/PET-Adjusted/blob/main/docs/guide.md
Provides-Extra: cuda
Provides-Extra: solweig
Description-Content-Type: text/markdown

# PET Adjusted

**Street-level heat-stress maps for cities.** 

`pet-adjusted` computes the Physiological Equivalent Temperature (PET) on a fine grid (typically 1 m) for any hour of a summer day.

PET is the air temperature of a standard indoor room in which a person would feel the same heat stress as outdoors. It combines four variables, each of which changes from street to street:
- air temperature;
- humidity;
- wind;
- radiation, through the mean radiant temperature (Tmrt).

The inputs are:
- **Maps:** a DSM, a DEM, a land-cover map and NDVI;
- **Weather:** hourly data from one reference weather station;
- **Subject:** the attributes of a person (activity, clothing, age, sex, weight, height).


## Why "adjusted"

Weather stations measure air temperature and wind in open, rural surroundings, at a standard height of 10 m for wind. Applying PET to those values directly describes conditions on an airfield, not in a street. This package adjusts every input to the conditions a pedestrian actually experiences at that location:

| Input | Station value | Adjusted to |
|---|---|---|
| **Wind speed** | 10 m, open terrain | **1.2 m** (the height of a person's centre of gravity), slowed down by the buildings and trees upwind. The MacDonald method uses the local **morphology**: the frontal area of buildings and trees and their mean height, over a source area oriented to the wind direction. |
| **Air temperature** | rural | rural plus the local **urban heat island**. It is scaled by the sky-view factor and green fraction of the area upwind and by the day's weather, and follows the typical daily cycle of the heat island. |
| **Mean radiant temperature** | – | computed per cell from sun position, shadows of buildings and trees, sky-view factor and ground surface (land cover), with SOLWEIG. |
| **Person** | standard PET reference person | your own subject: activity, clothing, age, sex, weight, height, posture. |

The wind and air-temperature adjustments follow the Dutch standardized PET heat map (Koopmans et al. 2020, supplementary material B2 and B5). Here they are computed from the rasters for every cell and any wind direction. PET is then solved with the full physical model (MEMI), not the regression equations used for the original map.

## Components

- **PET**: a GPU port of [`pythermalcomfort.models.pet_steady`](https://github.com/pythermalcomfort/pythermalcomfort/blob/master/pythermalcomfort/models/pet_steady.py) (Höppe's MEMI with the Walther & Goestchel corrections). It uses the same equations and is tested to give the same results.
- **Air temperature**: station temperature plus the urban heat island (Eqs. S.3–S.4, Tables S.3–S.4 of Koopmans et al. 2020; UHImax after Theeuwes et al. 2017).
- **Wind speed**: the station's 10 m wind brought down to 1.2 m in the urban canopy (Eqs. S.6–S.14, Table S.5 of Koopmans et al. 2020; after Macdonald 2000).
- **Sky-view factor**: horizon search on the DSM (port of the Relief Visualization Toolbox).
- **Mean radiant temperature**: [SOLWEIG-GPU](https://github.com/nvnsudharsan/SOLWEIG-GPU) with land cover.

Everything runs on a CUDA GPU when one is available: CuPy for PET, wind, air temperature and sky-view factor, and PyTorch for SOLWEIG-GPU. Without a GPU it falls back to NumPy, which is much slower.

## Install

With pip:

```bash
pip install pet-adjusted                 # CPU only
pip install "pet-adjusted[cuda]"         # + CuPy for CUDA 13 GPUs (driver 580+); for CUDA 12 use: pip install cupy-cuda12x
```

For Tmrt with SOLWEIG-GPU, install CUDA PyTorch and GDAL **first**. pip cannot get them by itself: PyPI's PyTorch is CPU-only on Windows, and PyPI's GDAL is source code only.

```bash
pip install torch --index-url https://download.pytorch.org/whl/cu130
# GDAL, one of:
#   Windows: pip install <the gdal wheel for your Python from https://github.com/cgohlke/geospatial-wheels/releases>
#   Linux:   sudo apt install libgdal-dev && pip install "gdal==$(gdal-config --version)"
#   Any OS:  conda install -c conda-forge gdal   (then pip install the rest in that conda environment)
pip install "pet-adjusted[cuda,solweig]"
```

From a clone of the repository, uv does all of this itself (`[tool.uv.sources]` in `pyproject.toml` points to the CUDA PyTorch index and, on Windows with Python 3.12, to Gohlke's GDAL wheel):

```bash
uv sync --extra cuda --extra solweig
```

## Usage

**Step-by-step guide: [docs/guide.md](https://github.com/ivan-cardenas/PET-Adjusted/blob/main/docs/guide.md)**. It covers where to get the DSM/DEM, land cover, NDVI and weather data, how to put them on one grid, and how to describe the person. [`examples/run_pet.py`](https://github.com/ivan-cardenas/PET-Adjusted/blob/main/examples/run_pet.py) runs everything from GeoTIFFs and a weather CSV.

```python
from datetime import date
from pet_adjusted import pet_map, read_raster, write_raster

if __name__ == "__main__":  # needed on Windows: SOLWEIG-GPU uses process pools
    dsm, cell, origin, epsg = read_raster("data/dsm.tif")  # all four on the same grid
    dem, landcover, ndvi = (read_raster(f"data/{n}.tif")[0] for n in ("dem", "landcover", "ndvi"))
    weather = dict(hour_utc=..., t_ref=..., rh=..., ff10=..., wind_dir=..., kdown=...)  # 24 hourly values each
    subject = dict(met=2.0, clo=0.5, age=35, sex="female", weight=60, height=1.65, position="standing")
    pet, tmrt = pet_map(dsm, dem, landcover, ndvi, cell, origin, epsg, date(2026, 7, 15),
                        weather, subject, workdir="data/solweig_run")  # (24, rows, cols) each
    write_raster("data/pet.tif", pet, cell, origin, epsg)
```

Land cover uses the UMEP codes: 1 paved, 2 building, 5 grass, 6 bare soil, 7 water. SOLWEIG-GPU needs consecutive hours (ideally the whole day), because it carries ground temperature over from one hour to the next.

What is derived from the rasters:

| Input | From |
|---|---|
| object height | DSM − DEM |
| buildings | object height > 2 m and land cover 2 (without land cover: NDVI ≤ 0.16) |
| trees | object height > 2 m, NDVI > 0.16, not a building |
| vegetation, water | NDVI > 0.16; land cover 7 (without land cover: NDVI < 0) |
| ground albedo, emissivity, surface temperature for Tmrt | land cover (SOLWEIG) |
| Svf, Fveg for UHImax | Svf from the DSM without buildings, water and vegetation, on 25 m tiles, averaged over the 500 × 1100 m upwind source area (700 × 700 m when ff10 < 1.5 m/s) |
| λ buildings, λ trees, H for the wind | frontal areas and mean obstacle height over the 280 × 140 m source area (175 × 175 m when ff10 < 1.5 m/s) |

The individual steps are public too: `solweig_tmrt`, `urban_pet_from_rasters`, `sky_view_factor`, `uhi_inputs`, `wind_inputs`, `urban_air_temperature`, `urban_wind_speed`, `pet_steady`, and `urban_pet` (for when you already have Svf, Fveg, λ and H). Pass `device="cpu"` or `device="gpu"` to choose the backend; the default is `"auto"`.


## Quick test: any place in the Netherlands

The `pet-nl` command makes a PET map for any Dutch address or place. It downloads the open data it needs:
- AHN heights;
- BGT land cover;
- the PDOK infrared aerial photo;
- hourly weather from the nearest KNMI station that measures radiation.

It asks for the place, date, hours and person. Press Enter to keep a default.

```bash
uv sync --extra cuda --extra solweig
uv run pet-nl
```

```text
Place or address (or x,y in EPSG:28992) [Oude Markt, Enschede]: Domplein, Utrecht
Size of the square area [m] [300.0]:
Date (YYYY-MM-DD, April-September) [2025-07-02]:
UTC hours (e.g. 14, 10-16, all) [all]: 14
Subject (Enter keeps the default):
  activity [met] (1.0 seated, 1.2 standing, 2.0 walking) [2.0]:
  ...
```

You can also pass everything as options, for example `pet-nl --place "Domplein, Utrecht" --date 2025-07-02 --hours 14 --met 1.2 --clo 0.5` (see `pet-nl --help`). The same works from Python:

```python
from datetime import date
from pet_adjusted import pet_netherlands

if __name__ == "__main__":  # required on Windows
    pet, tmrt = pet_netherlands("Domplein, Utrecht", date(2025, 7, 2), {"met": 2.0, "clo": 0.5}, hours=[14])
```

The results go to `pet_nl/`:
- `pet.tif` and `tmrt.tif`, one band per hour, with roofs as nodata;
- `pet.png`, a figure of the hottest hour;
- the downloaded inputs.

A 300 × 300 m area takes about 6 minutes on a laptop GPU.

Example: Enschede city centre on 2 July 2025, 14:00 UTC (36.7 °C at KNMI Twente).

![PET and Tmrt in Enschede city centre](https://raw.githubusercontent.com/ivan-cardenas/PET-Adjusted/main/examples/enschede/enschede_pet.png)

Shade from street trees and buildings lowers PET by 5–10 °C compared with open, sunlit squares. See [examples/enschede](https://github.com/ivan-cardenas/PET-Adjusted/blob/main/examples/enschede/README.md) for every step and how to read the results. For places outside the Netherlands, prepare the rasters yourself with the [guide](https://github.com/ivan-cardenas/PET-Adjusted/blob/main/docs/guide.md) and call `pet_map`.

## Performance

1 million PET points take about 40 s on an RTX 4050 laptop GPU. pythermalcomfort solves one point at a time and would take hours. Most points are solved with a vectorised Newton method. The roughly 0.5% where the equations have kinks (sweating limits) are solved with SciPy's `fsolve`, the same way pythermalcomfort solves them.

## Limitations

- `solweig_tmrt` has only been tested with rasters that fit in one SOLWEIG tile (3600 × 3600 cells by default). Larger rasters are put back together from tiles by their georeferencing, but this is untested.
- SOLWEIG-GPU 2.0 applies its fixed water surface temperature to land-cover code 3 instead of 7, so water (7) gets the water albedo and emissivity but not that temperature. Do not use codes 3/4 (see the guide).
- Daily Tmax/Tmin, radiation and wind for Eq. S.3 come from the given day's hours; the paper uses 08 UTC to 07 UTC the next day (pass them in `weather` to override).
- Cropland is not treated as vegetation unless its NDVI is above 0.16.
- The frontal area of a cell is its rise in height from the upwind neighbour × the cell width. This is exact for N/E/S/W winds and approximate for other directions.
- The diurnal UHI tables only cover 1 April – 30 September, with sunrise and sunset times for the Netherlands.

## How to cite

If you use `pet-adjusted`, please cite the software:

> Cárdenas-León, I. (2026). *PET-Adjusted: Urban Physiological Equivalent Temperature adjusted to urban morphology conditions* (Version 0.1.0) [Computer software]. https://github.com/ivan-cardenas/PET-Adjusted

GitHub's "Cite this repository" button gives the same reference in APA and BibTeX, from [`CITATION.cff`](https://github.com/ivan-cardenas/PET-Adjusted/blob/main/CITATION.cff).

```bibtex
@software{cardenas_pet_adjusted_2026,
  author  = {Cárdenas-León, Ivan},
  title   = {PET-Adjusted: Urban Physiological Equivalent Temperature adjusted to urban morphology conditions},
  year    = {2026},
  version = {0.1.0},
  url     = {https://github.com/ivan-cardenas/PET-Adjusted},
  license = {GPL-3.0-or-later}
}
```

Please also cite the methods it builds on:
- Koopmans et al. (2020), for the wind and air-temperature adjustment;
- Tartarini & Schiavon (2020), for pythermalcomfort;
- Kamath et al. (2026) and Lindberg et al. (2008), for SOLWEIG-GPU and SOLWEIG.

See [Credits](#credits) for the full references.

## Licence

GPL-3.0-or-later (see [LICENSE](https://github.com/ivan-cardenas/PET-Adjusted/blob/main/LICENSE)), compatible with SOLWEIG-GPU (GPL-3.0).

## Credits

- PET implementation: Tartarini, F., Schiavon, S. (2020). *pythermalcomfort: A Python package for thermal comfort research*. SoftwareX, 12, 100578. https://doi.org/10.1016/j.softx.2020.100578
- PET model: Höppe, P. (1999). *Int. J. Biometeorol.*, 43, 71–75; corrected by Walther, E., Goestchel, Q. (2018). *Building and Environment*, 137, 1–26.
- Tmrt: Kamath, H. G., Sudharsan, N., Singh, M., Wallenberg, N., Lindberg, F., Niyogi, D. (2026). SOLWEIG-GPU: GPU-Accelerated Thermal Comfort Modeling Framework for Urban Digital Twins. *Journal of Open Source Software*, 11(118), 9535. https://doi.org/10.21105/joss.09535
- SOLWEIG: Lindberg, F., Holmer, B., Thorsson, S. (2008). SOLWEIG 1.0 – Modelling spatial variations of 3D radiant fluxes and mean radiant temperature in complex urban settings. *Int. J. Biometeorol.*, 52, 697–713. https://doi.org/10.1007/s00484-008-0162-7
- UMEP: Lindberg, F., Grimmond, C. S. B., Gabey, A., et al. (2018). Urban Multi-scale Environmental Predictor (UMEP): An integrated tool for city-based climate services. *Environmental Modelling & Software*, 99, 70–87. https://doi.org/10.1016/j.envsoft.2017.09.020
- Windows GDAL wheels: Gohlke, C. geospatial-wheels. https://github.com/cgohlke/geospatial-wheels
- Sky-view factor: Zakšek, K., Oštir, K., Kokalj, Ž. (2011). *Remote Sensing*, 3, 398–415; Kokalj, Ž., Zakšek, K., Oštir, K. (2011). *Antiquity*, 85, 263–273 (Relief Visualization Toolbox).
- Wind and air-temperature adjustment (standardized Dutch PET heat map): Koopmans, S., Heusinkveld, B. G., Steeneveld, G. J. (2020). A standardized Physical Equivalent Temperature urban heat map at 1-m spatial resolution to facilitate climate stress tests in the Netherlands. *Building and Environment*, 181, 106984. https://doi.org/10.1016/j.buildenv.2020.106984 (supplementary material B2, B5).
- UHImax equation: Theeuwes, N. E., et al. (2017). *Int. J. Climatol.*, 37, 443–454.
- Urban wind profile: Macdonald, R. W. (2000). *Boundary-Layer Meteorology*, 97, 25–45.
