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

Commit 11f8e235 authored by Pierre Paleo's avatar Pierre Paleo

Replace text file with iterable

Ignored projections will be provided directly with an iterable rather than in a file to read
parent bac27908
Pipeline #36711 passed with stages
in 10 minutes and 12 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
......@@ -75,7 +75,7 @@ class EDFTomoScan(TomoScanBase):
self,
scan: Union[str, None],
n_frames: Union[int, None] = None,
ignore_projections: Union[None, str] = None,
ignore_projections: Union[None, Iterable] = None,
):
TomoScanBase.__init__(
self, scan=scan, type_=self._TYPE, ignore_projections=ignore_projections
......@@ -269,8 +269,8 @@ class EDFTomoScan(TomoScanBase):
else:
self._projections = all_projections
self._alignment_projections = {}
if self._ignored_projections is not None:
for idx in self._ignored_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)
......
......@@ -118,7 +118,7 @@ class HDF5TomoScan(TomoScanBase):
scan: str,
entry: str = None,
index: typing.Union[int, None] = 0,
ignore_projections: typing.Union[None, str] = None,
ignore_projections: typing.Union[None, typing.Iterable] = None,
):
if entry is not None:
index = None
......@@ -336,8 +336,8 @@ class HDF5TomoScan(TomoScanBase):
if self._projections is None:
if self.frames:
ignored_projs = []
if self._ignored_projections is not None:
ignored_projs = self._ignored_projections
if self.ignore_projections is not None:
ignored_projs = self.ignore_projections
proj_frames = tuple(
filter(
lambda x: (
......
......@@ -607,13 +607,6 @@ class TestIgnoredProjections(unittest.TestCase):
def setUp(self) -> None:
self.folder = tempfile.mkdtemp()
self.ignored_projs = [5, 6, 7]
self.ignored_projs_fname = os.path.join(self.folder, "ignored_projections.txt")
numpy.savetxt(
self.ignored_projs_fname,
self.ignored_projs,
header="Indices of ignored projections",
comments="#",
)
def tearDown(self) -> None:
shutil.rmtree(self.folder)
......@@ -623,10 +616,7 @@ class TestIgnoredProjections(unittest.TestCase):
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_fname
)
self.assertTrue(numpy.allclose(scan._ignored_projections, self.ignored_projs))
scan = EDFTomoScan(scan=self.folder, ignore_projections=self.ignored_projs)
for idx in self.ignored_projs:
self.assertFalse(
idx in scan.projections,
......
......@@ -318,24 +318,12 @@ class TestIgnoredProjections(HDF5TestBaseClass):
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]
self.ignored_projs_fname = os.path.join(
self.test_dir, "ignored_projections.txt"
)
numpy.savetxt(
self.ignored_projs_fname,
self.ignored_projs,
header="Indices of ignored projections",
comments="#",
)
def testIgnoreProjections(self):
self.scan = HDF5TomoScan(
scan=self.dataset_file, ignore_projections=self.ignored_projs_fname
scan=self.dataset_file, ignore_projections=self.ignored_projs
)
self.scan._projections = None
self.assertTrue(
numpy.allclose(self.scan._ignored_projections, self.ignored_projs)
)
for idx in self.ignored_projs:
self.assertFalse(
idx in self.scan.projections,
......
......@@ -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
......@@ -74,7 +74,7 @@ class TomoScanBase:
self,
scan: Union[None, str],
type_: str,
ignore_projections: Union[None, str] = None,
ignore_projections: Union[None, Iterable] = None,
):
self.path = scan
self._type = type_
......@@ -92,7 +92,7 @@ class TomoScanBase:
self._flats_weights = None
"""list flats indexes to use for flat field correction and associate
weights"""
self._get_ignored_projections(ignore_projections)
self.ignore_projections = ignore_projections
def clear_caches(self):
"""clear caches. Might be call if some data changed after
......@@ -634,15 +634,3 @@ class TomoScanBase:
for proj_index in self.projections:
res[proj_index] = get_weights(proj_index=proj_index)
return res
def _get_ignored_projections(self, ignore_projections):
self.ignore_projections = ignore_projections
self._ignored_projections = None
if ignore_projections is not None:
self._ignored_projections = numpy.loadtxt(ignore_projections, comments="#")
if self._ignored_projections.ndim > 1:
raise ValueError(
"Expected exactly one row or one column in file %s"
% ignore_projections
)
self._ignored_projections = self._ignored_projections.astype(numpy.uint32)
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