Commit 1dc31042 authored by payno's avatar payno Committed by payno
Browse files

move get_sinogram to the scan base function

parent 62597a91
......@@ -724,46 +724,3 @@ class EDFTomoScan(TomoScanBase):
return self.get_scan_range(self.path)
else:
return None
@docstring(TomoScanBase.get_sinogram)
def get_sinogram(self, line, subsampling=1):
"""
extract the sinogram from projections
:param line: which sinogram we want
:type: int
:param subsampling: subsampling to apply if any. Allows to skip some io
:type: int
:return: sinogram from the radio lines
:rtype: numpy.array
"""
_logger.info(
"compute sinogram for line {} of {} (subsampling: {})".format(
line, self.path, subsampling
)
)
assert isinstance(line, int)
if self.tomo_n is not None and self.dim_2 is not None and line > self.dim_2:
raise ValueError("requested line %s is not in the scan")
else:
y_dim = ceil(self.tomo_n / subsampling)
sinogram = numpy.empty((y_dim, self.dim_1))
proj_urls = self.get_proj_angle_url()
assert len(proj_urls) >= self.tomo_n
proj_sort = list(proj_urls.keys())
proj_sort = list(filter(lambda x: not isinstance(x, str), proj_sort))
proj_sort.sort()
advancement = Progress(
name="compute sinogram for %s, line=%s,"
"sampling=%s" % (os.path.basename(self.path), line, subsampling)
)
advancement.setMaxAdvancement(len(proj_sort))
for i_proj, proj in enumerate(proj_sort):
if i_proj % subsampling == 0:
url = proj_urls[proj]
radio = silx.io.utils.get_data(url)
radio = self.flat_field_correction(radio, proj_indexes=i_proj)
sinogram[i_proj // subsampling] = radio[line]
advancement.increaseAdvancement(1)
return sinogram
......@@ -44,9 +44,6 @@ from silx.io.utils import get_data
from ..unitsystem import metricsystem
from .utils import get_compacted_dataslices
import typing
import silx.io.utils
from math import ceil
from ..progress import Progress
import logging
_logger = logging.getLogger(__name__)
......@@ -766,54 +763,6 @@ class HDF5TomoScan(TomoScanBase):
"file %s" % (self._entry, self.master_file)
)
@docstring(TomoScanBase.get_sinogram)
def get_sinogram(self, line, subsampling=1):
"""
extract the sinogram from projections
:param line: which sinogram we want
:type: int
:param subsampling: subsampling to apply if any. Allows to skip some io
:type: int
:return: sinogram from the radio lines
:rtype: numpy.array
"""
if (
self.tomo_n is not None and self.dim_2 is not None and line > self.dim_2
) or line < 0:
raise ValueError("requested line {} is not in the scan".format(line))
if self.projections is not None:
dim1, dim2 = self.dim_1, self.dim_2
y_dim = ceil(self.tomo_n / subsampling)
sinogram = numpy.empty((y_dim, dim1))
_logger.info(
"compute sinogram for line {} of {} (subsampling: {})".format(
line, self.path, subsampling
)
)
advancement = Progress(
name="compute sinogram for {}, line={},"
"sampling={}".format(os.path.basename(self.path), line, subsampling)
)
advancement.setMaxAdvancement(self.tomo_n)
projections = self.projections
o_keys = list(projections.keys())
o_keys.sort()
for i_proj, proj_key in enumerate(o_keys):
if i_proj % subsampling == 0:
proj_url = projections[proj_key]
proj = silx.io.utils.get_data(proj_url)
proj = self.flat_field_correction(
projs=[proj], proj_indexes=[i_proj]
)[0]
sinogram[i_proj // subsampling] = proj[line]
advancement.increaseAdvancement(1)
return sinogram
else:
return None
class Frame:
"""class to store all metadata information of a frame"""
......
......@@ -38,8 +38,11 @@ from .unitsystem.metricsystem import MetricSystem
from silx.utils.enum import Enum as _Enum
from silx.io.url import DataUrl
from silx.io.utils import get_data
import silx.io.utils
from math import ceil
from .progress import Progress
logger = logging.getLogger(__name__)
_logger = logging.getLogger(__name__)
class _FOV(_Enum):
......@@ -354,7 +357,7 @@ class TomoScanBase:
extraImgs = list(ordered_url.keys())[n_projection:]
if len(extraImgs) in (4, 5):
if scan_range < 360:
logger.warning(
_logger.warning(
"incoherent data information to retrieve"
"scan extra images angle"
)
......@@ -371,7 +374,7 @@ class TomoScanBase:
res["0(1)"] = ordered_url[extraImgs[4]]
elif len(extraImgs) in (2, 3):
if scan_range > 180:
logger.warning(
_logger.warning(
"incoherent data information to retrieve"
"scan extra images angle"
)
......@@ -400,7 +403,40 @@ class TomoScanBase:
:return: computed sinogram from projections
:rtype: numpy.array
"""
raise NotImplementedError("Base class")
if (
self.tomo_n is not None and self.dim_2 is not None and line > self.dim_2
) or line < 0:
raise ValueError("requested line {} is not in the scan".format(line))
if self.projections is not None:
dim1, dim2 = self.dim_1, self.dim_2
y_dim = ceil(self.tomo_n / subsampling)
sinogram = numpy.empty((y_dim, dim1))
_logger.info(
"compute sinogram for line {} of {} (subsampling: {})".format(
line, self.path, subsampling
)
)
advancement = Progress(
name="compute sinogram for {}, line={},"
"sampling={}".format(os.path.basename(self.path), line, subsampling)
)
advancement.setMaxAdvancement(self.tomo_n)
projections = self.projections
o_keys = list(projections.keys())
o_keys.sort()
for i_proj, proj_key in enumerate(o_keys):
if i_proj % subsampling == 0:
proj_url = projections[proj_key]
proj = silx.io.utils.get_data(proj_url)
proj = self.flat_field_correction(
projs=[proj], proj_indexes=[i_proj]
)[0]
sinogram[i_proj // subsampling] = proj[line]
advancement.increaseAdvancement(1)
return sinogram
else:
return None
def _flat_field_correction(
self,
......@@ -423,36 +459,36 @@ class TomoScanBase:
if dark is None:
if self._notify_ffc_rsc_missing:
logger.error("cannot make flat field correction, dark not found")
_logger.error("cannot make flat field correction, dark not found")
can_process = False
if dark is not None and dark.ndim != 2:
logger.error(
_logger.error(
"cannot make flat field correction, dark should be of " "dimension 2"
)
can_process = False
if flat1 is None:
if self._notify_ffc_rsc_missing:
logger.error("cannot make flat field correction, flat not found")
_logger.error("cannot make flat field correction, flat not found")
can_process = False
else:
if flat1.ndim != 2:
logger.error(
_logger.error(
"cannot make flat field correction, flat should be of "
"dimension 2"
)
can_process = False
if flat2 is not None and flat1.shape != flat2.shape:
logger.error("the tow flats provided have different shapes.")
_logger.error("the tow flats provided have different shapes.")
can_process = False
if dark is not None and flat1 is not None and dark.shape != flat1.shape:
logger.error("Given dark and flat have incoherent dimension")
_logger.error("Given dark and flat have incoherent dimension")
can_process = False
if dark is not None and data.shape != dark.shape:
logger.error(
_logger.error(
"Image has invalid shape. Cannot apply flat field" "correction it"
)
can_process = False
......
Supports Markdown
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