Beispiel #1
0
 def test_get_available_bintypes(self, galaxy, mode):
     if mode == 'db':
         cube = Cube(plateifu=galaxy.plateifu)
     else:
         cube = Cube(filename=galaxy.cubepath)
     bintypes = cube.get_available_bintypes()
     expbins = galaxy.dap['stellar_sigma'].keys()
     assert set(bintypes) == set(expbins)
Beispiel #2
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')

        # 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())

        # check that selected bintemp is available for target
        hasbin = selected_bintemp.split('-')[0] in cube.get_available_bintypes() if selected_bintemp else None

        # 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]
            if hasbin:
                mapmsg = 'Error getting maps: {0}'.format(e)
            else:
                mapmsg = 'No maps available for selected bintype {0}. Try a different one.'.format(selected_bintemp)
        else:
            output['mapstatus'] = 1

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

        output['image'] = get_manga_image(cube)
        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