本文整理汇总了Python中hyperspy.misc.utils.DictionaryTreeBrowser.set_item方法的典型用法代码示例。如果您正苦于以下问题:Python DictionaryTreeBrowser.set_item方法的具体用法?Python DictionaryTreeBrowser.set_item怎么用?Python DictionaryTreeBrowser.set_item使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy.misc.utils.DictionaryTreeBrowser
的用法示例。
在下文中一共展示了DictionaryTreeBrowser.set_item方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import set_item [as 别名]
def setUp(self):
self.shape = (5, 7)
self.s = LocalStrategy('test diffusion strategy')
self.samf = create_artificial_samfire(self.shape)
m = DictionaryTreeBrowser()
m.set_item('chisq.data', np.ones(self.shape) * 5.)
self.samf.model = m
示例2: setUp
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import set_item [as 别名]
def setUp(self):
self.shape = (7, 15)
art_model = DictionaryTreeBrowser()
art_model.set_item("red_chisq.data", np.ones(self.shape))
art_model.red_chisq.data[3, 5] = 0.8
art_model.red_chisq.data[2, 5] = 2.0
self.m = art_model
# have to be imported here, as otherwise crashes nosetools
from hyperspy.samfire_utils.goodness_of_fit_tests.red_chisq import red_chisq_test as rct
self.t = rct(0.9)
示例3: _get_example
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import set_item [as 别名]
def _get_example(date, time, time_zone=None):
md = DictionaryTreeBrowser({'General': {'date': date,
'time': time}})
if time_zone:
md.set_item('General.time_zone', time_zone)
dt = parser.parse('%sT%s' % (date, time))
dt = dt.replace(tzinfo=tz.gettz(time_zone))
iso = dt.isoformat()
else:
iso = '%sT%s' % (date, time)
dt = parser.parse(iso)
return md, dt, iso
示例4: file_reader
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import set_item [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, ]
示例5: parse_msa_string
# 需要导入模块: from hyperspy.misc.utils import DictionaryTreeBrowser [as 别名]
# 或者: from hyperspy.misc.utils.DictionaryTreeBrowser import set_item [as 别名]
def parse_msa_string(string, filename=None):
"""Parse an EMSA/MSA file content.
Parameters
----------
string: string or file object
It must complain with the EMSA/MSA standard.
filename: string or None
The filename.
Returns:
--------
file_data_list: list
The list containts a dictionary that contains the parsed
information. It can be used to create a `:class:Signal`
using `:func:hyperspy.io.dict2signal`.
"""
if not hasattr(string, "readlines"):
string = string.splitlines()
parameters = {}
mapped = DictionaryTreeBrowser({})
y = []
# Read the keywords
data_section = False
for line in string:
if data_section is False:
if line[0] == "#":
try:
key, value = line.split(': ')
value = value.strip()
except ValueError:
key = line
value = None
key = key.strip('#').strip()
if key != 'SPECTRUM':
parameters[key] = value
else:
data_section = True
else:
# Read the data
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))
#.........这里部分代码省略.........