HTML result recap

html – The interface

Interface for the html renderer The relevant parts are imported into html/__init__.py

libvhc.html.communication.HTML_RECAP = '{{recipe}}_recap_{}.html'

Template name for the html recap files

exception libvhc.html.communication.HtmlRecipeError[source]

The html render for the recipe has not been initialised

libvhc.html.communication.get_listener(name)[source]

Return the queue listener

Parameters:
name : string

name of the logger

Returns:
libvhc.html.queue.SetupQueueListener

can be used once in a with

Raises:
KeyError

if the name listener is not found

libvhc.html.communication.get_queue(name)[source]

Returns the queue saved under the name.

If it does not exist, create it first

Parameters:
path : string

path of the two above files

Returns:
libvhc.html.queue.HTMLQueue
libvhc.html.communication.html_context(name)[source]

Yield the listener and the queue associated with name from within a with statement

Parameters:
name : string

name of the listener and the queue

Yields:
queue-like instance
SetupQueueListener
libvhc.html.communication.clear_html(name)[source]

Remove the queue and the listener

Parameters:
name : string

name of the queue and logger

libvhc.html.communication.init_renderer(recipe, fplane_file, use_process=True)[source]

Initialize the renderer for the HTML file and the fplane.FPlane

Parameters:
recipe : string

name of the recipe

fplane_file : string

name of the file describing the focal plane.

use_process : bool, optional

run the listener in a process or in a thread

libvhc.html.communication._mkmessage(vcheck, message)[source]

Prepend the string from vcheck to the message

Parameters:
vcheck : instance of VCheck

store the recipe name and the check currently executing

message : string

message of the test

Returns:
string
libvhc.html.communication.add_fplane_test(vcheck, message, success)[source]

Append a new TestResults to the focal plane tests

The name of the recipe and driver are prepended to the message.

Parameters:
vcheck : instance of VCheck

store the recipe name and the check currently executing

message : string

message of the test

success : string or bool

success status of the test; must be one of the accepted values of TestResults

Raises:
HtmlRecipeError

if the recipe renderer has not been initialized

libvhc.html.communication.add_ifu_test(vcheck, ifuslot, message, success)[source]

Append a new TestResults to the ifu tests

The name of the recipe and driver are prepended to the message.

Parameters:
vcheck : instance of VCheck

store the recipe name and the check currently executing

ifuslot : string

id of the ifu slot, if the IFU does not exists, add the message to the global messages marking it as a failure. Use a non existing ifuslot (e.g. None) to add it to the orphaned tests

message : string

message of the test

success : string or bool

success status of the test; must be one of the accepted values of TestResults

Raises:
HtmlRecipeError

if the recipe renderer has not been initialized

libvhc.html.communication.add_ntests(vcheck, new_tests)[source]

Add new_tests to the number of tests

Parameters:
vcheck : instance of VCheck

store the recipe name and the check currently executing

new_tests : int

number on tests to add

Raises:
HtmlRecipeError

if the recipe renderer has not been initialized

libvhc.html.communication.render_html(recipe, fnames, path, xmin=-450, ymin=-550, xscale=1, yscale=1, open_html=False)[source]

Render the html and save it into outpath.

The name of the output html is recipe_recap.html. If it already exists, a counter is added: recipe_recap_n.html

Parameters:
recipe : string

name of the recipe

fnames : libvhc.utils.FileNameRotator

object containing the file names. It expects the html file on fnames.html_recap, the log file on fnames.logfile and the result file on fnames.result_file. The html recap file name is expected to contain a placeholder {recipe}

path : string

path given to vhc

xmin, ymin : float

minimum x and y coordinate to rescale the ifu positions

scale : float

divide the x and y by this value after subtracting the minima. See fplane.IFU.rescale() for further details

open_html : bool

open the new html in the default browser

libvhc.html.communication.write_html(recipe, fname, open_html=False)[source]

