def getDir3d(inputid, mode=None, release=None): ''' Get the 3d redux Image directory from an input plate or plate-IFU ''' idtype = parseIdentifier(inputid) if idtype == 'plate': plateid = inputid elif idtype == 'plateifu': plateid, __ = inputid.split('-') release = marvin.config.release if not release else release drpver, __ = marvin.config.lookUpVersions(release=release) if check_versions(drpver, 'v1_5_4'): from marvin.tools.plate import Plate try: plate = Plate(plate=plateid, nocubes=True, mode=mode, release=release) except Exception as e: raise MarvinError('Could not retrieve a remote plate. If it is a mastar ' 'plate you are after, Marvin currently does not handle those: {0}'.format(e)) else: dir3d = plate.dir3d else: dir3d = 'stack' return dir3d
def _getRSS(name, **kwargs): """Retrieves a RSS Marvin object.""" rss = None results = {} # Pop the release to remove a duplicate input to Maps release = kwargs.pop('release', None) # parse name into either mangaid or plateifu try: idtype = parseIdentifier(name) except Exception as e: results['error'] = 'Failed to parse input name {0}: {1}'.format(name, str(e)) return rss, results try: if idtype == 'plateifu': plateifu = name mangaid = None elif idtype == 'mangaid': mangaid = name plateifu = None else: raise MarvinError('invalid plateifu or mangaid: {0}'.format(idtype)) rss = RSS(mangaid=mangaid, plateifu=plateifu, mode='local', release=release) results['status'] = 1 except Exception as e: results['error'] = 'Failed to retrieve RSS {0}: {1}'.format(name, str(e)) return rss, results
def __init__(self, targetid, vacfile, **kwargs): self.targetid = targetid self._ttype = parseIdentifier(targetid) assert self._ttype in ['plateifu', 'mangaid'], 'Input targetid must be a valid plateifu or mangaid' self._vacfile = vacfile self._data = self._get_data(self._vacfile) self._indata = targetid in self._data[self._ttype]
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
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
def has_target(self, target): ''' Checks if a target is contained within the VAC Parameters: target (str): The name of the target Returns: A boolean indicating if the target is in the VAC or not ''' assert isinstance(target, six.string_types), 'target must be a string' targ_type = parseIdentifier(target) ttypes = ['plateifu', 'mangaid'] other = ttypes[ttypes.index(targ_type) - 1] data = self.data[1].data assert targ_type in map(str.lower, data.columns.names), \ 'Identifier "{0}" is not available. Try a "{1}".'.format(targ_type, other) return target in data[targ_type]
def _getSpaxel(name, x, y, **kwargs): """Retrieves a Marvin Spaxel object.""" spaxel = None results = {} # Pop the release to remove a duplicate input to Maps release = kwargs.pop('release', None) # parse name into either mangaid or plateifu try: idtype = parseIdentifier(name) except Exception as e: results['error'] = 'Failed to parse input name {0}: {1}'.format( name, str(e)) return spaxel, results try: if idtype == 'plateifu': plateifu = name mangaid = None elif idtype == 'mangaid': mangaid = name plateifu = None else: raise MarvinError( 'invalid plateifu or mangaid: {0}'.format(idtype)) spaxel = Spaxel(x=x, y=y, mangaid=mangaid, plateifu=plateifu, release=release, **kwargs) results['status'] = 1 except Exception as e: results['error'] = 'Failed to retrieve Spaxels {0}: {1}'.format( name, str(e)) return spaxel, results
def _getCube(name, **kwargs): ''' Retrieve a cube using marvin tools ''' # Pop the release to remove a duplicate input to Maps release = kwargs.pop('release', None) 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 try: if idtype == 'plateifu': plateifu = name mangaid = None elif idtype == 'mangaid': mangaid = name plateifu = None else: raise MarvinError( 'invalid plateifu or mangaid: {0}'.format(idtype)) cube = Cube(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
def _get_model_cube(name, **kwargs): """Retrieves a Marvin ModelCube object.""" model_cube = None results = {} # Pop the release to remove a duplicate input to Maps release = kwargs.pop('release', None) # 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 try: if idtype == 'plateifu': plateifu = name mangaid = None elif idtype == 'mangaid': mangaid = name plateifu = None else: raise MarvinError( 'invalid plateifu or mangaid: {0}'.format(idtype)) model_cube = ModelCube(mangaid=mangaid, plateifu=plateifu, release=release, **kwargs) results['status'] = 1 except Exception as err: results['error'] = 'Failed to retrieve ModelCube {0}: {1}'.format( name, str(err)) return model_cube, results
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
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