Skip to content
Snippets Groups Projects
Unverified Commit 602a3f57 authored by Werner Alfons Hilda Van Geit's avatar Werner Alfons Hilda Van Geit Committed by GitHub
Browse files

Merge pull request #198 from arnaudon/recipe_yaml

Yaml loader for recipes
parents 8756ab0e ce307a02
No related branches found
Tags 0.7
No related merge requests found
...@@ -27,6 +27,7 @@ Copyright (c) 2018, EPFL/Blue Brain Project ...@@ -27,6 +27,7 @@ Copyright (c) 2018, EPFL/Blue Brain Project
import pandas import pandas
import re import re
import os
import lxml import lxml
import lxml.etree import lxml.etree
...@@ -92,6 +93,52 @@ def read_mm_recipe(recipe_filename): ...@@ -92,6 +93,52 @@ def read_mm_recipe(recipe_filename):
"""Read a BBP builder recipe and return a pandas.DataFrame with all """Read a BBP builder recipe and return a pandas.DataFrame with all
possible (layer, m-type, e-type)-combinations. possible (layer, m-type, e-type)-combinations.
Args:
recipe_filename(str): filename of recipe (XML/YAML)
Returns:
A pandas.DataFrame with fields "layer", "fullmtype", and "etype".
"""
if os.path.splitext(recipe_filename)[1] == '.xml':
return read_mm_recipe_xml(recipe_filename)
elif os.path.splitext(recipe_filename)[1] == '.yaml':
return read_mm_recipe_yaml(recipe_filename)
else:
raise Exception('Please provide an .xml or .yaml as recipe file')
def read_mm_recipe_yaml(recipe_filename):
"""Read a BBP builder recipe and return a pandas.DataFrame with all
possible (layer, m-type, e-type)-combinations.
Args:
recipe_filename(str): filename of recipe (YAML)
Returns:
A pandas.DataFrame with fields "layer", "fullmtype", and "etype".
"""
import yaml
with open(recipe_filename, 'r') as f:
recipe = yaml.safe_load(f)
if recipe['version'] not in ('v2.0',):
raise Exception('Only v2.0 of recipe yaml files are supported')
mecombos = pandas.DataFrame(columns=["layer", "fullmtype", "etype"])
for region in recipe['neurons']:
for etype in region['traits']['etype'].keys():
n_combos = len(mecombos)
mecombos.loc[n_combos, 'layer'] = region['traits']['layer']
mecombos.loc[n_combos, 'fullmtype'] = region['traits']['mtype']
mecombos.loc[n_combos, 'etype'] = etype
return mecombos
def read_mm_recipe_xml(recipe_filename):
"""Read a BBP builder recipe and return a pandas.DataFrame with all
possible (layer, m-type, e-type)-combinations.
Args: Args:
recipe_filename(str): filename of recipe (XML) recipe_filename(str): filename of recipe (XML)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment