Single Dish Radio Astronomy Software Tools

For an overview of SDRAST and the current status please visit https://sdrast.github.io/.

Please note that the modules configuration, messagebus, pyro, trifeni and tunneling are not yet working under Python 3.

support Package

Package to provide support for various objects and modules

This module contains functions that don’t have an obvious home in a submodule.

Functions

array(object[, dtype, copy, order, subok, ndmin])

Create an array.

check_permission(group)

Verify that the user has the necessary permissions.

cpu_arch()

exists(path)

Test whether a path exists.

get_user()

Returns the user running this session

makedirs(name [[, mode, exist_ok])

Super-mkdir; create a leaf directory and all intermediate ones.

mkdir_if_needed(path)

nearest_index(np_array, value)

Return the index of the element of the array with the nearest value

python_version()

sleep(seconds)

Delay execution for a given number of seconds.

sync_second()

Wait until the second changes

time()

Return the current time in seconds since the Epoch.

Classes

NamedClass(name)

A base class enhanced with methods for reporting self.

PropertiedClass()

A subclass of MCobject enhanced with properties.

Class Inheritance Diagram

Inheritance diagram of support.NamedClass, support.PropertiedClass

support.arguments Module

Support for Python argparse (or optparse) module

How to use this:

p = initiate_option_parser(description,examples)
p.usage = usage
# Add other options here

opts, args = p.parse_args(sys.argv[1:])

# This cannot be delegated to another module or class
mylogger = init_logging(logging.getLogger(),
                        loglevel   = get_loglevel(opts.file_loglevel),
                        consolevel = get_loglevel(opts.stderr_loglevel),
                        logname    = opts.logpath+__name__+".log")
loggers = set_module_loggers(eval(opts.modloglevels))

In either case, the parser object will be a argparse.ArgumentParser object

Converting from optparse to argparse

The package ‘optparse’ has been made obsolescent. In converting from ‘optparse’ to ‘argparse’, replace ‘add_option’ with ‘add_argument’ and change the ‘type’ value from a string to a Python variable type, e.g. float

Functions

initiate_option_parser(description, examples)

Initiate an option parser with default logging options

simple_parse_args(init_description)

Grab arguments relevant to the Pyro nameserver that have APC and Spectrometer servers registered.

Classes

ArgumentInterpreter()

Interprets the argument provided as the specied type of iterable

OptParser([prog, usage, description, …])

Subclass of OptionParser which does not mess up examples formatting

OptionParser([description, usage, examples])

front end for ArgumentParser for older programs from ‘optparse’ days

PlainHelpFormatter(prog[, indent_increment, …])

Formatter which does not remove newline codes

Class Inheritance Diagram

Inheritance diagram of support.arguments.ArgumentInterpreter, support.arguments.OptParser, support.arguments.OptionParser, support.arguments.PlainHelpFormatter

support.control_flow Package

Classes

ControlFlowMixin

Mixin class for controlling when and until when functions are called.

Class Inheritance Diagram

Inheritance diagram of support.control_flow.ControlFlowMixin

support.coroutine Module

Functions

coroutine(func)

Simple decorator to “prime” a coroutine

Classes

CoroutineMixin

This provides a subclass with a _coro attribute which provides the class with the new generator features defined in Python 2.5.

Class Inheritance Diagram

Inheritance diagram of support.coroutine.CoroutineMixin

support.dicts Module

support for dict objects

Functions

flattenDict(dictionary[, init])

Converts nested dicts with numeric or str keys to flat dict with tuple keys.

get_from_deep_dict(values, keys)

Extract values from a multi-depth dictionary

make_key_if_needed(thisdict, key[, value])

Creates a key in an existing dictionary if it does not exist

tuple_keys_to_str(dictionary)

Converts tuple keys to str keys

support.doc_util Package

Functions

get_help(cls)

generate help text from a class.

support.excel Module

Support for openpyxl

Use of module functions is not elegant. I should try to subclass openpyxl.workbook.Workbook

This works for open-pyxl 1.x. Starting with 2.0, the row and column indexing starts with 1 instead of 0.

Functions

add_column(sheet, meta_column, col, colname)

Add one empty column to a sheet

add_columns(sheet, names)

Add a list of empty columns to a sheet

column_ID_dict(worksheet)

Create a dictionary of column number indexed by column name

column_id(index)

Return the column label given its numerical index

column_number(code)

Return column number, with left column being 0.

find_column(sh, name)

Find or create a column

getValueWithMergeLookup(sheet, col, row)

from http://stackoverflow.com/questions/23562366/ how-do-i-get-value-present-in-a-merged-cell does not work in this version of openpyxl

get_column(ws, column_name)

Get the data as a list from a column identified by its name.

get_column_id(sh, col_name)

Returns column letter of the first column with that name

get_column_letter(idx)

Convert a column index into a column letter (3 -> ‘C’)

get_column_names(sh)

Dictionary of column names indexed by column letter

get_row_number(ws, column, value)

Get the first row which has the specified value in the designated column

get_row_numbers(sh, colname, value)

Get the row numbers for rows with a given value in a column

get_rows(sh, colname, value)

Get a list of rows (each a list of cells) with a given value in a column

insert_empty_row_after(ws, prior_row)

Move all the rows above ‘prior_row’ down one and ‘prior_row’+1 emptied.

load_workbook(filename[, read_only, …])

Open the given filename and return the workbook

set_column_dimensions(ws)

Set the width of the columns to fit the data in the top two rows

Classes

Workbookclass([path, file])

incomplete

Class Inheritance Diagram

Inheritance diagram of support.excel.Workbookclass

support.git Package

support.git - creates superdep.txt and subdep.txt files

subdep.txt lists repositories below the current repository in the filesystem.

superdep.txt lists repositories above the current one to the top of tree.

TO DO:: * Handle the case of multiple remotes. Use only ‘jpl’ and ‘jplra’. * Take care of the intermediate repositories * Look at the imports in __init__.py to see what other repos are needed

Functions

add_new_files()

Finds new files in the current directory as does ‘git add’ for them.

check_repo(path)

Convenience so this test hast to be done only once

compare_to_remote(remote)

Compares status of local and remote repo

compare_to_remotes(remote)

Compares status of all local and remote repos

find_sub_repos([path, fileobj])

Find the repo trunk(s) in the specified directory

get_git_dirs()

Finds all the sub-directories on the system which are git sandboxes.

get_loglevel(level)

Get the level value from text

init_logging(extlogger[, loglevel, …])

Create a logger that displays to the console and writes a log file.

install_dependencies()

Clones the repos needed by this repo.

make_subdep_entry(path[, fileobj])

Add submodule (separate repo in this directory) to subdep.txt

make_superdeps(top_repos)

Create list of repos in the directory tree above this repo

report_status([show_all])

Does ‘git status’ for all the sandboxes.

support.git.pull_submodule_branches Module

Functions

pull_submodule_branches()

Even after calling git submodule update –init –recursive submodule will be on a detached branch.

support.graphics Package

Various routines to support matplotlib graphics

Functions

X_axis_label_format(format)

Define the X-axis label format

auto_ticks(vmin, vmax)

Optional over-ride for matplotlib tick placement.

empty(shape[, dtype, order])

Return a new array of given shape and type, without initializing entries.

fft(a[, n, axis, norm])

Compute the one-dimensional discrete Fourier Transform.

fftshift(x[, axes])

Shift the zero-frequency component to the center of the spectrum.

get_screen_resolution()

from https://stackoverflow.com/questions/3597965/ getting-monitor-resolution-in-python-on-ubuntu

make_spectrogram(data, num_spec, num_bins[, …])

Converts a sequence of complex samples into a spectrogram

ticks(axis, axis_limits, new_limits, …)

Label an axis with different units from the data

twiny([ax])

Make a second axes overlay ax (or the current axes if ax is None) sharing the xaxis.

support.graphics.colormap Module

These functions, when given a magnitude mag between cmin and cmax, return a colour tuple (red, green, blue). Light blue is cold (low magnitude) and yellow is hot (high magnitude). From http://code.activestate.com/recipes/52273/

Functions

colorbar(cmin, cmax)

Create a color bar using the RGB mapping of this module

floatRgb(mag, cmin, cmax)

Return a tuple of floats between 0 and 1 for the red, green and blue amplitudes.

htmlRgb(mag, cmin, cmax)

Return a tuple of strings to be used in HTML documents.

indexed_color(index)

rgb(mag, cmin, cmax)

Return a tuple of integers to be used in AWT/Java plots.

strRgb(mag, cmin, cmax)

Return a tuple of strings to be used in Tk plots.

support.graphics.northpolar Module

from http://stackoverflow.com/questions/2417794/how-to-make-the-angles-in-a-matplotlib-polar-plot-go-clockwise-with-0-at-the-top

Classes

Affine2D([matrix])

A mutable 2D affine transformation.

Bbox(points, **kwargs)

A mutable bounding box.

IdentityTransform(*args, **kwargs)

A special class that does one thing, the identity transform, in a fast way.

NorthPolarAxes(*args[, theta_offset, …])

A variant of PolarAxes where theta starts pointing north and goes clockwise.

PolarAxes(*args[, theta_offset, …])

A polar graph projection, where the input dimensions are theta, r.

Class Inheritance Diagram

Inheritance diagram of support.graphics.northpolar.NorthPolarAxes

support.hdf5_util Package

Functions

inspect_file_attrs(f_path_or_f_obj)

List out the attributes of some HDF5 file object.

inspect_file_structure(f_path_or_f_obj)

Get a dictionary that reports the structure of some HDF5 file.

dump_dict(f_obj_or_group, data_dict)

Dump the contents of a data dictionary into some file object or group.

Classes

HDF5Mixin

Mixin class with methods for creating and writing to HDF5 files.

Class Inheritance Diagram

Inheritance diagram of support.hdf5_util.hdf5_mixin.HDF5Mixin

support.HTML Module

Classes

Body(*args, **kwargs)

Centering(*args, **kwargs)

H1(*args, **kwargs)

HTMLpage(*args, **kwargs)

Head(*args, **kwargs)

Link(*args, **kwargs)

Table(*args, **kwargs)

TableData(*args, **kwargs)

TableHeader(*args, **kwargs)

TableRow(*args, **kwargs)

TagBody(*args, **kwargs)

superclass for HTML tag classes

Title(text, **kwargs)

Class Inheritance Diagram

Inheritance diagram of support.HTML.Body, support.HTML.Centering, support.HTML.H1, support.HTML.HTMLpage, support.HTML.Head, support.HTML.Link, support.HTML.Table, support.HTML.TableData, support.HTML.TableHeader, support.HTML.TableRow, support.HTML.TagBody, support.HTML.Title

support.lists Module

Methods to support lists

Functions

contains(List, value)

Reports whether ‘value’ is in ‘List’

flatten(List)

Make a list of nested lists a simple list

list_dictionary(dictionary)

Print a dictionary, one line for each item, with the keys sorted

remove_item(thislist, item)

Remove item from list without complaining if absent

rotate(List, first_value[, direction, …])

Rotate one or more lists subject to constraints on the first list

unique(hasDupes)

Removes duplicate elements from a list

support.local_dirs Module

paths to local packages and data

support.logs Module

module with enhancements to the Python logging

Functions

setup_logging([logger, logfile, logLevel, …])

setup up some logging.getLogger instance with console logging and file logging handlers (StreamHandler and FileHandler handlers, respectively.)

set_loglevel(logger, level)

Set the level of a logger

get_loglevel(level)

Get the level value from text

init_logging(extlogger[, loglevel, …])

Create a logger that displays to the console and writes a log file.

setup_email_handler(toaddr[, logLevel])

Setup an instance of TLSSMTPHandler

remove_handlers(logger)

remove any handlers associated with a logger.

Classes

TLSSMTPHandler(mailhost, fromaddr, toaddrs, …)

Custom handler for email logging using TLS encryption.

Class Inheritance Diagram

Inheritance diagram of support.logs.TLSSMTPHandler

support.markdown_util Package

Classes

MarkdownTable([header, data])

Create a formatted markdown table from some header and data.

Class Inheritance Diagram

Inheritance diagram of support.markdown_util.table.MarkdownTable

support.markdown_util.table Module

Classes

MarkdownTable([header, data])

Create a formatted markdown table from some header and data.

Class Inheritance Diagram

Inheritance diagram of support.markdown_util.table.MarkdownTable

support.network Module

Functions

LAN_hosts_status([port, private])

Get information about and status of local network hosts with port open

decode_IP(IP_address)

Returns a long int for an IPv4 or IPv6 address.

decode_MAC(MAC_address)

Returns a long int for a MAC address

encode_IP(intIP)

get_domain(netIP)

Returns the networks key whose list contains netIP

get_local_network([private, subnet])

Returns the IP address of the local network

invoke(command)

Convenient alternate for a command without stdin.

report_LAN_hosts_status()

support.options Module

Support for Python argparse (or optparse) module

How to use this:

p = initiate_option_parser(description,examples)
p.usage = usage
# Add other options here

opts, args = p.parse_args(sys.argv[1:])

# This cannot be delegated to another module or class
mylogger = init_logging(logging.getLogger(),
                        loglevel   = get_loglevel(opts.file_loglevel),
                        consolevel = get_loglevel(opts.stderr_loglevel),
                        logname    = opts.logpath+__name__+".log")
loggers = set_module_loggers(eval(opts.modloglevels))

In either case, the parser object will be a argparse.ArgumentParser object

Converting from optparse to argparse

The package ‘optparse’ has been made obsolescent. In converting from ‘optparse’ to ‘argparse’, replace ‘add_option’ with ‘add_argument’ and change the ‘type’ value from a string to a Python variable type, e.g. float

Functions

initiate_option_parser(description, examples)

Initiate an option parser with default logging options

simple_parse_args(init_description)

Grab arguments relevant to the Pyro nameserver that have APC and Spectrometer servers registered.

Classes

ArgumentInterpreter()

Interprets the argument provided as the specied type of iterable

OptParser([prog, usage, description, …])

Subclass of OptionParser which does not mess up examples formatting

OptionParser([description, usage, examples])

front end for ArgumentParser for older programs from ‘optparse’ days

PlainHelpFormatter(prog[, indent_increment, …])

Formatter which does not remove newline codes

Class Inheritance Diagram

Inheritance diagram of support.options.ArgumentInterpreter, support.options.OptParser, support.options.OptionParser, support.options.PlainHelpFormatter

support.process Module

process - support for executing shell commands

Functions

invoke(command)

Convenient alternate for a command without stdin.

is_running(task)

search_response(command_list1, command_list2)

Search a local command response.

Classes

BasicProcess([name, pid, ps_line, command_name])

Class representing a basic process, with name and pid.

Popen(args[, bufsize, executable, stdin, …])

Execute a child program in a new process.

Class Inheritance Diagram

Inheritance diagram of support.process.BasicProcess

support.rtc Package

Module for using the computer’s Real Time Clock device

Provides class RTC

The rtc time structure is:

struct rtc_time {
  int tm_sec;
  int tm_min;
  int tm_hour;
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_wday;     /\* unused \*/
  int tm_yday;     /\* unused \*/
  int tm_isdst;    /\* unused \*/};

Compiled C program ‘rtc_constants’ returns the addresses of the RTC registers for the RTC.

See ‘man rtc’ for documentation

From http://www.larsen-b.com/Article/221.html

Classes

RTC([signalHandler])

Class for the Real Time Clock device

Signaller([rtc, signalHandler, interval])

Class Inheritance Diagram

Inheritance diagram of support.rtc.RTC, support.rtc.Signaller

support.text Module

text - functions for handling text

Functions

basename(p)

Returns the final component of a pathname

clean_TeX(string)

Remove or replace math mode symbols like underscore

distance(a, b)

Calculates the Levenshtein distance between a and b.

get_version(fileroot, filetype)

Append an updated version number to a file

glob(pathname, *[, recursive])

Return a list of paths matching a pathname pattern.

isdir(s)

Return true if the pathname refers to an existing directory.

isfile(path)

Test whether a path is a regular file

longest_text(textlist)

Find the length of the longest string in a list

make_title(text)

turn a text string of words into a title by capitalizing each word

nocase_distance(aa, bb)

same as distance() but ignores case

remove_extra_spaces(data)

reduce multiple whitespaces to one

remove_html_tags(data)

remove HTML tags from text

select_files(pattern[, text, ftype, single])

Select files by glob pattern

send_email(msg_text, to[, Subject, From, …])

Send an e-mail message

splitext(p)

Split the extension from a pathname.

user_input(prompt, default)

Like ‘raw_input’ except that a default value can be specified.

support.threading_util Package

Functions

iterativeRun(run_fn)

A decorator for running functions repeatedly inside a PausableThread.

Classes

PausableThread([name])

A pausable stoppable thread.

Pause(pausable_thread)

A context manager for pausing threads.

PublisherThread(server[, thread_name, bus])

A barebones publisher thread.

Class Inheritance Diagram

Inheritance diagram of support.threading_util.pausable_thread.PausableThread, support.threading_util.pausable_thread.Pause, support.threading_util.publisher_thread.PublisherThread

support.threading_util.pausable_thread Module

Functions

iterativeRun(run_fn)

A decorator for running functions repeatedly inside a PausableThread.

Classes

Pause(pausable_thread)

A context manager for pausing threads.

PausableThread([name])

A pausable stoppable thread.

PausableThreadCallback(callback[, name])

A thread that runs the same callback over an over again, with some predetermined wait time.

Class Inheritance Diagram

Inheritance diagram of support.threading_util.pausable_thread.Pause, support.threading_util.pausable_thread.PausableThread, support.threading_util.pausable_thread.PausableThreadCallback

support.threading_util.publisher_thread Module

Classes

PausableThread([name])

A pausable stoppable thread.

PublisherThread(server[, thread_name, bus])

A barebones publisher thread.

Class Inheritance Diagram

Inheritance diagram of support.threading_util.publisher_thread.PublisherThread

support.weather Module

Functions

get_lat_lon(address, **kwargs)

Format response object from _make_geocoding_api_request.

get_current_weather(lat, lon[, mode])

Get the weather at a certain latitude and longitude

Indices and tables