Esempio n. 1
0
    def mangaid2plateifu(self, args, mangaid):
        """ Returns a plateifu given a mangaid

        .. :quickref: General; Returns a plateifu given a mangaid

        :param mangaid: The name of the cube as mangaid
        :form release: the release of MaNGA
        :resjson int status: status of response. 1 if good, -1 if bad.
        :resjson string error: error message, null if None
        :resjson json inconfig: json of incoming configuration
        :resjson json utahconfig: json of outcoming configuration
        :resjson string traceback: traceback of an error, null if None
        :resjson json data: dictionary of returned data
        :json string plateifu: id of cube as plateifu
        :resheader Content-Type: application/json
        :statuscode 200: no error
        :statuscode 422: invalid input parameters

        **Example request**:

        .. sourcecode:: http

           GET /marvin/api/general/mangaid2plateifu/1-209232/ HTTP/1.1
           Host: api.sdss.org
           Accept: application/json, */*

        **Example response**:

        .. sourcecode:: http

           HTTP/1.1 200 OK
           Content-Type: application/json
           {
              "status": 1,
              "error": null,
              "inconfig": {"release": "MPL-5"},
              "utahconfig": {"release": "MPL-5", "mode": "local"},
              "traceback": null,
              "data": {8485-1901"}
           }

        """
        # get drpver
        drpver = get_drpver(release=args.get('release', None))

        try:
            plateifu = mangaid2plateifu(mangaid, mode='db', drpver=drpver)
            self.results['data'] = plateifu
            self.results['status'] = 1
        except Exception as ee:
            self.results['status'] = -1
            self.results['error'] = (
                'manga2plateifu failed with error: {0}'.format(str(ee)))

        return jsonify(self.results)
Esempio n. 2
0
File: rss.py Progetto: zpace/marvin
def _getRSS(name, use_file=True, release=None, **kwargs):
    """Retrieves a RSS Marvin object."""

    drpver, __ = marvin.config.lookUpVersions(release)

    rss = None
    results = {}

    # parse name into either mangaid or plateifu
    try:
        idtype = parseIdentifier(name)
    except Exception as ee:
        results['error'] = 'Failed to parse input name {0}: {1}'.format(name, str(ee))
        return rss, results

    filename = None
    plateifu = None
    mangaid = None

    try:
        if use_file:

            if idtype == 'mangaid':
                plate, ifu = mangaid2plateifu(name, drpver=drpver)
            elif idtype == 'plateifu':
                plate, ifu = name.split('-')

            if Path is not None:
                filename = Path().full('mangarss', ifu=ifu, plate=plate, drpver=drpver)
                assert os.path.exists(filename), 'file not found.'
            else:
                raise MarvinError('cannot create path for MaNGA rss.')

        else:

            if idtype == 'plateifu':
                plateifu = name
            elif idtype == 'mangaid':
                mangaid = name
            else:
                raise MarvinError('invalid plateifu or mangaid: {0}'.format(idtype))

        rss = marvin.tools.RSS(filename=filename, mangaid=mangaid, plateifu=plateifu,
                               mode='local', release=release)

        results['status'] = 1

    except Exception as ee:

        results['error'] = 'Failed to retrieve RSS {0}: {1}'.format(name, str(ee))

    return rss, results
Esempio n. 3
0
def _getCube(name, use_file=False, release=None, **kwargs):
    ''' Retrieve a cube using marvin tools '''

    drpver, __ = config.lookUpVersions(release)

    cube = None
    results = {}

    # parse name into either mangaid or plateifu
    try:
        idtype = parseIdentifier(name)
    except Exception as ee:
        results['error'] = 'Failed to parse input name {0}: {1}'.format(name, str(ee))
        return cube, results

    filename = None
    plateifu = None
    mangaid = None

    try:
        if use_file:

            if idtype == 'mangaid':
                plate, ifu = mangaid2plateifu(name, drpver=drpver)
            elif idtype == 'plateifu':
                plate, ifu = name.split('-')

            if Path is not None:
                filename = Path(release=release).full('mangacube', ifu=ifu, plate=plate, drpver=drpver, wave='LOG')
                assert os.path.exists(filename), 'file not found.'
            else:
                raise MarvinError('cannot create path for MaNGA cube.')

        else:

            if idtype == 'plateifu':
                plateifu = name
            elif idtype == 'mangaid':
                mangaid = name
            else:
                raise MarvinError('invalid plateifu or mangaid: {0}'.format(idtype))

        cube = Cube(filename=filename, mangaid=mangaid, plateifu=plateifu,
                    mode='local', release=release)

        results['status'] = 1

    except Exception as ee:

        results['error'] = 'Failed to retrieve cube {0}: {1}'.format(name, str(ee))

    return cube, results