Send the command to write the html recap file.

Parameters:
recipe : string

name of the recipe

fname : string

name of the file

open_html : bool

open the new html in the default browser

html.fplane – Focal plane containers

There should be no need to use the following classes directly.

Create, deal with, render and save the html result file

class libvhc.html.fplane.TestResults(message, status)[source]

Bases: object

Simple container for the test result

Parameters:
message : string

string describing the test or the message

status : string or bool

whether the test was successful. Accepts 'success', 'fail', True or False. Any thing else is interpreted as failure

Attributes:
message : string

message or test description

css_status : string

string of the status

bool_status : bool

bool of the status

message

message or test description

css_status

string of the status

bool_status

bool of the status

_bool2css(self, bsuccess)[source]

convert bool to the string used by css

Parameters:
bsuccess : bool

whether it’s successful or not

Returns:
string

'success' or 'fail'

_css2bool(self, ssuccess)[source]

convert css string to bool

Parameters:
ssuccess : bool

'success' or 'fail'

Returns:
bool

whether it’s a success or not

Raises:
ValueError

if ssuccess is not 'success' nor 'fail'

class libvhc.html.fplane.IFU(*args)[source]

Bases: pyhetdex.het.fplane.IFU

Contain the information for the IFU from the focal plane file and the list of tests for the ifu

Parameters:
ifuslot : string

id of the ifu

x, y : float

x and y position of the ifu in the focal plane

specid : int

id of the spectrograph where the ifu is plugged into

specslot : int

id of the spectrograph slot where the spectrograph is plugged into

ifuid : string

id of the virus ifu bundle

ifurot : float

rotation of the IFU in its seat in the IHMP

platescl : float

focal plane plate scale at the position in the IHMP

Attributes:
ifuid, x, y, xid, yspecid : as before
xid, yid : string or int

x (column) and y (row) id of the ifu in the ifu head mounting plate (IHMP), generated from the ifuslot

ifuslot : string

id of the IHMP seat address

success : string

global success state. Must be one of:

tests : list of TestResults

Returns the test, with the failures first

tests

Returns the test, with the failures first

success

global success state. Must be one of:

['success', 'fail', 'failsome', 'miss', 'successmiss',
'failmiss', 'failsomemiss']

Set to ‘unknown’ when none of the above is set

rescale(self, xmin, ymin, xscale, yscale)[source]

Rescale the x and y position of the IFU:

(x - xmin) / xscale
(y - ymin) / yscale
Parameters:
xmin, ymin : float

minimum x and y coordinate

xscale, yscale : float

divide the x and y by these values after subtracting the minima

add_test(self, message, success)[source]

Append a new TestResults

Parameters:
message : string

message of the test

success : string or bool

success status of the test; must be one of the accepted values of TestResults

class libvhc.html.fplane.FPlane(recipe, fplane_file)[source]

Bases: pyhetdex.het.fplane.FPlane

Focal plane.

Contains the dictionary of IFU instance, with the ifu id as key, the list of test common to the focal plane and provide the tools to process the ifus before rendering the html.

The focal plane is expected to be like:

# IFUSLOT X_FP   Y_FP   SPECID SPECSLOT IFUID IFUROT PLATESC
013     -450.0  150.0   00      000     000     0.0     1.0
014     -450.0  50.0    00      000     000     0.0     1.0
Parameters:
recipe : string

name of the current recipe

fplane_file : string

name of the file containing the ids and position of the IFUs

conf : confp.ConfigParser instance

configuration option

Attributes:
difus
ids
ifus

list of IFU instances

tests

List of TestResults: tests run for whole focal plane

tests_orphan

List of TestResults: orphaned tests with failures first.

recipe : string

name of the recipe

ntests : int

number of tests expected per IFU. It’s used in postprocess_ifus() to determine whether all expected tests are present

template : jinja template

Jinja template

rendered : string

rendered jinja template

