<commit_before>#!/usr/bin/env python
# encoding: utf-8

'''
Created by <NAME> on 2016-04-08 14:31:34
Licensed under a 3-clause BSD license.

Revision History:
    Initial Version: 2016-04-08 14:31:34 by <NAME>
    Last Modified On: 2016-04-08 14:31:34 by Brian

'''
from __future__ import print_function
from __future__ import division
from flask import current_app, Blueprint, render_template, session as current_session, request, redirect, url_for, jsonify
from flask.ext.classy import FlaskView, route
from brain.api.base import processRequest
from marvin.utils.general.general import findClosestVector, convertImgCoords, parseIdentifier
from brain.utils.general.general import convertIvarToErr
from marvin.core import MarvinError
from marvin.tools.cube import Cube
from marvin import config
import os

try:
    from sdss_access.path import Path
except ImportError as e:
    Path = None

galaxy = Blueprint("galaxy_page", __name__)


def getWebSpectrum(cube, x, y, xyorig=None, byradec=False):
    ''' Get and format a spectrum for the web '''
    webspec = None
    try:
        if byradec:
            spectrum = cube.getSpaxel(ra=x, dec=y, xyorig=xyorig)
        else:
            spectrum = cube.getSpaxel(x=x, y=y, xyorig=xyorig)
    except Exception as e:
        specmsg = 'Could not get spectrum: {0}'.format(e)
    else:
        # get error and wavelength
        error = convertIvarToErr(spectrum.ivar)
        wave = spectrum.wavelength
        # make input array for Dygraph
        webspec = [[wave[i], [s, error[i]]] for i, s in enumerate(spectrum.flux)]

        specmsg = "Spectrum in Spaxel ({2},{3}) at RA, Dec = ({0}, {1})".format(x, y, spectrum.x, spectrum.y)

    return webspec, specmsg


class Galaxy(FlaskView):
    route_base = '/galaxy'

    def __init__(self):
        ''' Initialize the route '''
        self.galaxy = {}
        self.galaxy['title'] = 'Marvin | Galaxy'
        self.galaxy['page'] = 'marvin-galaxy'
        self.galaxy['error'] = None

    def before_request(self, *args, **kwargs):
        ''' Do these things before a request to any route '''
        self.galaxy['error'] = None
        self.galaxy['cube'] = None
        self.galaxy['image'] = ''
        self.galaxy['spectra'] = 'null'

    def index(self):
        ''' Main galaxy page '''
        self.galaxy['error'] = 'Not all there are you...  Try adding a plate-IFU or manga-ID to the end of the address.'
        return render_template("galaxy.html", **self.galaxy)

    def get(self, galid):
        ''' Retrieve info for a given cube '''<commit_msg>added init of none specmsg<commit_after>#!/usr/bin/env python
# encoding: utf-8

'''
Created by <NAME> on 2016-04-08 14:31:34
Licensed under a 3-clause BSD license.

Revision History:
    Initial Version: 2016-04-08 14:31:34 by <NAME>
    Last Modified On: 2016-04-08 14:31:34 by Brian

'''
from __future__ import print_function
from __future__ import division
from flask import current_app, Blueprint, render_template, session as current_session, request, redirect, url_for, jsonify
from flask.ext.classy import FlaskView, route
from brain.api.base import processRequest
from marvin.utils.general.general import findClosestVector, convertImgCoords, parseIdentifier
from brain.utils.general.general import convertIvarToErr
from marvin.core import MarvinError
from marvin.tools.cube import Cube
from marvin import config
import os

try:
    from sdss_access.path import Path
except ImportError as e:
    Path = None

galaxy = Blueprint("galaxy_page", __name__)


def getWebSpectrum(cube, x, y, xyorig=None, byradec=False):
    ''' Get and format a spectrum for the web '''
    webspec = None
    try:
        if byradec:
            spectrum = cube.getSpaxel(ra=x, dec=y, xyorig=xyorig)
        else:
            spectrum = cube.getSpaxel(x=x, y=y, xyorig=xyorig)
    except Exception as e:
        specmsg = 'Could not get spectrum: {0}'.format(e)
    else:
        # get error and wavelength
        error = convertIvarToErr(spectrum.ivar)
        wave = spectrum.wavelength
        # make input array for Dygraph
        webspec = [[wave[i], [s, error[i]]] for i, s in enumerate(spectrum.flux)]

        specmsg = "Spectrum in Spaxel ({2},{3}) at RA, Dec = ({0}, {1})".format(x, y, spectrum.x, spectrum.y)

    return webspec, specmsg


class Galaxy(FlaskView):
    route_base = '/galaxy'

    def __init__(self):
        ''' Initialize the route '''
        self.galaxy = {}
        self.galaxy['title'] = 'Marvin | Galaxy'
        self.galaxy['page'] = 'marvin-galaxy'
        self.galaxy['error'] = None
        self.galaxy['specmsg'] = None

    def before_request(self, *args, **kwargs):
        ''' Do these things before a request to any route '''
        self.galaxy['error'] = None
        self.galaxy['cube'] = None
        self.galaxy['image'] = ''
        self.galaxy['spectra'] = 'null'

    def index(self):
        ''' Main galaxy page '''
        self.galaxy['error'] = 'Not all there are you...  Try adding a plate-IFU or manga-ID to the end of the address.'
        return render_template("galaxy.html", **self.galaxy)

    def get(self, galid):
        ''' Retrieve info for a given cube '''
{'fraction_non_alphanumeric': 0.11714672337135125, 'fraction_numerical': 0.018944519621109608, 'mean_word_length': 3.0901185770750987, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6187865', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1601, 'n_words': 502}