本文整理汇总了Python中hyperspy.misc.utils.DictionaryTreeBrowser.as_dictionary方法的典型用法代码示例。如果您正苦于以下问题:Python DictionaryTreeBrowser.as_dictionary方法的具体用法?Python DictionaryTreeBrowser.as_dictionary怎么用?Python DictionaryTreeBrowser.as_dictionary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy.misc.utils.DictionaryTreeBrowser
的用法示例。
在下文中一共展示了DictionaryTreeBrowser.as_dictionary方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emi_reader
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import as_dictionary [as 别名]
def emi_reader(filename, dump_xml=False, **kwds):
# TODO: recover the tags from the emi file. It is easy: just look for
# <ObjectInfo> and </ObjectInfo>. It is standard xml :)
# xml chunks are identified using UUID, if we can find how these UUID are
# generated then, it will possible to match to the corresponding ser file
# and add the detector information in the metadata
objects = get_xml_info_from_emi(filename)
filename = os.path.splitext(filename)[0]
if dump_xml is True:
for i, obj in enumerate(objects):
with open(filename + '-object-%s.xml' % i, 'w') as f:
f.write(obj)
ser_files = sorted(glob(filename + '_[0-9].ser'))
sers = []
for f in ser_files:
_logger.info("Opening %s", f)
try:
sers.append(ser_reader(f, objects))
except IOError: # Probably a single spectrum that we don't support
continue
index = int(os.path.splitext(f)[0].split("_")[-1]) - 1
op = DictionaryTreeBrowser(sers[-1]['original_metadata'])
emixml2dtb(ET.fromstring(objects[index]), op)
sers[-1]['original_metadata'] = op.as_dictionary()
return sers
示例2: emi_reader
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import as_dictionary [as 别名]
def emi_reader(filename, dump_xml=False, verbose=False, **kwds):
# TODO: recover the tags from the emi file. It is easy: just look for
# <ObjectInfo> and </ObjectInfo>. It is standard xml :)
objects = get_xml_info_from_emi(filename)
filename = os.path.splitext(filename)[0]
if dump_xml is True:
for i, obj in enumerate(objects):
with open(filename + '-object-%s.xml' % i, 'w') as f:
f.write(obj)
ser_files = glob(filename + '_[0-9].ser')
sers = []
for f in ser_files:
if verbose is True:
print "Opening ", f
try:
sers.append(ser_reader(f, objects))
except IOError: # Probably a single spectrum that we don't support
continue
index = int(os.path.splitext(f)[0].split("_")[-1]) - 1
op = DictionaryTreeBrowser(sers[-1]['original_metadata'])
emixml2dtb(ET.fromstring(objects[index]), op)
sers[-1]['original_metadata'] = op.as_dictionary()
return sers
示例3: file_reader
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import as_dictionary [as 别名]
#.........这里部分代码省略.........
if 'depth-scale' in rpl_info:
scales[idepth] = rpl_info['depth-scale']
# ev-per-chan is the only calibration supported by the original ripple
# format
elif 'ev-per-chan' in rpl_info:
scales[idepth] = rpl_info['ev-per-chan']
if 'depth-origin' in rpl_info:
origins[idepth] = rpl_info['depth-origin']
if 'depth-units' in rpl_info:
units[idepth] = rpl_info['depth-units']
if 'depth-name' in rpl_info:
names[idepth] = rpl_info['depth-name']
if 'width-origin' in rpl_info:
origins[iwidth] = rpl_info['width-origin']
if 'width-scale' in rpl_info:
scales[iwidth] = rpl_info['width-scale']
if 'width-units' in rpl_info:
units[iwidth] = rpl_info['width-units']
if 'width-name' in rpl_info:
names[iwidth] = rpl_info['width-name']
if 'height-origin' in rpl_info:
origins[iheight] = rpl_info['height-origin']
if 'height-scale' in rpl_info:
scales[iheight] = rpl_info['height-scale']
if 'height-units' in rpl_info:
units[iheight] = rpl_info['height-units']
if 'height-name' in rpl_info:
names[iheight] = rpl_info['height-name']
mp = DictionaryTreeBrowser({
'General': {'original_filename': os.path.split(filename)[1],
'date': rpl_info['date'],
'time': rpl_info['time']},
"Signal": {'signal_type': rpl_info['signal'],
'record_by': record_by},
})
if 'convergence-angle' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.convergence_angle',
rpl_info['convergence-angle'])
if 'tilt-stage' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.tilt_stage',
rpl_info['tilt-stage'])
if 'collection-angle' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.Detector.EELS.' +
'collection_angle',
rpl_info['collection-angle'])
if 'beam-energy' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.beam_energy',
rpl_info['beam-energy'])
if 'elevation-angle' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.Detector.EDS.elevation_angle',
rpl_info['elevation-angle'])
if 'azimuth-angle' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.Detector.EDS.azimuth_angle',
rpl_info['azimuth-angle'])
if 'energy-resolution' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.Detector.EDS.' +
'energy_resolution_MnKa',
rpl_info['energy-resolution'])
if 'detector-peak-width-ev' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.Detector.EDS.' +
'energy_resolution_MnKa',
rpl_info['detector-peak-width-ev'])
if 'live-time' in rpl_info:
mp.set_item('Acquisition_instrument.TEM.Detector.EDS.live_time',
rpl_info['live-time'])
axes = []
index_in_array = 0
for i in range(3):
if sizes[i] > 1:
axes.append({
'size': sizes[i],
'index_in_array': index_in_array,
'name': names[i],
'scale': scales[i],
'offset': origins[i],
'units': units[i],
})
index_in_array += 1
dictionary = {
'data': data.squeeze(),
'axes': axes,
'metadata': mp.as_dictionary(),
'original_metadata': rpl_info
}
return [dictionary, ]
示例4: parse_msa_string
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import as_dictionary [as 别名]
#.........这里部分代码省略.........
if line[0] != "#" and line.strip():
if parameters['DATATYPE'] == 'XY':
xy = line.replace(',', ' ').strip().split()
y.append(float(xy[1]))
elif parameters['DATATYPE'] == 'Y':
data = [
float(i) for i in line.replace(',', ' ').strip().split()]
y.extend(data)
# We rewrite the format value to be sure that it complies with the
# standard, because it will be used by the writer routine
parameters['FORMAT'] = "EMSA/MAS Spectral Data File"
# Convert the parameters to the right type and map some
# TODO: the msa format seems to support specifying the units of some
# parametes. We should add this feature here
for parameter, value in parameters.items():
# Some parameters names can contain the units information
# e.g. #AZIMANGLE-dg: 90.
if '-' in parameter:
clean_par, units = parameter.split('-')
clean_par, units = clean_par.strip(), units.strip()
else:
clean_par, units = parameter, None
if clean_par in keywords:
try:
parameters[parameter] = keywords[clean_par]['dtype'](value)
except:
# Normally the offending mispelling is a space in the scientic
# notation, e.g. 2.0 E-06, so we try to correct for it
try:
parameters[parameter] = keywords[clean_par]['dtype'](
value.replace(' ', ''))
except:
_logger.exception(
"The %s keyword value, %s could not be converted to "
"the right type", parameter, value)
if keywords[clean_par]['mapped_to'] is not None:
mapped.set_item(keywords[clean_par]['mapped_to'],
parameters[parameter])
if units is not None:
mapped.set_item(keywords[clean_par]['mapped_to'] +
'_units', units)
# The data parameter needs some extra care
# It is necessary to change the locale to US english to read the date
# keyword
loc = locale.getlocale(locale.LC_TIME)
# Setting locale can raise an exception because
# their name depends on library versions, platform etc.
try:
if os_name == 'posix':
locale.setlocale(locale.LC_TIME, ('en_US', 'utf8'))
elif os_name == 'windows':
locale.setlocale(locale.LC_TIME, 'english')
try:
H, M = time.strptime(parameters['TIME'], "%H:%M")[3:5]
mapped.set_item('General.time', datetime.time(H, M))
except:
if 'TIME' in parameters and parameters['TIME']:
_logger.warn('The time information could not be retrieved')
try:
Y, M, D = time.strptime(parameters['DATE'], "%d-%b-%Y")[0:3]
mapped.set_item('General.date', datetime.date(Y, M, D))
except:
if 'DATE' in parameters and parameters['DATE']:
_logger.warn('The date information could not be retrieved')
except:
warnings.warn("I couldn't write the date information due to"
"an unexpected error. Please report this error to "
"the developers")
locale.setlocale(locale.LC_TIME, loc) # restore saved locale
axes = [{
'size': len(y),
'index_in_array': 0,
'name': parameters['XLABEL'] if 'XLABEL' in parameters else '',
'scale': parameters['XPERCHAN'] if 'XPERCHAN' in parameters else 1,
'offset': parameters['OFFSET'] if 'OFFSET' in parameters else 0,
'units': parameters['XUNITS'] if 'XUNITS' in parameters else '',
}]
if filename is not None:
mapped.set_item('General.original_filename',
os.path.split(filename)[1])
mapped.set_item('Signal.record_by', 'spectrum')
if mapped.has_item('Signal.signal_type'):
if mapped.Signal.signal_type == 'ELS':
mapped.Signal.signal_type = 'EELS'
else:
# Defaulting to EELS looks reasonable
mapped.set_item('Signal.signal_type', 'EELS')
dictionary = {
'data': np.array(y),
'axes': axes,
'metadata': mapped.as_dictionary(),
'original_metadata': parameters
}
file_data_list = [dictionary, ]
return file_data_list