Esempio n. 4
0
    def _determine_inputs(self, input):
        """Determines what inputs to use in the decision tree."""

        if input:

            assert self.filename is None and self.plateifu is None and self.mangaid is None, \
                'if input is set, filename, plateifu, and mangaid cannot be set.'

            assert isinstance(input,
                              six.string_types), 'input must be a string.'

            input_dict = self._parse_input(input)

            if input_dict['plate'] is not None and input_dict[
                    'ifu'] is not None:
                self.plateifu = input
            elif input_dict['plate'] is not None and input_dict['ifu'] is None:
                self._plate = input
            elif input_dict['mangaid'] is not None:
                self.mangaid = input
            else:
                # Assumes the input must be a filename
                self.filename = input

        if self.filename is None and self.mangaid is None and self.plateifu is None:
            raise MarvinError('no inputs defined.')

        if self.filename:
            self.mangaid = None
            self.plateifu = None

            if self.mode == 'remote':
                raise MarvinError('filename not allowed in remote mode.')

            assert os.path.exists(self.filename), \
                'filename {} does not exist.'.format(str(self.filename))

        elif self.plateifu:
            assert not self.filename, 'invalid set of inputs.'

        elif self.mangaid:
            assert not self.filename, 'invalid set of inputs.'
            self.plateifu = mangaid2plateifu(self.mangaid,
                                             drpall=self._drpall,
                                             drpver=self._drpver)

        elif self._plate:
            assert not self.filename, 'invalid set of inputs.'
Esempio n. 5
0
def _get_model_cube(name, use_file=False, release=None, **kwargs):
    """Retrieves a Marvin ModelCube object."""

    model_cube = None
    results = {}

    drpver, dapver = config.lookUpVersions(release)

    # parse name into either mangaid or plateifu
    try:
        idtype = parseIdentifier(name)
    except Exception as err:
        results['error'] = 'Failed to parse input name {0}: {1}'.format(
            name, str(err))
        return model_cube, results

    filename = None
    plateifu = None
    mangaid = None

    bintype = kwargs.pop('bintype')
    template = kwargs.pop('template')

    try:
        if use_file:

            if idtype == 'mangaid':
                plate, ifu = mangaid2plateifu(name, drpver=drpver)
            elif idtype == 'plateifu':
                plate, ifu = name.split('-')

            if Path is not None:

                daptype = '{0}-{1}'.format(bintype, template)

                filename = Path().full('mangadap5',
                                       ifu=ifu,
                                       drpver=drpver,
                                       dapver=dapver,
                                       plate=plate,
                                       mode='LOGCUBE',
                                       daptype=daptype)
                assert os.path.exists(filename), 'file not found.'
            else:
                raise MarvinError('cannot create path for MaNGA cube.')

        else:

            if idtype == 'plateifu':
                plateifu = name
            elif idtype == 'mangaid':
                mangaid = name
            else:
                raise MarvinError(
                    'invalid plateifu or mangaid: {0}'.format(idtype))

        model_cube = ModelCube(filename=filename,
                               mangaid=mangaid,
                               plateifu=plateifu,
                               release=release,
                               template=template,
                               bintype=bintype,
                               **kwargs)

        results['status'] = 1

    except Exception as err:

        results['error'] = 'Failed to retrieve ModelCube {0}: {1}'.format(
            name, str(err))

    return model_cube, results
