def main(): try: #用来存放钥匙 if not os.path.exists('/etc/mng/priv'): os.makedirs('/etc/mng/priv') if not os.path.exists('/etc/mng/logfiles'): os.makedirs('/etc/mng/logfiles') #初始化日志文件 init_logger('log_all', LOG_LEVEL, "/etc/mng/logfiles/log_all.log") init_logger('log_terminal', LOG_LEVEL, "/etc/mng/logfiles/log_terminal.log") #创建数据库 db = None db_name = "MNGDB" tb_name = "user_info" col_list = [("username", "char", "50"), ("password", "char", "50"), ("role", "char", "50"), ("expire", "char", "50"), ("comment", "char", "50")] mysql_api = MysqlApi() db = mysql_api.open_db(db_name) if db is None: mysql_api.create_db(db_name) db = mysql_api.open_db(db_name) cursor = db.cursor() mysql_api.create_table(cursor, db_name, tb_name, col_list) mysql_api.close_db(db) #启动服务 http_server = HTTPServer(Application(),xheaders=True) http_server.bind(8888, '127.0.0.1') http_server.start(1) IOLoop.instance().start() except Exception,e: mysql_api.close_db(db) exstr = traceback.format_exc() #logger.log('the process is running unnormal... \n error_traceback == %s' % str(exstr)) print exstr
def main(): ''' main section, read date from command line, and read all files for this date ''' logger = init_logger() logger.info('Reading data') parser = argparse.ArgumentParser() parser.add_argument( "date", help="date for which reading into the db is forced, YYYYMMDD") # parser.add_argument("location", help="location of the instrument") parser.add_argument( "-l", "--location", type=str, choices=['SABA', 'SEUT', 'all'], default='all', help="optional: give location for the forced ingestion") args = parser.parse_args() logger.debug('Read date {}'.format(args.date)) readdir = find_directory_for_date(args.date, logger) read_forced(readdir, logger, loc=args.location)
import plot_ismr import plot_ismr_map from lib.tools import init_logger, read_yaml, read_confdate def main(): ''' Main section of the calibration script ''' print('Put main script in here') if __name__ == '__main__': main() logger = init_logger() logger.info('Plotting data') parser = argparse.ArgumentParser() parser.add_argument("infile", help="the configuration file on what to plot") args = parser.parse_args() logger.debug(args.infile) # read where the database is dbconfig = read_yaml('local.yaml') # read what plot(s) to make plotconfig = read_yaml(args.infile) ismrdb = os.path.join( dbconfig['ismrdb_path'],
def main(configfile): ''' perform a number of steps: - logger - read configfile - create a baseline -- read baseline data -- determine histogram - see how other data relates -- read other data -- subtract baseline signal ''' log = tools.init_logger() log.info('Read config') config = tools.read_yaml(configfile) dbconfig = tools.read_yaml('local.yaml') for key, val in dbconfig.items(): if key not in config.keys(): config[key] = val # make db filename loc = config['location'] tabname = config['tabname'].format(loc) config['ismrdb'] = os.path.join(config['ismrdb_path'], config['ismrdb_name'].format(loc)) config['startdt'] = tools.read_confdate(config['startdate']) config['enddt'] = tools.read_confdate(config['enddate']) config['clim']['startdt'] = tools.read_confdate(config['startdate']) config['clim']['enddt'] = tools.read_confdate(config['enddate']) svid = tools.interpret_svid(config['satellites']) log.debug('Read config: {}'.format(config)) # Here, take the header, the S4 and TEC and the timestamp: req_list = constants.HEADER_NAMES + ['sig1_S4', 'sig1_TEC', 'timestamp'] query_start = time.time() rawdata = tools.get_sqlite_data(req_list, config['ismrdb'], table=tabname, svid=svid, tstart=config['clim']['startdt'], tend=config['clim']['enddt'], restrict_crit=None, log=log) query_end = time.time() log.debug('Query took {:.3f} seconds'.format(query_end - query_start)) log.debug('Got {}, {}'.format(len(rawdata), np.asarray(rawdata).shape, rawdata)) nonandata = tools.nice_data(rawdata, req_list, log=log) fulldata = tools.add_timedata(nonandata) log.debug('first 20 times {}'.format(fulldata['time'][:20])) log.debug('first 20 hours {} ({})'.format(fulldata['timeofday'][:20], [t.hour for t in fulldata['time'][:20]])) # sys.exit(0) log.info('Create a mean signal and its excursions') pdict = { 'satellites': svid, # which satellites 'location': loc, 'startdt': config['startdt'], 'enddt': config['enddt'], 'tag': 'first_test_hist', } # pdict['histbins'] = lib.scintplots.hist2D_plot(fulldata['timestamp'], 'time', fulldata['sig1_TEC'], 'TEC', 300, 150, xrange=None, yrange=None, tagdict=pdict, outdir= './plots/clim', log=log) # houroftheday = np.array([t.hour for t in fulldata['time']]) # secondoftheday = np.array([tools.second_of_day(t) for t in fulldata['time']]) # print(fulldata['time']) # print(secondoftheday) lib.scintplots.hist2D_plot(fulldata['timeofday'], 'hour_of_day', fulldata['sig1_TEC'], 'TEC', 24, 200, xrange=None, yrange=None, tagdict=pdict, outdir= './plots/clim', log=log) lib.scintplots.hist2D_plot(fulldata['secondofday'], 'second_of_day', fulldata['sig1_TEC'], 'TEC', 96, 200, xrange=None, yrange=None, tagdict=pdict, outdir= './plots/clim', log=log)
self.timedata[-1].strftime('%Y%m%d%H%M'))) cb = fig.colorbar(azel, ax=ax) cb.set_label('{} [units]'.format(var)) outfig = os.path.join( self.config['outputdir'], 'azel_map_{}_{}_{}-{}_sat_{}_{}.png'.format( var, self.config['location'], self.timedata[0].strftime('%Y%m%d%H%M'), self.timedata[-1].strftime('%Y%m%d%H%M'), self._sats_for_figname(), self.tag)) fig.savefig(outfig, dpi=100) plt.close(fig) self.log.debug('Plotted {}'.format(outfig)) if __name__ == '__main__': tag = 'test' print('Do test plot: tag="{}"'.format(tag)) test_yaml_file = 'test_simple_TEC_scatter.yaml' log = init_logger() parser = argparse.ArgumentParser() parser.add_argument("infile", help="the configuration file on what to plot", default=test_yaml_file) args = parser.parse_args() log.debug('Plotting from {}'.format(args.infile)) test_inst = ISMRplot(args.infile, log, tag)