Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ build

librir/libs/*

plugins/*
plugins/*


.vscode/*
61 changes: 48 additions & 13 deletions librir/video_io/IRMovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
import numpy as np
from librir.tools.utils import init_thermavip, unbind_thermavip_shared_mem
from librir.tools.FileAttributes import FileAttributes
from typing import List, Dict, Union

from librir.low_level.rir_video_io import (
enable_motion_correction,
load_motion_correction_file,
motion_correction_enabled,
)
from typing import List, Dict

from librir.low_level.rir_video_io import (
Expand Down Expand Up @@ -52,6 +59,10 @@ class IncoherentMetadata(Exception):
pass


class CalibrationNotFound(Exception):
pass


def create_pcr_header(rows, columns, frequency=50, bits=16):
pcr_header = np.zeros((256,), dtype=np.uint32)
pcr_header[2] = columns
Expand All @@ -68,7 +79,7 @@ class IRMovie(object):
_header_offset = 1024
__tempfile__ = None
handle = -1

_calibration_nickname_mapper = {"DL": "Digital Level"}
_roi_result_line = {"CEDIP": 240, "WEST": 512, "NIT": 256}

_SHAPES = {
Expand Down Expand Up @@ -151,17 +162,40 @@ def __init__(self, handle):

try:
self.calibration = "T"
except (IndexError, ValueError):
except (IndexError, ValueError, CalibrationNotFound):
logger.debug(
f"There is no temperature calibration. Switching back to Digital Level"
"There is no temperature calibration. Switching back to Digital Level"
)
self.calibration = "DL"

# if not ('Type' in self.attributes):
# d = self.attributes
# # inv_shapes = {v: k for k, v in self._SHAPES.items()}
# d['Type'] = self._SHAPES[self.image_size].encode('utf8')
# self.attributes = d
# # self._file_attributes.flush()
@property
def calibration(self):
return list(self._calibration_nickname_mapper.keys())[self._calibration_index]

@calibration.setter
def calibration(self, value: Union[str, int]):
searching_keys = self.calibrations + list(
self._calibration_nickname_mapper.keys()
)
_calibrations = self.calibrations
if isinstance(value, int):
if value >= len(_calibrations):
raise CalibrationNotFound(
f"Available calibrations : {self.calibrations}."
"Calibration index out of range"
)

self._calibration_index = value
return

if value not in searching_keys:
raise CalibrationNotFound(f"Available calibrations : {self.calibrations}")
try:
self._calibration_index = list(self._calibration_nickname_mapper).index(
value
)
except ValueError as e:
raise CalibrationNotFound(f"calibration {value} is not registered")

def __enter__(self):
"""
Expand Down Expand Up @@ -195,12 +229,11 @@ def close(self):
logger.warning(p_exc)

self.__tempfile__ = None



@property
def registration_file(self) -> Path:
"""
Returns the registration file name for this camera, and tries to download it
Returns the registration file name for this camera, and tries to download it
from ARCADE if not already done.
"""

Expand Down Expand Up @@ -283,7 +316,9 @@ def load_pos(self, pos, calibration=None):
"""Returns the image at given position using given calibration index (integer)"""
if calibration is None:
calibration = 0
res = load_image(self.handle, pos, calibration)

self.calibration = calibration
res = load_image(self.handle, pos, self._calibration_index)
self._frame_attributes_d[pos] = get_attributes(self.handle)
# self.frame_attributes = get_attributes(self.handle)
return res
Expand Down
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pytest]
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
concurrent: Concurrent and parallel jobs
h264
thermavip
io
needs_improvement
Empty file removed tests/__init__.py
Empty file.
104,781 changes: 102,078 additions & 2,703 deletions tests/python/circle.py

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions tests/python/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import os

import sys
from pathlib import Path

Expand All @@ -13,11 +13,8 @@
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

pulse = 56927
base = Path(thismodule.__file__).parent

ROWS = 512
COLUMNS = 640
IMAGES = 10
N_TIS = 7
DL_MAX_VALUE = 8192
Expand All @@ -33,7 +30,7 @@ def generate_mock_movie_data_uniform(*shape):
tis = np.zeros(shape, dtype=np.uint16)
step = 2**13
if n_images > 1:
step /= n_images - 1
step /= n_images - 2

for i in range(n_images):
tis[i] = i % N_TIS
Expand Down Expand Up @@ -67,14 +64,15 @@ def generate_random_movie_data(n_rows, n_columns, n_images):
VALID_3D_SHAPES = [
(1, 512, 640),
(10, 512, 640),
(10, 515, 640),
(10, 515, 640), # pb
(10, 240, 320),
(10, 243, 320),
(10, 243, 320), # pb
(10, 256, 320),
(10, 259, 320),
]
VALID_2D_SHAPES = [
(512, 640),
(515, 640),
]

VALID_SHAPES = VALID_2D_SHAPES + VALID_3D_SHAPES
Expand All @@ -85,8 +83,6 @@ def generate_random_movie_data(n_rows, n_columns, n_images):
]




VALID_UNIFORM_2D_NUMPY_ARRAYS = [
generate_mock_movie_data_uniform(*shape) for shape in VALID_2D_SHAPES
]
Expand All @@ -106,41 +102,41 @@ def generate_random_movie_data(n_rows, n_columns, n_images):
VALID_MASKS = [generate_constant_mask_array(*shape) for shape in VALID_3D_SHAPES]



# @pytest.fixture(scope="module")
# def uniform_movies():
# return [IRMovie.from_numpy_array(arr) for arr in VALID_UNIFORM_NUMPY_ARRAYS]



@pytest.fixture(scope="session", params=VALID_SHAPES)
def array(request):
shape = request.param
yield generate_mock_movie_data_uniform(*shape)



@pytest.fixture(scope="session", params=VALID_3D_SHAPES)
def valid_3d_array(request):
shape = request.param
yield generate_mock_movie_data_uniform(*shape)


@pytest.fixture(scope="session", params=INVALID_SHAPES)
def bad_array(request):
shape = request.param
yield generate_mock_movie_data_uniform(*shape)


@pytest.fixture(scope="session", params=VALID_2D_SHAPES)
def valid_2D_array(request):
shape = request.param
yield generate_mock_movie_data_uniform(*shape)


@pytest.fixture(scope="session")
def movie(array):
return IRMovie.from_numpy_array(array)
with IRMovie.from_numpy_array(array) as mov:
yield mov


@pytest.fixture(scope="session")
def filename(movie):
return movie.filename

# filenames = pytest.mark.parametrize("filenames", [mov.filename for mov in uniform_movies])
6 changes: 3 additions & 3 deletions tests/python/create_file_for_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def generate_mock_movie_data_uniform(*shape):

dl = np.zeros(shape, dtype=np.uint16)
tis = np.zeros(shape, dtype=np.uint16)
step = 2 ** 13
step = 2**13
if n_images > 1:
step /= n_images - 1

Expand Down Expand Up @@ -66,10 +66,10 @@ def generate_constant_mask_array(*shape):

def generate_random_movie_data(n_rows, n_columns, n_images):
dl = np.random.randint(
0, (2 ** 13), size=(n_images, n_rows, n_columns), dtype=np.uint16
0, (2**13), size=(n_images, n_rows, n_columns), dtype=np.uint16
) # >> 16 & (2**13)-1
tis = np.random.randint(
0, (2 ** 3) - 1, size=(n_images, n_rows, n_columns), dtype=np.uint16
0, (2**3) - 1, size=(n_images, n_rows, n_columns), dtype=np.uint16
) # >> 29 & (2**3)-1

data = dl | (tis << 13)
Expand Down
5 changes: 0 additions & 5 deletions tests/python/pytest.ini

This file was deleted.

Loading