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') # datamodel dm = datamodel[self._dapver] # turning toggle on nowebsession = marvin.config._custom_config.get('no_web_session', None) if not nowebsession: 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, badspots = getWebSpectrum(cube, cube.ra, cube.dec, byradec=True) daplist = [p.full(web=True) for p in dm.properties] dapdefaults = dm.get_default_mapset() # select any DAP maps and bin-template from the session selected_bintemp = current_session.get('bintemp', None) selected_maps = current_session.get('selected_dapmaps', dapdefaults) # check for correct bintemp if selected_bintemp and selected_bintemp not in dm.get_bintemps( db_only=True): selected_bintemp = '{0}-{1}'.format(dm.get_bintype(), dm.get_template()) # build the uber map dictionary try: mapdict = buildMapDict(cube, selected_maps, self._dapver, bintemp=selected_bintemp) 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 output['image'] = cube.getImage().url output['spectra'] = webspec output['specmsg'] = specmsg output['maps'] = mapdict output['mapmsg'] = mapmsg output['dapmaps'] = daplist output['dapmapselect'] = selected_maps output['daplines'] = dm.get_channels('emline_gflux', formatted=True) output['badspots'] = badspots output['dapbintemps'] = dm.get_bintemps(db_only=True) if 'bintemp' not in current_session: 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
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)