def get_concentration_functions(composition_table_dict): meta = composition_table_dict["meta"] composition_table = Table.from_dict(composition_table_dict["data"]) elements = [col for col in composition_table.columns if col not in meta] x = composition_table["X"].values y = composition_table["Y"].values cats = composition_table["X"].unique() concentration, conc, d, y_c, functions = {}, {}, {}, {}, RecursiveDict() for el in elements: concentration[el] = to_numeric(composition_table[el].values) / 100.0 conc[el], d[el], y_c[el] = {}, {}, {} if meta["X"] == "category": for i in cats: k = "{:06.2f}".format(float(i)) y_c[el][k] = to_numeric(y[where(x == i)]) conc[el][k] = to_numeric(concentration[el][where(x == i)]) d[el][k] = interp1d(y_c[el][k], conc[el][k]) functions[el] = lambda a, b, el=el: d[el][a](b) else: functions[el] = interp2d(float(x), float(y), concentration[el]) return functions
def get_concentration_functions(composition_table_dict): meta = composition_table_dict['meta'] composition_table = Table.from_dict(composition_table_dict['data']) elements = [col for col in composition_table.columns if col not in meta] x = composition_table["X"].values y = composition_table["Y"].values cats = composition_table["X"].unique() concentration, conc, d, y_c, functions = {}, {}, {}, {}, RecursiveDict() for el in elements: concentration[el] = to_numeric(composition_table[el].values)/100. conc[el], d[el], y_c[el] = {}, {}, {} if meta['X'] == 'category': for i in cats: k = '{:06.2f}'.format(float(i)) y_c[el][k] = to_numeric(y[where(x==i)]) conc[el][k] = to_numeric(concentration[el][where(x==i)]) d[el][k] = interp1d(y_c[el][k], conc[el][k]) functions[el] = lambda a, b, el=el: d[el][a](b) else: functions[el] = interp2d(float(x), float(y), concentration[el]) return functions
def iterate(self, nested_dict=None): """http://stackoverflow.com/questions/10756427/loop-through-all-nested-dictionary-values""" from mpcontribs.io.core.components import Table from pymatgen import Structure d = self if nested_dict is None else nested_dict if nested_dict is None: self.level = 0 for key in list(d.keys()): value = d[key] if isinstance(value, _Mapping): if value.get('@class') == 'Structure': yield key, Structure.from_dict(value) continue yield (self.level, key), None if value.get('@class') == 'Table': yield key, Table.from_dict(value) continue self.level += 1 for inner_key, inner_value in self.iterate(nested_dict=value): yield inner_key, inner_value self.level -= 1 elif isinstance(value, list) and isinstance(value[0], dict): # index (from archieml parser) table = '' for row_dct in value: table = '\n'.join([table, row_dct['value']]) yield '_'.join([mp_level01_titles[1], key]), table else: yield (self.level, key), value
def index(request, cid=None, db_type=None, mdb=None): try: response = None if request.method == 'GET': axes, dopings = ['<S>', '<σ>', '<S²σ>'], ['n', 'p'] projection = dict( ('content.data.{}'.format(k[1:-1]), 1) for k in axes) projection.update({'identifier': 1}) docs = mdb.contrib_ad.query_contributions( {'project': 'carrier_transport'}, projection=projection) response = {'text': []} response.update(dict((k, []) for k in axes)) for doc in docs: d = doc['content']['data'] for doping in dopings: for idx, k in enumerate(axes): kk = k[1:-1] if kk in d and doping in d[kk]: value = d[kk][doping]['<ε>'] value = float(value.split()[0]) if idx == 2: value = math.log10(value) response['text'].append(doc['identifier']) response[k].append(value) elif request.method == 'POST': name = json.loads(request.body)['name'] names = name.split('##') key, subkey = names[0][1:-1], names[1][0] table_name = '{}({})'.format(key, subkey) doc = mdb.contrib_ad.query_contributions( {'_id': cid}, projection={ '_id': 0, 'content.{}'.format(table_name): 1, 'content.data.{}.{}'.format(key, subkey): 1 })[0] table = doc['content'].get(table_name) if table: table = Table.from_dict(table) x = [col.split()[0] for col in table.columns[1:]] y = list(table[table.columns[0]]) z = table[table.columns[1:]].values.tolist() if not table_name.startswith('S'): z = [[math.log10(float(c)) for c in r] for r in z] title = ' '.join([table_name, names[1].split()[-1]]) response = { 'x': x, 'y': y, 'z': z, 'type': 'heatmap', 'colorbar': { 'title': title } } except Exception as ex: raise ValueError('"REST Error: "{}"'.format(str(ex))) return {"valid_response": True, 'response': response}
def index(request, cid=None, db_type=None, mdb=None): try: response = None if request.method == 'GET': axes, dopings = ['<S>', '<σ>', '<S²σ>'], ['n', 'p'] projection = dict(('content.data.{}'.format(k[1:-1]), 1) for k in axes) projection.update({'identifier': 1}) docs = mdb.contrib_ad.query_contributions( {'project': 'carrier_transport'}, projection=projection ) response = {'text': []} response.update(dict((k, []) for k in axes)) for doc in docs: d = doc['content']['data'] for doping in dopings: for idx, k in enumerate(axes): kk = k[1:-1] if kk in d and doping in d[kk]: value = d[kk][doping]['<ε>'] value = float(value.split()[0]) if idx == 2: value = math.log10(value) response['text'].append(doc['identifier']) response[k].append(value) elif request.method == 'POST': name = json.loads(request.body)['name'] names = name.split('##') key, subkey = names[0][1:-1], names[1][0] table_name = '{}({})'.format(key, subkey) doc = mdb.contrib_ad.query_contributions( {'_id': cid}, projection={ '_id': 0, 'content.{}'.format(table_name): 1, 'content.data.{}.{}'.format(key, subkey): 1 } )[0] table = doc['content'].get(table_name) if table: table = Table.from_dict(table) x = [col.split()[0] for col in table.columns[1:]] y = list(table[table.columns[0]]) z = table[table.columns[1:]].values.tolist() if not table_name.startswith('S'): z = [[math.log10(float(c)) for c in r] for r in z] title = ' '.join([table_name, names[1].split()[-1]]) response = {'x': x, 'y': y, 'z': z, 'type': 'heatmap', 'colorbar': {'title': title}} except Exception as ex: raise ValueError('"REST Error: "{}"'.format(str(ex))) return {"valid_response": True, 'response': response}