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 MarvinToolsClass.download
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 MarvinToolsClass.save
and MarvinToolsClass.restore
. While these work in most cases, depending on the specifics of the subclass some additional handling may be necessary.
marvin.core.core.
MarvinToolsClass
(input=None, 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.
Parameters: |
|
---|---|
Variables: |
|
_getFullPath
(pathType=None, url=None, **pathParams)[source]¶Returns the full path of the file in the tree.
This method must be overridden by each subclass.
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.
Parameters: | |
---|---|
Returns: | str – Path of saved file. |
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):
pass
def _set_datamodel(self):
pass
note that we use a direct call to __init__
instead of super
to make sure that both parent classes are initialised.
marvin.core.core.
NSAMixIn
(nsa_source='auto')[source]¶A mixin that provides access to NSA paremeters.
Must be used in combination with MarvinToolsClass
and initialised
before nsa
can be called.
Parameters: | nsa_source ({'auto', 'drpall', 'nsa'}) – Defines how the NSA data for this object should loaded when
.nsa is first called. If drpall , the drpall file will
be used (note that this will only contain a subset of all the NSA
information); if nsa , the full set of data from the DB will be
retrieved. If the drpall file or a database are not available, a
remote API call will be attempted. If nsa_source='auto' , the
source will depend on how the parent object has been
instantiated. If the parent has data_origin='file' ,
the drpall file will be used (as it is more likely that the user
has that file in their system). Otherwise, nsa_source='nsa'
will be assumed. This behaviour can be modified during runtime by
modifying the nsa_mode attribute with one of the valid values. |
---|
nsa
¶Returns the contents of the NSA catalogue for this target.
marvin.core.core.
DAPallMixIn
[source]¶A mixin that provides access to DAPall paremeters.
Must be used in combination with MarvinToolsClass
and initialised
before dapall
can be called.
DAPallMixIn
uses the MarvinToolsClass.data_origin
of the object to
determine how to obtain the DAPall information. However, if the object
contains a dapall
attribute with the path to a DAPall file, that file
will be used.
dapall
¶Returns the contents of the DAPall data for this target.