def main(config_yaml): with open(config_yaml, 'r') as fp: config_str = jinja2.Template(fp.read()).render() config = yaml.load(config_str, Loader=yaml.Loader) # Get the classes associated with each for name in config['run']: try: config['cls'] = tc.Tomographer._find_subclass(name) except KeyError: raise ValueError(f"Tomographer {name} is not defined") # Decide if anyone needs the colors calculating and/or errors loading anyone_wants_colors = False anyone_wants_errors = False for run in config['run'].values(): for version in run.values(): if version.get('errors'): anyone_wants_errors = True if version.get('colors'): anyone_wants_colors = True bands = config['bands'] training_data = tc.load_data( config['training_file'], bands, errors=anyone_wants_errors, colors=anyone_wants_colors ) validation_data = tc.load_data( config['validation_file'], bands, errors=anyone_wants_errors, colors=anyone_wants_colors ) training_z = tc.load_redshift(config['training_file']) validation_z = tc.load_redshift(config['validation_file']) if (('metrics_impl' not in config) or (config['metrics_impl'] == 'firecrown')): metrics_fn = tc.compute_scores elif config['metrics_impl'] == 'jax-cosmo': metrics_fn = tc.jc_compute_scores else: raise ValueError('Unknown metrics_impl value') with open(config['output_file'],'w') as output_file: for classifier_name, runs in config['run'].items(): for run, settings in runs.items(): scores = run_one(classifier_name, bands, settings, training_data, training_z, validation_data, validation_z, config['metrics'], metrics_fn) output_file.write (f"{classifier_name} {run} {settings} {scores} \n")
def load_data(fname, bands): data = tc.load_magnitudes_and_colors(fname, bands) Nbands = len(bands) print('max mag before:', data[:, :Nbands].max(axis=0), 'nobj:', data.shape[0]) z = tc.load_redshift(fname) data, z = tc.add_noise_snr_cut(data, z, bands) print('max mag after:', data[:, :Nbands].max(axis=0), 'nobj:', data.shape[0]) return data, z