-
-
Save ivastar/36466f0d97b0944caac42e0c12e4d95e to your computer and use it in GitHub Desktop.
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
import csv | |
import numpy as np | |
import yaml | |
from yaml.loader import SafeLoader | |
import os | |
def read_template(file, verbose=False): | |
with open(file) as t: | |
template = yaml.load(t, Loader = SafeLoader) | |
if verbose: | |
print(f'Template has the following keys:{template.keys()}') | |
return template | |
def create_test(**entries): | |
""" | |
Function which creates an entry for the z10-galaxies repository. | |
Example use: | |
If you already have your values defined in a table tab loaded in memory, you can | |
generate the YML entries like this: | |
for id, ra, dec, z, fa, ref in zip(tab['id'],tab['ra'],tab['dec'],tab['z'],tab['fa'],tab['ref']): | |
create(default_id = id, default_ra = ra, default_dec = dec,\ | |
default_phot_z = z, default_first_author = fa, default_ref = ref) | |
""" | |
template = read_template(template_file) | |
default_keys = [] | |
for key in template.keys(): | |
if 'default' in key: | |
default_keys.append(key) | |
for key in default_keys: | |
if key not in entries.keys(): | |
raise Warning(f'{key} must be defined') | |
return | |
for key, value in entries.items(): | |
try: | |
template[key]['value'] = value | |
except KeyError: | |
print(f'{key} is not a valid key to this template') | |
return | |
outfile = f'{entries["default_ref"]}_{entries["default_id"]}.yml' | |
print(f'Writing {outfile}') | |
with open(outfile, 'w') as f: | |
data = yaml.dump(template, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment