Commit f9aa8251 authored by payno's avatar payno
Browse files

[edfscan] fix get_refs_urls when contains ref* and refHST*

- insure that no keys are overwrite when returns the refs_urls
- close partially the nxtomomill issue nxtomomill#1
parent 2ad1e25c
Pipeline #21501 failed with stages
in 2 minutes and 38 seconds
......@@ -469,6 +469,16 @@ class EDFTomoScan(TomoScanBase):
_logger.error(scan_path + ' is not a directory. Cannot extract '
'RefHST files')
return res
def get_next_free_index(key, keys):
"""return next free key from keys by converting it to a string
with `key_value (n)` after it
"""
new_key = key
index = 2
while new_key in keys:
new_key = '%s (%s)' % (key, index)
index += 1
return new_key
for file_ in os.listdir(scan_path):
if file_.startswith(prefix) and file_.endswith(file_ext):
......@@ -476,7 +486,12 @@ class EDFTomoScan(TomoScanBase):
basename=os.path.basename(scan_path))
file_fp = os.path.join(scan_path, file_)
urls = extract_urls_from_edf(start_index=index, file_=file_fp)
res.update(urls)
for key in urls:
if key in res:
key_ = get_next_free_index(key, res.keys())
else:
key_ = key
res[key_] = urls[key]
return res
@staticmethod
......
......@@ -159,13 +159,21 @@ class TestOriDarksFlats(unittest.TestCase):
self.det_height = 10
self.folder = tempfile.mkdtemp()
# create 2 series of ref with 20 frames each
# create 2 series of ref with 20 frames each and 2 refHST file
for ref_index in ('0000', '1500'):
# ref files
for ref_sub_index in range(20):
file_desc = fabio.edfimage.EdfImage(data=numpy.random.random((self.det_height,self.det_width)))
file_name = '_'.join(('ref', str(ref_sub_index).zfill(4), str(ref_index).zfill(4) + '.edf'))
file_name = os.path.join(self.folder, file_name)
file_desc.write(file_name)
# simulate two refHST generated by tomwer
file_desc = fabio.edfimage.EdfImage(
data=numpy.random.random((self.det_height, self.det_width)))
file_name = 'refHST' + str(ref_index).zfill(4) + '.edf'
file_name = os.path.join(self.folder, file_name)
file_desc.write(file_name)
# create one dark with 10 frames
file_desc = fabio.edfimage.EdfImage(
data=numpy.random.random((self.det_height, self.det_width)))
......@@ -206,12 +214,14 @@ class TestOriDarksFlats(unittest.TestCase):
def testFlatsOri(self):
ref_urls = (self.scan.get_refs_url(prefix='ref', scan_path=self.scan.path))
self.assertEqual(len(ref_urls), 40)
self.assertEqual(len(ref_urls), 42)
# checks some random files
file_paths = [url.file_path() for url in ref_urls.values()]
for ref_file in ('ref_0000_1500.edf', 'ref_0004_0000.edf', 'ref_0019_1500.edf'):
ref_full_path = os.path.join(self.scan.path, ref_file)
self.assertTrue(ref_full_path in file_paths)
ref_urls = (self.scan.get_refs_url(prefix='refHST', scan_path=self.scan.path))
self.assertEqual(len(ref_urls), 2)
def testDarksOri(self):
darks = self.scan.get_darks_url(prefix='darkend',
......
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