Marvin internals (marvin.core)

This section describes how Marvin works internally. Most users do not need to understand all of these details. However, they are important if you plan to write contributed code or if you are forking Marvin.

Regardless of how you use Marvin, it is always a good idea to have a general understanding of the configuration system and the data access modes.


MarvinToolsClass is the main class from which most Marvin tool classes subclass (e.g., Cube or Maps). It encapsulates the data access decision tree and implements high level methods such as and MarvinToolsClass._getFullPath for using the tree product to determine paths and download files. In general, any class that represents a file should subclass from MarvinToolsClass.

MarvinToolsClass uses abc.ABCMeta as a metaclass to mark abstractmethods. Any subclass must override and define MarvinToolsClass._getFullPath and MarvinToolsClass._set_datamodel.

Generic methods for pickling and unpickling the subclassed objects are implemented in and MarvinToolsClass.restore. While these work in most cases, depending on the specifics of the subclass some additional handling may be necessary.

class, filename=None, mangaid=None, plateifu=None, mode=None, data=None, release=None, drpall=None, download=None)[source]

Marvin tools main base class.

This super class implements the decision tree for using local files, database, or remote connection when initialising a Marvin tools object.

  • input (str) – A string that can be a filename, plate-ifu, or mangaid. It will be automatically identified based on its unique format. This argument is always the first one, so it can be defined without the keyword for convenience.

  • filename (str) – The path of the file containing the file to load. If set, input is ignored.

  • mangaid (str) – The mangaid of the file to load. If set, input is ignored.

  • plateifu (str) – The plate-ifu of the data cube to load. If set, input is ignored.

  • mode ({'local', 'remote', 'auto'}) – The load mode to use. See Mode Decision Tree.

  • data (HDUList, SQLAlchemy object, or None) – An astropy HDUList or a SQLAlchemy object, to be used for initialisation. If None, the normal <marvin-dma>` mode will be used.

  • release (str) – The MPL/DR version of the data to use.

  • drpall (str) – The path to the drpall file to use. If not set it will use the default path for the file based on the release.

  • download (bool) – If True, the data will be downloaded on instantiation. See Downloading Objects.

  • data (HDUList, SQLAlchemy object, or dict) – Depending on the access mode, data is populated with the HDUList from the FITS file, a SQLAlchemy object, or a dictionary of values returned by an API call.

  • datamodel – A datamodel object, whose type depends on the subclass that initialises the datamodel.

  • data_origin ({'file', 'db', 'api'}) – Indicates the origin of the data, either from a file, the DB, or an API call.

  • filename (str) – The path of the file used, if any.

  • mangaid (str) – The mangaid of the target.

  • plateifu – The plateifu of the target

abstract _getFullPath(pathType=None, url=None, **pathParams)

Returns the full path of the file in the tree.

This method must be overridden by each subclass.


Sets the datamodel for this object. Must be overridden by each subclass.

download(pathType=None, **pathParams)

Download using sdss_access Rsync


Retrieves the Image Image for this object

classmethod restore(path, delete=False)[source]

Restores a MarvinToolsClass object from a pickled file.

If delete=True, the pickled file will be removed after it has been unplickled. Note that, for objects with data_origin='file', the original file must exists and be in the same path as when the object was first created.

save(path=None, overwrite=False)[source]

Pickles the object.

If path=None, uses the default location of the file in the tree but changes the extension of the file to .mpf. Returns the path of the saved pickle file.

  • obj – Marvin object to pickle.

  • path (str) – Path of saved file. Default is None.

  • overwrite (bool) – If True, overwrite existing file. Default is False.


str – Path of saved file.

property release

Returns the release.


Some features are implemented in the form of mixins: parent classes that provide modular functionality. In particular, mixins are provided for accessing the NSA parameters for an object, and the DAPall information.

NSAMixIn must be called with when initialising the child class, and passed the source of the NSA data. DAPallMixIn does not need to be instantiated, and uses release to determine the location of the DAPall file.

An example of a class that uses both NSAMixIn and DAPallMixIn would be

class MyClass(MarvinToolsClass, NSAMixIn, DAPallMixIn):

    def __init__(self, **kwargs):

        MarvinToolsClass.__init__(self, **kwargs)
        NSAMixIn.__init__(self, **kwargs)

    # Overrides abstractmethods
    def _getFullPath(self):

    def _set_datamodel(self):

note that we use a direct call to __init__ instead of super to make sure that both parent classes are initialised.

Further reading