def main_init( cfg, cs_store_name, __file__=None, ): """ - prints parameters - prints message that program (__file__ or cs_store_name) started - converts cfg parameters to types according to its prefixes/suffixes names (see ini2dict()) :param cfg: :param cs_store_name: :param __file__: :return: """ # global lf # if cfg.search_path is not None: # override_path = hydra.utils.to_absolute_path(cfg.search_path) # override_conf = OmegaConf.load(override_path) # cfg = OmegaConf.merge(cfg, override_conf) print("Working directory : {}".format(os.getcwd())) # todo: print only if config changed print(OmegaConf.to_yaml(cfg)) # cfg = cfg_from_args(argparser_files(), **kwargs) if not cfg.program.return_: print('Can not initialise') return cfg elif cfg.program.return_ == '<cfg_from_args>': # to help testing return cfg hydra.verbose = 1 if cfg.program.verbose == 'DEBUG' else 0 # made compatible to my old cfg print('\n' + this_prog_basename(__file__) if __file__ else cs_store_name, end=' started. ') try: cfg_t = ini2dict( cfg) # fields named with type pre/suffixes are converted except MissingMandatoryValue as e: lf.error(standard_error_info(e)) raise Ex_nothing_done() except Exception: lf.exception('startup error') # OmegaConf.update(cfg, "in", cfg.input, merge=False) # error # to allow non primitive types (cfg.out['db']) and special words field names ('in'): # cfg = omegaconf.OmegaConf.to_container(cfg) return cfg_t
def main_init( cfg, cs_store_name, __file__=None, ): """ Common startup initializer: - finds input files - asks user to proceed if need - prints message that program (__file__ or cs_store_name) started :param cfg: :return: Note: if new_arg=='<cfg_from_args>' returns cfg but it will be None if argument argv[1:] == '-h' or '-v' passed to this code argv[1] is cfgFile. It was used with cfg files: 'csv2h5_nav_supervisor.ini' 'csv2h5_IdrRedas.ini' 'csv2h5_Idronaut.ini' """ # global lf # if cfg.search_path is not None: # override_path = hydra.utils.to_absolute_path(cfg.search_path) # override_conf = OmegaConf.load(override_path) # cfg = OmegaConf.merge(cfg, override_conf) print("Working directory : {}".format(os.getcwd())) print(OmegaConf.to_yaml(cfg)) # cfg = cfg_from_args(argparser_files(), **kwargs) if not cfg.program.return_: print('Can not initialise') return cfg elif cfg.program.return_ == '<cfg_from_args>': # to help testing return cfg hydra.verbose = 1 if cfg.program.verbose == 'DEBUG' else 0 # made compatible to my old cfg print('\n' + this_prog_basename(__file__) if __file__ else cs_store_name, end=' started. ') cfg_t = ini2dict(cfg) # fields named with type pre/suffixes are converted # OmegaConf.update(cfg, "in", cfg.input, merge=False) # error # to allow non primitive types (cfg.out['db']) and special words field names ('in'): # cfg = omegaconf.OmegaConf.to_container(cfg) return cfg_t
If "<filename>" found it will be sabstituted with [1st file name]+, if "<dir>" - with last ancestor directory name. "<filename>" string will be sabstituted with correspondng input file names. ''') parser.add_argument( '-verbose', nargs=1, type=str, default=['INFO'], choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'], help='Verbosity of messages in log file') args = parser.parse_args() args.verbose = args.verbose[0] try: cfg = ini2dict(args.cfgFile) cfg['in']['paths'], cfg['in']['nfiles'], cfg['in'][ 'path'] = init_file_names(**cfg['in']) except (IOError, Ex_nothing_done) as e: cfg = {'in': {'paths': [args.path], 'nfiles': 1}} # one file if not os_path.isfile(args.path): print('\n==> '.join([s for s in e.args if isinstance(s, str)])) # e.message raise (e) ############################################################################ # set_field_if_no(cfg['in'],'types',None) # set_field_if_no(cfg['skiprows'],'types') if cfg['in']['nfiles']: # ## Main circle ############################################################
import pandas as pd from utils2init import ini2dict cfg = ini2dict(r'D:\Work\_Python3\_projects\PyCharm\h5toGrid\CTD_calc.ini') tblD = cfg['out']['table'][0] tblL = tblD + '/logFiles' store = pd.HDFStore( r'd:\WorkData\_source\AtlanticOcean\161113_Strahov\161113_Strahov.h5') dfL = store[tblL] qstr_trange_pattern = "index>=Timestamp('{}') & index<=Timestamp('{}')" r = [r for n, r in enumerate(dfL.itertuples()) if n == 3][0] # dfL.iloc[3], r['Index']= dfL.index[3] qstr = qstr_trange_pattern.format(r.Index, r.DateEnd) Dat = store.select(tblD, qstr) store.close()
break else: out_numbers.append(0) return out_numbers if __name__ == '__main__': # unittest.main() if __package__ is None: from sys import path as sys_path from os import path as os_path sys_path.append(os_path.dirname(os_path.dirname(os_path.abspath(__file__)))) from utils2init import ini2dict, pathAndMask, name_output_file # dir_walker, readable, bGood_dir, bGood_file cfg = ini2dict() cfg['out']['digits'] = cfg_prepare(cfg) if 'path' not in cfg['out']: cfg['out']['path'] = cfg['in']['path'] / os_path.basename(cfg['out']['name']) cfg['out']['path'] = Path(*pathAndMask(*[cfg['out'][spec] if spec in cfg['out'] else None for \ spec in ['path', 'name', 'ext']])) cfg['out']['path'], writeMode, msgFile = name_output_file( cfg['out']['path'].parent, cfg['out']['path'].stem, cfg['out']['path'].suffix, False) root = ET.Element('TTF') child1 = ET.SubElement(root, 'Subscription') child1.set('Id', "WinRiver Processed Data") child11 = ET.SubElement(ET.SubElement(child1, 'Translator'), 'XMLFile') ET.SubElement(child11, 'Name').text = "Proc_Ensemble_schema.xml" ET.SubElement(child11, 'Title').text = "Processed Ensemble Data" child2 = ET.SubElement(root, 'Settings')