Пример #1
0
    def test_public(self):
        path = Path()
        url = path.url('mangacube', drpver='v2_3_1', plate=8485, ifu='1901')
        assert 'mangawork' in url

        release = 'dr14'
        path = Path(public=True, release=release)
        url = path.url('mangacube', drpver='v2_3_1', plate=8485, ifu='1901')
        assert release in url
Пример #2
0
    def _getFullPath(self, pathType=None, url=None, **pathParams):
        """Returns the full path of the file in the tree.

        This method must be overridden by each subclass.

        """

        # # check for public release
        # is_public = 'DR' in self._release
        # ismpl = 'MPL' in self._release
        # path_release = self._release.lower() if is_public or ismpl else None

        if not Path:
            raise MarvinMissingDependency('sdss_access is not installed')
        else:
            path = Path(release=self._release)
            try:
                if url:
                    fullpath = path.url(pathType, **pathParams)
                else:
                    fullpath = path.full(pathType, **pathParams)
            except Exception as ee:
                warnings.warn(
                    'sdss_access was not able to retrieve the full path of the file. '
                    'Error message is: {0}'.format(str(ee)), MarvinUserWarning)
                fullpath = None

        return fullpath
Пример #3
0
def getDapRedux(release=None):
    ''' Retrieve SAS url link to the DAP redux directory

    Parameters:
        release (str):
            The release version of the data to download.
            Defaults to Marvin config.release.

    Returns:
        dapredux (str):
            The full redux path to the DAP MAPS
    '''

    if not Path:
        raise MarvinError('sdss_access is not installed')
    else:
        sdss_path = Path()

    release = release or marvin.config.release
    drpver, dapver = marvin.config.lookUpVersions(release=release)
    # hack a url version of MANGA_SPECTRO_ANALYSIS
    dapdefault = sdss_path.dir('mangadefault',
                               drpver=drpver,
                               dapver=dapver,
                               plate=None,
                               ifu=None)
    dappath = dapdefault.rsplit('/', 2)[0]
    dapredux = sdss_path.url('', full=dappath)
    return dapredux
Пример #4
0
    def initDynamic(self):
        ''' Route to run when the dynamic toggle is initialized
            This creates the web spectrum and dap heatmaps
        '''

        # get the form parameters
        args = av.manual_parse(self, request, use_params='galaxy', required='plateifu')

        # turning toggle on
        current_session['toggleon'] = args.get('toggleon')

        # get the cube
        cubeinputs = {'plateifu': args.get('plateifu'), 'release': self._release}
        cube = Cube(**cubeinputs)
        output = {'specstatus': -1, 'mapstatus': -1}

        # get web spectrum
        webspec, specmsg = getWebSpectrum(cube, cube.ra, cube.dec, byradec=True)
        daplist = get_dap_maplist(self._dapver, web=True)
        dapdefaults = get_default_mapset(self._dapver)

        # build the uber map dictionary
        try:
            mapdict = buildMapDict(cube, dapdefaults, self._dapver)
            mapmsg = None
        except Exception as e:
            mapdict = [{'data': None, 'msg': 'Error', 'plotparams': None} for m in dapdefaults]
            mapmsg = 'Error getting maps: {0}'.format(e)
        else:
            output['mapstatus'] = 1

        if not webspec:
            output['error'] = 'Error: {0}'.format(specmsg)
        else:
            output['specstatus'] = 1

        sdss_path = Path()
        output['image'] = sdss_path.url('mangaimage', drpver=cube._drpver, plate=cube.plate, ifu=cube.ifu, dir3d=cube.dir3d)
        output['spectra'] = webspec
        output['specmsg'] = specmsg
        output['maps'] = mapdict
        output['mapmsg'] = mapmsg
        output['dapmaps'] = daplist
        output['dapmapselect'] = dapdefaults

        dm = datamodel[self._dapver]
        output['dapbintemps'] = dm.get_bintemps(db_only=True)
        current_session['bintemp'] = '{0}-{1}'.format(dm.get_bintype(), dm.get_template())

        # try to jsonify the result
        try:
            jsonout = jsonify(result=output)
        except Exception as e:
            jsonout = jsonify(result={'specstatus': -1, 'mapstatus': -1, 'error': '{0}'.format(e)})

        return jsonout
