def harmonize(inf, history, regions, rc, output_path, output_prefix, return_result=False, write_output=True): # check files exist check = [inf, history, regions, rc] for f in check: if f and not os.path.exists(f): raise IOError('{} does not exist on the filesystem.'.format(f)) # read input hist = aneris.pd_read(history, str_cols=True) if hist.empty: raise ValueError('History file is empty') regions = aneris.pd_read(regions, str_cols=True) if regions.empty: raise ValueError('Region definition is empty') model, overrides, config = aneris.read_excel(inf) rc = aneris.RunControl(rc=rc) rc.recursive_update('config', config) # do core harmonization driver = aneris.HarmonizationDriver(rc, hist, model, overrides, regions) for scenario in driver.scenarios(): driver.harmonize(scenario) model, metadata, diagnostics = driver.harmonized_results() if write_output: # write to excel prefix = output_prefix or inf.split('.')[0] fname = os.path.join(output_path, '{}_harmonized.xlsx'.format(prefix)) logger().info('Writing result to: {}'.format(fname)) aneris.pd_write(model, fname, sheet_name='data') # save data about harmonization fname = os.path.join(output_path, '{}_metadata.xlsx'.format(prefix)) logger().info('Writing metadata to: {}'.format(fname)) aneris.pd_write(metadata, fname) # save data about harmonization if not diagnostics.empty: fname = os.path.join(output_path, '{}_diagnostics.xlsx'.format(prefix)) logger().info('Writing diagnostics to: {}'.format(fname)) aneris.pd_write(diagnostics, fname) if return_result: return model, metadata, diagnostics
def _warn(msg, *args, **kwargs): utils.logger().warning(msg, *args, **kwargs)
def _log(msg, *args, **kwargs): utils.logger().info(msg, *args, **kwargs)