GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 1f26b23a authored by payno's avatar payno

Merge branch 'ignore_projections' into 'master'

Ignore projections

See merge request !29
parents adb08973 11f8e235
Pipeline #36785 passed with stages
in 9 minutes and 19 seconds
......@@ -37,7 +37,7 @@ import copy
from lxml import etree
import json
import io
from typing import Union
from typing import Union, Iterable
from ..scanbase import TomoScanBase
from .utils import get_parameters_frm_par_or_info, extract_urls_from_edf
from ..unitsystem.metricsystem import MetricSystem
......@@ -71,8 +71,15 @@ class EDFTomoScan(TomoScanBase):
_SCHEME = "fabio"
def __init__(self, scan: Union[str, None], n_frames: Union[int, None] = None):
TomoScanBase.__init__(self, scan=scan, type_=self._TYPE)
def __init__(
self,
scan: Union[str, None],
n_frames: Union[int, None] = None,
ignore_projections: Union[None, Iterable] = None,
):
TomoScanBase.__init__(
self, scan=scan, type_=self._TYPE, ignore_projections=ignore_projections
)
# data caches
self._darks = None
......@@ -262,6 +269,9 @@ class EDFTomoScan(TomoScanBase):
else:
self._projections = all_projections
self._alignment_projections = {}
if self.ignore_projections is not None:
for idx in self.ignore_projections:
self._projections.pop(idx, None)
self._darks = EDFTomoScan.get_darks_url(self.path)
self._flats = EDFTomoScan.get_refs_url(self.path)
......
......@@ -113,7 +113,11 @@ class HDF5TomoScan(TomoScanBase):
_EPSILON_ROT_ANGLE = 0.02
def __init__(
self, scan: str, entry: str = None, index: typing.Union[int, None] = 0
self,
scan: str,
entry: str = None,
index: typing.Union[int, None] = 0,
ignore_projections: typing.Union[None, typing.Iterable] = None,
):
if entry is not None:
index = None
......@@ -130,7 +134,9 @@ class HDF5TomoScan(TomoScanBase):
else:
self.master_file = None
super(HDF5TomoScan, self).__init__(scan=scan, type_=HDF5TomoScan._TYPE)
super(HDF5TomoScan, self).__init__(
scan=scan, type_=HDF5TomoScan._TYPE, ignore_projections=ignore_projections
)
if scan is None:
self._entry = None
......@@ -328,10 +334,16 @@ class HDF5TomoScan(TomoScanBase):
def projections(self) -> typing.Union[dict, None]:
if self._projections is None:
if self.frames:
ignored_projs = []
if self.ignore_projections is not None:
ignored_projs = self.ignore_projections
proj_frames = tuple(
filter(
lambda x: x.image_key == ImageKey.PROJECTION
and x.is_control == False,
lambda x: (
x.image_key == ImageKey.PROJECTION
and x.index not in ignored_projs
and x.is_control == False
),
self.frames,
)
)
......
......@@ -601,6 +601,29 @@ class TestScanBaseJSON(unittest.TestCase):
scan_to_update.load_from_dict(outfile)
class TestIgnoredProjections(unittest.TestCase):
"""Test the ignore_projections parameter"""
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
self.ignored_projs = [5, 6, 7]
def tearDown(self) -> None:
shutil.rmtree(self.folder)
def testIgnoreProjections(self):
mock = MockEDF(
scan_path=self.folder, n_radio=15, n_ini_radio=10, n_extra_radio=0, dim=10
)
mock.end_acquisition()
scan = EDFTomoScan(scan=self.folder, ignore_projections=self.ignored_projs)
for idx in self.ignored_projs:
self.assertFalse(
idx in scan.projections,
"Projection index %d is supposed to be ignored" % idx,
)
def suite():
test_suite = unittest.TestSuite()
for ui in (
......@@ -613,6 +636,7 @@ def suite():
TestOriDarksFlats,
TestFlatFieldCorrection,
TestGetSinogram,
TestIgnoredProjections,
):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
......@@ -34,7 +34,7 @@ import os
import tempfile
from tomoscan.test.utils import UtilsTest
from tomoscan.esrf.hdf5scan import HDF5TomoScan, ImageKey, Frame
from ...unitsystem import metricsystem
from tomoscan.unitsystem import metricsystem
from silx.io.utils import get_data
import numpy
......@@ -311,9 +311,34 @@ class TestGetSinogram(HDF5TestBaseClass):
self.scan.get_sinogram(line=25, subsampling=1)
class TestIgnoredProjections(HDF5TestBaseClass):
"""Test the ignore_projections parameter"""
def setUp(self) -> None:
super(TestIgnoredProjections, self).setUp()
self.dataset_file = self.get_dataset("frm_edftomomill_oneentry.nx")
self.ignored_projs = [387, 388, 389, 390, 391, 392, 393, 394, 395, 396]
def testIgnoreProjections(self):
self.scan = HDF5TomoScan(
scan=self.dataset_file, ignore_projections=self.ignored_projs
)
self.scan._projections = None
for idx in self.ignored_projs:
self.assertFalse(
idx in self.scan.projections,
"Projection index %d is supposed to be ignored" % idx,
)
def suite():
test_suite = unittest.TestSuite()
for ui in (TestHDF5Scan, TestFlatFieldCorrection, TestGetSinogram):
for ui in (
TestHDF5Scan,
TestFlatFieldCorrection,
TestGetSinogram,
TestIgnoredProjections,
):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
......@@ -32,7 +32,7 @@ import os
import typing
import logging
import numpy
from typing import Union
from typing import Union, Iterable
from collections import OrderedDict
from .unitsystem.metricsystem import MetricSystem
from silx.utils.enum import Enum as _Enum
......@@ -70,7 +70,12 @@ class TomoScanBase:
_SCHEME = None
"""scheme to read data url for this type of acquisition"""
def __init__(self, scan: Union[None, str], type_: str):
def __init__(
self,
scan: Union[None, str],
type_: str,
ignore_projections: Union[None, Iterable] = None,
):
self.path = scan
self._type = type_
self._normed_flats = None
......@@ -87,6 +92,7 @@ class TomoScanBase:
self._flats_weights = None
"""list flats indexes to use for flat field correction and associate
weights"""
self.ignore_projections = ignore_projections
def clear_caches(self):
"""clear caches. Might be call if some data changed after
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment