Skip to content

Commit

Permalink
add float_utm34n_msl_dem_file fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
dugalh committed Apr 1, 2024
1 parent 23aa2a9 commit 66701cc
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import rasterio as rio
from click.testing import CliRunner
from rasterio.transform import from_bounds, from_origin
from rasterio.warp import transform_bounds, array_bounds
from rasterio.warp import array_bounds, transform_bounds

from orthority.camera import (
BrownCamera,
Expand Down Expand Up @@ -316,7 +316,7 @@ def utm34n_crs() -> str:

@pytest.fixture(scope='session')
def utm34n_wgs84_crs() -> str:
"""CRS string for UTM zone 34N with WGS84 ellipsoid vertical CRS."""
"""CRS string for UTM zone 34N with height above WGS84 ellipsoid vertical CRS."""
# TODO: GDAL/rasterio implements this CRS as a sidecar PAM file which cannot be written to /
# read from with rio.open(<python file object>). Perhaps this be fixed with when rio.open(
# opener=) when it is implemented.
Expand All @@ -326,16 +326,22 @@ def utm34n_wgs84_crs() -> str:

@pytest.fixture(scope='session')
def utm34n_egm96_crs() -> str:
"""CRS string for UTM zone 34N with EGM96 geoid vertical CRS."""
"""CRS string for UTM zone 34N with height above EGM96 geoid vertical CRS."""
return 'EPSG:32634+5773'


@pytest.fixture(scope='session')
def utm34n_egm2008_crs() -> str:
"""CRS string for UTM zone 34N with EGM2008 geoid vertical CRS."""
"""CRS string for UTM zone 34N with height above EGM2008 geoid vertical CRS."""
return 'EPSG:32634+3855'


@pytest.fixture(scope='session')
def utm34n_msl_crs() -> str:
"""CRS string for UTM zone 34N with height above MSL (feet) vertical CRS."""
return 'EPSG:32634+8050'


@pytest.fixture(scope='session')
def webmerc_crs() -> str:
"""CRS string for web mercator with no vertical CRS."""
Expand All @@ -344,21 +350,21 @@ def webmerc_crs() -> str:

@pytest.fixture(scope='session')
def webmerc_wgs84_crs() -> str:
"""CRS string for web mercator with WGS84 ellipsoid vertical CRS."""
"""CRS string for web mercator with height above WGS84 ellipsoid vertical CRS."""
# return '+proj=webmerc +datum=WGS84 +ellps=WGS84 +vunits=m'
# see utm34n_wgs84_crs note above
raise NotImplementedError()


@pytest.fixture(scope='session')
def webmerc_egm96_crs() -> str:
"""CRS string for web mercator with EGM96 geoid vertical CRS."""
"""CRS string for web mercator with height above EGM96 geoid vertical CRS."""
return '+proj=webmerc +datum=WGS84 +geoidgrids=egm96_15.gtx +vunits=m'


@pytest.fixture(scope='session')
def webmerc_egm2008_crs() -> str:
"""CRS string for web mercator with EGM2008 geoid vertical CRS."""
"""CRS string for web mercator with height above EGM2008 geoid vertical CRS."""
return '+proj=webmerc +datum=WGS84 +geoidgrids=egm08_25.gtx +vunits=m'


Expand All @@ -370,19 +376,19 @@ def wgs84_crs() -> str:

@pytest.fixture(scope='session')
def wgs84_wgs84_crs() -> str:
"""CRS string for WGS84 with WGS84 ellipsoid vertical CRS."""
"""CRS string for WGS84 with height above WGS84 ellipsoid vertical CRS."""
return 'EPSG:4979'


@pytest.fixture(scope='session')
def wgs84_egm96_crs() -> str:
"""CRS string for WGS84 with EGM96 geoid vertical CRS."""
"""CRS string for WGS84 with height above EGM96 geoid vertical CRS."""
return 'EPSG:4326+5773'


@pytest.fixture(scope='session')
def wgs84_egm2008_crs() -> str:
"""CRS string for WGS84 with EGM2008 geoid vertical CRS."""
"""CRS string for WGS84 with height above EGM2008 geoid vertical CRS."""
return 'EPSG:4326+3855'


Expand Down Expand Up @@ -451,7 +457,7 @@ def float_utm34n_wgs84_dem_file(
tmp_path_factory: pytest.TempPathFactory, pinhole_camera: Camera, utm34n_wgs84_crs: str
) -> Path:
"""
A 2 band float DEM file in UTM zone 34N with WGS84 ellipsoid vertical CRS.
A 2 band float DEM file in UTM zone 34N with height above WGS84 ellipsoid vertical CRS.
Band 1 is a sinusoidal surface, and band 2, a horizontal plane.
"""
Expand All @@ -470,7 +476,7 @@ def float_utm34n_egm96_dem_file(
tmp_path_factory: pytest.TempPathFactory, pinhole_camera: Camera, utm34n_egm96_crs: str
) -> Path:
"""
A 2 band float DEM file in UTM zone 34N with EGM96 geoid vertical CRS.
A 2 band float DEM file in UTM zone 34N with height above EGM96 geoid vertical CRS.
Band 1 is a sinusoidal surface, and band 2, a horizontal plane.
"""
Expand All @@ -489,7 +495,7 @@ def float_utm34n_egm2008_dem_file(
tmp_path_factory: pytest.TempPathFactory, pinhole_camera: Camera, utm34n_egm2008_crs: str
) -> Path:
"""
A 2 band float DEM file in UTM zone 34N with EGM2008 geoid vertical CRS.
A 2 band float DEM file in UTM zone 34N with height above EGM2008 geoid vertical CRS.
Band 1 is a sinusoidal surface, and band 2, a horizontal plane.
"""
Expand All @@ -513,15 +519,15 @@ def float_wgs84_wgs84_dem_file(
wgs84_wgs84_crs: str,
) -> Path:
"""
A 2 band float DEM file in WGS84 with WGS84 ellipsoid vertical CRS.
A 2 band float DEM file in WGS84 with height above WGS84 ellipsoid vertical CRS.
Band 1 is a sinusoidal surface, and band 2, a horizontal plane.
"""
bounds = ortho_bounds(pinhole_camera)
array, transform = create_zsurf(bounds)
bounds = array_bounds(*array.shape[-2:], transform)
bounds = transform_bounds(utm34n_crs, wgs84_wgs84_crs, *bounds)
transform = from_bounds(*bounds, *array.shape[-2::-1])
transform = from_bounds(*bounds, *array.shape[1:][::-1])
profile = create_profile(array, transform=transform, crs=wgs84_wgs84_crs, nodata=float('nan'))

filename = tmp_path_factory.mktemp('data').joinpath('float_wgs84_wgs84_dem.tif')
Expand All @@ -530,6 +536,30 @@ def float_wgs84_wgs84_dem_file(
return filename


@pytest.fixture(scope='session')
def float_utm34n_msl_dem_file(
tmp_path_factory: pytest.TempPathFactory,
pinhole_camera: Camera,
utm34n_msl_crs: str,
) -> Path:
"""
A 2 band float DEM file in UTM zone 34N with height above MSL (feet) vertical CRS.
Band 1 is a sinusoidal surface, and band 2, a horizontal plane.
"""
bounds = ortho_bounds(pinhole_camera)
array, transform = create_zsurf(bounds)
array *= 3.28084 # meters to feet
profile = create_profile(
array, transform=transform, crs=utm34n_msl_crs, nodata=float('nan')
)

filename = tmp_path_factory.mktemp('data').joinpath('float_utm34n_msl_dem.tif')
with rio.open(filename, 'w', **profile) as im:
im.write(array)
return filename


@pytest.fixture(scope='session')
def float_utm34n_partial_dem_file(
tmp_path_factory: pytest.TempPathFactory, pinhole_camera: Camera, utm34n_crs: str
Expand Down

0 comments on commit 66701cc

Please sign in to comment.