NXFlatField fails on NX file with no projections
Reported by @bcordonn
Yet another failure case for NXFlatField
: a dataset with no projections (i.e image_key
do not contain any 0
).
import os
import sys
from silx.io.url import DataUrl
from tomoscan.io import HDF5File
from nabu.resources.nxflatfield import NXFlatField
from nabu.resources.dataset_analyzer import HDF5DatasetAnalyzer
file_path = '/data/visitor/es925/id19/REC/FS87_load_FS87_TOMO_POSTLOAD/FS87_load_FS87_TOMO_POSTLOAD_REF/FS87_load_FS87_TOMO_POSTLOAD_REF.nx'
with HDF5File(file_path, 'r') as fid:
keyroot = [key for key in fid.keys()]
entry = keyroot[0]
data_url = DataUrl(file_path=file_path, data_path=entry + "/instrument/detector/data")
output_file = DataUrl(
file_path='/tmp_14_days/paleo/FS87_load_FS87_TOMO_POSTLOAD_REF_REF.h5',
data_path=entry + "/flat_field_images"
)
with HDF5File(data_url.file_path(), 'a') as fid:
image_keys = fid[entry + "/instrument/detector/image_key"][()]
image_keys[image_keys==0]=1
del fid[entry + '/instrument/detector/image_key']
fid[entry + '/instrument/detector/image_key'] = image_keys
dataset_analyzer = HDF5DatasetAnalyzer(location=data_url.file_path(), extra_options={"hdf5_entry": entry})
nxf = NXFlatField( dataset_analyzer, image_keys, results_url=output_file, darks_reduction="mean", flats_reduction="median")
nxf.get_final_urls()
result:
Traceback (most recent call last):
File "tempref_test.py", line 32, in <module>
nxf = NXFlatField( dataset_analyzer, image_keys, results_url=output_file, darks_reduction="mean", flats_reduction="median")
File "/home/esrf/paleo/.venv/py37/lib/python3.7/site-packages/nabu/resources/nxflatfield.py", line 107, in __init__
self.data_url = dataset_info.dataset_hdf5_url
File "/home/esrf/paleo/.venv/py37/lib/python3.7/site-packages/nabu/resources/dataset_analyzer.py", line 268, in dataset_hdf5_url
return self._get_dataset_hdf5_url()
File "/home/esrf/paleo/.venv/py37/lib/python3.7/site-packages/nabu/resources/dataset_analyzer.py", line 257, in _get_dataset_hdf5_url
first_proj_idx = sorted(self.projections.keys())[0]
IndexError: list index out of range
Edited by Pierre Paleo