Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update to the docs for new config file capability #147

Merged
merged 3 commits into from

1 participant

This page is out of date. Refresh to see the latest.
View
59 doc/source/guide/customization.rst
@@ -0,0 +1,59 @@
+.. _customizing-matplotlib:
+
+**********************
+Customizing sunpy
+**********************
+
+.. _customizing-with-sunpyrc-files:
+
+The :file:`sunpyrc` file
+=============================
+
+sunpy uses :file:`sunprc` configuration files to customize all kinds
+of properties. You can control a number of key features of sunpy such as
+where your data will download. sunpy looks for :file:`sunpy` in three
+locations, in the following order:
+
+1. :file:`.sunpy/sunprc`, for the user's default customizations. See
+ :ref:`locating-sunpy-config-dir`.
+2. :file:`{INSTALL}/sunpy/data/sunprc`, where :file:`{INSTALL}`
+ is something like :file:`/usr/lib/python2.5/site-packages` on Linux, and
+ maybe :file:`C:\\Python25\\Lib\\site-packages` on Windows. Every time you
+ install sunpy, this file will be overwritten, so if you want your
+ customizations to be saved, please move this file to your :file:`.sunpy`
+ directory.
+
+To display where the currently active :file:`sunpyrc` file was
+loaded from, one can do the following::
+
+ >>> import sunpy
+ >>> sunpy.sunpy_configfile()
+ '/home/foo/.sunpy/sunpyrc'
+
+See below for a sample :ref:`sunpy file<sunpyrc-sample>`.
+
+.. _customizing-with-dynamic-settings:
+
+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
+dictionary-like variable called :data:`sunpy.configs`, which is global to
+the sunpy package. Configs can be modified directly, for example::
+
+ import sunpy
+ sunpy.config['data.save'] = True
+ sunpy.config['data.location'] = '/home/foo/desktop/'
+
+
+.. sunpyrc-sample:
+
+A sample sunpyrc file
+--------------------------------------------------------------------
+
+.. htmlonly::
+
+ `(download) <../_static/sunpyrc>`__
+
+.. literalinclude:: ../../lib/sunpy/data/sunpyrc
View
2  doc/source/guide/index.rst
@@ -9,5 +9,7 @@ Welcome to the SunPy User Guide!
installation/index
tutorial
+ customization
+ troubleshooting
.. overview
View
100 doc/source/guide/troubleshooting.rst
@@ -0,0 +1,100 @@
+.. _troubleshooting-faq:
+
+***************
+Troubleshooting
+***************
+
+.. contents::
+ :backlinks: none
+
+.. _sunpy-version:
+
+Obtaining sunpy version
+============================
+
+To find out your sunpy version number, import it and print the
+``__version__`` attribute::
+
+ >>> import sunpy
+ >>> matplotlib.__version__
+ '0.1'
+
+
+.. _locating-sunpy-install:
+
+:file:`sunpy` install location
+===================================
+
+You can find what directory sunpy is installed in by importing it
+and printing the ``__file__`` attribute::
+
+ >>> import sunpy
+ >>> sunpy.__file__
+ '/home/jdhunter/dev/lib64/python2.5/site-packages/matplotlib/__init__.pyc'
+
+.. _locating-matplotlib-config-dir:
+
+:file:`.sunpy` directory location
+======================================
+
+Each user has a :file:`.sunpy/` directory which may contain a
+:ref:`sunpyrc <customizing-with-sunpyrc-files>` file. To locate your :file:`.sunpy/`
+directory, use :func:`matplotlib.get_configdir`::
+
+ >>> import sunpy as sun
+ >>> sun.get_configdir()
+ '/home/moon/.matplotlib'
+
+On unix-like systems, this directory is generally located in your
+:envvar:`HOME` directory. On windows, it is in your documents and
+settings directory by default::
+
+ >>> import sunpy
+ >>> sunpy.get_configdir()
+ 'C:\\Documents and Settings\\jdhunter\\.sunpy'
+
+If you would like to use a different configuration directory, you can
+do so by specifying the location in your :envvar:`SUNPY_CONFIGDIR`
+environment variable -- see
+:ref:`setting-linux-osx-environment-variables`.
+
+
+.. _reporting-problems:
+
+Report a problem
+================
+
+If you are having a problem with matplotlib, search the mailing
+lists first: it is possible that someone else has already run into
+your problem.
+
+If not, please provide the following information in your e-mail to the
+`mailing list
+<http://lists.sourceforge.net/mailman/listinfo/matplotlib-users>`_:
+
+ * your operating system; (Linux/UNIX users: post the output of ``uname -a``)
+
+ * sunpy version::
+
+ python -c `import matplotlib; print matplotlib.__version__`
+
+ * where you obtained sunpy.
+
+ * any customizations to your ``sunpyrc`` file (see
+ :ref:`customizing-sunpyrc`).
+
+ * if the problem is reproducible, please try to provide a *minimal*,
+ standalone Python script that demonstrates the problem. This is
+ *the* critical step. If you can't post a piece of code that we
+ can run and reproduce your error, the chances of getting help are
+ significantly diminished. Very often, the mere act of trying to
+ minimize your code to the smallest bit that produces the error
+ will help you find a bug in *your* code that is causing the
+ problem.
+
+
+You will likely get a faster response writing to the mailing list than
+filing a bug in the bug tracker. Most developers check the bug
+tracker only periodically. If your problem has been determined to be
+a bug and can not be quickly solved, you may be asked to file a bug in
+the tracker so the issue doesn't get lost.
View
13 sunpy/__init__.py
@@ -104,6 +104,19 @@ def get_configdir():
#get_configdir = verbose.wrap('CONFIGDIR=%s', _get_configdir, always=False)
+
+def sunpy_configfile():
+ """
+ Give the name of the currently used configuration file.
+ """
+ config_path = get_configdir()
+ if os.path.exists(config_path + '/' + config_filename):
+ return config_path + '/' + config_filename
+ else:
+ module_dir = os.path.dirname(sunpy.__file__)
+ return module_dir + '/data/sunpyrc'
+
+
def read_configfile():
"""
Read the sunpyrc configuration file. If one does not exists in the user's
View
129 sunpy/cm/cm.py
@@ -3,13 +3,10 @@
"""
from __future__ import absolute_import
-__all__ = ["get_cmap", "show_colormaps", "test_equalize"]
-
+__all__ = ["get_cmap", "show_colormaps"]
+
import numpy as np
-from matplotlib import pylab
-import matplotlib.colors as colors
import matplotlib.pyplot as plt
-import matplotlib.cbook as cbook
import matplotlib.cm as cm
from sunpy.cm import _cm
@@ -49,9 +46,10 @@
'sohoeit304': sohoeit304,
'soholasco2': soholasco2,
'soholasco3': soholasco3,
- 'rhessi': cm.jet #pylint: disable=E1101
+ 'rhessi': cm.jet # pylint: disable=E1101
}
+
def get_cmap(name='sdoaia94'):
"""Get a colormap.
@@ -71,7 +69,7 @@ def get_cmap(name='sdoaia94'):
--------
>>> import sunpy.cm as cm
>>> colormap = cm.get_cmap(name = 'sdoaia94')
-
+
Reference
---------
| http://matplotlib.sourceforge.net/api/cm_api.html
@@ -82,6 +80,7 @@ def get_cmap(name='sdoaia94'):
else:
raise ValueError("Colormap %s is not recognized" % name)
+
def show_colormaps():
"""Displays a plot of the custom color maps supported in SunPy.
@@ -100,78 +99,78 @@ def show_colormaps():
--------
>>> import sunpy.cm as cm
>>> cm.show_colormaps()
-
+
Reference
---------
"""
maps = sorted(cmlist)
nmaps = len(maps) + 1
-
- a = np.linspace(0, 1, 256).reshape(1, -1) #pylint: disable=E1103
+
+ a = np.linspace(0, 1, 256).reshape(1, -1) # pylint: disable=E1103
a = np.vstack((a, a))
-
+
fig = plt.figure(figsize=(5, 10))
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
- for i,name in enumerate(maps):
+ for i, name in enumerate(maps):
ax = plt.subplot(nmaps, 1, i + 1)
plt.axis("off")
plt.imshow(a, aspect='auto', cmap=get_cmap(name), origin='lower')
pos = list(ax.get_position().bounds)
- fig.text(pos[0] - 0.01, pos[1], name, fontsize=10,
+ fig.text(pos[0] - 0.01, pos[1], name, fontsize=10,
horizontalalignment='right')
plt.show()
-def test_equalize(data):
- """Returns a color map which performs histogram equalization on the data.
-
- Parameters
- ----------
- data : ndarray
-
- Returns
- -------
- value : matplotlib colormap
-
- See Also
- --------
-
- Examples
- --------
- >>> import sunpy.cm as cm
- >>> cm.test_equalize()
-
- Reference
- ---------
- | http://matplotlib.sourceforge.net/api/cm_api.html
-
- .. warning:: this function is under development
-
- .. todo:: finish coding this function!
-
- """
- dfile = cbook.get_sample_data('s1045.ima', asfileobj=False)
-
- im = np.fromstring(file(dfile, 'rb').read(), np.uint16).astype(float)
- im.shape = 256, 256
-
- #imshow(im, ColormapJet(256))
- #imshow(im, cmap=cm.jet)
-
- imvals = np.sort(im.flatten())
- lo = imvals[0]
- hi = imvals[-1]
- steps = (imvals[::len(imvals)/256] - lo) / (hi - lo)
- num_steps = float(len(steps))
- interps = [(s, idx/num_steps, idx/num_steps) for idx, s in enumerate(steps)]
- interps.append((1, 1, 1))
- cdict = {'red': interps,
- 'green': interps,
- 'blue': interps}
- histeq_cmap = colors.LinearSegmentedColormap('HistEq', cdict)
- pylab.figure()
- pylab.imshow(im, cmap=histeq_cmap)
- pylab.title('histeq')
- pylab.show()
-
+#def test_equalize(data):
+# """Returns a color map which performs histogram equalization on the data.
+#
+# Parameters
+# ----------
+# data : ndarray
+#
+# Returns
+# -------
+# value : matplotlib colormap
+#
+# See Also
+# --------
+#
+# Examples
+# --------
+# >>> import sunpy.cm as cm
+# >>> cm.test_equalize()
+#
+# Reference
+# ---------
+# | http://matplotlib.sourceforge.net/api/cm_api.html
+#
+# .. warning:: this function is under development
+#
+# .. todo:: finish coding this function!
+#
+# """
+# dfile = cbook.get_sample_data('s1045.ima', asfileobj=False)
+#
+# im = np.fromstring(file(dfile, 'rb').read(), np.uint16).astype(float)
+# im.shape = 256, 256
+#
+# #imshow(im, ColormapJet(256))
+# #imshow(im, cmap=cm.jet)
+#
+# imvals = np.sort(im.flatten())
+# lo = imvals[0]
+# hi = imvals[-1]
+# steps = (imvals[::len(imvals)/256] - lo) / (hi - lo)
+# num_steps = float(len(steps))
+# interps = [(s, idx/num_steps, idx/num_steps) for idx,
+# s in enumerate(steps)]
+# interps.append((1, 1, 1))
+# cdict = {'red': interps,
+# 'green': interps,
+# 'blue': interps}
+# histeq_cmap = colors.LinearSegmentedColormap('HistEq', cdict)
+# pylab.figure()
+# pylab.imshow(im, cmap=histeq_cmap)
+# pylab.title('histeq')
+# pylab.show()
View
15 sunpy/map/basemap.py
@@ -223,6 +223,21 @@ def __add__(self, other):
return result
+ def __repr__(self):
+ output = "SunPy Map\n"
+ output += "---------\n"
+ output += "Observatory:\t" + self.observatory + "\n"
+ output += "Instrument:\t" + self.instrument + "\n"
+ output += "Detector:\t" + self.detector + "\n"
+ output += "Measurement:\t" + str(self.measurement) + "\n"
+ output += "Obs date:\t" + self.date.strftime("%Y-%m-%d %H:%M:%S") + "\n"
+ #output += "Coordinate System: " + self.coordinate_system + "\n"
+ output += "dt:\t\t" + str(self.exposure_time) + "\n"
+ output += "Dimension:\t[" + str(self.shape[0]) + ', ' + str(self.shape[1]) + "]\n"
+ output += "[dx, dy] =\t[" + str(self.scale['x']) + ', ' + str(self.scale['y']) + "]\n"
+
+ return output + "\n" + super(BaseMap, self).__repr__()
+
def __sub__(self, other):
"""Subtract two maps. Currently does not take into account the
alignment between the two maps.
Something went wrong with that request. Please try again.