Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
containers = [c + '.quantities' for c in self.props
if pydash.get(material, c)] + ['inputs']
for container in containers:
for q in pydash.get(material, container) or []:
this_q = q.copy()
this_q['material_key'] = material['task_id']
prov_inputs = pydash.get(this_q, 'provenance.inputs')
if prov_inputs:
new_prov_inputs = [qq['internal_id'] for qq in prov_inputs]
else:
new_prov_inputs = None
pydash.set_(this_q, 'provenance.inputs', new_prov_inputs)
quantities.append(this_q)
pydash.set_(material, container,
[q['internal_id']
for q in pydash.get(material, container) or []])
if container != 'inputs':
prop = container.split(".")[0]
units = Registry("units").get(prop)
if units != pydash.get(material, [prop, 'units']):
pq_mean = ureg.Quantity(material[prop]['mean'],
material[prop]['units']).to(units)
pq_std = ureg.Quantity(material[prop]['std'],
material[prop]['units']).to(units)
material[prop]['mean'] = pq_mean.magnitude
material[prop]['std'] = pq_std.magnitude
material[prop]['units'] = pq_mean.units.format_babel()
for q in quantities:
def inject_config(spec, config):
'''Inject flattened config into SLM Lab spec.'''
spec = deepcopy(spec)
spec.pop('search', None)
for k, v in config.items():
ps.set_(spec, k, v)
return spec
trace = {
'x': x,
'y': y,
'text': mpids,
'mode': 'markers',
'marker': {'size': 5},
}
if enable_color:
c = data['color']
color_prop = data['color_name']
color_title = "{} / {}".format(scalar_symbols[color_prop].display_names[0],
scalar_symbols[color_prop].unit_as_string)
if not color_range:
color_range = get_color_range(c, zoom)
set_(trace, 'marker.color', c)
set_(trace, 'marker.colorscale', 'Viridis')
set_(trace, 'marker.showscale', True)
set_(trace, 'marker.colorbar', {'title': color_title})
set_(trace, 'marker.cmin', color_range[0])
set_(trace, 'marker.cmax', color_range[1])
x_title = "{} / {}".format(scalar_symbols[x_prop].display_names[0],
scalar_symbols[x_prop].unit_as_string)
y_title = "{} / {}".format(scalar_symbols[y_prop].display_names[0],
scalar_symbols[y_prop].unit_as_string)
axes_layout = {
'xaxis': {'title': x_title, 'showgrid': True, 'showline': True,
'zeroline': False},
'yaxis': {'title': y_title, 'showgrid': True, 'showline': True,
scalar_symbols[x_prop].unit_as_string)
y_title = "{} / {}".format(scalar_symbols[y_prop].display_names[0],
scalar_symbols[y_prop].unit_as_string)
axes_layout = {
'xaxis': {'title': x_title, 'showgrid': True, 'showline': True,
'zeroline': False},
'yaxis': {'title': y_title, 'showgrid': True, 'showline': True,
'zeroline': False}
}
if zoom:
set_(axes_layout, 'xaxis.range', [np.percentile(x, 10),
np.percentile(x, 90)])
set_(axes_layout, 'yaxis.range', [np.percentile(y, 10),
np.percentile(y, 90)])
layout = {
'hovermode': 'closest',
'margin': {'t': 20}
}
if enable_z:
z_prop = data['z_name']
z = data['z']
trace['z'] = z
z_title = "{} / {}".format(scalar_symbols[z_prop].display_names[0],
scalar_symbols[z_prop].unit_as_string)
set_(axes_layout, 'zaxis', {'title': z_title, 'showgrid': True, 'showline': True,
'zeroline': False})
set_(axes_layout, 'yaxis.range', [np.percentile(y, 10),
np.percentile(y, 90)])
layout = {
'hovermode': 'closest',
'margin': {'t': 20}
}
if enable_z:
z_prop = data['z_name']
z = data['z']
trace['z'] = z
z_title = "{} / {}".format(scalar_symbols[z_prop].display_names[0],
scalar_symbols[z_prop].unit_as_string)
set_(axes_layout, 'zaxis', {'title': z_title, 'showgrid': True, 'showline': True,
'zeroline': False})
if zoom:
set_(axes_layout, 'zaxis.range', [np.percentile(z, 10),
np.percentile(z, 90)])
scatter = go.Scatter3d(**trace)
layout['scene'] = axes_layout
else:
scatter = go.Scattergl(**trace)
layout.update(axes_layout)
return {'data': [scatter], 'layout': go.Layout(**layout)}
'mode': 'markers',
'marker': {'size': 5},
}
if enable_color:
c = data['color']
color_prop = data['color_name']
color_title = "{} / {}".format(scalar_symbols[color_prop].display_names[0],
scalar_symbols[color_prop].unit_as_string)
if not color_range:
color_range = get_color_range(c, zoom)
set_(trace, 'marker.color', c)
set_(trace, 'marker.colorscale', 'Viridis')
set_(trace, 'marker.showscale', True)
set_(trace, 'marker.colorbar', {'title': color_title})
set_(trace, 'marker.cmin', color_range[0])
set_(trace, 'marker.cmax', color_range[1])
x_title = "{} / {}".format(scalar_symbols[x_prop].display_names[0],
scalar_symbols[x_prop].unit_as_string)
y_title = "{} / {}".format(scalar_symbols[y_prop].display_names[0],
scalar_symbols[y_prop].unit_as_string)
axes_layout = {
'xaxis': {'title': x_title, 'showgrid': True, 'showline': True,
'zeroline': False},
'yaxis': {'title': y_title, 'showgrid': True, 'showline': True,
'zeroline': False}
}
if zoom:
'x': x,
'y': y,
'text': mpids,
'mode': 'markers',
'marker': {'size': 5},
}
if enable_color:
c = data['color']
color_prop = data['color_name']
color_title = "{} / {}".format(scalar_symbols[color_prop].display_names[0],
scalar_symbols[color_prop].unit_as_string)
if not color_range:
color_range = get_color_range(c, zoom)
set_(trace, 'marker.color', c)
set_(trace, 'marker.colorscale', 'Viridis')
set_(trace, 'marker.showscale', True)
set_(trace, 'marker.colorbar', {'title': color_title})
set_(trace, 'marker.cmin', color_range[0])
set_(trace, 'marker.cmax', color_range[1])
x_title = "{} / {}".format(scalar_symbols[x_prop].display_names[0],
scalar_symbols[x_prop].unit_as_string)
y_title = "{} / {}".format(scalar_symbols[y_prop].display_names[0],
scalar_symbols[y_prop].unit_as_string)
axes_layout = {
'xaxis': {'title': x_title, 'showgrid': True, 'showline': True,
'zeroline': False},
'yaxis': {'title': y_title, 'showgrid': True, 'showline': True,
'zeroline': False}
def inject_config(spec, config):
'''Inject flattened config into SLM Lab spec.'''
spec = deepcopy(spec)
spec.pop('search', None)
for k, v in config.items():
ps.set_(spec, k, v)
return spec