-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create XML file with all the parameters
- script to generate XML file from existing CSV files - script to reconstruct CSV files from XML file
- Loading branch information
Showing
3 changed files
with
1,307 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
groups = { | ||
'w90': [ | ||
'disentanglement', | ||
'job', | ||
'plot', | ||
'system', | ||
'transport', | ||
'wannierise', | ||
], | ||
'postw90': [ | ||
'berry', | ||
'boltzwann', | ||
'dos', | ||
'geninterp', | ||
'global', | ||
'gyrotropic', | ||
'kpath', | ||
'kslice', | ||
], | ||
} | ||
|
||
tree = ET.parse('parameters.xml') | ||
root = tree.getroot() | ||
|
||
for tool in ['w90', 'postw90']: | ||
for group in groups[tool]: | ||
parameters = root.findall(f'./parameter[@tool="{tool}"][@group="{group}"]') | ||
with open(f'{tool}-{group}-parameters.csv', 'w') as fp: | ||
print('Keyword,Type,Description', file=fp) | ||
for parameter in parameters: | ||
name = parameter.find('name') | ||
type = parameter.find('type') | ||
description = parameter.find('description') | ||
if 'optional_prefix' in name.attrib: | ||
print(f'[{name.attrib["optional_prefix"]}]{name.text},', end='', file=fp) | ||
else: | ||
print(f'{name.text},', end='', file=fp) | ||
print(f'{type.text},', end='', file=fp) | ||
print(f'"{description.text}"', file=fp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import re | ||
import xml.etree.ElementTree as ET | ||
|
||
import pandas as pd | ||
|
||
|
||
csv_files = [ | ||
'w90-system-parameters.csv', | ||
'w90-job-parameters.csv', | ||
'w90-disentanglement-parameters.csv', | ||
'w90-wannierise-parameters.csv', | ||
'w90-plot-parameters.csv', | ||
'w90-transport-parameters.csv', | ||
'postw90-global-parameters.csv', | ||
'postw90-berry-parameters.csv', | ||
'postw90-dos-parameters.csv', | ||
'postw90-kpath-parameters.csv', | ||
'postw90-kslice-parameters.csv', | ||
'postw90-gyrotropic-parameters.csv', | ||
'postw90-boltzwann-parameters.csv', | ||
'postw90-geninterp-parameters.csv', | ||
] | ||
|
||
root = ET.Element('root') | ||
tree = ET.ElementTree(root) | ||
|
||
pattern = re.compile(r'(?P<tool>.+)-(?P<group>.+)-parameters.csv') | ||
|
||
for csv_file in csv_files: | ||
match1 = pattern.match(csv_file) | ||
|
||
table = pd.read_csv( | ||
csv_file, | ||
header=0, | ||
names=('keyword', 'type', 'description'), | ||
converters={'keyword': str.strip, 'type': str.strip, 'description': str.strip} | ||
) | ||
|
||
for row in table.itertuples(): | ||
parameter = ET.SubElement(root, 'parameter') | ||
parameter.set('tool', match1['tool']) | ||
parameter.set('group', match1['group']) | ||
# tool = ET.SubElement(parameter, 'tool') | ||
# group = ET.SubElement(parameter, 'group') | ||
name = ET.SubElement(parameter, 'name') | ||
# optional_prefix = ET.SubElement(parameter, 'optional_prefix') | ||
type = ET.SubElement(parameter, 'type') | ||
description = ET.SubElement(parameter, 'description') | ||
|
||
if (match2 := re.compile(r'^\[(?P<prefix>.+_)\]').match(row.keyword)) is not None: | ||
name.text = row.keyword.replace(f'[{match2["prefix"]}]', '') | ||
# optional_prefix.text = match2['prefix'] | ||
name.set('optional_prefix', match2['prefix']) | ||
else: | ||
name.text = row.keyword | ||
# tool.text = match1['tool'] | ||
# group.text = match1['group'] | ||
type.text = row.type | ||
description.text = row.description | ||
|
||
ET.indent(tree) | ||
with open('parameters.xml', 'wb') as fp: | ||
tree.write(fp) |
Oops, something went wrong.