Utilities (sunpy.util)#

sunpy.util Package#

Functions#

cached_property_based_on(attr_name)

A decorator to cache the value of a property based on the output of a different class attribute.

check_arithmetic_compatibility(func)

A decorator to check if an arithmetic operation can be performed between a map instance and some other operation.

deprecate_positional_args_since([func])

Decorator for methods that issues warnings for positional arguments.

deprecated(since[, message, name, ...])

Used to mark a function or class as deprecated.

deprecated_renamed_argument(old_name, ...[, ...])

Deprecate a _renamed_ or _removed_ function argument.

dict_keys_same(list_of_dicts)

Makes sure that a list of dictionaries all have the same keys.

expand_list(inp)

Expand a list of lists or tuples.

expand_list_generator(inp)

find_dependencies([package, extras])

List installed and missing dependencies.

fix_duplicate_notes(subclass_doc, cls_doc)

Returns a new documentation string such that there are notes section duplication in in Map subclasses.

get_keywords(func)

Returns a set of keyword names from func's signature.

get_set_methods(obj)

Returns a set of keyword names that can be handled by an object's set_... methods.

get_width()

Gets the width of the current terminal.

hash_file(path)

Returns the SHA-256 hash of a file.

missing_dependencies_by_extra([package, ...])

Get all the specified extras for a package and report any missing dependencies.

replacement_filename(path)

Return a replacement path if input path is currently in use.

sunpycontextmanager(func)

A decorator that tracks the entry and exit of a context manager, setting the key's value to True on entry and False on exit.

system_info()

Prints ones' system info in an "attractive" fashion.

unique(itr[, key])

Return only unique elements of a sequence.

warn_connection(msg[, stacklevel])

Raise a SunpyConnectionWarning.

warn_deprecated(msg[, stacklevel])

Raise a SunpyDeprecationWarning.

warn_metadata(msg[, stacklevel])

Raise a SunpyMetadataWarning.

warn_user(msg[, stacklevel])

Raise a SunpyUserWarning.

Classes#

MetaDict(*args[, save_original])

A class to hold metadata associated with a sunpy.map.Map derivative.

NoMapsInFileError

An error raised when a file is opened and no maps are found.

SunpyConnectionWarning

A warning class to indicate a connection warning.

SunpyDeprecationWarning

A warning class to indicate a deprecated feature.

SunpyMetadataWarning

Warning class for cases metadata is missing.

SunpyPendingDeprecationWarning

A warning class to indicate a soon-to-be deprecated feature.

SunpyUserWarning

The primary warning class for Sunpy.

SunpyWarning

The base warning class from which all Sunpy warnings should inherit.

add_common_docstring([append, prepend])

A function decorator that will append and/or prepend an addendum to the docstring of the target function.

Class Inheritance Diagram#

Inheritance diagram of sunpy.util.metadata.MetaDict, sunpy.util.exceptions.NoMapsInFileError, sunpy.util.exceptions.SunpyConnectionWarning, sunpy.util.exceptions.SunpyDeprecationWarning, sunpy.util.exceptions.SunpyMetadataWarning, sunpy.util.exceptions.SunpyPendingDeprecationWarning, sunpy.util.exceptions.SunpyUserWarning, sunpy.util.exceptions.SunpyWarning, sunpy.util.decorators.add_common_docstring

sunpy.util.config Module#

This module provides SunPy’s configuration file functionality.

Functions#

load_config()

Read the "sunpyrc" configuration file.

copy_default_config([overwrite])

Copies the default sunpy config file to the user's config directory.

print_config()

Print current configuration options.

sunpy.util.datatype_factory_base Module#

This module provides the base registration factory used for all SunPy data/net factories.

Classes#

BasicRegistrationFactory([...])

Generalized registerable factory type.

NoMatchError

Exception for when no candidate class is found.

MultipleMatchError

Exception for when too many candidate classes are 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.NoMatchError, sunpy.util.datatype_factory_base.MultipleMatchError, sunpy.util.datatype_factory_base.ValidationFunctionError

sunpy.util.net Module#

This module provides general net utility functions.

Functions#

parse_header(line)

Parse a Content-type like header.

slugify(text[, delim])

Slugify given unicode text.

get_content_disposition(content_disposition)

Get the content disposition filename from given header.

get_filename(sock, url)

Get filename from given urlopen object and URL.

get_system_filename(sock, url[, default])

Get filename from given urlopen object and URL.

download_file(url, directory[, default, ...])

Download a file from a url into a directory.

download_fileobj(opn, directory[, url, ...])

Download a file from a url into a directory.

sunpy.util.xml Module#

This module provides XML helper functions.

Functions#

xml_to_dict(xmlstring)

Converts an XML string to a Python dictionary.

node_to_dict(node)

Scans through the children of the node and makes a dictionary from the content.

get_node_text(node)

Scans through all children of Element node and gathers the text.

Classes#

Class Inheritance Diagram#

Inheritance diagram of sunpy.util.xml.NotTextNodeError

sunpy.util.sphinx Package#

Helpers and extensions for sphinx.

This subpackage contains two sphinx directives:

  • .. generate:: which includes raw output generated by a Python script into a .. raw:: block. This can be used to for example, include HTML output into the built docs.

  • .. changelog:: which renders the latest changelog with towncrier and includes it in the documentation.

To use them add 'sunpy.util.sphinx.generate' and 'sunpy.util.sphinx.changelog' to the extensions list in your conf.py file.

sunpy.util.sphinx.generate Module#

Classes#

Generate(name, arguments, options, content, ...)

Custom directive to include raw output generated using supplied Python code

Class Inheritance Diagram#

Inheritance diagram of sunpy.util.sphinx.generate.Generate

sunpy.util.functools Module#

This file defines wrappers and variants of things in the functools standard lib.

Functions#

seconddispatch(func)

A variant of functools.singledispatch which dispatches on type of the second argument.