Esempio n. 6
0
def getImagesByList(inputlist, download=False, mode=None, as_url=None, verbose=None, release=None):
    ''' Get all images from a list of ids

    .. deprecated:: 2.3.0
       Use :class:`marvin.utils.general.images.get_images_by_list` instead.

    Retrieve a list of images from either your local filesystem SAS
    or the Utah SAS.  Optionally can download the images by rsync using
    sdss_access.

    When as_url is False, both local and remote modes will allow you to access
    the full path to the images in your local SAS.  WHen as_url is True,
    local mode generates the Utah SAS url links, while remote mode generates the
    Utah SAS rsync links.

    Auto mode defaults to remote.

    Parameters:
        inputlist (list):
            A list of plate-ifus or mangaids for the images you want to retrieve. Required.
        download (bool):
            Set to download the images from the SAS.  Only works in remote mode.
        mode ({'local', 'remote', 'auto'}):
            The load mode to use. See
            :doc:`Mode secision tree</mode_decision>`.
            the cube exists.
        as_url (bool):
            Convert the list of images to use the SAS url (mode=local)
            or the SAS rsync url (mode=remote)
        verbose (bool):
            Turns on verbosity during rsync
        release (str):
            The release version of the images to return

    Returns:
        listofimages (list):
            The list of images you have requested

    '''

    warnings.warn('getImagesByList is deprecated as of Marvin 2.3.0. '
                  'Please use get_images_by_list', MarvinDeprecationWarning)

    # Check inputs
    assert isinstance(inputlist, (list, np.ndarray)), 'Input must be of type list or Numpy array'
    idtype = parseIdentifier(inputlist[0])
    assert idtype in ['plateifu', 'mangaid'], 'Input must be of type plate-ifu or mangaid'
    # mode is checked via decorator

    # convert mangaids into plateifus
    if idtype == 'mangaid':
        newlist = []
        for myid in inputlist:
            try:
                plateifu = mangaid2plateifu(myid)
            except MarvinError:
                plateifu = None
            newlist.append(plateifu)
        inputlist = newlist

    # setup Rsync Access
    release = release if release else marvin.config.release
    drpver, __ = marvin.config.lookUpVersions(release=release)
    is_public = 'DR' in release
    rsync_release = release.lower() if is_public else None
    rsync_access = RsyncAccess(label='marvin_getlist', verbose=verbose, public=is_public,
                               release=rsync_release)

    imgname = 'mangaimagenew' if check_versions(drpver, 'v2_5_3') else 'mangaimage'

    # if mode is auto, set it to remote:
    if mode == 'auto':
        warnings.warn('Mode is auto.  Defaulting to remote.  If you want to access your '
                      'local images, set the mode explicitly to local', MarvinUserWarning)
        mode = 'remote'

    # do a local or remote thing
    if mode == 'local':
        # Get list of images
        listofimages = []
        for plateifu in inputlist:
            dir3d = getDir3d(plateifu, mode=mode, release=release)
            plateid, ifu = plateifu.split('-')
            if as_url:
                path = rsync_access.url(imgname, plate=plateid, drpver=drpver, ifu=ifu, dir3d=dir3d)
            else:
                path = rsync_access.full(imgname, plate=plateid, drpver=drpver, ifu=ifu, dir3d=dir3d)
            listofimages.append(path)

        # if download, issue warning that cannot do it
        if download:
            warnings.warn('Download not available when in local mode', MarvinUserWarning)

        return listofimages
    elif mode == 'remote':
        rsync_access.remote()
        # Add plateifus to stream
        for plateifu in inputlist:
            dir3d = getDir3d(plateifu, mode=mode, release=release)
            plateid, ifu = plateifu.split('-')
            rsync_access.add(imgname, plate=plateid, drpver=drpver, ifu=ifu, dir3d=dir3d)

        # set the stream
        try:
            rsync_access.set_stream()
        except AccessError as e:
            raise MarvinError('Error with sdss_access rsync.set_stream. AccessError: {0}'.format(e))

        # get the list
        listofimages = rsync_access.get_urls() if as_url else rsync_access.get_paths()
        if download:
            rsync_access.commit()
        else:
            return listofimages
Esempio n. 7
0
    def __init__(self, *args, **kwargs):
        """Marvin tools main super class.

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

        """

        self.data = kwargsGet(kwargs, 'data', None)

        self.filename = kwargsGet(kwargs, 'filename', None)
        if self.filename:
            self.filename = os.path.realpath(os.path.expanduser(self.filename))

        self.mangaid = kwargsGet(kwargs, 'mangaid', None)
        self.plateifu = kwargsGet(kwargs, 'plateifu', None)

        self.mode = kwargsGet(kwargs, 'mode', marvin.config.mode)

        self._release = kwargsGet(kwargs, 'release', marvin.config.release)

        self._drpver, self._dapver = marvin.config.lookUpVersions(
            release=self._release)
        self._drpall = kwargsGet(kwargs, 'drpall',
                                 marvin.config._getDrpAllPath(self._drpver))

        self._nsa = None
        self.nsa_source = kwargs.pop('nsa_source', 'auto')
        assert self.nsa_source in ['auto', 'nsa', 'drpall'], \
            'nsa_source must be one of auto, nsa, or drpall'

        self._forcedownload = kwargsGet(kwargs, 'download',
                                        marvin.config.download)

        self.data_origin = None

        args = [self.filename, self.plateifu, self.mangaid]
        assert any(args), 'Enter filename, plateifu, or mangaid!'

        if self.filename:
            self.plateifu = None
            self.mangaid = None
        elif self.plateifu:
            self.filename = None
            self.mangaid = None
        elif self.mangaid:
            self.filename = None
            self.plateifu = mangaid2plateifu(self.mangaid,
                                             drpall=self._drpall,
                                             drpver=self._drpver)

        # drop breadcrumb
        breadcrumb.drop(message='Initializing MarvinTool {0}'.format(
            self.__class__),
                        category=self.__class__)

        if self.mode == 'local':
            self._doLocal()
        elif self.mode == 'remote':
            self._doRemote()
        elif self.mode == 'auto':
            try:
                self._doLocal()
            except Exception as ee:
                if self.filename:
                    # If the input contains a filename we don't want to go into remote mode.
                    raise (ee)
                else:
                    warnings.warn('local mode failed. Trying remote now.',
                                  MarvinUserWarning)
                    self._doRemote()

        # Sanity check to make sure data_origin has been properly set.
        assert self.data_origin in ['file', 'db',
                                    'api'], 'data_origin is not properly set.'