.. _marvin-spaxel: Spaxel ====== Getting and working with spaxels -------------------------------- The basics of spaxels has already been covered in various sections of the :ref:`Cube ` or :ref:`Maps >> from marvin.tools import Cube >>> cube = Cube('8485-1901') >>> spaxel = cube[17,17] >>> spaxel Each tool also provides a ``getSpaxel`` method, which allows access to a ``Spaxel`` with more fine-grained control. With ``getSpaxel``, the x, y spaxel coordinates are by default set to a central origin, with ``xyorig='center'``, indicating (0,0) as the spaxel at the center of the IFU. With ``xyorig='center'``, positive x is to the right, and positive y is up. :: >>> # access the central spaxel >>> cube.getSpaxel(x=0, y=0) >>> # access a spaxel 5 pixels north-east from the center >>> cube.getSpaxel(x=-5,y=5) You can change the ``xyorig`` as well. >>> # access the central spaxel at 0,0 >>> cube.getSpaxel(x=0, y=0) >>> # access the lower left spaxel using array index 0,0 >>> cube.getSpaxel(x=0, y=0, xyorig='lower') You can also access a spaxel by RA, Dec. :: >>> # access a spaxel by coordinate RA, Dec >>> cube.getSpaxel(ra=232.543, dec=48.691) Loading Attributes on Spaxels ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ By default, spaxels automatically load the attributes of the tool from which it is extracted. This is indicated with the **loaded** keyword in the **repr**. Spaxels can load ``cube``, ``maps``, or ``modelcube`` attributes. A loaded spaxel populates a ``{tool}_quantities`` attribute containing all the properties relevant for that tool. All attributes in the ``{tool}_quantities`` are also populated in the objects ``__dir__`` and available with iPython tab completion feature. Accessing a spaxel via a ``Cube`` object only loads ``Cube`` attributes. :: >>> # accessing via a Cube indicates loaded=cube >>> from marvin.tools import Cube >>> cube = Cube('8485-1901') >>> spaxel = cube[17,17] >>> # access the loaded cube properties >>> spaxel.cube_quantities FuzzyDict([('flux', ), ('dispersion', ), ('dispersion_prepixel', ), ('spectral_resolution', ), ('spectral_resolution_prepixel', )]) >>> # try tab completing to access dispersion >>> spaxel.dispersion Accessing from a ``Maps`` only loads the ``Maps`` attributes. :: >>> # accessing via a Maps indicates loaded=maps >>> maps = cube.getMaps() >>> spaxel = maps[17,17] >>> # access the loaded maps properties >>> spaxel.maps_quantities FuzzyDict([('spx_skycoo_on_sky_x', ), ('spx_skycoo_on_sky_y', ), ('spx_ellcoo_elliptical_radius', ), ....]) >>> # notice the empty cube_quantites >>> spaxel.cube_quantities FuzzyDict() You can load additional attributes using the ``load`` method on a spaxel. ``load`` takes either **cube**, **maps**, or **modelcube** as input. Let's load the ``cube_quantites`` from the spaxel in the previous example. :: >>> # load the cube quantities from the maps spaxel >>> spaxel.load('cube') >>> spaxel Now **loaded** is set to ``cube/maps`` indicating that both quantities are loaded and available. :: >>> spaxel.cube_quantities FuzzyDict([('flux', ), ('dispersion', ), ('dispersion_prepixel', ), ('spectral_resolution', ), ('spectral_resolution_prepixel', )]) You can also load multiple attributes when accessing a spaxel with the ``getSpaxel`` method on tools, by setting either the ``cube``, ``maps``, or ``modelcube`` keyword to ``True``. :: # load a spaxel from a cube also loading the maps quantities >>> spaxel = cube.getSpaxel(x=0,y=0, maps=True) >>> spaxel DataModels ---------- Spaxels have both the DRP and DAP datamodels attached, in the ``datamodels.drp`` and ``datamodels.dap`` attributes, respectively. :: >>> # access the drp datamodel >>> spaxel.datamodel.drp Working with Bins ----------------- All ``maps`` and ``modelcube`` properties contain a ``bin`` attribute, providing relevant information about the bin the spaxel belongs to. See the :ref:`Binning ` section for more information. Let's look at the bin info for the central spaxel from the previous example. :: >>> # access the bin info for stellar_velocity >>> stvel = spaxel.stellar_vel >>> stvel.bin The central spaxel has a binid of 0, with this spaxel the only one belonging in that bin. Let's look at the bin information for H-alpha flux. This bin also only has one spaxel in it. :: >>> spaxel.emline_gflux_ha_6564.bin The ``BinInfo`` also provides a convenience method, ``get_bin_spaxels``, for getting all spaxels belonging to that bin. These spaxels are unloaded by default. :: >>> stvel.bin.get_bin_spaxels() [