Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: New Cubes module #1078

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
fc30274
Created new branch to avoid weird commits
Jun 25, 2014
25b0a98
Fixed plot by wavelength, added plot by x-coordinate and conversion f…
Jun 26, 2014
c89a67d
fixed spectral_cube's __init__
Jun 26, 2014
417e0fb
The cube's header is now a dictionary, following sunpy convention, an…
Jun 27, 2014
6a5fd0f
Removed unused imports, added some missing docstrings
Jun 27, 2014
37aaaba
Spectral Cube doesn't use astropy spectral_cube anymore, in order to …
Jul 2, 2014
c218aa9
EIS now uses NDData instead of spectral_cube
Jul 2, 2014
4360c02
Merge remote-tracking branch 'upstream/master' into cubes
Jul 2, 2014
e557ea0
Fixed reindex_wcs, added test for it, PEP8 fixes to util.util while I…
Jul 3, 2014
bbcb0f5
test_util didn't commit for some reason...
Jul 3, 2014
de57664
fixed wrongly transposed array - spectral axis now always comes first.
Jul 3, 2014
fecc7a0
Added animation capabilities to cubes
Jul 3, 2014
2685126
Some tests added to spectral_cube
Jul 3, 2014
da757f0
Fixed choose slice functions to accept units, added _choose_wavelengt…
Jul 3, 2014
e72b364
Added tests for _choose_x_slice
Jul 3, 2014
4aed954
Minor cleanup - added some docstrings, renamed some variables to make…
Jul 5, 2014
e38f12d
Created wcs_util.py, added add_celestial_axis. Tests to follow.
Jul 8, 2014
8c4860c
Added a test for add_celestial_axis
Jul 8, 2014
4f59867
Renamed SpectralCube to Cube, to reflect the fact that they may not h…
Jul 8, 2014
f348025
Orient wcs and array now works for arbitrary axes. Some tests no long…
Jul 8, 2014
259e425
Fixed Choose_wavelength and x, added more tests
Jul 9, 2014
bb9a6d0
Reversed WCS to fit convention, added a test, fixed select_order to h…
Jul 10, 2014
3f32348
Fixed orient so that original axis correspondence is preserved.
Jul 10, 2014
503717b
Accidentally didn't commit cube.py.
Jul 10, 2014
3d2ebf8
Fixed reindex_wcs; added slice_to_lightcurve (still untested)
Jul 10, 2014
09e4b7d
Merge remote-tracking branch 'upstream/master' into cubes
Jul 10, 2014
1b028ef
Fixed warning and slice_to_lightcurve
Jul 11, 2014
5e2951a
Large commit: Most importantly, added numpy-style slicing and convers…
Jul 14, 2014
bb628e8
Merge remote-tracking branch 'upstream/master' into cubes
Jul 22, 2014
971ae33
Fixed some errors, added some tests (more to come)
Jul 23, 2014
f873c8b
Added more tests, minor fixes
Jul 23, 2014
55fa8ac
Fixed getitem error where some slices returned none; added another test
Jul 24, 2014
c3e7c08
refactored some methods into a new module, cube_utils
Jul 24, 2014
ae4694e
Moved CubeError to cube_utils
Jul 24, 2014
8b13f05
rewrote getitem to make it much more readable
Jul 24, 2014
b8e4bb6
Added a test for iter_isinstance
Jul 24, 2014
a85cf93
Merge remote-tracking branch 'upstream/master' into cubes
Jul 25, 2014
98eac06
Fixed reduce dim to create a copy of the object
Jul 25, 2014
76f4d44
Changed map slicing functionality to initialize the meta to a MapMeta…
Jul 28, 2014
8867be8
Added the _do_set=False kwarg to all WCS constructors to revert to as…
Jul 28, 2014
2d12438
Cleaned up sunpy.wcs in preparation for a (possible) extension
Jul 28, 2014
3f91b85
Merge remote-tracking branch 'upstream/master' into cubes
Jul 28, 2014
264cf65
Added WCS wrapper class for allowing unmatched celestial axes
Jul 31, 2014
7f04f68
Changed cube and cubeuutils to use sunpy.wcs.wcs.WCS
Jul 31, 2014
9dddae7
Changed EIS source class to use sunpy's WCS
Jul 31, 2014
5117e0e
Merge remote-tracking branch 'upstream/master' into cubes
Aug 4, 2014
0c46eaa
Started 4d capabilities. Lightcurve and spectrum still missing. Tests…
Aug 7, 2014
ba6654e
Merge remote-tracking branch 'upstream/master' into cubes
Aug 7, 2014
580a321
4d slice_to_spectrum added
Aug 7, 2014
7db64d2
Added 4D lightcurve slicing
Aug 8, 2014
29c4668
Added tests for 4D getitem
Aug 8, 2014
609ddfe
Merge remote-tracking branch 'upstream/master' into cubes
Aug 8, 2014
ddb8f0d
Added slicing by units. Tests to follow.
Aug 12, 2014
6613bca
Added a test for convert_point
Aug 12, 2014
cdeaeb4
Added test for convert_slice
Aug 13, 2014
3887960
Added test for pixelize_slice, enabled slicing by world coordinates
Aug 13, 2014
9985505
Added world coordinate slicing tests
Aug 13, 2014
9fa1e07
Minor changes, fixed _choose_wavelength
Aug 19, 2014
31b216e
Merge remote-tracking branch 'upstream/master' into cubes
Aug 26, 2014
75ccd2d
Added Changelog entry
Aug 26, 2014
8b23615
Added astropy quantity slicing to cube and spectrum; slicing by pixel…
Aug 26, 2014
7b2fd0f
Added quantity slicing to lightcurves, maps and spectrograms
Aug 29, 2014
f75db1a
Added check for aligned matrices during slicing
Sep 1, 2014
2ccf86b
Merge remote-tracking branch 'upstream/master' into cubes
Sep 1, 2014
a8284cb
Merge remote-tracking branch 'upstream/master' into cubes
Sep 6, 2014
3db674f
Added datatype guide
Sep 8, 2014
96313db
Merge remote-tracking branch 'upstream/master' into cubes
Sep 9, 2014
051952b
Merge remote-tracking branch 'upstream/master' into cubes
Sep 23, 2014
82ad51d
Merge remote-tracking branch 'upstream/master' into cubes
Sep 27, 2014
ec5c6ec
Merge remote-tracking branch 'upstream/master' into cubes
Sep 30, 2014
bfaa99f
Merge remote-tracking branch 'upstream/master' into cubes
Oct 5, 2014
2e05770
Merge remote-tracking branch 'upstream/master' into cubes
Oct 10, 2014
4fb0e8d
Merge remote-tracking branch 'upstream/master' into cubes
Oct 23, 2014
f9f3e6d
Merge remote-tracking branch 'upstream/master' into cubes
Nov 5, 2014
6d2a627
Merge remote-tracking branch 'upstream/master' into cubes
Nov 5, 2014
3ee8221
updated gitignore to include .spyderproject
mateoi Jun 29, 2015
fc2dd8b
Merge remote-tracking branch 'upstream/master'
mateoi Jun 29, 2015
9c4a4e9
Merge branch 'master' into cubes
mateoi Jun 29, 2015
2a5a3a9
Cleaned up a bit before starting work
mateoi Jul 1, 2015
8a2825a
Added shift_axis to spectrum - this way there can be a linear (or use…
mateoi Jul 1, 2015
28c19dc
Fixed all of the weird errors that have sprung up in the last year
mateoi Jul 2, 2015
9a3b463
Added test_spectrum
mateoi Jul 2, 2015
2b1a690
Merge remote branch 'upstream/master'
mateoi Jul 2, 2015
49ebc1e
Merge branch 'master' into cubes
mateoi Jul 2, 2015
33e9245
Merge remote branch 'upstream/master'
mateoi Jul 13, 2015
1c1b4c6
Merge branch 'master' into cubes
mateoi Jul 13, 2015
936a200
Merge remote branch 'upstream/master'
mateoi Jul 28, 2015
0c522c5
Merge branch 'master' into cubes
mateoi Jul 28, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ sunpy/data/sample/*.fit

### https://raw.github.com/github/gitignore/master/Global/OSX.gitignore

.DS_Store
.AppleDouble
.LSOverride

Expand Down Expand Up @@ -69,3 +68,4 @@ $RECYCLE.BIN/
*.msp


*.spyderworkspace
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Latest
* Added vso like querying feature to JSOC Client.
* Update to TimeRange API, removed t1 and t0, start and end are now read-only attributes
* Added ability to download level3 data for lyra Light Curve along with corresponding tests.
* Added 3D/4D Cubes module
* Added astropy.wcs.WCS subclass that supports unmatched celestial axes
* Added support for gzipped FITS files.
* Add STEREO HI Map subclass and color maps.
* Map.rotate() no longer crops any image data.
Expand Down
97 changes: 97 additions & 0 deletions doc/source/guide/data_types/cubes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
=====
Cubes
=====

SunPy Cubes are 3- or 4-dimensional arrays of continuous data with an associated coordinate system.
There are four possible cube types:: time and two solar dimensions (i.e. a time-series of maps); energy and two solar dimensions (i.e. a series of maps ordered by wavelength); time, energy and a single solar dimension (i.e. a timeseries cube); or a time, energy and two solar dimensions hypercube.
It is important to note that regardless of the data source used, the data held in the cube is ordered by the present dimension type:: the highest priority is assigned to time, then energy, and solar coordinates at the bottom. This means that if, for example, a cube is given solar-x, energy and solar-y as its dimensions, it will rearrange the axes and data to make it an energy-x-y cube. When more than one spatial dimansion is present, the oriiginal order is preserved.
This document is meant merely as an introduction; for the full documentation consult the API Reference.

------------
Data Support
------------
The cube datatype currently only supports EIS. Future datasources will be added.

1. Creating en EIS Cube
-----------------------
First of all, we need to initialize the current interactive python shell::

import sunpy
import sunpy.cube
from sunpy.cube.sources.eis import EISSpectralCube as eis
my_cubes = eis.read("/directory/file.fits")

This is assuming your FITS file's address is /directory/file.fits. EIS convention is to include several cubes in a single file, ordered by their principal wavelength. Therefore, my_cubes is a variable containing a python dictionary of cubes ordered by their principal wavelength.
Let's see a typical example::

In [5]: my_cubes.keys()
Out[5]: ['FE XV 284.160',
'SI VII 275.350',
'MG VI 270.400',
'FE XII 195.120',
'FE X 184.540',
'CA XVII 192.820',
'HE II 256.320',
'FE XIII 202.040',
'FE XII 186.880',
'FE XIII 203.830']
In [6]: my_cube = my_cubes['FE X 184.540']

The variable my_cube is now an EIS Spectral Cube.

2. Creating a Generic Cube
--------------------------
If you have your data and an associated WCS object, you can call the Cube constructor by doing::

my_generic_cube = Cube(data=my_data, wcs=my_wcs)

The internal rearrangement of data and coordinate system is done independently of the variables you put in, so they are not changed.
Note that, due to the way in which WCS objects are handled, wcs cannot be an astropy wcs object; it must be a SunPy WCS one.

3. Converting to other SunPy Datatypes
--------------------------------------
Cubes can be automatically converted to all other SunPy datatypes either pixel-wise or by using world coordinates.
There are two ways of achieving this:: Using the dedicated methods or by slicing the cube as if it were a numpy array. The dedicated methods, which are all called some variation of slice_to_map, slice_to_lightcurve, etc., are more flexible and powerful but at the same time more verbose. Consult the documentation for specifics.
Continuing from the example above, my_cube is a wavelength-solar y-solar x cube. This means that a slice along the energy axis yields an x-y slice - that's a map! Here's an example of one::

from astropy import units as u
my_map = my_cube[184.552 * u.Angstrom]
my_map.peek()

Numpy-style slicing supports almost the same syntax that numpy does, except using None as an index to create another axis. Ranges and increments are fully supported.
Note that you only have to provide the unit once per axis. That is::

my_cube[184.540 * u.Angstrom:184.550:0.05]

is just as valid as::

my_cube[184.540 * u.Angstrom:184.550 * u.Angstrom:0.05 * u.Angstrom]

However, you should keep in mind that units cannot be mixed, even between units that represent the same dimension.
The following table shows how slices are interpreted.

+------------+-----------------------------------+
| Datatype | Resulting Slice |
+============+===================================+
| Map | Celestial x and y |
+------------+-----------------------------------+
| Lightcurve |- Time (wavelength present in cube)|
| | |
| |- Wavelength and a range of time |
+------------+-----------------------------------+
| Spectrogram| Time and Energy |
+------------+-----------------------------------+
| Spectrum | Spatial or energy and spatial |
+------------+-----------------------------------+
| Cube | Any 3D result |
+------------+-----------------------------------+
| Numpy array| Any other slicing |
+------------+-----------------------------------+

4. Animating a cube
-------------------
You can view a cube like this::

my_cube.animate()

This creates a new window with a slider that you can adjust to travel between the different 2D slices.
1 change: 1 addition & 0 deletions sunpy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.spyderproject
7 changes: 7 additions & 0 deletions sunpy/cube/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'''SunPy Spectral Cubes'''

__author__ = 'Mateo Inchaurrandieta'
__email__ = 'mateo.inchaurrandieta@gmail.com'

from . cube import Cube
from . import cube_utils