Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
d = {key: {k: astype(v[0]) if len(v) == 1 else astype(v)
for k, v in dd.items()}}
if t.attrib:
d[key].update((at + k, astype(v)) for k, v in t.attrib.items())
if t.text:
text = t.text.strip()
if children or t.attrib:
if text:
d[key][tx + 'value'] = astype(text)
else:
d[key] = astype(text)
return d
return etree2dict(etree.fromstring(xml))
tifff.xml2dict = xml2dict
def astype(value):
if isinstance(value, six.string_types) and (value[0].isdigit() or value[-1].isdigit()):
if value.isdigit():
return int(value)
else:
try:
return float(value)
except:
try:
return tifff.asbool(value)
except:
return value
else:
try:
flatThetaDataset[flatImageCounter] = rotmax
flatImageName = samplename + str(flatImageCounter +offset +1).zfill(4) + "." + "tif"
flatImageFullPath = tifdir + "/" + flatImageName
with tifffile(flatImageFullPath) as tif:
imageAs2DArray = tif.asarray() # image is a np.ndarray
flatImagesDataset[flatImageCounter, :, :] = imageAs2DArray
rawImagesDataset = exchangeGrp.create_dataset('data', (nprj*grid_steps, height, width), 'uint16')
dataThetaDataset = exchangeGrp.create_dataset('theta_data', (nprj*grid_steps,), 'float') # Create dataset
for rawDataImageCounter in range(0, nprj*grid_steps):
#print rawDataImageCounter//grid_steps
dataThetaDataset[rawDataImageCounter] = rotmin+(rawDataImageCounter//grid_steps)*angularStep
print "Projection " + str(rawDataImageCounter)
rawDataImageName = samplename + str(rawDataImageCounter +ndrk +nflt*grid_steps +1).zfill(4) + "." + "tif"
rawDataImageFullPath = tifdir + "/" + rawDataImageName
with tifffile(rawDataImageFullPath) as tif:
imageAs2DArray = tif.asarray() # image is a np.ndarray
rawImagesDataset[rawDataImageCounter, :, :] = imageAs2DArray
imageFile.close() # Close file
endtime = time.clock()
print "time to write", str(endtime - starttime), "sec"
print "speed", 2*(20+400+1441)*2048*2048/((endtime - starttime)*1000000000), "Gigabyte/s"
grid_periods = int(linelist[3])
interferometerGrp.create_dataset('number_of_grid_periods', data = int(linelist[3]))
FILE.close()
imageAs2DArray = np.zeros((height,width), dtype=np.uint16)
starttime = time.clock()
darkImagesDataset = exchangeGrp.create_dataset('data_dark', (ndrk, height, width), 'uint16') # Create dataset
darkThetaDataset = exchangeGrp.create_dataset('theta_dark', (ndrk,), 'float') # Create dataset
for darkImageCounter in range(0, ndrk):
print "Dark " + str(darkImageCounter)
darkThetaDataset[darkImageCounter] = rotmin
darkImageName = samplename + str(darkImageCounter +1).zfill(4) + "." + "tif"
darkImageFullPath = tifdir + "/" + darkImageName
with tifffile(darkImageFullPath) as tif:
imageAs2DArray = tif.asarray() # image is a np.ndarray
darkImagesDataset[darkImageCounter, :, :] = imageAs2DArray # Fill dataset
flatImagesDataset = exchangeGrp.create_dataset('data_white', (2*nflt*grid_steps, height, width), 'uint16')
flatThetaDataset = exchangeGrp.create_dataset('theta_flat', (2*nflt*grid_steps,), 'float') # Create dataset
for flatImageCounter in range(0, 2*nflt*grid_steps):
print "Flat " + str(flatImageCounter)
if flatImageCounter < nflt*grid_steps:
offset = ndrk
flatThetaDataset[flatImageCounter] = rotmin
else:
offset = ndrk+nprj*grid_steps
flatThetaDataset[flatImageCounter] = rotmax
flatImageName = samplename + str(flatImageCounter +offset +1).zfill(4) + "." + "tif"
flatImageFullPath = tifdir + "/" + flatImageName
with tifffile(flatImageFullPath) as tif:
imageAs2DArray = tif.asarray() # image is a np.ndarray
darkImagesDataset[darkImageCounter, :, :] = imageAs2DArray # Fill dataset
flatImagesDataset = exchangeGrp.create_dataset('data_white', (2*nflt*grid_steps, height, width), 'uint16')
flatThetaDataset = exchangeGrp.create_dataset('theta_flat', (2*nflt*grid_steps,), 'float') # Create dataset
for flatImageCounter in range(0, 2*nflt*grid_steps):
print "Flat " + str(flatImageCounter)
if flatImageCounter < nflt*grid_steps:
offset = ndrk
flatThetaDataset[flatImageCounter] = rotmin
else:
offset = ndrk+nprj*grid_steps
flatThetaDataset[flatImageCounter] = rotmax
flatImageName = samplename + str(flatImageCounter +offset +1).zfill(4) + "." + "tif"
flatImageFullPath = tifdir + "/" + flatImageName
with tifffile(flatImageFullPath) as tif:
imageAs2DArray = tif.asarray() # image is a np.ndarray
flatImagesDataset[flatImageCounter, :, :] = imageAs2DArray
rawImagesDataset = exchangeGrp.create_dataset('data', (nprj*grid_steps, height, width), 'uint16')
dataThetaDataset = exchangeGrp.create_dataset('theta_data', (nprj*grid_steps,), 'float') # Create dataset
for rawDataImageCounter in range(0, nprj*grid_steps):
#print rawDataImageCounter//grid_steps
dataThetaDataset[rawDataImageCounter] = rotmin+(rawDataImageCounter//grid_steps)*angularStep
print "Projection " + str(rawDataImageCounter)
rawDataImageName = samplename + str(rawDataImageCounter +ndrk +nflt*grid_steps +1).zfill(4) + "." + "tif"
rawDataImageFullPath = tifdir + "/" + rawDataImageName
with tifffile(rawDataImageFullPath) as tif:
imageAs2DArray = tif.asarray() # image is a np.ndarray
rawImagesDataset[rawDataImageCounter, :, :] = imageAs2DArray
imageFile.close() # Close file