pypeit.pypmsgs module

Module for terminal and file logging.

Todo

Why not use pythons native logging package?

class pypeit.pypmsgs.Messages(log=None, verbosity=None, colors=True)[source]

Bases: object

Create coloured text for messages printed to screen.

For further details on colours see the following example: http://ascii-table.com/ansi-escape-sequences.php

Parameters:
  • log (str or file-like object,optional) – Name of saved log file (no log will be saved if log==””). If None, no log is saved.

  • verbosity (int) –

    Level of verbosity. Options are
    • 0 = No output

    • 1 = Minimal output

    • 2 = All output (default)

  • colors (bool) – If true, the screen output will have colors, otherwise normal screen output will be displayed

_cleancolors(msg)[source]
_devmsg()[source]
_initialize_log_file(log=None)[source]

Expects self._log is already None.

_print(premsg, msg, last=True, printDevMsg=True)[source]

Print to standard error and the log file

bug(msg)[source]

Print a bug message

close()[source]

Close the log file before the code exits

disablecolors()[source]

Disable colored output text

enablecolors()[source]

Enable colored output text

error(msg, cls='PypeItError')[source]

Print an error message

static indent()[source]

Return a text string containing an indent to be used with messages

info(msg)[source]

Print an information message

info_update(msg, last=False)[source]

Print an information message that needs to be updated

input()[source]

Return a text string to be used to display input required from the user

static newline()[source]

Return a text string containing a newline to be used with messages

prindent(msg)[source]

Print an indent

pypeitpar(msglist)[source]

Print a message with the pypeit par formatting.

Parameters:

msglist (list) –

A list containing the pypeit parameter strings. The last element of the list must be the argument and the variable. For example, to print:

[sensfunc]
    [[UVIS]]
        polycorrect = False

you should set msglist = ['sensfunc', 'UVIS', 'polycorrect = False'].

pypeitpar_text(msglist)[source]

Prepare a text string with the pypeit par formatting.

Parameters:

msglist (list) –

A list containing the pypeit parameter strings. The last element of the list must be the argument and the variable. For example, to print:

[sensfunc]
    [[UVIS]]
        polycorrect = False

you should set msglist = ['sensfunc', 'UVIS', 'polycorrect = False'].

Returns:

parstring – The parameter string

Return type:

str

reset(log=None, verbosity=None, colors=True, log_to_stderr=None)[source]

Reinitialize the object.

Needed so that there can be a default object for all modules, but also a dynamically defined log file.

reset_log_file(log)[source]
set_logfile_and_verbosity(scriptname, verbosity)[source]

Set the logfile name and verbosity level for a script run.

PypeIt scripts (with the exception of run_pypeit) default to verbosity level = 1. For certain scripts, having a more verbose output (with an accompanying log file) would be helpful for debugging purposes. This function provides the ability to set the msgs verbosity and create a log file for those certain scripts.

Log filenames have the form scriptname_YYYYMMDD_HHMM.log to differentiate between different runs of the script. Timestamp is UT.

Parameters:
  • scriptname (str, optional) – The name of the calling script for use in the logfile

  • verbosity (int, optional) – The requested verbosity, passed in from the argument parser. Verbosity level between 0 [none] and 2 [all]

test(msg)[source]

Print a test message

warn(msg)[source]

Print a warning message

work(msg)[source]

Print a work in progress message

exception pypeit.pypmsgs.PypeItBitMaskError[source]

Bases: PypeItError

exception pypeit.pypmsgs.PypeItDataModelError[source]

Bases: PypeItError

exception pypeit.pypmsgs.PypeItError[source]

Bases: Exception