Skip to content
Open

f32 #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demos/athens-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
cdsm_rast,
cdsm_transf.to_gdal(),
CRS.from_epsg(working_crs).to_wkt(),
coerce_f64_to_f32=True,
)
# %%
# wall info for SOLWEIG
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "umep"
version = "0.0.1b47"
version = "0.0.1a6"
description = "urban multi-scale environmental predictor"
readme = "README.md"
requires-python = ">=3.9, <3.14"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_save_and_load_raster_roundtrip(tmp_path):
crs_wkt = pyproj.CRS.from_epsg(4326).to_wkt()

# save and load
save_raster(str(out), data, trf, crs_wkt, no_data_val=-9999)
rast, trf_out, crs_out, nodata = load_raster(str(out))
save_raster(str(out), data, trf, crs_wkt, no_data_val=-9999, coerce_f64_to_f32=True)
rast, trf_out, crs_out, nodata = load_raster(str(out), coerce_f64_to_f32=True)

np.testing.assert_array_equal(rast, data)
assert isinstance(trf_out, list) and len(trf_out) == 6
Expand All @@ -34,12 +34,12 @@ def test_load_raster_with_bbox(tmp_path):
data = np.arange(100, dtype=np.float32).reshape(10, 10)
trf = _make_gt(10, 10)
crs_wkt = pyproj.CRS.from_epsg(4326).to_wkt()
save_raster(str(out), data, trf, crs_wkt, -9999)
save_raster(str(out), data, trf, crs_wkt, -9999, coerce_f64_to_f32=True)

# bbox in spatial coords: [minx, miny, maxx, maxy]
# For our geotransform bounds = [0,0,10,10]
bbox = [2, 2, 5, 5]
rast_crop, trf_crop, crs_crop, nd = load_raster(str(out), bbox=bbox)
rast_crop, trf_crop, crs_crop, nd = load_raster(str(out), bbox=bbox, coerce_f64_to_f32=True)

# Expected slice computed from implementation mapping
assert rast_crop.shape == (3, 3)
Expand Down
63 changes: 63 additions & 0 deletions tests/test_solweig_rasters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from pathlib import Path
from typing import Optional

import numpy as np

from umep.class_configs import SolweigConfig
from umep.functions.SOLWEIGpython.solweig_runner_core import SolweigRunCore

PROJECT_ROOT = Path(__file__).resolve().parents[1]
CONFIG_PATH = PROJECT_ROOT / "demos/data/athens/configsolweig.ini"
PARAMS_PATH = PROJECT_ROOT / "demos/data/athens/parametersforsolweig.json"


def _prepare_temp_config(tmp_path: Path) -> Path:
"""Return a config file that writes outputs into a temp dir."""
config = SolweigConfig()
config.from_file(str(CONFIG_PATH))

output_dir = tmp_path / "output"
working_dir = tmp_path / "working"

config.output_dir = str(output_dir)
config.working_dir = str(working_dir)

path_overrides = {
"dsm_path": PROJECT_ROOT / "demos/data/athens/DSM.tif",
"cdsm_path": PROJECT_ROOT / "temp/athens/CDSM.tif",
"dem_path": PROJECT_ROOT / "demos/data/athens/DEM.tif",
"wh_path": PROJECT_ROOT / "temp/athens/walls/wall_hts.tif",
"wa_path": PROJECT_ROOT / "temp/athens/walls/wall_aspects.tif",
"svf_path": PROJECT_ROOT / "temp/athens/svf/svfs.zip",
"aniso_path": PROJECT_ROOT / "temp/athens/svf/shadowmats.npz",
"epw_path": PROJECT_ROOT / "demos/data/athens/athens_2023.epw",
}
for attr, path in path_overrides.items():
setattr(config, attr, str(path))

tmp_config = tmp_path / "configsolweig.ini"
config.to_file(str(tmp_config))
return tmp_config


def _assert_float32(array: Optional[np.ndarray], name: str):
if array is not None:
assert array.dtype == np.float32, f"{name} dtype was {array.dtype}, expected float32"


def test_athens_runner_rasters_are_float32(tmp_path):
tmp_config = _prepare_temp_config(tmp_path)
runner = SolweigRunCore(str(tmp_config), str(PARAMS_PATH))
raster_data = runner.raster_data

_assert_float32(raster_data.dsm, "dsm")
_assert_float32(raster_data.wallheight, "wallheight")
_assert_float32(raster_data.wallaspect, "wallaspect")
_assert_float32(raster_data.dem, "dem")
_assert_float32(raster_data.cdsm, "cdsm")
_assert_float32(raster_data.tdsm, "tdsm")
_assert_float32(raster_data.bush, "bush")
_assert_float32(raster_data.svfbuveg, "svfbuveg")
_assert_float32(raster_data.buildings, "buildings")

runner.test_hook()
Loading
Loading