<commit_before>import numpy as np
import matplotlib
#matplotlib.use('KtAgg')
import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
from matplotlib import colors
from matplotlib.patches import Circle
from matplotlib.figure import *
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as NavigationToolbar
import os
if os.environ.get('QT_API', None) is None:
    from PyQt4 import QtGui, QtCore
else:
    from PySide import QtGui, QtCore
    
from astropy import units as u
from tardis import analysis, util

# def current_ion_index(index, index_list):
#     if not index in index_list:
#         return None
#     if not (index - 1) in index_list:
#         return 0
#     else:
#         return current_ion_index(index - 1, index_list) + 1
#
# def current_ion_index(index, duplicate_list):
#     if duplicate_list[index - 1] != duplicate_list[index]:
#         return 0
#     else:
#         return current_ion_index(index - 1, duplicate_list) + 1

#The main TARDIS window
class ModelViewer(QtGui.QWidget):
    def __init__(self, parent=None):
        # assumes that qt has already been initialized by starting IPython with the flag "--pylab=qt"
        app = QtCore.QCoreApplication.instance()
        if app is None:
            app = QtGui.QApplication([])
        try:
            from IPython.lib.guisupport import start_event_loop_qt4
            start_event_loop_qt4(app)
        except ImportError:
            app.exec_()

        super(ModelViewer, self).__init__(parent)
        
        #Data structures
        self.model = None
        self.shell_info = {}
        self.line_info = []

        #Setting QWidget properties
        self.setGeometry(20, 35, 1250, 500)
        self.setWindowTitle('Shells Viewer')

        #Plot of shells
        self.graph = MatplotlibWidget(self, 'model')
        self.graph_label = QtGui.QLabel('Select Property:')
        self.graph_button = QtGui.QToolButton()
        self.graph_button.setText('Rad. temp')
        self.graph_button.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
        self.graph_button.setMenu(QtGui.QMenu(self.graph_button))
        self.graph_button.menu().addAction('Rad. temp').triggered.connect(self.change_graph_to_t_rads)
        self.graph_button.menu().addAction('Ws').triggered.connect(self.change_graph_to_ws)
        
        #Plot of spectrum
        self.spectrum = MatplotlibWidget(self)
        self.spectrum_label = QtGui.QLabel('Select Spectrum:')<commit_msg>New class added to wrap modelviewer<commit_after>import numpy as np
import matplotlib
#matplotlib.use('KtAgg')
import matplotlib.pylab as plt
import matplotlib.gridspec as gridspec
from matplotlib import colors
from matplotlib.patches import Circle
from matplotlib.figure import *
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as NavigationToolbar
import os
if os.environ.get('QT_API', None) is None:
    from PyQt4 import QtGui, QtCore
else:
    from PySide import QtGui, QtCore
    
from astropy import units as u
from tardis import analysis, util

# def current_ion_index(index, index_list):
#     if not index in index_list:
#         return None
#     if not (index - 1) in index_list:
#         return 0
#     else:
#         return current_ion_index(index - 1, index_list) + 1
#
# def current_ion_index(index, duplicate_list):
#     if duplicate_list[index - 1] != duplicate_list[index]:
#         return 0
#     else:
#         return current_ion_index(index - 1, duplicate_list) + 1

#The main TARDIS window
class Tardis(QtGui.QMainWindow):

    def __init__(self, parent=None):
        # assumes that qt has already been initialized by starting IPython with the flag "--pylab=qt"
        app = QtCore.QCoreApplication.instance()
        if app is None:
            app = QtGui.QApplication([])
        try:
            from IPython.lib.guisupport import start_event_loop_qt4
            start_event_loop_qt4(app)
        except ImportError:
            app.exec_()

        super(Tardis, self).__init__(parent)

        self.mdv = ModelViewer() 
        self.setCentralWidget(self.mdv) 

    def show_model(self, model=None):
        if model:
            self.mdv.change_model(model)
        self.mdv.tableview.setModel(self.mdv.tablemodel)
        self.mdv.plot_model()
        self.mdv.plot_spectrum()
        self.show()

#The central widget
class ModelViewer(QtGui.QWidget):

    def __init__(self, parent=None):

        super(ModelViewer, self).__init__(parent)
        
        #Data structures
        self.model = None
        self.shell_info = {}
        self.line_info = []

        #Setting QWidget properties
        self.setGeometry(20, 35, 1250, 500)
        self.setWindowTitle('Shells Viewer')

        #Plot of shells
        self.graph = MatplotlibWidget(self, 'model')
        self.graph_label = QtGui.QLabel('Select Property:')
        self.graph_button = QtGui.QToolButton()
        self.graph_button.setText('Rad. temp')
        self.graph_button.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
        self.graph_button.setMenu(QtGui.QMenu(self.graph_button))
        self.graph_button.menu().addAction('Rad. temp').triggered.connect(self.change_graph_to_t_rads)
        self.graph_button.menu().addAction('Ws').triggered.connect(self.change_graph_to_ws)
        
        #Plot of spectrum
        self.spectrum = MatplotlibWidget(self)
        self.spectrum_label = QtGui.QLabel('Select Spectrum:')
{'fraction_non_alphanumeric': 0.09011264080100125, 'fraction_numerical': 0.008939746111210442, 'mean_word_length': 2.9871703492516035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '600158', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1715, 'n_words': 405}