Utilities (sunpy.util)

sunpy.util Package

Functions

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

Used to mark a function or class as deprecated.

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.

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.

system_info()

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

unique(itr[, key])

Return only unique elements of a sequence.

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.

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.

Class Inheritance Diagram

digraph inheritancec239ba0b61 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "MetaDict" [URL="../../api/sunpy.util.MetaDict.html#sunpy.util.MetaDict",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A class to hold metadata associated with a `sunpy.map.Map` derivative."]; "OrderedDict" -> "MetaDict" [arrowsize=0.5,style="setlinewidth(0.5)"]; "NoMapsInFileError" [URL="../../api/sunpy.util.NoMapsInFileError.html#sunpy.util.NoMapsInFileError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An error raised when a file is opened and no maps are found."]; "OrderedDict" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Dictionary that remembers insertion order"]; "SunpyDeprecationWarning" [URL="../../api/sunpy.util.SunpyDeprecationWarning.html#sunpy.util.SunpyDeprecationWarning",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A warning class to indicate a deprecated feature."]; "SunpyWarning" -> "SunpyDeprecationWarning" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SunpyMetadataWarning" [URL="../../api/sunpy.util.SunpyMetadataWarning.html#sunpy.util.SunpyMetadataWarning",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Warning class for cases metadata is missing."]; "SunpyWarning" -> "SunpyMetadataWarning" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SunpyPendingDeprecationWarning" [URL="../../api/sunpy.util.SunpyPendingDeprecationWarning.html#sunpy.util.SunpyPendingDeprecationWarning",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A warning class to indicate a soon-to-be deprecated feature."]; "SunpyWarning" -> "SunpyPendingDeprecationWarning" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SunpyUserWarning" [URL="../../api/sunpy.util.SunpyUserWarning.html#sunpy.util.SunpyUserWarning",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The primary warning class for Sunpy."]; "SunpyWarning" -> "SunpyUserWarning" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SunpyWarning" [URL="../../api/sunpy.util.SunpyWarning.html#sunpy.util.SunpyWarning",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The base warning class from which all Sunpy warnings should inherit."]; }

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

digraph inheritance3920b86d35 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "BasicRegistrationFactory" [URL="../../api/sunpy.util.datatype_factory_base.BasicRegistrationFactory.html#sunpy.util.datatype_factory_base.BasicRegistrationFactory",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Generalized registerable factory type."]; "MultipleMatchError" [URL="../../api/sunpy.util.datatype_factory_base.MultipleMatchError.html#sunpy.util.datatype_factory_base.MultipleMatchError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Exception for when too many candidate classes are found."]; "NoMatchError" [URL="../../api/sunpy.util.datatype_factory_base.NoMatchError.html#sunpy.util.datatype_factory_base.NoMatchError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Exception for when no candidate class is found."]; "ValidationFunctionError" [URL="../../api/sunpy.util.datatype_factory_base.ValidationFunctionError.html#sunpy.util.datatype_factory_base.ValidationFunctionError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Exception for when no candidate class is found."]; }

sunpy.util.net Module

This module provides general net utility functions.

Functions

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

NotTextNodeError

Class Inheritance Diagram

digraph inheritancebc48ce8133 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "NotTextNodeError" [URL="../../api/sunpy.util.xml.NotTextNodeError.html#sunpy.util.xml.NotTextNodeError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }

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

digraph inheritance8944e4337e { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Directive" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for reStructuredText directives."]; "Generate" [URL="../../api/sunpy.util.sphinx.generate.Generate.html#sunpy.util.sphinx.generate.Generate",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Custom directive to include raw output generated using supplied Python code"]; "Directive" -> "Generate" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

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.

sunpy.util.types Module

A collection of base classes to use to shortcut having to import things.

This is used to provide a base class which can be imported into two locations to identify a type, so that either location doesn’t have to import the other.

Classes

DatabaseEntryType()

A base class for sunpy.database.tables.DatabaseEntry.

Class Inheritance Diagram

digraph inheritance503d57e175 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DatabaseEntryType" [URL="../../api/sunpy.util.types.DatabaseEntryType.html#sunpy.util.types.DatabaseEntryType",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A base class for `sunpy.database.tables.DatabaseEntry`."]; }