本文整理汇总了Python中hyperspy.misc.utils.DictionaryTreeBrowser.has_item方法的典型用法代码示例。如果您正苦于以下问题:Python DictionaryTreeBrowser.has_item方法的具体用法?Python DictionaryTreeBrowser.has_item怎么用?Python DictionaryTreeBrowser.has_item使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy.misc.utils.DictionaryTreeBrowser
的用法示例。
在下文中一共展示了DictionaryTreeBrowser.has_item方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_msa_string
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import has_item [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