sdss_brain Reference

Config

class sdss_brain.config.Config[source]

Bases: object

Main configuration class for SDSS

set_release(version=None)[source]

Set a new release

If version not specified, uses the latest public DR

Parameters

version (str) – The new data release to set

property mode
property release

Multi-Modal Access (MMA)

class sdss_brain.mma.MMAMixIn(data_input=None, filename=None, objectid=None, mode=None, release=None, download=None, ignore_db=False, use_db=None)[source]

Bases: abc.ABC

Mixin for implementing multi-modal data access

This is a mixin class that adds multi-modal data access to any class that subclasses from this one. The MMA allows toggling between local and remote data access modes, or leaving it on automatic. Local mode access tries to load data via a database, if one exists, otherwise it loads data via a local filepath. Remote mode will try to load data over an API. When the mode is set to “auto”, it automatically tries to first load things locally, and then remotely. Depending on the mode and logic, the MMA will set data_origin to either file, db, or api.

This mixin contains two abstractmethods you must override when subclassing.
  • _set_access_path_params: sets the arguments needed by sdss_access

  • _parse_inputs: provides logic to parse data_input into either filename or objectid

Parameters
  • data_input (str) – The file or name of target data to load

  • filename (str) – The absolute filepath to data to load

  • objectid (str) – The object identifier of the data to load

  • mode (str) – The operating mode: auto, local, or remote

  • release (str) – The data release of the object, e.g. “DR16”

  • download (bool) – If True, downloads the object locally with sdss_access

  • ignore_db (bool) – If True, ignores any database connection for local access

  • use_db (sdssdb.DatabaseConnection) – a database connection to override the default with

Variables
  • release (str) – The current data release loaded

  • access (sdss_access.Access) – An instance of sdss_access using for all path creation and file downloads

download()[source]

Download the file using sdss_access

get_full_path(url=None)[source]

Returns the full path of the file in the tree.

Parameters

url (bool) – If True, specifies the url location rather than the local file location

Returns

The full path as built by sdss_access

property access

Returns an instance of sdss_access.Access

property release

Returns the release.

class sdss_brain.core.Base[source]

Bases: abc.ABC

abstract base class for tools

class sdss_brain.core.Brain(data_input=None, filename=None, objectid=None, mode=None, data=None, release=None, download=None, ignore_db=None, use_db=None)[source]

Bases: sdss_brain.core.Base, sdss_brain.mma.MMAMixIn

Convenience class for utilizing the MMA mixin

This is a convenience class with the MMAMixIn already implemented. This class initializes the MMAMixIn and provides logic to load data based on the data_origin. It also provides a simple repr.

This class contains three abstractmethods you must override when subclassing.
  • _load_object_from_file: defines data load/handling from a local file

  • _load_object_from_db: defines data load/handling from a local database

  • _load_object_from_api: defines data load/handling from a remote API

Parameters
  • data_input (str) – The file or name of target data to load

  • filename (str) – The absolute filepath to data to load

  • objectid (str) – The object identifier of the data to load

  • mode (str) – The operating mode: auto, local, or remote

  • release (str) – The data release of the object, e.g. “DR16”

  • data (object) – Optional data to instantiate the object with

  • download (bool) – If True, downloads the object locally with sdss_access

  • ignore_db (bool) – If True, ignores any database connection for local access

  • use_db (sdssdb.DatabaseConnection) – a database connection to override the default with

Variables
  • _db (sdssdb.DatabaseConnection) – A relevant sdssdb database connection for the object

  • mapped_version (str) – The name of survey/category in the mapped_versions dictionary

mapped_version = None

Helpers

sdss_brain.helpers.get_mapped_version(name, release=None, key=None)[source]

Get a version id mapped to a release number

For a given named category, looks up the “mapped_versions” attribute from the configuration yaml file and returns a version number that has been mapped to a specific release. For example, for manga, DR16 maps to drpver=’v2_4_3’ and dapver=’2.2.1’. This can be useful when needing to specify certain versions when defining paths to files.

Parameters
  • name (str) – The name of the set of versions to access

  • release (str) – The SDSS release. Default is config.release.

  • key (str) – Optional name of dictionary key to access specific value

Example

>>> # access the MaNGA versions for release DR16
>>> get_mapped_version('manga', release='DR16')
>>> {'drpver': 'v2_4_3', 'dapver': '2.2.1'}
>>>
>>> # access specific key
>>> get_mapped_version('manga', release='DR16', key='drpver')
>>> 'v2_4_3'
sdss_brain.helpers.load_fits_file(filename)[source]

Load a FITS file

Opens and loads a FITS file with astropy.io.fits.

Parameters

filename (str) – A FITS filen to open

Returns

an Astropy HDUList