tests

List of TestResults: tests run for whole focal plane with failures first

tests_orphan

List of TestResults: orphaned tests with failures first.

They should belong to one IFU, but its ID is not known.

ifu_rescale(self, xmin, ymin, xscale, yscale)[source]

Rescale the x and y position of all the ifus. See IFU.rescale() for further details

add_test(self, message, success)[source]

Append a new TestResults to the focal plane tests

Parameters:
message : string

message of the test

success : string or bool

success status of the test; must be one of the accepted values of TestResults

add_orphan_test(self, message, success)[source]

Append a new TestResults to the orphan tests

Parameters:
message : string

message of the test

success : string or bool

success status of the test; must be one of the accepted values of TestResults

add_ifu_test(self, ifuslot, message, success)[source]

Add to the ifu identified by ifuid

Parameters:
ifuslot : int

id of the ifu slot, if the IFU does not exists, add the message to the global messages marking it as a failure

message : string

message of the test

success : string or bool

success status of the test; must be one of the accepted values of TestResults

add_ntests(self, new_tests)[source]

Add new_tests to the number of tests

Parameters:
new_tests : int

number on tests to add

postprocess_ifus(self)[source]

Post process the ifu, to check if all the expected checks are present and set the IFU.success correspondingly

load_template(self)[source]

Load the default vhc template and save it template property

_load_fplane(self, fname, empty_specid, empty_ifuid, exclude_ifuslot, skip_empty)[source]

Load the focal plane file and creates the IFU instances

Parameters:
fname : string

name of the focal plane file

empty_specid, empty_ifuid, exclude_ifuslot, skip_empty :

see FPlane

add_ifu(self, fpars)[source]

Parse a fplane line and add the IFU to the internal dictionary.

Make sure that the ifuid, specid are a three digit string. Override this method if the ifu class constructor is not as the one of IFU.

Parameters:
line : string

line of the fplane file

by_id(self, id_, idtype)[source]

Returns the ifu with id_

Parameters:
id_ : string

id of the spectrograph

idtype : str

type of the id; must be one of ‘ifuid’, ‘ifuslot’, ‘specid’

Returns:
IFU instance
Raises:
NoIFUError

if there is no IFU identified by the input ID

UnknownIDTypeError

if the ID type is not known

by_ifuid(self, ifuid)[source]

Returns the ifu with ifuid

Parameters:
ifuid : string

id of the ifu

Returns:
IFU instance
Raises:
NoIFUError

if there is no IFU identified by the input ID

by_ifuslot(self, ifuslot)[source]

Returns the ifu with ifuslot

Parameters:
ifuslot : string

id of the ihmp slot

Returns:
IFU instance
Raises:
NoIFUError

if there is no IFU identified by the input ID

by_slotpos(self, x, y)[source]

Returns the ifu in ifu slot position x, y

Parameters:
x : int

x position in the IHMP (1 to 10)

y : int

y position in the IHMP (1 to 9)

Returns:
IFU instance
Raises:
NoIFUError

if there is no IFU for the input positions

by_specid(self, specid)[source]

Returns the ifu with specid

Parameters:
specid : int or string

id of the spectrograph; the value is cast to an integer

Returns:
IFU instance
Raises:
NoIFUError

if there is no IFU identified by the input ID

TypeError

if the input is not an int or a string that can be cast to an int

difus_ifuid

dictionary of ifus; key: IFUID (string); value: IFU instance

difus_ifuslot

dictionary of ifus; key: IFUSLOT (string); value: IFU instance

difus_specid

dictionary of ifus; key: SPECID (int); value: IFU instance

ifuids

list of IFUIDs (strings)

ifus

list of IFU instances

ifuslots

list of IFUSLOTs (strings)

specids

list of SPECIDs (integers)

template

Jinja template

render(self, path, logs, v_results, driver)[source]

Render the template.

Parameters:
path : string