Пример #5
0
def getDefaultMapPath(**kwargs):
    ''' Retrieve the default Maps path

    Uses sdss_access Path to generate a url download link to the
    default MAPS file for a given MPL.

    Parameters:
        release (str):
            The release version of the data to download.
            Defaults to Marvin config.release.
        plate (int):
            The plate id
        ifu (int):
            The ifu number
        bintype (str):
            The bintype of the default file to grab. Defaults to MAPS
        daptype (str):
            The daptype of the default map to grab.  Defaults to SPX-MILESHC

    Returns:
        maplink (str):
            The sas url to download the default maps file
    '''

    if not Path:
        raise MarvinError('sdss_access is not installed')
    else:
        sdss_path = Path()

    # Get kwargs
    release = kwargs.get('release', marvin.config.release)
    drpver, dapver = marvin.config.lookUpVersions(release=release)
    plate = kwargs.get('plate', None)
    ifu = kwargs.get('ifu', None)
    daptype = kwargs.get('daptype', 'SPX-GAU-MILESHC')
    bintype = kwargs.get('bintype', 'MAPS')

    # get the sdss_path name by MPL
    # TODO: this is likely to break in future MPL/DRs. Just a heads up.
    if '4' in release:
        name = 'mangadefault'
    elif '5' in release:
        name = 'mangadap5'
    else:
        return None

    # construct the url link to default maps file
    maplink = sdss_path.url(name,
                            drpver=drpver,
                            dapver=dapver,
                            mpl=release,
                            plate=plate,
                            ifu=ifu,
                            daptype=daptype,
                            mode=bintype)
    return maplink
Пример #6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     p = Path()
     self.template = p.templates[self.name]
     if self.kwargs:
         self.full = p.full(self.name, **self.kwargs)
         self.url = p.url(self.name, **self.kwargs)
         self.file = p.name(self.name, **self.kwargs)
         self.location = p.location(self.name, **self.kwargs)
         self.exists = p.exists(self.name, **self.kwargs)
Пример #7
0
    def get(self, galid):
        ''' Retrieve info for a given cube '''

        # determine type of galid
        args = av.manual_parse(self, request, use_params='galaxy')
        self.galaxy['id'] = args['galid']
        idtype = parseIdentifier(galid)
        if idtype in ['plateifu', 'mangaid']:
            # set plateifu or mangaid
            self.galaxy['idtype'] = idtype
            galaxyid = {self.galaxy['idtype']: galid, 'release': self._release}

            # Get cube
            try:
                cube = Cube(**galaxyid)
            except MarvinError as e:
                self.galaxy['cube'] = None
                self.galaxy['error'] = 'MarvinError: {0}'.format(e)
                return render_template("galaxy.html", **self.galaxy)
            else:
                self.galaxy['cube'] = cube
                self.galaxy['daplink'] = getDapRedux(release=self._release)
                # get SAS url links to cube, rss, maps, image
                if Path:
                    sdss_path = Path()
                    self.galaxy['image'] = sdss_path.url('mangaimage', drpver=cube._drpver, plate=cube.plate, ifu=cube.ifu, dir3d=cube.dir3d)
                    cubelink = sdss_path.url('mangacube', drpver=cube._drpver, plate=cube.plate, ifu=cube.ifu)
                    rsslink = sdss_path.url('mangarss', drpver=cube._drpver, plate=cube.plate, ifu=cube.ifu)
                    maplink = getDefaultMapPath(release=self._release, plate=cube.plate, ifu=cube.ifu, daptype='SPX-GAU-MILESHC', mode='MAPS')
                    self.galaxy['links'] = {'cube': cubelink, 'rss': rsslink, 'map': maplink}
                else:
                    self.galaxy['image'] = cube.data.image

            # Get the initial spectrum
            if cube:
                daplist = get_dap_maplist(self._dapver, web=True)
                dapdefaults = get_default_mapset(self._dapver)
                self.galaxy['cube'] = cube
                self.galaxy['toggleon'] = current_session.get('toggleon', 'false')
                self.galaxy['cubehdr'] = cube.header
                self.galaxy['quality'] = ('DRP3QUAL', cube.quality_flag.mask, cube.quality_flag.labels)
                self.galaxy['mngtarget'] = {'bits': [it.mask for it in cube.target_flags if it.mask != 0],
                                            'labels': [it.labels for it in cube.target_flags if len(it.labels) > 0],
                                            'names': [''.join(('MNGTARG', it.name[-1])) for it in cube.target_flags if it.mask != 0]}

                # make the nsa dictionary
                hasnsa = cube.nsa is not None
                self.galaxy['hasnsa'] = hasnsa
                if hasnsa:
                    cols = self.galaxy.get('nsaplotcols')
                    nsadict, nsacols = make_nsa_dict(cube.nsa)
                    nsatmp = [nsacols.pop(nsacols.index(i)) for i in cols]
                    nsatmp.extend(nsacols)
                    self.galaxy['nsacols'] = nsatmp
                    self.galaxy['nsadict'] = nsadict

                self.galaxy['dapmaps'] = daplist
                self.galaxy['dapmapselect'] = dapdefaults
                dm = datamodel[self._dapver]
                self.galaxy['dapbintemps'] = dm.get_bintemps(db_only=True)
                current_session['bintemp'] = '{0}-{1}'.format(dm.get_bintype(), dm.get_template())
                # TODO - make this general - see also search.py for querystr
                self.galaxy['cubestr'] = ("<html><samp>from marvin.tools.cube import Cube<br>cube = \
                    Cube(plateifu='{0}')<br># access the header<br>cube.header<br># get NSA data<br>\
                    cube.nsa<br></samp></html>".format(cube.plateifu))

                self.galaxy['spaxelstr'] = ("<html><samp>from marvin.tools.cube import Cube<br>cube = \
                    Cube(plateifu='{0}')<br># get a spaxel<br>spaxel=cube[16, 16]<br>flux = \
                    spaxel.flux<br>wave = flux.wavelength<br>ivar = flux.ivar<br>mask = \
                    flux.mask<br>flux.plot()<br></samp></html>".format(cube.plateifu))

                self.galaxy['mapstr'] = ("<html><samp>from marvin.tools.maps import Maps<br>maps = \
                    Maps(plateifu='{0}')<br>print(maps)<br># get an emission \
                    line map<br>haflux = maps.emline_gflux_ha_6564<br>values = \
                    haflux.value<br>ivar = haflux.ivar<br>mask = haflux.mask<br>haflux.plot()<br>\
                    </samp></html>".format(cube.plateifu))
        else:
            self.galaxy['error'] = 'Error: Galaxy ID {0} must either be a Plate-IFU, or MaNGA-Id designation.'.format(galid)
            return render_template("galaxy.html", **self.galaxy)

        return render_template("galaxy.html", **self.galaxy)
