casagui.utils
General utility functions used by the casagui
tools and applications.
Package Contents
Functions
|
Convert a single filesystem path to a URL. |
|
Find free port on |
|
Split |
|
standard method for reporting errors which do not result in aborting out of python |
|
standard method for reporting (optional) package import failure |
check to see if an active network with general internet connectivity |
|
|
collect elements of |
|
split iterable into contiguous index sequence, i.e. reduce consecutive index runs |
expand the tuple supplied as |
|
|
Convert stokes axis index to alphabetic value. |
|
Convert masks in standard format (as defined by |
|
Given an object and a set of keyword arguments, set the attributes |
- casagui.utils.path_to_url(path)
Convert a single filesystem path to a URL.
If the string specified in the
path
parameter exists. It is turned into a fully qualified path and converted to a URL and returned. Ifpath
does not exist,path
is returned unchanged.- Parameters:
path (str) – path to be checked and expanded
- Returns:
path
converted to a URL ifpath
exists, otherwisepath
unchanged- Return type:
str
- casagui.utils.find_ws_address(address='127.0.0.1')
Find free port on
address
network and return a tuple withaddress
and port numberThis function uses the low level socket function to find a free port and return a tuple representing the address plus port number.
- Parameters:
address (str) – network to be probed for an available port
- Returns:
network address (str) and port number (int)
- Return type:
tuple of str and int
- casagui.utils.partition(pred, iterable)
Split
iterable
into two lists based onpred
predicate.
- casagui.utils.error_msg(*args, **kwargs)
standard method for reporting errors which do not result in aborting out of python
This function takes the standard set of arguments that the python
print
function takes. The primary difference is that the output will go tostderr
and perhaps other error logs.
- casagui.utils.warn_import(package)
standard method for reporting (optional) package import failure
- Parameters:
package (str) – name of a package whose attempted import failed
- casagui.utils.have_network()
check to see if an active network with general internet connectivity is available. returns
True
if we have internet connectivity andFalse
if we do not.
- casagui.utils.ranges(iterable, order=sorted, key=lambda x: ...)
collect elements of
iterable
into tuple ranges where each tuple represents a concesecutive range within the iterable.key
can be used to provide ranges for other objects wherekey(element)
returns the key to be used for sorting into ranges
- casagui.utils.contiguous_ranges(iterable, order=sorted, key=lambda x: ...)
split iterable into contiguous index sequence, i.e. reduce consecutive index runs to a tuple containing the first and last.
iterable
can be a sequence of values that can be subtracted or a list of more complex values where the functionkey
returns the key to be used for ordering.iterable
is ordered byorder
which by default sortsiterable
.
- casagui.utils.expand_range_incl(r)
expand the tuple supplied as
r
into a range which includes the first and last elementr
- casagui.utils.index_to_stokes(index: int)
Convert stokes axis index to alphabetic value.
- Parameters:
index (int) – enumerated index defining stokes value.
- Returns:
String indicating stokes value.
- Return type:
str
- casagui.utils.convert_masks(masks: dict, coord='pixel', cdesc=None) list
Convert masks in standard format (as defined by
CubeMask.jsmask_to_raw
) into other formats like list of CRTF, single region, etc.- Parameters:
masks (dict) – Dictionary containing
masks
andpolys
keys. The values formasks
are the polygon references for each channel and the values forpolys
contain the points making up each polygon.coord (str) – Coordinate system that should be used in the returned masks. Allowed values are ‘pixel’.
cdesc (dict) – Dictionary containing
csys
andshape
which describes the coordinate system to be used for creating world coordinate coordinates. Theshape
is required along with the coordinate system for coordinate conversion.
- casagui.utils.set_attributes(obj, **kw)
Given an object and a set of keyword arguments, set the attributes in the object that correspond to the keywords to the specified values.
- Parameters:
obj (object) – Object whose attributes should be set
kw (keyword and object) – Attributes to be set
- Returns:
obj
parameter- Return type:
object