tomwer 1.0.4__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orangecontrib/tomwer/tutorials/EBS_tomo_listener.ows +39 -0
- orangecontrib/tomwer/tutorials/cast_volume.ows +34 -0
- orangecontrib/tomwer/tutorials/simple_slice_reconstruction.ows +39 -0
- orangecontrib/tomwer/tutorials/simple_volume_local_reconstruction.ows +49 -0
- orangecontrib/tomwer/tutorials/simple_volume_to_slurm_reconstruction.ows +59 -0
- orangecontrib/tomwer/tutorials/using_saaxis_to_find_cor.ows +44 -0
- orangecontrib/tomwer/widgets/cluster/FutureSupervisorOW.py +1 -1
- orangecontrib/tomwer/widgets/cluster/SlurmClusterOW.py +14 -4
- orangecontrib/tomwer/widgets/cluster/__init__.py +1 -1
- orangecontrib/tomwer/widgets/control/DataListOW.py +12 -5
- orangecontrib/tomwer/widgets/control/DataListenerOW.py +18 -9
- orangecontrib/tomwer/widgets/control/DataSelectorOW.py +13 -6
- orangecontrib/tomwer/widgets/control/DataTransfertOW.py +4 -5
- orangecontrib/tomwer/widgets/control/DataValidatorOW.py +8 -4
- orangecontrib/tomwer/widgets/control/DataWatcherOW.py +4 -6
- orangecontrib/tomwer/widgets/control/EDF2NXTomomillOW.py +49 -62
- orangecontrib/tomwer/widgets/control/FilterOW.py +2 -4
- orangecontrib/tomwer/widgets/control/NXTomomillMixIn.py +93 -0
- orangecontrib/tomwer/widgets/control/NXTomomillOW.py +135 -128
- orangecontrib/tomwer/widgets/control/NotifierOW.py +31 -7
- orangecontrib/tomwer/widgets/control/SingleTomoObjOW.py +3 -5
- orangecontrib/tomwer/widgets/control/TomoObjSerieOW.py +85 -0
- orangecontrib/tomwer/widgets/control/VolumeSelector.py +12 -4
- orangecontrib/tomwer/widgets/control/VolumeSymLinkOW.py +11 -7
- orangecontrib/tomwer/widgets/control/icons/notification.svg +4 -4
- orangecontrib/tomwer/widgets/control/icons/nxtomomill.png +0 -0
- orangecontrib/tomwer/widgets/control/icons/nxtomomill.svg +8 -5
- orangecontrib/tomwer/widgets/control/icons/tomoobjserie.png +0 -0
- orangecontrib/tomwer/widgets/control/icons/tomoobjserie.svg +138 -0
- orangecontrib/tomwer/widgets/edit/DarkFlatPatchOW.py +16 -4
- orangecontrib/tomwer/widgets/edit/NXtomoEditorOW.py +100 -0
- orangecontrib/tomwer/widgets/edit/icons/image_key_editor.png +0 -0
- orangecontrib/tomwer/widgets/edit/icons/image_key_upgrader.png +0 -0
- orangecontrib/tomwer/widgets/edit/icons/nx_tomo_editor.png +0 -0
- orangecontrib/tomwer/widgets/edit/icons/nx_tomo_editor.svg +123 -0
- orangecontrib/tomwer/widgets/edit/test/test_dark_flat_patch.py +21 -1
- orangecontrib/tomwer/widgets/edit/test/test_image_key_editor.py +1 -1
- orangecontrib/tomwer/widgets/edit/test/test_image_key_upgrader.py +1 -1
- orangecontrib/tomwer/widgets/edit/test/test_nxtomo_editor.py +25 -0
- orangecontrib/tomwer/widgets/other/PythonScriptOW.py +19 -10
- orangecontrib/tomwer/widgets/reconstruction/AxisOW.py +20 -14
- orangecontrib/tomwer/widgets/reconstruction/CastNabuVolumeOW.py +24 -10
- orangecontrib/tomwer/widgets/reconstruction/DarkRefAndCopyOW.py +26 -21
- orangecontrib/tomwer/widgets/reconstruction/NabuOW.py +29 -12
- orangecontrib/tomwer/widgets/reconstruction/NabuVolumeOW.py +44 -17
- orangecontrib/tomwer/widgets/reconstruction/SAAxisOW.py +28 -18
- orangecontrib/tomwer/widgets/reconstruction/SADeltaBetaOW.py +24 -17
- orangecontrib/tomwer/widgets/reconstruction/SinoNormOW.py +6 -6
- orangecontrib/tomwer/widgets/reconstruction/TofuOW.py +4 -2
- orangecontrib/tomwer/widgets/reconstruction/icons/nabu_2d.png +0 -0
- orangecontrib/tomwer/widgets/reconstruction/icons/nabu_2d.svg +11 -8
- orangecontrib/tomwer/widgets/visualization/DataViewerOW.py +10 -4
- orangecontrib/tomwer/widgets/visualization/DiffViewerOW.py +1 -1
- orangecontrib/tomwer/widgets/visualization/NXtomoMetadataViewerOW.py +69 -0
- orangecontrib/tomwer/widgets/visualization/SampleMovedOW.py +2 -4
- orangecontrib/tomwer/widgets/visualization/icons/nx_tomo_metadata_viewer.png +0 -0
- orangecontrib/tomwer/widgets/visualization/icons/nx_tomo_metadata_viewer.svg +105 -0
- tomwer/__main__.py +10 -5
- tomwer/app/canvas_launcher/config.py +10 -10
- tomwer/app/canvas_launcher/mainwindow.py +68 -6
- tomwer/app/canvas_launcher/widgetsscheme.py +1 -3
- tomwer/app/darkref.py +16 -12
- tomwer/app/imagekeyeditor.py +2 -2
- tomwer/app/imagekeyupgrader.py +104 -0
- tomwer/app/nxtomoeditor.py +103 -0
- tomwer/app/rsync.py +1 -1
- tomwer/core/cluster/cluster.py +1 -1
- tomwer/core/futureobject.py +1 -0
- tomwer/core/process/control/datalistener/datalistener.py +7 -1
- tomwer/core/process/control/datalistener/rpcserver.py +3 -3
- tomwer/core/process/control/datawatcher/datawatcher.py +18 -18
- tomwer/core/process/control/datawatcher/datawatcherobserver.py +5 -8
- tomwer/core/process/control/datawatcher/datawatcherprocess.py +2 -3
- tomwer/core/process/control/datawatcher/edfdwprocess.py +2 -2
- tomwer/core/process/control/nxtomomill.py +33 -58
- tomwer/core/process/control/scanlist.py +2 -1
- tomwer/core/process/control/scanselector.py +7 -0
- tomwer/core/process/control/scantransfer.py +9 -18
- tomwer/core/process/control/scanvalidator.py +6 -5
- tomwer/core/process/control/singletomoobj.py +2 -1
- tomwer/core/process/control/timer.py +2 -1
- tomwer/core/process/control/tomoobjserie.py +8 -0
- tomwer/core/process/control/volumeselector.py +2 -1
- tomwer/core/process/control/volumesymlink.py +2 -1
- tomwer/core/process/edit/darkflatpatch.py +2 -1
- tomwer/core/process/edit/imagekeyeditor.py +4 -3
- tomwer/core/process/reconstruction/axis/axis.py +29 -32
- tomwer/core/process/reconstruction/axis/mode.py +3 -2
- tomwer/core/process/reconstruction/axis/params.py +35 -16
- tomwer/core/process/reconstruction/darkref/darkrefs.py +90 -707
- tomwer/core/process/reconstruction/darkref/darkrefscopy.py +44 -16
- tomwer/core/process/reconstruction/darkref/params.py +62 -67
- tomwer/core/process/reconstruction/lamino/tofu.py +1 -1
- tomwer/core/process/reconstruction/nabu/castvolume.py +21 -26
- tomwer/core/process/reconstruction/nabu/nabucommon.py +36 -38
- tomwer/core/process/reconstruction/nabu/nabuscores.py +28 -13
- tomwer/core/process/reconstruction/nabu/nabuslices.py +41 -14
- tomwer/core/process/reconstruction/nabu/nabuvolume.py +21 -12
- tomwer/core/process/reconstruction/nabu/utils.py +12 -1
- tomwer/core/process/reconstruction/normalization/normalization.py +9 -8
- tomwer/core/process/reconstruction/saaxis/saaxis.py +46 -20
- tomwer/core/process/reconstruction/sadeltabeta/sadeltabeta.py +38 -12
- tomwer/core/process/reconstruction/test/__init__.py +0 -39
- tomwer/core/process/reconstruction/test/test_axis_params.py +25 -3
- tomwer/core/process/reconstruction/test/test_darkref_copy.py +117 -1
- tomwer/core/process/script/python.py +16 -12
- tomwer/core/process/task.py +3 -7
- tomwer/core/process/test/test_axis.py +1 -1
- tomwer/core/process/test/test_dark_and_flat.py +41 -111
- tomwer/core/process/test/test_data_listener.py +0 -29
- tomwer/core/process/test/test_data_transfer.py +10 -14
- tomwer/core/process/test/test_nabu.py +1 -1
- tomwer/core/process/test/test_normalization.py +1 -1
- tomwer/core/process/visualization/liveslice.py +6 -0
- tomwer/core/scan/blissscan.py +37 -2
- tomwer/core/scan/edfscan.py +14 -4
- tomwer/core/scan/hdf5scan.py +10 -4
- tomwer/core/scan/scanbase.py +35 -29
- tomwer/core/scan/scanfactory.py +3 -17
- tomwer/core/scan/test/test_h5.py +1 -1
- tomwer/core/scan/test/test_process_registration.py +0 -11
- tomwer/core/scan/test/test_scan.py +32 -30
- tomwer/core/settings.py +2 -2
- tomwer/core/test/test_utils.py +1 -1
- tomwer/core/tomwer_object.py +19 -0
- tomwer/core/utils/__init__.py +0 -45
- tomwer/core/utils/char.py +2 -0
- tomwer/core/utils/gpu.py +5 -5
- tomwer/core/utils/nxtomoutils.py +2 -2
- tomwer/core/utils/scanutils.py +50 -0
- tomwer/core/utils/volumeutils.py +13 -0
- tomwer/core/volume/edfvolume.py +4 -0
- tomwer/core/volume/hdf5volume.py +4 -0
- tomwer/core/volume/jp2kvolume.py +4 -0
- tomwer/core/volume/rawvolume.py +4 -0
- tomwer/core/volume/tiffvolume.py +4 -0
- tomwer/core/volume/volumebase.py +19 -12
- tomwer/core/volume/volumefactory.py +20 -1
- tomwer/gui/cluster/slurm.py +1 -1
- tomwer/gui/cluster/test/test_cluster.py +2 -2
- tomwer/gui/control/datalist.py +109 -34
- tomwer/gui/control/datatransfert.py +1 -1
- tomwer/gui/control/datawatcher/datawatcher.py +23 -13
- tomwer/gui/control/datawatcher/datawatcherobserver.py +1 -1
- tomwer/gui/control/observations.py +0 -3
- tomwer/gui/control/selectorwidgetbase.py +42 -11
- tomwer/gui/control/serie/seriecreator.py +967 -0
- tomwer/{web/__init__.py → gui/control/serie/seriewaiter.py} +5 -7
- tomwer/gui/control/singletomoobj.py +15 -3
- tomwer/gui/control/test/test_datalist.py +1 -1
- tomwer/gui/control/test/test_datalistener.py +1 -1
- tomwer/gui/control/test/test_inputwidget.py +1 -1
- tomwer/gui/control/test/test_process_manager.py +1 -13
- tomwer/gui/control/test/test_scanselector.py +1 -1
- tomwer/gui/control/test/test_scanvalidator.py +1 -1
- tomwer/gui/control/test/test_single_tomo_obj.py +1 -1
- tomwer/gui/control/test/test_volume_dialog.py +19 -7
- tomwer/gui/control/test/test_volumeselector.py +4 -4
- tomwer/gui/debugtools/datasetgenerator.py +1 -8
- tomwer/gui/edit/dkrfpatch.py +2 -2
- tomwer/gui/edit/imagekeyeditor.py +12 -9
- tomwer/gui/edit/nxtomoeditor.py +475 -0
- tomwer/gui/edit/test/test_dkrf_patch.py +2 -14
- tomwer/gui/edit/test/test_image_key_editor.py +2 -2
- tomwer/gui/edit/test/test_nx_editor.py +155 -0
- tomwer/gui/qfolderdialog.py +11 -0
- tomwer/gui/reconstruction/axis/CompareImages.py +27 -29
- tomwer/gui/reconstruction/axis/axis.py +2 -0
- tomwer/gui/reconstruction/axis/radioaxis.py +67 -11
- tomwer/gui/reconstruction/darkref/darkrefcopywidget.py +7 -9
- tomwer/gui/reconstruction/darkref/darkrefwidget.py +22 -24
- tomwer/gui/reconstruction/lamino/tofu/projections.py +1 -1
- tomwer/gui/reconstruction/lamino/tofu/tofu.py +3 -3
- tomwer/gui/reconstruction/lamino/tofu/tofuexpert.py +4 -4
- tomwer/gui/reconstruction/lamino/tofu/tofuoutput.py +10 -4
- tomwer/gui/reconstruction/nabu/castvolume.py +80 -11
- tomwer/gui/reconstruction/nabu/check.py +1 -1
- tomwer/gui/reconstruction/nabu/nabuconfig/ctf.py +352 -0
- tomwer/gui/reconstruction/nabu/nabuconfig/nabuconfig.py +0 -9
- tomwer/gui/reconstruction/nabu/nabuconfig/output.py +1 -1
- tomwer/gui/reconstruction/nabu/nabuconfig/phase.py +18 -19
- tomwer/gui/reconstruction/nabu/nabuconfig/preprocessing.py +30 -7
- tomwer/gui/reconstruction/nabu/nabuconfig/reconstruction.py +26 -13
- tomwer/gui/reconstruction/nabu/slices.py +10 -2
- tomwer/gui/reconstruction/nabu/slurm.py +1 -1
- tomwer/gui/reconstruction/nabu/volume.py +13 -7
- tomwer/gui/reconstruction/normalization/intensity.py +1 -1
- tomwer/gui/reconstruction/saaxis/corrangeselector.py +10 -34
- tomwer/gui/reconstruction/saaxis/saaxis.py +11 -6
- tomwer/gui/reconstruction/saaxis/sliceselector.py +11 -26
- tomwer/gui/reconstruction/sadeltabeta/saadeltabeta.py +13 -8
- tomwer/gui/reconstruction/scores/scoreplot.py +67 -61
- tomwer/gui/reconstruction/test/test_axis.py +2 -2
- tomwer/gui/reconstruction/test/test_lamino.py +2 -2
- tomwer/gui/reconstruction/test/test_nabu.py +14 -1
- tomwer/gui/reconstruction/test/test_saaxis.py +8 -17
- tomwer/gui/reconstruction/test/test_sadeltabeta.py +7 -13
- tomwer/gui/stackplot.py +11 -28
- tomwer/gui/test/test_axis_gui.py +4 -4
- tomwer/gui/test/test_qfolder_dialog.py +12 -0
- tomwer/gui/utils/inputwidget.py +42 -21
- tomwer/gui/utils/lineselector/lineselector.py +13 -21
- tomwer/gui/utils/scandescription.py +2 -4
- tomwer/gui/utils/slider.py +1 -102
- tomwer/gui/utils/unitsystem.py +48 -11
- tomwer/gui/visualization/dataviewer.py +24 -17
- tomwer/gui/visualization/diffviewer/diffviewer.py +2 -11
- tomwer/gui/visualization/nxtomometadata.py +21 -0
- tomwer/gui/visualization/scanoverview.py +0 -1
- tomwer/gui/visualization/test/test_nx_tomo_metadata_viewer.py +72 -0
- tomwer/gui/visualization/test/test_stacks.py +1 -1
- tomwer/gui/visualization/tomoobjoverview.py +49 -0
- tomwer/gui/visualization/volumeoverview.py +64 -0
- tomwer/gui/visualization/volumeviewer.py +1 -1
- tomwer/resources/gui/icons/multi-document-save.png +0 -0
- tomwer/resources/gui/icons/multi-document-save.svg +101 -0
- tomwer/resources/gui/illustrations/ctf_z1.png +0 -0
- tomwer/resources/gui/illustrations/ctf_z1.svg +471 -0
- tomwer/synctools/datalistener.py +5 -1
- tomwer/synctools/imageloaderthread.py +2 -2
- tomwer/synctools/stacks/edit/imagekeyeditor.py +1 -1
- tomwer/synctools/stacks/processingstack.py +2 -2
- tomwer/synctools/stacks/reconstruction/castvolume.py +1 -0
- tomwer/synctools/stacks/reconstruction/lamino.py +1 -3
- tomwer/synctools/stacks/reconstruction/sadeltabeta.py +0 -2
- tomwer/synctools/test/test_darkRefs.py +32 -149
- tomwer/synctools/test/test_foldertransfer.py +1 -1
- tomwer/synctools/test/test_scanstages.py +2 -2
- tomwer/tests/__init__.py +0 -0
- tomwer/tests/conftest.py +51 -0
- tomwer/{test → tests}/test_scripts.py +1 -1
- tomwer/tests/test_utils.py +10 -0
- tomwer/{test → tests}/utils/utilstest.py +0 -11
- tomwer/version.py +3 -3
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/METADATA +14 -16
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/RECORD +245 -217
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/WHEEL +1 -1
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/entry_points.txt +6 -0
- orangecontrib/tomwer/setup.py +0 -45
- orangecontrib/tomwer/widgets/setup.py +0 -49
- tomwer/app/process.py +0 -153
- tomwer/core/process/reconstruction/nabu/slurm.py +0 -36
- tomwer/core/process/reconstruction/utils/nabu_slice_exec.py +0 -10
- tomwer/core/utils/laminoutils.py +0 -80
- tomwer/gui/utils/lineselector/lineselection.py +0 -76
- tomwer/setup.py +0 -52
- tomwer/web/client.py +0 -43
- tomwer/web/config.py +0 -36
- tomwer/web/test/test_graylog_connection.py +0 -59
- {tomwer/test → orangecontrib/tomwer/tutorials}/__init__.py +0 -0
- /tomwer/{web/test → gui/control/serie}/__init__.py +0 -0
- /tomwer/{test → tests}/utils/__init__.py +0 -0
- /tomwer-1.0.4-py3.8-nspkg.pth → /tomwer-1.1.0-py3.9-nspkg.pth +0 -0
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/LICENSE +0 -0
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/namespace_packages.txt +0 -0
- {tomwer-1.0.4.dist-info → tomwer-1.1.0.dist-info}/top_level.txt +0 -0
@@ -31,43 +31,29 @@ __license__ = "MIT"
|
|
31
31
|
__date__ = "06/09/2017"
|
32
32
|
|
33
33
|
import os
|
34
|
-
import
|
35
|
-
|
36
|
-
import fabio
|
37
|
-
import numpy
|
34
|
+
import typing
|
35
|
+
import logging
|
38
36
|
from queue import Queue
|
37
|
+
import tomwer.version
|
39
38
|
from tomwer.utils import docstring
|
40
|
-
from tomoscan.esrf.scan.utils import get_data
|
41
39
|
from tomwer.core import settings
|
42
40
|
from tomwer.core import utils
|
43
41
|
from tomwer.core.process.task import Task
|
44
|
-
from
|
45
|
-
from tomwer.core.utils import getDARK_N
|
46
|
-
import logging
|
42
|
+
from tomwer.core.utils.scanutils import data_identifier_to_scan
|
47
43
|
from tomwer.core.scan.scanbase import TomwerScanBase
|
48
|
-
from tomwer.core.scan.edfscan import EDFTomoScan
|
49
44
|
from tomwer.core.scan.hdf5scan import HDF5TomoScan
|
50
45
|
from . import params as dkrf_reconsparams
|
51
46
|
from tomwer.core.scan.scanfactory import ScanFactory
|
52
|
-
from tomoscan.
|
47
|
+
from tomoscan.framereducerbase import ReduceMethod, REDUCER_TARGET
|
53
48
|
from processview.core.manager import ProcessManager
|
54
49
|
from tomoscan.io import HDF5File
|
50
|
+
from processview.core.superviseprocess import SuperviseProcess
|
55
51
|
from processview.core.manager import DatasetState
|
56
|
-
import tomwer.version
|
57
52
|
from silx.io.utils import h5py_read_dataset
|
58
53
|
from silx.io.url import DataUrl
|
59
|
-
import typing
|
60
54
|
|
61
55
|
logger = logging.getLogger(__name__)
|
62
56
|
|
63
|
-
try:
|
64
|
-
from tomwer.synctools.rsyncmanager import RSyncManager
|
65
|
-
except ImportError:
|
66
|
-
logger.warning("rsyncmanager not available")
|
67
|
-
has_rsync = True
|
68
|
-
else:
|
69
|
-
has_rsync = False
|
70
|
-
|
71
57
|
|
72
58
|
class DarkRefs(
|
73
59
|
Task, SuperviseProcess, Queue, input_names=("data",), output_names=("data",)
|
@@ -228,7 +214,7 @@ class DarkRefs(
|
|
228
214
|
if "dark" in properties:
|
229
215
|
self._recons_params.dark_calc_method = properties["dark"]
|
230
216
|
if "refs" in properties:
|
231
|
-
self._recons_params.
|
217
|
+
self._recons_params.flat_calc_method = properties["refs"]
|
232
218
|
if "_rpSetting" in properties:
|
233
219
|
self._recons_params.load_from_dict(properties["_rpSetting"])
|
234
220
|
else:
|
@@ -360,7 +346,15 @@ class DarkRefs(
|
|
360
346
|
return res
|
361
347
|
|
362
348
|
def run(self):
|
363
|
-
|
349
|
+
if isinstance(self.inputs.data, str):
|
350
|
+
try:
|
351
|
+
scan = data_identifier_to_scan(self.inputs.data)
|
352
|
+
except ValueError:
|
353
|
+
# in the case fails to cast str to identifier (data can be a simple folder in the case of dark ref)
|
354
|
+
scan = self.inputs.data
|
355
|
+
else:
|
356
|
+
scan = self.inputs.data
|
357
|
+
|
364
358
|
if scan is None:
|
365
359
|
self.outputs.data = None
|
366
360
|
return
|
@@ -413,38 +407,44 @@ class DarkRefs(
|
|
413
407
|
self.outputs.data = None
|
414
408
|
return
|
415
409
|
whats = (DarkRefs.WHAT_REF, DarkRefs.WHAT_DARK)
|
410
|
+
overwrites = (
|
411
|
+
self.recons_params.overwrite_flat,
|
412
|
+
self.recons_params.overwrite_dark,
|
413
|
+
)
|
416
414
|
modes = (
|
417
|
-
self.recons_params.
|
415
|
+
self.recons_params.flat_calc_method,
|
418
416
|
self.recons_params.dark_calc_method,
|
419
417
|
)
|
418
|
+
has_reduced = (
|
419
|
+
scan.reduced_flats not in (None, {}),
|
420
|
+
scan.reduced_darks not in (None, {}),
|
421
|
+
)
|
420
422
|
|
421
|
-
for what, mode in zip(whats, modes):
|
422
|
-
|
423
|
-
|
423
|
+
for what, mode, overwrite, exists in zip(whats, modes, overwrites, has_reduced):
|
424
|
+
# if reduced already exists and user didn't asked for overwritting it
|
425
|
+
if exists and not overwrite:
|
426
|
+
continue
|
424
427
|
logger.debug(
|
425
428
|
"compute {what} using mode {mode} for {scan}"
|
426
429
|
"".format(what=what, mode=mode, scan=str(scan))
|
427
430
|
)
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
)
|
441
|
-
logger.processFailed(info)
|
442
|
-
self.outputs.data = None
|
443
|
-
return
|
431
|
+
try:
|
432
|
+
self.compute(scan=scan, target=what, method=mode, overwrite=True)
|
433
|
+
except Exception as e:
|
434
|
+
info = "Fail computing dark and flat for {}. Reason is {}".format(
|
435
|
+
str(scan), e
|
436
|
+
)
|
437
|
+
self.notify_to_state_to_managed(
|
438
|
+
dataset=scan, state=DatasetState.FAILED, details=info
|
439
|
+
)
|
440
|
+
logger.processFailed(info)
|
441
|
+
self.outputs.data = None
|
442
|
+
return
|
444
443
|
results = {}
|
445
444
|
interpretations = {}
|
446
445
|
if (
|
447
|
-
self.recons_params.dark_calc_method
|
446
|
+
self.recons_params.dark_calc_method
|
447
|
+
is not dkrf_reconsparams.ReduceMethod.NONE
|
448
448
|
and scan.reduced_darks is not None
|
449
449
|
):
|
450
450
|
# cast darks and flats keys from int (index) to str
|
@@ -454,11 +454,11 @@ class DarkRefs(
|
|
454
454
|
f_darks[str(index)] = data
|
455
455
|
interpretations["/".join(("darks", str(index)))] = "image"
|
456
456
|
results["darks"] = f_darks
|
457
|
-
|
458
|
-
|
459
|
-
scan.save_reduced_darks(f_darks)
|
457
|
+
|
458
|
+
scan.save_reduced_darks(f_darks)
|
460
459
|
if (
|
461
|
-
self.recons_params.
|
460
|
+
self.recons_params.flat_calc_method
|
461
|
+
is not dkrf_reconsparams.ReduceMethod.NONE
|
462
462
|
and scan.reduced_flats is not None
|
463
463
|
):
|
464
464
|
results["flats"] = scan.reduced_flats
|
@@ -468,9 +468,8 @@ class DarkRefs(
|
|
468
468
|
f_flats[str(index)] = data
|
469
469
|
interpretations["/".join(("flats", str(index)))] = "image"
|
470
470
|
results["flats"] = f_flats
|
471
|
-
|
472
|
-
|
473
|
-
scan.save_reduced_flats(f_flats)
|
471
|
+
|
472
|
+
scan.save_reduced_flats(f_flats)
|
474
473
|
|
475
474
|
if len(results) > 0:
|
476
475
|
# if some processing to be registered
|
@@ -500,662 +499,46 @@ class DarkRefs(
|
|
500
499
|
else:
|
501
500
|
self.outputs.data = scan
|
502
501
|
|
503
|
-
|
504
|
-
|
505
|
-
self.compute_edf(scan, what=what, mode=mode)
|
506
|
-
elif isinstance(scan, HDF5TomoScan):
|
507
|
-
self.compute_hdf5(scan, what=what, mode=mode)
|
508
|
-
else:
|
509
|
-
raise ValueError("scan type is not recognized ofr %s" % scan)
|
510
|
-
|
511
|
-
def compute_hdf5(self, scan, what, mode):
|
512
|
-
"""Compute the requested what in the given mode for `directory`
|
513
|
-
|
514
|
-
:param str directory: path of the scan
|
515
|
-
:param what: what to compute (ref or dark)
|
516
|
-
:param mode: how to compute it (median or average...)
|
502
|
+
@staticmethod
|
503
|
+
def _target_to_reducer_target(target):
|
517
504
|
"""
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
current_index = index
|
537
|
-
else:
|
538
|
-
series.append(current_serie)
|
539
|
-
current_serie = {}
|
540
|
-
current_index = index
|
541
|
-
current_serie[index] = raw_what[index]
|
542
|
-
if len(current_serie) > 0:
|
543
|
-
series.append(current_serie)
|
544
|
-
return series
|
545
|
-
|
546
|
-
if mode is dkrf_reconsparams.Method.median:
|
547
|
-
method_ = numpy.median
|
548
|
-
elif mode is dkrf_reconsparams.Method.average:
|
549
|
-
method_ = numpy.mean
|
550
|
-
elif mode is dkrf_reconsparams.Method.none:
|
551
|
-
return None
|
552
|
-
elif mode is dkrf_reconsparams.Method.first:
|
553
|
-
method_ = "raw"
|
554
|
-
elif mode is dkrf_reconsparams.Method.last:
|
555
|
-
method_ = "raw"
|
556
|
-
else:
|
557
|
-
raise ValueError(
|
558
|
-
"Mode {mode} for {what} is not managed" "".format(mode=mode, what=what)
|
505
|
+
util to insure connection between 'historical' tomwer dark / ref and latest tomoscan FrameReducer
|
506
|
+
"""
|
507
|
+
if target == "refs":
|
508
|
+
return REDUCER_TARGET.FLATS
|
509
|
+
elif target == "dark":
|
510
|
+
return REDUCER_TARGET.DARKS
|
511
|
+
return REDUCER_TARGET.from_value(target)
|
512
|
+
|
513
|
+
def compute(
|
514
|
+
self, scan, target: REDUCER_TARGET, method: ReduceMethod, overwrite: bool
|
515
|
+
):
|
516
|
+
target = self._target_to_reducer_target(target)
|
517
|
+
method = ReduceMethod.from_value(method)
|
518
|
+
if target is REDUCER_TARGET.DARKS:
|
519
|
+
reduced_darks, metadata = scan.compute_reduced_darks(
|
520
|
+
reduced_method=method,
|
521
|
+
overwrite=overwrite,
|
522
|
+
return_info=True,
|
559
523
|
)
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
}
|
576
|
-
|
577
|
-
cpt_slices = get_compacted_dataslices(urls)
|
578
|
-
url_set = {}
|
579
|
-
for url in cpt_slices.values():
|
580
|
-
path = url.file_path(), url.data_path(), str(url.data_slice())
|
581
|
-
url_set[path] = url
|
582
|
-
|
583
|
-
n_elmts = 0
|
584
|
-
for url in url_set.values():
|
585
|
-
my_slice = url.data_slice()
|
586
|
-
n_elmts += my_slice.stop - my_slice.start
|
587
|
-
|
588
|
-
data = None
|
589
|
-
start_z = 0
|
590
|
-
for url in url_set.values():
|
591
|
-
my_slice = url.data_slice()
|
592
|
-
my_slice = slice(my_slice.start, my_slice.stop, 1)
|
593
|
-
new_url = DataUrl(
|
594
|
-
file_path=url.file_path(),
|
595
|
-
data_path=url.data_path(),
|
596
|
-
data_slice=my_slice,
|
597
|
-
scheme="silx",
|
598
|
-
)
|
599
|
-
loaded_data = get_data(new_url)
|
600
|
-
|
601
|
-
# init data if dim is not know
|
602
|
-
if data is None:
|
603
|
-
data = numpy.empty(
|
604
|
-
shape=(
|
605
|
-
n_elmts,
|
606
|
-
scan.dim_2 or loaded_data.shape[-2],
|
607
|
-
scan.dim_1 or loaded_data.shape[-1],
|
608
|
-
)
|
609
|
-
)
|
610
|
-
if loaded_data.ndim == 2:
|
611
|
-
data[start_z, :, :] = loaded_data
|
612
|
-
start_z += 1
|
613
|
-
elif loaded_data.ndim == 3:
|
614
|
-
delta_z = my_slice.stop - my_slice.start
|
615
|
-
data[start_z:delta_z, :, :] = loaded_data
|
616
|
-
start_z += delta_z
|
617
|
-
else:
|
618
|
-
raise ValueError("Dark and ref raw data should be 2D or 3D")
|
619
|
-
|
620
|
-
return data
|
621
|
-
|
622
|
-
res = {}
|
623
|
-
# res: index: sequence when the serie was taken
|
624
|
-
|
625
|
-
self.__new_hdf5_entry_created = False
|
626
|
-
# flag to know if we could load all dark and flats from a previous
|
627
|
-
# process file or if we add to create a new entry
|
628
|
-
for serie_ in raw_series:
|
629
|
-
serie_index = min(serie_)
|
630
|
-
if what == "dark" and len(res) > 0:
|
631
|
-
continue
|
632
|
-
old_data = None
|
633
|
-
has_p_file = os.path.exists(scan.process_file)
|
634
|
-
if (
|
635
|
-
has_p_file
|
636
|
-
and what == DarkRefs.WHAT_DARK
|
637
|
-
and not self.recons_params.overwrite_dark
|
638
|
-
):
|
639
|
-
old_data = DarkRefs.get_darks_frm_process_file(
|
640
|
-
scan.process_file, entry=scan.entry
|
641
|
-
)
|
642
|
-
elif (
|
643
|
-
has_p_file
|
644
|
-
and what == DarkRefs.WHAT_REF
|
645
|
-
and not self.recons_params.overwrite_ref
|
646
|
-
):
|
647
|
-
old_data = DarkRefs.get_flats_frm_process_file(
|
648
|
-
scan.process_file, entry=scan.entry
|
649
|
-
)
|
650
|
-
if old_data is not None and serie_index in old_data:
|
651
|
-
logger.info("load {} from existing data".format(what))
|
652
|
-
res[serie_index] = old_data[serie_index]
|
653
|
-
continue
|
654
|
-
self.__new_hdf5_entry_created = True
|
655
|
-
serie_data = load_data_serie(serie_)
|
656
|
-
if method_ == "raw":
|
657
|
-
res[serie_index] = serie_data.reshape(-1, serie_data.shape[-1])
|
658
|
-
else:
|
659
|
-
res[serie_index] = method_(serie_data, axis=0)
|
660
|
-
if what == "dark":
|
661
|
-
scan.set_reduced_darks(res)
|
524
|
+
scan.set_reduced_darks(darks=reduced_darks, darks_infos=metadata)
|
525
|
+
try:
|
526
|
+
scan.save_reduced_darks(darks=reduced_darks, darks_infos=metadata)
|
527
|
+
except Exception as e:
|
528
|
+
logger.error(f"Fail to save reduced darks. Error is {e}")
|
529
|
+
elif target is REDUCER_TARGET.FLATS:
|
530
|
+
reduced_flats, metadata = scan.compute_reduced_flats(
|
531
|
+
reduced_method=method,
|
532
|
+
overwrite=overwrite,
|
533
|
+
return_info=True,
|
534
|
+
)
|
535
|
+
scan.set_reduced_flats(flats=reduced_flats, flats_infos=metadata)
|
536
|
+
try:
|
537
|
+
scan.save_reduced_flats(flats=reduced_flats, flats_infos=metadata)
|
538
|
+
except Exception as e:
|
539
|
+
logger.error(f"Fail to save reduced flats. Error is {e}")
|
662
540
|
else:
|
663
|
-
|
664
|
-
|
665
|
-
def compute_edf(self, scan, what, mode):
|
666
|
-
"""Compute the requested what in the given mode for `directory`
|
667
|
-
|
668
|
-
:param str directory: path of the scan
|
669
|
-
:param what: what to compute (ref or dark)
|
670
|
-
:param mode: how to compute it (median or average...)
|
671
|
-
"""
|
672
|
-
directory = scan.path
|
673
|
-
assert type(directory) is str
|
674
|
-
|
675
|
-
def removeFiles():
|
676
|
-
"""Remove orignals files fitting the what (dark or ref)"""
|
677
|
-
if what is DarkRefs.WHAT_DARK:
|
678
|
-
# In the case originals has already been found for the median
|
679
|
-
# calculation
|
680
|
-
if len(self._originalsDark) > 0:
|
681
|
-
files = self._originalsDark
|
682
|
-
else:
|
683
|
-
files = getOriginals(DarkRefs.WHAT_DARK)
|
684
|
-
elif what is DarkRefs.WHAT_REF:
|
685
|
-
if len(self._originalsRef) > 0:
|
686
|
-
files = self._originalsRef
|
687
|
-
else:
|
688
|
-
files = getOriginals(DarkRefs.WHAT_REF)
|
689
|
-
else:
|
690
|
-
logger.error(
|
691
|
-
"the requested what (%s) is not recognized. "
|
692
|
-
"Can't remove corresponding file" % what
|
693
|
-
)
|
694
|
-
return
|
695
|
-
|
696
|
-
_files = set(files)
|
697
|
-
if len(files) > 0:
|
698
|
-
if has_rsync:
|
699
|
-
logger.info(
|
700
|
-
"ask RSyncManager for removal of %s files in %s"
|
701
|
-
% (what, directory)
|
702
|
-
)
|
703
|
-
# for lbsram take into account sync from data watcher
|
704
|
-
if directory.startswith(settings.get_lbsram_path()):
|
705
|
-
for f in files:
|
706
|
-
_files.add(
|
707
|
-
f.replace(
|
708
|
-
settings.get_lbsram_path(),
|
709
|
-
settings.get_dest_path(),
|
710
|
-
1,
|
711
|
-
)
|
712
|
-
)
|
713
|
-
RSyncManager().removesync_files(
|
714
|
-
dir=directory, files=_files, block=self._forceSync
|
715
|
-
)
|
716
|
-
else:
|
717
|
-
for _file in _files:
|
718
|
-
try:
|
719
|
-
os.remove(_file)
|
720
|
-
except Exception as e:
|
721
|
-
logger.error(e)
|
722
|
-
|
723
|
-
def getOriginals(what):
|
724
|
-
if what is DarkRefs.WHAT_REF:
|
725
|
-
try:
|
726
|
-
pattern = re.compile(self.recons_params.ref_pattern)
|
727
|
-
except Exception:
|
728
|
-
pattern = None
|
729
|
-
logger.error(
|
730
|
-
"Fail to compute regular expresion for %s"
|
731
|
-
% self.recons_params.ref_pattern
|
732
|
-
)
|
733
|
-
elif what is DarkRefs.WHAT_DARK:
|
734
|
-
re.compile(self.recons_params.dark_pattern)
|
735
|
-
try:
|
736
|
-
pattern = re.compile(self.recons_params.dark_pattern)
|
737
|
-
except Exception:
|
738
|
-
pattern = None
|
739
|
-
logger.error(
|
740
|
-
"Fail to compute regular expresion for %s"
|
741
|
-
% self.recons_params.dark_pattern
|
742
|
-
)
|
743
|
-
|
744
|
-
filelist_fullname = []
|
745
|
-
if pattern is None:
|
746
|
-
return filelist_fullname
|
747
|
-
for file in os.listdir(directory):
|
748
|
-
if pattern.match(file) and file.endswith(self._file_ext):
|
749
|
-
if (
|
750
|
-
file.startswith(self.recons_params.ref_prefix)
|
751
|
-
or file.startswith(self.recons_params.dark_prefix)
|
752
|
-
) is False:
|
753
|
-
filelist_fullname.append(os.path.join(directory, file))
|
754
|
-
return sorted(filelist_fullname)
|
755
|
-
|
756
|
-
def setup():
|
757
|
-
"""setup parameter to process the requested what
|
758
|
-
|
759
|
-
:return: True if there is a process to be run, else false
|
760
|
-
"""
|
761
|
-
|
762
|
-
def getNDigits(_file):
|
763
|
-
file_without_scanID = _file.replace(os.path.basename(directory), "", 1)
|
764
|
-
return len(re.findall(r"\d+", file_without_scanID))
|
765
|
-
|
766
|
-
def dealWithPCOTomo():
|
767
|
-
filesPerSerie = {}
|
768
|
-
if self.nfiles % self.nacq == 0:
|
769
|
-
assert self.nacq < self.nfiles
|
770
|
-
self.nseries = self.nfiles // self.nacq
|
771
|
-
self.series = self.fileNameList
|
772
|
-
else:
|
773
|
-
logger.warning("Fail to deduce series")
|
774
|
-
return None, None
|
775
|
-
|
776
|
-
linear = getNDigits(self.fileNameList[0]) < 2
|
777
|
-
if linear is False:
|
778
|
-
# which digit pattern contains the file number?
|
779
|
-
lastone = True
|
780
|
-
penulti = True
|
781
|
-
for first_files in range(self.nseries - 1):
|
782
|
-
digivec_1 = re.findall(r"\d+", self.fileNameList[first_files])
|
783
|
-
digivec_2 = re.findall(
|
784
|
-
r"\d+", self.fileNameList[first_files + 1]
|
785
|
-
)
|
786
|
-
if lastone:
|
787
|
-
lastone = (int(digivec_2[-1]) - int(digivec_1[-1])) == 0
|
788
|
-
if penulti:
|
789
|
-
penulti = (int(digivec_2[-2]) - int(digivec_1[-2])) == 0
|
790
|
-
|
791
|
-
linear = not penulti
|
792
|
-
|
793
|
-
if linear is False:
|
794
|
-
digivec_1 = re.findall(r"\d+", self.fileNameList[self.nseries - 1])
|
795
|
-
digivec_2 = re.findall(r"\d+", self.fileNameList[self.nseries])
|
796
|
-
# confirm there is 1 increment after self.nseries in the uperlast last digit patern
|
797
|
-
if (int(digivec_2[-2]) - int(digivec_1[-2])) != 1:
|
798
|
-
linear = True
|
799
|
-
|
800
|
-
# series are simple sublists in main filelist
|
801
|
-
# self.series = []
|
802
|
-
if linear is True:
|
803
|
-
is_there_digits = len(re.findall(r"\d+", self.fileNameList[0])) > 0
|
804
|
-
if is_there_digits:
|
805
|
-
serievec = set([re.findall(r"\d+", self.fileNameList[0])[-1]])
|
806
|
-
else:
|
807
|
-
serievec = set(["0000"])
|
808
|
-
for i in range(self.nseries):
|
809
|
-
if is_there_digits:
|
810
|
-
serie = re.findall(
|
811
|
-
r"\d+", self.fileNameList[i * self.nacq]
|
812
|
-
)[-1]
|
813
|
-
serievec.add(serie)
|
814
|
-
filesPerSerie[serie] = self.fileNameList[
|
815
|
-
i * self.nacq : (i + 1) * self.nacq
|
816
|
-
]
|
817
|
-
else:
|
818
|
-
serievec.add("%04d" % i)
|
819
|
-
# in the sorted filelist, the serie is incremented, then the acquisition number:
|
820
|
-
else:
|
821
|
-
self.series = self.fileNameList[0 :: self.nseries]
|
822
|
-
serievec = set([re.findall(r"\d+", self.fileNameList[0])[-1]])
|
823
|
-
for serie in serievec:
|
824
|
-
# serie = re.findall(r'\d+', self.fileNameList[i])[-1]
|
825
|
-
# serievec.add(serie)
|
826
|
-
filesPerSerie[serie] = self.fileNameList[0 :: self.nseries]
|
827
|
-
serievec = list(sorted(serievec))
|
828
|
-
|
829
|
-
if len(serievec) > 2:
|
830
|
-
logger.error(
|
831
|
-
"DarkRefs do not deal with multiple scan."
|
832
|
-
" (scan %s)" % directory
|
833
|
-
)
|
834
|
-
return None, None
|
835
|
-
assert len(serievec) <= 2
|
836
|
-
if len(serievec) > 1:
|
837
|
-
key = serievec[-1]
|
838
|
-
tomoN = self.getInfo(self.TOMO_N)
|
839
|
-
if tomoN is None:
|
840
|
-
logger.error(
|
841
|
-
"Fail to found information %s. Can't "
|
842
|
-
"rename %s" % (self.TOMO_N, key)
|
843
|
-
)
|
844
|
-
del serievec[-1]
|
845
|
-
serievec.append(str(tomoN).zfill(4))
|
846
|
-
filesPerSerie[serievec[-1]] = filesPerSerie[key]
|
847
|
-
del filesPerSerie[key]
|
848
|
-
assert len(serievec) == 2
|
849
|
-
assert len(filesPerSerie) == 2
|
850
|
-
|
851
|
-
return serievec, filesPerSerie
|
852
|
-
|
853
|
-
# start setup function
|
854
|
-
if mode == dkrf_reconsparams.Method.none:
|
855
|
-
return False
|
856
|
-
if what == "dark":
|
857
|
-
self.out_prefix = self.recons_params.dark_prefix
|
858
|
-
self.info_nacq = "DARK_N"
|
859
|
-
else:
|
860
|
-
self.out_prefix = self.recons_params.ref_prefix
|
861
|
-
self.info_nacq = "REF_N"
|
862
|
-
|
863
|
-
# init
|
864
|
-
self.nacq = 0
|
865
|
-
"""Number of acquisition runned"""
|
866
|
-
self.files = 0
|
867
|
-
"""Ref or dark files"""
|
868
|
-
self.nframes = 1
|
869
|
-
"""Number of frame per ref/dark file"""
|
870
|
-
self.serievec = ["0000"]
|
871
|
-
"""List of series discover"""
|
872
|
-
self.filesPerSerie = {}
|
873
|
-
"""Dict with key the serie id and values list of files to compute
|
874
|
-
for median or mean"""
|
875
|
-
self.infofile = ""
|
876
|
-
"""info file of the acquisition"""
|
877
|
-
|
878
|
-
# sample/prefix and info file
|
879
|
-
self.prefix = os.path.basename(directory)
|
880
|
-
extensionToTry = (DarkRefs.info_suffix, "0000" + DarkRefs.info_suffix)
|
881
|
-
for extension in extensionToTry:
|
882
|
-
infoFile = os.path.join(directory, self.prefix + extension)
|
883
|
-
if os.path.exists(infoFile):
|
884
|
-
self.infofile = infoFile
|
885
|
-
break
|
886
|
-
|
887
|
-
if self.infofile == "":
|
888
|
-
logger.debug("fail to found .info file for %s" % directory)
|
889
|
-
|
890
|
-
"""
|
891
|
-
Set filelist
|
892
|
-
"""
|
893
|
-
# do the job only if not already done and overwrite not asked
|
894
|
-
self.out_files = sorted(glob(directory + os.sep + "*." + self._file_ext))
|
895
|
-
|
896
|
-
self.filelist_fullname = getOriginals(what)
|
897
|
-
self.fileNameList = []
|
898
|
-
[
|
899
|
-
self.fileNameList.append(os.path.basename(_file))
|
900
|
-
for _file in self.filelist_fullname
|
901
|
-
]
|
902
|
-
self.fileNameList = sorted(self.fileNameList)
|
903
|
-
self.nfiles = len(self.filelist_fullname)
|
904
|
-
# if nothing to process
|
905
|
-
if self.nfiles == 0:
|
906
|
-
logger.info(
|
907
|
-
"no %s for %s, because no file to compute found" % (what, directory)
|
908
|
-
)
|
909
|
-
return False
|
910
|
-
|
911
|
-
self.fid = fabio.open(self.filelist_fullname[0])
|
912
|
-
self.nframes = self.fid.nframes
|
913
|
-
self.nacq = 0
|
914
|
-
# get the info of number of acquisitions
|
915
|
-
if self.infofile != "":
|
916
|
-
self.nacq = self.getInfo(self.info_nacq)
|
917
|
-
|
918
|
-
if self.nacq == 0:
|
919
|
-
self.nacq = self.nfiles
|
920
|
-
|
921
|
-
self.nseries = 1
|
922
|
-
if self.nacq > self.nfiles:
|
923
|
-
# get ready for accumulation and/or file multiimage?
|
924
|
-
self.nseries = self.nfiles
|
925
|
-
if self.nacq < self.nfiles and getNDigits(self.fileNameList[0]) < 2:
|
926
|
-
self.nFilePerSerie = self.nseries
|
927
|
-
self.serievec, self.filesPerSerie = dealWithPCOTomo()
|
928
|
-
else:
|
929
|
-
self.series = self.fileNameList
|
930
|
-
self.serievec = _getSeriesValue(self.fileNameList)
|
931
|
-
self.filesPerSerie, self.nFilePerSerie = groupFilesPerSerie(
|
932
|
-
self.filelist_fullname, self.serievec
|
933
|
-
)
|
934
|
-
|
935
|
-
if self.filesPerSerie is not None:
|
936
|
-
for serie in self.filesPerSerie:
|
937
|
-
for _file in self.filesPerSerie[serie]:
|
938
|
-
if what == "dark":
|
939
|
-
self._originalsDark.append(os.path.join(scan.path, _file))
|
940
|
-
elif what == "ref":
|
941
|
-
self._originalsRef.append(os.path.join(scan.path, _file))
|
942
|
-
|
943
|
-
return self.serievec is not None and self.filesPerSerie is not None
|
944
|
-
|
945
|
-
def _getSeriesValue(fileNames):
|
946
|
-
assert len(fileNames) > 0
|
947
|
-
is_there_digits = len(re.findall(r"\d+", fileNames[0])) > 0
|
948
|
-
series = set()
|
949
|
-
i = 0
|
950
|
-
for fileName in fileNames:
|
951
|
-
if is_there_digits:
|
952
|
-
name = fileName.rstrip(self._file_ext)
|
953
|
-
file_index = name.split("_")[-1]
|
954
|
-
rm_not_numeric = re.compile(r"[^\d.]+")
|
955
|
-
file_index = rm_not_numeric.sub("", file_index)
|
956
|
-
series.add(file_index)
|
957
|
-
else:
|
958
|
-
series.add("%04d" % i)
|
959
|
-
i += 1
|
960
|
-
return list(series)
|
961
|
-
|
962
|
-
def groupFilesPerSerie(files, series):
|
963
|
-
def findFileEndingWithSerie(poolFiles, serie):
|
964
|
-
res = []
|
965
|
-
for _file in poolFiles:
|
966
|
-
_f = _file.rstrip(".edf")
|
967
|
-
if _f.endswith(serie):
|
968
|
-
res.append(_file)
|
969
|
-
return res
|
970
|
-
|
971
|
-
def checkSeriesFilesLength(serieFiles):
|
972
|
-
length = -1
|
973
|
-
for serie in serieFiles:
|
974
|
-
if length == -1:
|
975
|
-
length = len(serieFiles[serie])
|
976
|
-
elif len(serieFiles[serie]) != length:
|
977
|
-
logger.error("Series with inconsistant number of ref files")
|
978
|
-
|
979
|
-
assert len(series) > 0
|
980
|
-
if len(series) == 1:
|
981
|
-
return {series[0]: files}, len(files)
|
982
|
-
assert len(files) > 0
|
983
|
-
|
984
|
-
serieFiles = {}
|
985
|
-
unattributedFiles = files.copy()
|
986
|
-
for serie in series:
|
987
|
-
serieFiles[serie] = findFileEndingWithSerie(unattributedFiles, serie)
|
988
|
-
[unattributedFiles.remove(_f) for _f in serieFiles[serie]]
|
989
|
-
|
990
|
-
if len(unattributedFiles) > 0:
|
991
|
-
logger.error("Failed to associate %s to any serie" % unattributedFiles)
|
992
|
-
return {}, 0
|
993
|
-
|
994
|
-
checkSeriesFilesLength(serieFiles)
|
995
|
-
|
996
|
-
return serieFiles, len(serieFiles[list(serieFiles.keys())[0]])
|
997
|
-
|
998
|
-
def process():
|
999
|
-
"""process calculation of the what"""
|
1000
|
-
if mode is dkrf_reconsparams.Method.none:
|
1001
|
-
return
|
1002
|
-
shape = fabio.open(self.filelist_fullname[0]).shape
|
1003
|
-
|
1004
|
-
for i in range(len(self.serievec)):
|
1005
|
-
largeMat = numpy.zeros(
|
1006
|
-
(self.nframes * self.nFilePerSerie, shape[0], shape[1])
|
1007
|
-
)
|
1008
|
-
|
1009
|
-
if what == "dark" and len(self.serievec) == 1:
|
1010
|
-
fileName = self.out_prefix
|
1011
|
-
if fileName.endswith(self._file_ext) is False:
|
1012
|
-
fileName = fileName + self._file_ext
|
1013
|
-
else:
|
1014
|
-
fileName = (
|
1015
|
-
self.out_prefix.rstrip(self._file_ext)
|
1016
|
-
+ self.serievec[i]
|
1017
|
-
+ self._file_ext
|
1018
|
-
)
|
1019
|
-
fileName = os.path.join(directory, fileName)
|
1020
|
-
if os.path.isfile(fileName):
|
1021
|
-
if (
|
1022
|
-
what == "refs" and self.recons_params.overwrite_ref is False
|
1023
|
-
) or (
|
1024
|
-
what == "dark" and self.recons_params.overwrite_dark is False
|
1025
|
-
):
|
1026
|
-
logger.info("skip creation of %s, already existing" % fileName)
|
1027
|
-
continue
|
1028
|
-
|
1029
|
-
if self.nFilePerSerie == 1:
|
1030
|
-
fSerieName = os.path.join(directory, self.series[i])
|
1031
|
-
header = {"method": mode.name + " on 1 image"}
|
1032
|
-
header["SRCUR"] = utils.getClosestSRCurrent(
|
1033
|
-
scan_dir=directory, refFile=fSerieName
|
1034
|
-
)
|
1035
|
-
if self.nframes == 1:
|
1036
|
-
largeMat[0] = fabio.open(fSerieName).data
|
1037
|
-
else:
|
1038
|
-
handler = fabio.open(fSerieName)
|
1039
|
-
dShape = (self.nframes, handler.dim2, handler.dim1)
|
1040
|
-
largeMat = numpy.zeros(dShape)
|
1041
|
-
for iFrame in range(self.nframes):
|
1042
|
-
largeMat[iFrame] = handler.getframe(iFrame).data
|
1043
|
-
else:
|
1044
|
-
header = {
|
1045
|
-
"method": mode.name + " on %d images" % self.nFilePerSerie
|
1046
|
-
}
|
1047
|
-
header["SRCUR"] = utils.getClosestSRCurrent(
|
1048
|
-
scan_dir=directory, refFile=self.series[i][0]
|
1049
|
-
)
|
1050
|
-
for j, fName in zip(
|
1051
|
-
range(self.nFilePerSerie), self.filesPerSerie[self.serievec[i]]
|
1052
|
-
):
|
1053
|
-
file_BigMat = fabio.open(fName)
|
1054
|
-
if self.nframes > 1:
|
1055
|
-
for fr in range(self.nframes):
|
1056
|
-
jfr = fr + j * self.nframes
|
1057
|
-
largeMat[jfr] = file_BigMat.getframe(fr).getData()
|
1058
|
-
else:
|
1059
|
-
largeMat[j] = file_BigMat.data
|
1060
|
-
if mode == dkrf_reconsparams.Method.median:
|
1061
|
-
data = numpy.median(largeMat, axis=0)
|
1062
|
-
elif mode == dkrf_reconsparams.Method.average:
|
1063
|
-
data = numpy.mean(largeMat, axis=0)
|
1064
|
-
elif mode == dkrf_reconsparams.Method.first:
|
1065
|
-
data = largeMat[0]
|
1066
|
-
elif mode == dkrf_reconsparams.Method.last:
|
1067
|
-
data = largeMat[-1]
|
1068
|
-
elif mode == dkrf_reconsparams.Method.none:
|
1069
|
-
return
|
1070
|
-
else:
|
1071
|
-
raise ValueError(
|
1072
|
-
"Unrecognized calculation type request {}" "".format(mode)
|
1073
|
-
)
|
1074
|
-
|
1075
|
-
self.nacq = getDARK_N(directory) or 1
|
1076
|
-
if what == "dark" and self.nacq > 1: # and self.nframes == 1:
|
1077
|
-
data = data / self.nacq
|
1078
|
-
# add one to add to avoid division by zero
|
1079
|
-
# data = data + 1
|
1080
|
-
file_desc = fabio.edfimage.EdfImage(data=data, header=header)
|
1081
|
-
i += 1
|
1082
|
-
_ttype = numpy.uint16 if what == "dark" else numpy.int32
|
1083
|
-
file_desc.write(fileName, force_type=_ttype)
|
1084
|
-
|
1085
|
-
if directory is None:
|
1086
|
-
return
|
1087
|
-
if setup():
|
1088
|
-
logger.info("start proccess darks and flat fields for %s" % scan.path)
|
1089
|
-
process()
|
1090
|
-
logger.info("end proccess darks and flat fields")
|
1091
|
-
|
1092
|
-
self._store_result(what=what, scan=scan)
|
1093
|
-
if (what == "dark" and self.recons_params.remove_dark is True) or (
|
1094
|
-
what == "refs" and self.recons_params.remove_ref is True
|
1095
|
-
):
|
1096
|
-
removeFiles()
|
1097
|
-
|
1098
|
-
def _store_result(self, what, scan):
|
1099
|
-
try:
|
1100
|
-
if what == "dark":
|
1101
|
-
dark = DarkRefs.getDarkHSTFiles(
|
1102
|
-
directory=scan.path, prefix=self.recons_params.dark_prefix
|
1103
|
-
)
|
1104
|
-
dark_1 = fabio.open(dark[0]).data
|
1105
|
-
scan.set_reduced_darks({0: dark_1})
|
1106
|
-
else:
|
1107
|
-
refs = DarkRefs.getRefHSTFiles(
|
1108
|
-
directory=scan.path, prefix=self.recons_params.ref_prefix
|
1109
|
-
)
|
1110
|
-
refs_dict = {}
|
1111
|
-
if len(refs) == 1:
|
1112
|
-
ref_1 = fabio.open(refs[0]).data
|
1113
|
-
refs_dict[0] = ref_1
|
1114
|
-
elif len(refs) >= 2:
|
1115
|
-
ref_1 = fabio.open(refs[0]).data
|
1116
|
-
refs_dict[0] = ref_1
|
1117
|
-
ref_f = fabio.open(refs[-1]).data
|
1118
|
-
refs_dict[len(scan.projections)] = ref_f
|
1119
|
-
scan.set_reduced_flats(refs_dict)
|
1120
|
-
except Exception as e:
|
1121
|
-
logger.info(e)
|
1122
|
-
|
1123
|
-
def getInfo(self, what):
|
1124
|
-
with open(self.infofile) as file:
|
1125
|
-
infod = file.readlines()
|
1126
|
-
for line in infod:
|
1127
|
-
if what in line:
|
1128
|
-
return int(line.split("=")[1])
|
1129
|
-
# not found:
|
1130
|
-
return 0
|
1131
|
-
|
1132
|
-
def getDarkFiles(self, directory):
|
1133
|
-
"""
|
1134
|
-
|
1135
|
-
:return: the list of existing darks files in the directory according to
|
1136
|
-
the file pattern.
|
1137
|
-
"""
|
1138
|
-
patternDark = re.compile(self.recons_params.dark_pattern)
|
1139
|
-
|
1140
|
-
res = []
|
1141
|
-
for file in os.listdir(directory):
|
1142
|
-
if patternDark.match(file) is not None and file.endswith(self._file_ext):
|
1143
|
-
res.append(os.path.join(directory, file))
|
1144
|
-
return res
|
1145
|
-
|
1146
|
-
def getRefFiles(self, directory):
|
1147
|
-
"""
|
1148
|
-
|
1149
|
-
:return: the list of existing refs files in the directory according to
|
1150
|
-
the file pattern.
|
1151
|
-
"""
|
1152
|
-
patternRef = re.compile(self.recons_params.ref_pattern)
|
1153
|
-
|
1154
|
-
res = []
|
1155
|
-
for file in os.listdir(directory):
|
1156
|
-
if patternRef.match(file) and file.endswith(self._file_ext):
|
1157
|
-
res.append(os.path.join(directory, file))
|
1158
|
-
return res
|
541
|
+
raise RuntimeError(f"{target} not handled")
|
1159
542
|
|
1160
543
|
@docstring(Task.program_name)
|
1161
544
|
@staticmethod
|
@@ -1190,8 +573,8 @@ def requires_reduced_dark_and_flat(scan: TomwerScanBase, logger_=None) -> tuple:
|
|
1190
573
|
recons_params = dkrf_reconsparams.DKRFRP()
|
1191
574
|
recons_params.overwrite_dark = False
|
1192
575
|
recons_params.overwrite_flat = False
|
1193
|
-
recons_params.dark_calc_method = dkrf_reconsparams.
|
1194
|
-
recons_params.flat_calc_method = dkrf_reconsparams.
|
576
|
+
recons_params.dark_calc_method = dkrf_reconsparams.ReduceMethod.NONE
|
577
|
+
recons_params.flat_calc_method = dkrf_reconsparams.ReduceMethod.FIRST
|
1195
578
|
|
1196
579
|
drp = DarkRefs(
|
1197
580
|
inputs={
|
@@ -1211,8 +594,8 @@ def requires_reduced_dark_and_flat(scan: TomwerScanBase, logger_=None) -> tuple:
|
|
1211
594
|
recons_params = dkrf_reconsparams.DKRFRP()
|
1212
595
|
recons_params.overwrite_dark = False
|
1213
596
|
recons_params.overwrite_flat = False
|
1214
|
-
recons_params.dark_calc_method = dkrf_reconsparams.
|
1215
|
-
recons_params.flat_calc_method = dkrf_reconsparams.
|
597
|
+
recons_params.dark_calc_method = dkrf_reconsparams.ReduceMethod.FIRST
|
598
|
+
recons_params.flat_calc_method = dkrf_reconsparams.ReduceMethod.NONE
|
1216
599
|
|
1217
600
|
drp = DarkRefs(
|
1218
601
|
inputs={
|