SunPy util

sunpy.util Package

SunPy utility functions

Functions

common_base(objs) Find class that every item of objs is an instance of.
deprecated(since[, message, name, alternative]) Used to mark a function or class as deprecated.
expand_list(inp) Expand a list of lists.
expand_list_generator(inp)
get_sys_dict() Test which packages are installed on system.
merge(items[, key]) Given sorted lists of iterables, return new iterable that returns elements of all iterables sorted with respect to key.
minimal_pairs(one, other) Find pairs of values in one and other with minimal distance.
print_table(lst[, colsep, linesep])
replacement_filename(path) Return replacement path for already used path.
system_info() Takes dictionary from sys_info() and prints the contents in an attractive fashion.
to_signed(dtype) Return dtype that can hold data of passed dtype but is signed.
unique(itr[, key]) not documented yet

Classes

MetaDict(*args) A class to hold meta data associated with a Map derivative.
SunpyDeprecationWarning A warning class to indicate a deprecated feature.
SunpyUserWarning The primary warning class for Sunpy.
SunpyWarning The base warning class from which all Sunpy warnings should inherit.

Class Inheritance Diagram

Inheritance diagram of sunpy.util.metadata.MetaDict, sunpy.util.exceptions.SunpyDeprecationWarning, sunpy.util.exceptions.SunpyUserWarning, sunpy.util.exceptions.SunpyWarning

sunpy.util.cond_dispatch Module

Offer a callable object that dispatches based on arbitrary conditions and function signature. That means, whenever it is called, it finds the registered methods that match the input’s signature and then checks for user-defined conditions and types.

First, we need to create a new ConditionalDispatch

>>> from sunpy.util.cond_dispatch import ConditionalDispatch
>>> fun = ConditionalDispatch()

We then can start adding branches, in this case we add a branch for even integers, in which case the function applied is a multiplication by three.

>>> fun.add(lambda x: 3 * x, lambda x: x % 2 == 0, [int])

By adding the other branch (odd), the function can be used for all integers. In the case of an odd integer, we double the input. Please note that the system has no way of verifying the conditions are mutually exclusive. In some cases it can even be useful to use not mutually exclusive conditions, in which case the branch that was added the earliest is executed.

>>> fun.add(lambda x: 2 * x, lambda x: x % 2 == 1, [int])

We can verify this is working.

>>> fun(2)
6
>>> fun(3)
6

And that using a float, e.g., does not.

>>> fun(3.2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/florian/Projects/sunpy/sunpy/util/cond_dispatch.py", line 128, in __call__
    "There are no functions matching your input parameter "
TypeError: There are no functions matching your input parameter signature.

We can then add a branch for floats, giving the condition None that means that this branch is always executed for floats.

>>> fun.add(lambda y: 5 * y, None, [float])

Also note that the float branch takes y, while the integer branch takes x. Thus, if the user explicitly passes fun(x=1) using a keyword argument, only the integer branch is considered. This can be useful if the user wants control over which kind of data they are passing the the function.

>>> fun(2.0)
10.0
>>> fun(y=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/florian/Projects/sunpy/sunpy/util/cond_dispatch.py", line 128, in __call__
    "There are no functions matching your input parameter "
TypeError: There are no functions matching your input parameter signature.
>>> fun(y=2.5)
12.5
>>> fun(x=2)
6
>>> fun(x=2.5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/florian/Projects/sunpy/sunpy/util/cond_dispatch.py", line 128, in __call__
    "There are no functions matching your input parameter "
TypeError: There are no functions matching your input parameter signature.

Functions

run_cls((“foo”)(cls, *args, …)
matches_types(fun, types, args, kwargs) See if args and kwargs match are instances of types.
arginize(fun, a, kw) Turn args and kwargs into args by considering the function signature.
correct_argspec(fun) Remove first argument if method is bound.
matches_signature(fun, a, kw) Check whether function can be called with a as args and kw as kwargs.
fmt_argspec_types(fun, types[, start])

Class Inheritance Diagram

Inheritance diagram of sunpy.util.cond_dispatch.ConditionalDispatch

sunpy.util.config Module

SunPy configuration file functionality

Functions

load_config() Read the sunpyrc configuration file.
print_config() Print current configuration options

sunpy.util.create Module

Classes

Parent

Class Inheritance Diagram

Inheritance diagram of sunpy.util.create.Parent

sunpy.util.datatype_factory_base Module

Classes

BasicRegistrationFactory([…]) Generalized registerable factory type.
MultipleMatchError Exception for when too many candidate classes are found.
NoMatchError Exception for when no candidate class is found.
ValidationFunctionError Exception for when no candidate class is found.

Class Inheritance Diagram

Inheritance diagram of sunpy.util.datatype_factory_base.BasicRegistrationFactory, sunpy.util.datatype_factory_base.MultipleMatchError, sunpy.util.datatype_factory_base.NoMatchError, sunpy.util.datatype_factory_base.ValidationFunctionError

sunpy.util.multimethod Module

Multimethod implementation in pure Python.

Classes

TypeWarning
MultiMethod(get) A multimethod is a callable object that decides which code to execute based on the type of one or more of its arguments.

Class Inheritance Diagram

Inheritance diagram of sunpy.util.multimethod.TypeWarning, sunpy.util.multimethod.MultiMethod

sunpy.util.net Module

Functions

slugify(text[, delim, encoding]) Slugify given unicode text.
get_content_disposition(content_disposition) Get content disposition filename from given header.
get_filename(sock, url) Get filename from given urllib2.urlopen object and URL.
get_system_filename(sock, url[, default]) Get filename from given urllib2.urlopen object and URL.
get_system_filename_slugify(sock, url[, default]) Get filename from given urllib2.urlopen object and URL.
download_file(url, directory[, default, …]) Download file from url into directory.
download_fileobj(opn, directory[, url, …]) Download file from url into directory.
check_download_file(filename, remotepath, …) Downloads a file from remotepath to localpath if it isn’t there.
url_exists(url[, timeout]) Checks whether a url is online.

sunpy.util.progressbar Module

Classes

TTYProgressBar(n[, current, width, output]) A simple progress bar to visualize progress on a TTY (teletypewriter).

Class Inheritance Diagram

Inheritance diagram of sunpy.util.progressbar.TTYProgressBar

sunpy.util.xml Module

XML helper functions

Functions

xml_to_dict(xmlstring) Converts an XML string to a Python dictionary
node_to_dict(node) node_to_dict() scans through the children of node and makes a dictionary
get_node_text(node) scans through all children of node and gathers the text. if node has

Class Inheritance Diagram

Inheritance diagram of sunpy.util.xml.NotTextNodeError

sunpy.util.scraper Module

Classes

Scraper(pattern, **kwargs) A Scraper to scrap web data archives based on dates.

Class Inheritance Diagram

Inheritance diagram of sunpy.util.scraper.Scraper