Skip to content

Commit

Permalink
set PROj_NETWORK before importing rasterio
Browse files Browse the repository at this point in the history
  • Loading branch information
dugalh committed Apr 18, 2024
1 parent c266d5a commit 3460aef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-unit-tests_conda-forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
conda-solver: libmamba

- name: Install dependencies
# Note that conda-forge OpenCV 4.9 package has *GL dependencies that are not satisfied by
# GitHub's Ubuntu image, so 'opencv-python-headless' is installed with pip below.
# TODO: change this if a headless conda-forge version becomes available
run: |
conda info
conda install -c conda-forge rasterio click tqdm pyyaml fsspec requests aiohttp pytest pytest-cov
Expand Down
6 changes: 4 additions & 2 deletions orthority/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
# If not, see <https://www.gnu.org/licenses/>.

"""Orthorectification toolkit."""
import logging
import os
import pathlib

# enable on-demand download and caching of proj transformation grids (NB must be done before
# importing rasterio)
os.environ.update(PROJ_NETWORK='ON')

import logging
import pathlib

from orthority.enums import Compress, Interp
from orthority.factory import FrameCameras, RpcCameras
from orthority.ortho import Ortho


# Add a NullHandler to the package logger to hide logs by default. Applications can then add
# their own handler(s).
log = logging.getLogger(__name__)
Expand Down
2 changes: 0 additions & 2 deletions orthority/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,4 @@ def simple_ortho(argv=None):
if __name__ == '__main__':
cli()

# TODO: test CLI exceptions are meaningful

##
20 changes: 20 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright The Orthority Contributors.
#
# This file is part of Orthority.
#
# Orthority is free software: you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# Orthority is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License along with Orthority.
# If not, see <https://www.gnu.org/licenses/>.

# enable on-demand download and caching of proj transformation grids (NB must be done before
# importing rasterio)
import os

os.environ.update(PROJ_NETWORK='ON')
30 changes: 12 additions & 18 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@

from __future__ import annotations

from pathlib import Path
from typing import Sequence

import cv2
import numpy as np
import pytest
from pathlib import Path
import rasterio as rio
import cv2
from rasterio.transform import from_bounds
from typing import Sequence

from orthority import utils
from orthority.camera import (
BrownCamera,
Camera,
create_camera,
FisheyeCamera,
FrameCamera,
OpenCVCamera,
PinholeCamera,
BrownCamera, Camera, create_camera, FisheyeCamera, FrameCamera, OpenCVCamera, PinholeCamera,
RpcCamera,
)
from orthority.enums import CameraType, Interp
from orthority.errors import CameraInitError, OrthorityWarning
from tests.conftest import _dem_offset, _dem_gain, checkerboard, ortho_bounds, create_zsurf
from orthority import utils
from tests.conftest import _dem_offset, checkerboard, create_zsurf, ortho_bounds


@pytest.mark.parametrize(
Expand Down Expand Up @@ -129,13 +124,14 @@ def test_frame_update(im_size: tuple, focal_len: float, sensor_size: tuple, xyz:
assert np.all(camera._R != 0)


@pytest.mark.parametrize('cam_type',
[CameraType.pinhole, CameraType.opencv, CameraType.brown, CameraType.fisheye]
@pytest.mark.parametrize(
'cam_type', [CameraType.pinhole, CameraType.opencv, CameraType.brown, CameraType.fisheye]
)
def test_frame_update_error(
cam_type: CameraType, im_size: tuple, focal_len: float, sensor_size: tuple
):
"""Test an error is raised if a ``FrameCamera`` is used before initialising exterior parameters.
"""Test an error is raised if a ``FrameCamera`` is used before initialising exterior
parameters.
"""
camera = create_camera(cam_type, im_size, focal_len, sensor_size=sensor_size)

Expand Down Expand Up @@ -874,9 +870,7 @@ def test_frame_world_boundary_equiv(camera: str, camera_und: str, request: pytes
assert xyz == pytest.approx(xyz_und, abs=1e-6)


@pytest.mark.parametrize(
'camera', ['pinhole_camera', 'rpc_camera']
)
@pytest.mark.parametrize('camera', ['pinhole_camera', 'rpc_camera'])
def test_world_boundary_errors(camera: str, request: pytest.FixtureRequest):
"""Test ``Camera.world_boundary()`` error conditions."""
camera: Camera = request.getfixturevalue(camera)
Expand Down

0 comments on commit 3460aef

Please sign in to comment.