directory in which vhc has run

logs, v_results, driver : strings

name of the logs, the result and the driver files

write_recap(self, fname, auto_open=False)[source]

Write the rendered template into file fname

Parameters:
fname : string

name of the file where to save the rendered recap

auto_open : bool

if true, auto open the rendered html

libvhc.html.fplane._log_to_list(lines)[source]

Loop through the lines and collect all log lines into a list collecting multi-lines into one entry.

Empty lines are ignored and new lines are stripped.

Warning

adapt the regex pattern if the log format is changed in libvhc.loggers.set_logger()

Parameters:
lines : iterable

lines to parser

Returns:
logs : list

list of log messages

libvhc.html.fplane.get_template()[source]

Returns the Jinja template used by vhc

html.queue – The queue listener process

There should be no need to use the following classes directly.

Implement a queue based communication system for the html render

The QueueListener creates and store internally an instance of FPlane. Each element put into the queue is interpreted as a list of three elements:

  1. the name of the method or of a property of the FPlane instance: this must be present;
  2. the list of args of the method (optional): if absent or None, interpreted as an empty list; if the first element is a property, the first element of this list is assigned to the property;
  3. the dictionary of kwargs the method (optional): if absent or None, interpreted as an empty dictionary; if the first element is a property, this is ignored.

The only exception is the sentinel, defaulting to None, that is passed along without any manipulation.

Example:

class libvhc.html.queue.HTMLQueue(*args, **kwargs)[source]

Bases: pyhetdex.tools.queue.QueueContext

Queue used in the HTML interface to communicate from the processes to FPlane object

Attributes:
sentinel

if the object put into the queue is sentinel no check is done

put(self, obj, block=True, timeout=None)[source]

Check that obj comply with the specifications in libvhc.html.queue and, if it does, put obj into the queue.

Parameters:
obj :

object to insert into the queue

block : bool, optional

if True, block until a free slot in the queue is available or, if set, timeout seconds pass; if False raise a queue.Full error if there are no free slots

timeout : number, optional

number of seconds to wait if block if True before raising a queue.Full error; ignored if block is False

Raises:
VHCQueueItemError

if the obj is not of the correct type or shape

class libvhc.html.queue.QueueListener(queue_, fplane_class, recipe, fplane_file)[source]

Bases: pyhetdex.tools.queue.QueueListener

This class implements an internal threaded listener which watches for LogRecords being added to a queue, removes them and passes them to a list of handlers for processing.

Parameters:
queue_ : queue-like instance

queue to use to transmit the information

fplane_class : FPlane class

class declaration that will be instantiated by the lister

recipe : string

name of the recipe

fplane_file : string

name of the file describing the focal plane.

handle(self, record)[source]

Handle a record.

This just loops through the handlers offering them the record to handle.

If the handling of any of the records fails, a message with be logged on screen

class libvhc.html.queue.SetupQueueListener(queue_, fplane_class, recipe, fplane_file, use_process=True)[source]

Bases: pyhetdex.tools.queue.SetupQueueListener

Start the QueueListener, in a separate process if required.

Adapted from logging cookbook.

The SetupQueueListener instance can be used as a context manager for a with statement. Upon exiting the statement, the process and QueueListener are stopped. If an exception happens, it will be logged as critical before stopping: in order to avoid possible errors with missing formatter keywords, the handler formatters are temporarily substituted with “%(level)s %(message)s”.

Parameters:
queue_ : queue-like instance

queue to use to transmit the information

fplane_class : FPlane class

class declaration that will be instantiated by the listener

recipe : string

name of the recipe

fplane_file : string

name of the file describing the focal plane.

use_process : bool, optional

if True start the listener in a separate process

Attributes:
queue : as above
stop_event : multiprocessing.Event instance

event used to signal to stop the listener

lp : :class multiprocessing.Process instance

process running the listener, if use_process is True

listener : QueueListener instance