def show_timfiles(timfiles): if len(timfiles): print "--"*25 for timfile in timfiles: print colour.cstring("Timfile ID:", underline=True, bold=True) + \ colour.cstring(" %d" % timfile['timfile_id'], bold=True) print "Pulsar name: %s" % timfile['pulsar_name'] print "Master timfile? %s" % \ (((timfile['mtimid'] is not None) and "Yes") or "No") print "Last edited by: %s (%s)" % (timfile['real_name'], timfile['email_address']) print "Comments: %s" % timfile['comments'] print "Date and time timfile was last edited: %s" % \ timfile['add_time'].isoformat(' ') print "Number of TOAs: %d" % timfile['numtoas'] if timfile['any_replaced'] is not None: colour.cprint("Some TOAs are from rawfiles that been " "superseded", 'warning') # Show extra information if verbosity is >= 1 lines = ["First TOA (MJD): %s" % timfile['startmjd'], "Last TOA (MJD): %s" % timfile['endmjd'], "Number of telescopes used: %d" % timfile['numtelescopes'], "Number of observing systems used: %d" % timfile['numobsys']] notify.print_info("\n".join(lines), 1) print "--"*25 else: raise errors.ToasterError("No timfiles match parameters provided!")
def print_debug(msg, category, stepsback=1): """Print a debugging message if the given debugging category is turned on. The message will be colourized as 'debug'. Inputs: msg: The message to print. category: The debugging category of the message. stepsback: The number of steps back into the call stack to get function calling information from. (Default: 1). Outputs: None """ if debug.is_on(category): if config.cfg.helpful_debugging: # Get caller info fn, lineno, funcnm = inspect.stack()[stepsback][1:4] to_print = colour.cstring("DEBUG %s [%s:%d - %s(...)]:\n" % (category.upper(), os.path.split(fn)[-1], lineno, funcnm), 'debughdr') msg = msg.replace('\n', '\n ') to_print += colour.cstring(" %s" % msg, 'debug') else: to_print = colour.cstring(msg, 'debug') sys.stderr.write(to_print + '\n') sys.stderr.flush()
def show_templates(templates): if len(templates): print "--"*25 for tdict in templates: print colour.cstring("Template ID:", underline=True, bold=True) + \ colour.cstring(" %d" % tdict['template_id'], bold=True) fn = os.path.join(tdict['filepath'], tdict['filename']) print "\nTemplate: %s" % fn print "Pulsar name: %s" % tdict['pulsar_name'] print "Master template? %s" % \ (((tdict['mtempid'] is not None) and "Yes") or "No") print "Number of phase bins: %d" % tdict['nbin'] print "Uploaded by: %s (%s)" % (tdict['real_name'], tdict['email_address']) print "Uploader's comments: %s" % tdict['comments'] print "Date and time template was added: %s" % \ tdict['add_time'].isoformat(' ') # Show extra information if verbosity is >= 1 lines = ["Observing System ID: %d" % tdict['obssystem_id'], "Observing System Name: %s" % tdict['obssys_name'], "Telescope: %s" % tdict['telescope_name'], "Frontend: %s" % tdict['frontend'], "Backend: %s" % tdict['backend'], "Clock: %s" % tdict['clock']] notify.print_info("\n".join(lines), 1) try: # Show the template if verbosity is >= 2 cmd = ["psrtxt", fn] psrtxtout, stderr = utils.execute(cmd) gnuplotcode = """set term dumb set format y "" set nokey set border 1 set tics out set xtics nomirror set ytics 0,1,0 set xlabel "Phase Bin" set xrange [0:%d] plot "-" using 3:4 w l %s end """ % (tdict.nbin-1, psrtxtout) plot, stderr = utils.execute(["gnuplot"], stderr=open(os.devnull), stdinstr=gnuplotcode) notify.print_info(plot, 2) except errors.SystemCallError: # gnuplot is probably not installed pass print "--"*25 else: raise errors.ToasterError("No templates match parameters provided!")
def show_pulsars(psrinfo): """Print pulsar info to screen in a human-readable format. Input: psrinfo: A dictionary of pulsar info dictionaries. (As returned by get_pulsarinfo(...)) Outputs: None """ print "--"*25 for psrid in sorted(psrinfo.keys()): psr = psrinfo[psrid] print colour.cstring("Pulsar ID:", underline=True, bold=True) + \ colour.cstring(" %d" % psrid, bold=True) print "Pulsar Name: %s" % psr['name'] print "Aliases:" for alias in psr['aliases']: if alias == psr['name']: continue print " %s" % alias if psr['parfile_id'] is None: print "No parfile loaded!" else: if psr['period'] > 1: print "Period: %.3f s" % psr['period'] else: print "Period: %.2f ms" % (1000.0*psr['period']) print "DM: %.2f pc/cc" % psr['dm'] print "R.A. (J2000): %s" % psr['raj'] print "Dec. (J2000): %s" % psr['decj'] print "Binary model: %s" % psr['binary'] lines = ["Number of observations: %d" % psr['numobs']] if psr['numobs'] > 0: lines.append("Telescopes used:\n " + "\n ".join(psr['telescopes'])) lines.append("Number of TOAs: %d" % psr['numtoas']) if psr['curators'] == 'Everyone': lines.append("Curators: Everyone") elif psr['curators']: lines.append("Curators:\n " + "\n ".join(psr['curators'])) else: lines.append("Curators: None") notify.print_info("\n".join(lines), 1) print "--"*25
def main(args): # Build cache obssysinfo_cache = cache.get_obssysinfo_cache() obssys_ids = obssysinfo_cache.keys() print "--"*25 for id in sorted(obssys_ids): obssysinfo = cache.get_obssysinfo(id) print colour.cstring("Observing System ID:", underline=True, bold=True) + \ colour.cstring(" %d" % id, bold=True) print "Observing System Name: %s" % obssysinfo['name'] print "Telescope: %d" % obssysinfo['telescope_id'] print "Receiver: %s" % obssysinfo['frontend'] print "Backend: %s" % obssysinfo['backend'] print "Observing Band: %s" % obssysinfo['band_descriptor'] print "--"*25
def __call__(self, parser, namespace, values, option_string): colour.cprint("Available Manipulators:", bold=True, underline=True) for name in sorted(registered_manipulators): manip = load_manipulator(name) wrapper = textwrap.TextWrapper(subsequent_indent=" "*(len(name)+4)) print "%s -- %s" % (colour.cstring(name, bold=True), wrapper.fill(manip.description)) sys.exit(1)
def show_parfiles(parfiles): if len(parfiles): print "--"*25 for parfile in parfiles: print colour.cstring("Parfile ID:", underline=True, bold=True) + \ colour.cstring(" %d" % parfile['parfile_id'], bold=True) fn = os.path.join(parfile['filepath'], parfile['filename']) print "\nParfile: %s" % fn print "Pulsar name: %s" % parfile['pulsar_name'] print "Master parfile? %s" % \ (((parfile['mparid'] is not None) and "Yes") or "No") print "Date and time parfile was added: %s" % \ parfile['add_time'].isoformat(' ') msg = "Parfile contents:\n\n" for line in open(fn, 'r'): msg += "%s\n" % line.strip() notify.print_info(msg, 1) print "--"*25 else: raise errors.ToasterError("No parfiles match parameters provided!")
def __call__(self, parser, namespace, values, option_string): colour.cprint("Available Diagnostics:", \ bold=True, underline=True) descwrapper = textwrap.TextWrapper(initial_indent=" ", subsequent_indent=" ") for key in sorted(diagnostics.registered_diagnostics): diagcls = diagnostics.get_diagnostic_class(key) wrapper = textwrap.TextWrapper(subsequent_indent=" "*(len(key)+4)) print "%s -- %s" % (colour.cstring(key, bold=True), wrapper.fill(diagcls.name)) if diagcls.description is not None: print descwrapper.fill(diagcls.description) sys.exit(1)
def show_procjobs(procjobs): print "--" * 25 for procjob in procjobs: print colour.cstring("Process Id:", underline=True, bold=True) + colour.cstring( " %d" % procjob.process_id, bold=True ) print "\nPulsar name: %s" % cache.get_pulsarname(procjob.pulsar_id) print "Rawfile (ID=%d): %s" % (procjob.rawfile_id, procjob.rawfn) if procjob.replacement_rawfile_id is not None: colour.cprint("Rawfile has been superseded by rawfile_id=%d" % procjob.replacement_rawfile_id, "warning") print "Manipulator: %s" % procjob.manipulator print " Args: %s" % procjob.manipulator_args print "Number of freq. chunks: %d" % procjob.nchan print "Number of time chunks: %d" % procjob.nsub print "Uploaded by: %s (%s)" % (procjob.real_name, procjob.email_address) print "Date and time job completed: %s" % procjob.add_time.isoformat(" ") if config.cfg.verbosity >= 1: lines = ["Template (ID=%d): %s" % (procjob.template_id, procjob.tempfn)] if procjob.parfile_id is not None: lines.append("Parfile (ID=%d): %s" % (procjob.parfile_id, procjob.parfn)) else: lines.append("No parfile installed during processing.") notify.print_info("\n".join(lines), 1) print "--" * 25
fn = toadiagfn else: fn = "%s_%d" % (toadiagfn, ii+1) shutil.move(fn, os.path.join(diagdir, outfn)) ins = db.toa_diagnostic_plots.insert() values.append({'toa_id': toa_id, 'filename': outfn, 'filepath': diagdir, 'plot_type': 'Prof-Temp Resids'}) result = db.execute(ins, values) result.close() notify.print_info("Inserted %d TOA diagnostic plots." % len(toa_ids), 2) except: db.rollback() sys.stdout.write(colour.cstring("Error encountered. " "Rolling back DB transaction!\n", 'error')) raise else: # No exceptions encountered # Commit database transaction db.commit() finally: # Clean up for fn in [adjustfn, manipfn]: if os.path.isfile(fn): os.remove(fn) # End pipeline print "###################################################" print random.choice(SUCCESSMSGS) print "End time: %s" % utils.give_utc_now()