Skip to content

Commit

Permalink
add fixture and test for csv angles in radians
Browse files Browse the repository at this point in the history
  • Loading branch information
dugalh committed Oct 14, 2023
1 parent d78d68d commit c8bdef1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,24 @@ def ngi_xyz_opk_csv_file() -> Path:
return root_path.joinpath('tests', 'data', 'io', 'ngi_xyz_opk.csv')


@pytest.fixture(scope='session')
def ngi_xyz_opk_radians_csv_file(ngi_xyz_opk_csv_file: Path, tmp_path_factory: pytest.TempPathFactory) -> Path:
"""
Exterior parameters for NGI data in (easting, northing, altitude), (omega, phi, kappa) CSV format. Includes
a header and .proj file. Angles in radians.
"""
filename = tmp_path_factory.mktemp('data').joinpath('ngi_xyz_opk_radians.csv')
dialect = dict(delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
with open(ngi_xyz_opk_csv_file, 'r', newline=None) as rf, open(filename, 'w', newline='') as wf:
reader = csv.reader(rf, **dialect)
writer = csv.writer(wf, **dialect)
writer.writerow(next(iter(reader))) # write header
for row in reader:
row[4:7] = np.radians(np.float64(row[4:7])).tolist()
writer.writerow(row)
return filename


@pytest.fixture(scope='session')
def odm_lla_rpy_csv_file() -> Path:
"""
Expand Down
27 changes: 16 additions & 11 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,11 @@ def test_read_exif_int_param_dewarp(odm_image_file: Path, odm_reconstruction_fil
_validate_int_param_dict(int_param_dict)


def test_read_exif_int_param_no_dewarp(xmp_no_dewarp_image_file: Path):
@pytest.mark.parametrize('filename', ['exif_image_file', 'exif_no_focal_image_file', 'xmp_no_dewarp_image_file'])
def test_read_exif_int_param_no_dewarp(filename: str, request: pytest.FixtureRequest):
""" Test reading EXIF / XMP tag interior parameters from an image without the 'DewarpData' XMP tag. """
int_param_dict = io.read_exif_int_param(xmp_no_dewarp_image_file)
int_params = next(iter(int_param_dict.values()))
assert int_params.get('cam_type', None) == 'pinhole'
_validate_int_param_dict(int_param_dict)


def test_read_exif_int_param_no_xmp(exif_image_file: Path):
""" Test reading EXIF interior parameters from an image with sensor size tags and no XMP tags. """
int_param_dict = io.read_exif_int_param(exif_image_file)
filename: Path = request.getfixturevalue(filename)
int_param_dict = io.read_exif_int_param(filename)
int_params = next(iter(int_param_dict.values()))
assert int_params.get('cam_type', None) == 'pinhole'
_validate_int_param_dict(int_param_dict)
Expand All @@ -175,7 +169,8 @@ def test_read_exif_int_param_no_xmp(exif_image_file: Path):
]) # yapf: disable
def test_read_exif_int_param_values(image_file: str, odm_reconstruction_file: Path, request: pytest.FixtureRequest):
"""
Test EXIF interior parameter values against those from OsfmReader for images with different tag combinations.
Test EXIF focal length and sensor size interior parameter values against those from OsfmReader for images with
different tag combinations.
"""
# read EXIF and OpenSfM interior parameters
image_file: Path = request.getfixturevalue(image_file)
Expand Down Expand Up @@ -328,6 +323,16 @@ def test_csv_reader_xyz_opk_values(odm_xyz_opk_csv_file: Path, odm_crs: str, odm
assert test_ext_param['opk'] == pytest.approx(ref_ext_param['opk'], abs=1e-6)


def test_csv_reader_xyz_opk_radians(ngi_xyz_opk_csv_file: Path, ngi_xyz_opk_radians_csv_file: Path, ngi_crs: str):
"""
Test CsvReader(..., radians=True) by comparing exterior parameters from files with angles in degrees and
radians.
"""
deg_reader = io.CsvReader(ngi_xyz_opk_csv_file, crs=ngi_crs)
rad_reader = io.CsvReader(ngi_xyz_opk_radians_csv_file, crs=ngi_crs, radians=True)
assert deg_reader.read_ext_param() == rad_reader.read_ext_param()


def test_csv_reader_lla_rpy(
odm_lla_rpy_csv_file: Path, odm_crs: str, odm_image_files: Tuple[Path, ...], odm_reconstruction_file: Path
):
Expand Down

0 comments on commit c8bdef1

Please sign in to comment.