casagui.utils
General utility functions used by the casagui tools and applications.
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 |
Package Contents
- casagui.utils.path_to_url(path)
Convert a single filesystem path to a URL.
If the string specified in the
pathparameter exists. It is turned into a fully qualified path and converted to a URL and returned. Ifpathdoes not exist,pathis returned unchanged.- Parameters:
path (str) – path to be checked and expanded
- Returns:
pathconverted to a URL ifpathexists, otherwisepathunchanged- Return type:
str
- casagui.utils.find_ws_address(address='127.0.0.1')
Find free port on
addressnetwork and return a tuple withaddressand 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
iterableinto two lists based onpredpredicate.
- 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
printfunction takes. The primary difference is that the output will go tostderrand 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
Trueif we have internet connectivity andFalseif we do not.
- casagui.utils.ranges(iterable, order=sorted, key=lambda x: ...)
collect elements of
iterableinto tuple ranges where each tuple represents a concesecutive range within the iterable.keycan 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.
iterablecan be a sequence of values that can be subtracted or a list of more complex values where the functionkeyreturns the key to be used for ordering.iterableis ordered byorderwhich by default sortsiterable.
- casagui.utils.expand_range_incl(r)
expand the tuple supplied as
rinto 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
masksandpolyskeys. The values formasksare the polygon references for each channel and the values forpolyscontain 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
csysandshapewhich describes the coordinate system to be used for creating world coordinate coordinates. Theshapeis 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:
objparameter- Return type:
object