Customizing SunPy

The sunpyrc file

Sunpy uses a sunpyrc configuration file to customize certain properties. You can control a number of key features of SunPy such as where your data will download to. SunPy looks for sunpyrc in two locations, in the following order:

  1. .sunpy/sunpyrc, for the user’s default customizations.
  2. INSTALL/sunpy/data/sunpyrc. You can find where SunPy is installed by printing out sunpy.__file__ after importing SunPy.

To display where the currently active sunpyrc file was loaded from, one can do the following:

>>> import sunpy
>>> sunpy.print_config()   

To maintain your own customizations place a copy of the default sunpyrc file into .sunpy. Do not edit the default file directly as every time you install or update SunPy, this file will be overwritten.

See below for the example config file.

Dynamic settings

You can also dynamically change the default settings in a python script or interactively from the python shell. All of the settings are stored in a Python ConfigParser instance called sunpy.config, which is global to the sunpy package. Settings can be modified directly, for example:

import sunpy
sunpy.config.set('downloads', 'download_dir', '/home/user/Downloads')

A sample sunpyrc file


; SunPy Configuration
; This is a sample sunpy configuration file - you can find a copy
; of it on your system in site-packages/sunpy/data/sunpyrc.  If you edit it
; there, please note that it will be overridden in your next install.
; If you want to keep a permanent local copy that will not be
; over-written, place it in HOME/.sunpy/sunpyrc (unix/linux
; like systems) and C:\Documents and Settings\yourname\.sunpy
; (win32 systems).
; Note that any relative filepaths specified in the SunPy configuration file
; will be relative to SunPy's working directory.

; General Options ;

; The SunPy working directory is the parent directory where all generated
; and download files will be stored.
; Default Value: <user's home directory>/sunpy
; working_dir = /home/$USER/sunpy

; Time Format to be used for displaying time in output (e.g. graphs)
; The default time format is based on ISO8601 (replacing the T with space)
; note that the extra '%'s are escape characters
time_format = %%Y-%%m-%%d %%H:%%M:%%S

; Downloads ;

; Location to save download data to. Path should be specified relative to the
; SunPy working directory.
; Default value: data/
;download_dir = /tmp
download_dir = data

; Location where the sample data will be downloaded. Path should be specified
; relative to the SunPy working directory.
sample_dir = data/sample_data

; Database ;

; Location to specify sunpy database parameters.
; The default url of the database location can specified here. The url of
; the database comprises the database driver, its location and name, as well
; as optional authentication parameters 
; Default value: sqlite:////<user's home directory>/sunpy/sunpydb.sqlite
; url = sqlite:////home/$USER/sunpy/sunpydb.sqlite