Пример #8
0
    def get(self, galid):
        ''' Retrieve info for a given cube '''

        # determine type of galid
        args = av.manual_parse(self, request, use_params='galaxy')
        self.galaxy['id'] = args['galid']
        self.galaxy['latest_dr'] = self._release.lower(
        ) if 'DR' in self._release else marvin.config._get_latest_release(
            dr_only=True).lower()
        idtype = parseIdentifier(galid)
        if idtype in ['plateifu', 'mangaid']:
            # set plateifu or mangaid
            self.galaxy['idtype'] = idtype
            galaxyid = {self.galaxy['idtype']: galid, 'release': self._release}

            # Get cube
            try:
                cube = Cube(**galaxyid)
            except MarvinError as e:
                self.galaxy['cube'] = None
                errmsg = 'MarvinError: {0}'.format(e)

                # check target status and fine-tune the error message
                if idtype == 'mangaid':
                    status = target_status(galid, drpver=self._drpver)
                    if status == 'not yet observed':
                        errmsg = '{0} is a valid target but has not yet been observed'.format(
                            galid)
                    elif status == 'not valid target':
                        errmsg = '{0} is not valid MaNGA target.  Check your syntax'.format(
                            galid)

                self.galaxy['error'] = errmsg
                return render_template("galaxy.html", **self.galaxy)
            else:
                dm = datamodel[self._dapver]
                self.galaxy['cube'] = cube
                self.galaxy['daplink'] = getDapRedux(release=self._release)
                # get SAS url links to cube, rss, maps, image
                if Path:
                    is_public = 'DR' in self._release
                    path_release = self._release.lower() if is_public else None
                    sdss_path = Path(public=is_public, release=path_release)
                    self.galaxy['image'] = cube.getImage().url
                    cubelink = sdss_path.url('mangacube',
                                             drpver=cube._drpver,
                                             plate=cube.plate,
                                             ifu=cube.ifu)
                    rsslink = sdss_path.url('mangarss',
                                            drpver=cube._drpver,
                                            plate=cube.plate,
                                            ifu=cube.ifu)
                    daptype = "{0}-{1}".format(dm.default_bintype,
                                               dm.default_template)
                    maplink = getDefaultMapPath(release=self._release,
                                                plate=cube.plate,
                                                ifu=cube.ifu,
                                                daptype=daptype,
                                                mode='MAPS')
                    mclink = getDefaultMapPath(release=self._release,
                                               plate=cube.plate,
                                               ifu=cube.ifu,
                                               daptype=daptype,
                                               mode='LOGCUBE')
                    self.galaxy['links'] = {
                        'cube': cubelink,
                        'rss': rsslink,
                        'map': maplink,
                        'mc': mclink
                    }
                else:
                    self.galaxy['image'] = cube.data.image

            # Get the initial spectrum
            if cube:
                dm = datamodel[self._dapver]
                daplist = [p.full(web=True) for p in dm.properties]
                dapdefaults = dm.get_default_mapset()
                self.galaxy['cube'] = cube
                self.galaxy['toggleon'] = current_session.get(
                    'toggleon', 'false')
                self.galaxy['cubehdr'] = cube.header
                self.galaxy['quality'] = ('DRP3QUAL', cube.quality_flag.mask,
                                          cube.quality_flag.labels)
                self.galaxy['mngtarget'] = {
                    'bits':
                    [it.mask for it in cube.target_flags if it.mask != 0],
                    'labels': [
                        it.labels for it in cube.target_flags
                        if len(it.labels) > 0
                    ],
                    'names': [
                        ''.join(('MNGTARG', it.name[-1]))
                        for it in cube.target_flags if it.mask != 0
                    ]
                }

                # make the nsa dictionary
                hasnsa = cube.nsa is not None
                self.galaxy['hasnsa'] = hasnsa
                if hasnsa:
                    cols = self.galaxy.get('nsaplotcols')
                    nsadict, nsacols = make_nsa_dict(cube.nsa)
                    nsatmp = [
                        nsacols.pop(nsacols.index(i)) for i in cols
                        if i in nsacols
                    ]
                    nsatmp.extend(nsacols)
                    self.galaxy['nsacols'] = nsatmp
                    self.galaxy['nsadict'] = nsadict

                self.galaxy['dapmaps'] = daplist
                self.galaxy['dapmapselect'] = current_session.get(
                    'selected_dapmaps', dapdefaults)
                dm = datamodel[self._dapver]
                self.galaxy['dapbintemps'] = dm.get_bintemps(db_only=True)
                if 'bintemp' not in current_session or current_session[
                        'bintemp'] not in self.galaxy['dapbintemps']:
                    current_session['bintemp'] = '{0}-{1}'.format(
                        dm.get_bintype(), dm.get_template())

                # get default map quality
                maps = cube.getMaps(
                    plateifu=cube.plateifu,
                    mode='local',
                    bintype=current_session['bintemp'].split('-')[0])
                mapqual = ('DAPQUAL', maps.quality_flag.mask,
                           maps.quality_flag.labels)
                self.galaxy['mapquality'] = mapqual

                # TODO - make this general - see also search.py for querystr
                self.galaxy['cubestr'] = (
                    "<html><samp>from marvin.tools.cube import Cube<br>cube = \
                    Cube(plateifu='{0}')<br># access the header<br>cube.header<br># get NSA data<br>\
                    cube.nsa<br></samp></html>".format(cube.plateifu))

                self.galaxy['spaxelstr'] = (
                    "<html><samp>from marvin.tools.cube import Cube<br>cube = \
                    Cube(plateifu='{0}')<br># get a spaxel by slicing cube[i,j]<br>spaxel=cube[16, 16]<br>flux = \
                    spaxel.flux<br>wave = flux.wavelength<br>ivar = flux.ivar<br>mask = \
                    flux.mask<br>flux.plot()<br></samp></html>".format(
                        cube.plateifu))

                self.galaxy['mapstr'] = (
                    "<html><samp>from marvin.tools.maps import Maps<br>maps = \
                    Maps(plateifu='{0}')<br>print(maps)<br># get an emission \
                    line map<br>haflux = maps.emline_gflux_ha_6564<br>values = \
                    haflux.value<br>ivar = haflux.ivar<br>mask = haflux.mask<br>haflux.plot()<br>\
                    </samp></html>".format(cube.plateifu))
        else:
            self.galaxy[
                'error'] = 'Error: Galaxy ID {0} must either be a Plate-IFU, or MaNGA-Id designation.'.format(
                    galid)
            return render_template("galaxy.html", **self.galaxy)

        return render_template("galaxy.html", **self.galaxy)