def write(system, outfile, skip_empty=True, overwrite=None, add_book=None, **kwargs): """ Write loaded ANDES system data into an xlsx file Parameters ---------- system : System A loaded system with parameters outfile : str Path to the output file skip_empty : bool Skip output of empty models (n = 0) overwrite : bool, optional None to prompt for overwrite selection; True to overwrite; False to not overwrite add_book : str, optional An optional model to be added to the output spreadsheet Returns ------- bool True if file written; False otherwise """ if not confirm_overwrite(outfile, overwrite=overwrite): return False writer = pd.ExcelWriter(outfile, engine='xlsxwriter') writer = _write_system(system, writer, skip_empty) writer = _add_book(system, writer, add_book) writer.save() logger.info(f'xlsx file written to "{outfile}"') return True
def write(system, outfile, skip_empty=True, overwrite=None, **kwargs): """ Write loaded ANDES system data into a JSON file. Parameters ---------- system : System A loaded system with parameters outfile : str Path to the output file skip_empty : bool Skip output of empty models (n = 0) overwrite : bool None to prompt for overwrite selection; True to overwrite; False to not overwrite Returns ------- bool True if file written; False otherwise """ if not confirm_overwrite(outfile, overwrite): return False with open(outfile, 'w') as writer: writer.write(_dump_system(system, writer, skip_empty)) logger.info('JSON file written to "%s"', outfile) return True
def save_config(self, file_path=None, overwrite=False): """ Save all system, model, and routine configurations to an rc-formatted file. Parameters ---------- file_path : str, optional path to the configuration file default to `~/andes/andes.rc`. overwrite : bool, optional If file exists, True to overwrite without confirmation. Otherwise prompt for confirmation. Warnings -------- Saved config is loaded back and populated *at system instance creation time*. Configs from the config file takes precedence over default config values. """ if file_path is None: andes_path = os.path.join(os.path.expanduser('~'), '.andes') os.makedirs(andes_path, exist_ok=True) file_path = os.path.join(andes_path, 'andes.rc') elif os.path.isfile(file_path): if not confirm_overwrite(file_path, overwrite=overwrite): return conf = self.get_config() with open(file_path, 'w') as f: conf.write(f) logger.info(f'Config written to "{file_path}"') return file_path