<commit_before>"""
Unit test for PlotGroupPanel
$Id$
"""
__version__='$Revision$'

import unittest, os
import topo
from topo.sheets.generatorsheet import *
from topo.tkgui import *
from topo.base.patterngenerator import *
from topo.base.simulator import *
from PIL import Image
from topo.base.sheetview import *
from topo.plotting.bitmap import *
import topo.tkgui.topoconsole 
import topo.tkgui.plotgrouppanel
import Tkinter
from topo.sheets.cfsom import CFSOM
from math import pi
from topo.base.parameter import Dynamic
import random
import pdb #debugger
import topo.patterns.basic

class TestPlotGroupPanel(unittest.TestCase):

    def setUp(self):
        """
        Create a Simulator that has a couple of sheets within it that
        have data within them that can then be used by the GUI tests.
        Two objects created after completion:
            self.s   Sample simulation with a couple of sheets
        """
        GeneratorSheet.period = 1.0
        GeneratorSheet.density = 30
#        base.print_level = topo.base.topoobject.WARNING
#        GeneratorSheet.print_level = topo.base.topoobject.WARNING
        
        topo.patterns.basic.Gaussian.x = Dynamic(lambda : random.uniform(-0.5,0.5))
        topo.patterns.basic.Gaussian.y = Dynamic(lambda : random.uniform(-0.5,0.5))
        topo.patterns.basic.Gaussian.orientation = Dynamic(lambda :random.uniform(-pi,pi))

        width = 0.02
        height = 0.9
        topo.patterns.basic.Gaussian.size = height
        topo.patterns.basic.Gaussian.aspect_ratio = width/height
        topo.patterns.basic.Gaussian.bounds = BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))

        ###########################################
        # build simulation
        
#        topo.base.topoobject.min_print_level = topo.base.topoobject.WARNING
        
        self.s = Simulator()
        self.s.verbose("Creating simulation objects...")

        # Uses testbitmap.jpg.
        # Converts a JPG to a triple of arrays of [0 <= i <= 1].
        miata = Image.open('topo/tests/testbitmap.jpg')
        miata = miata.resize((miata.size[0]/2,miata.size[1]/2))
        self.rIm, self.gIm, self.bIm = miata.split()
        self.rseq = self.rIm.getdata()
        self.gseq = self.gIm.getdata()
        self.bseq = self.bIm.getdata()
        self.rar = Numeric.array(self.rseq)
        self.gar = Numeric.array(self.gseq)
        self.bar = Numeric.array(self.bseq)
        self.ra = Numeric.reshape(self.rar,miata.size) / 255.0
        self.ga = Numeric.reshape(self.gar,miata.size) / 255.0
        self.ba = Numeric.reshape(self.bar,miata.size) / 255.0

        sheetR = Sheet()
        sheetG = Sheet()
        sheetB = Sheet()
        retina = GeneratorSheet(input_generator=topo.patterns.basic.Gaussian())
        retina.print_level = topo.base.topoobject.WARNING

        # For a new sheet_group named Miata:
        sviewR = SheetView((self.ra,BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))))
        sviewG = SheetView((self.ga,BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))))
        sviewB = SheetView((self.ba,BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))))
        sheetR.add_sheet_view("Miata",sviewR)
        sheetG.add_sheet_view("Miata",sviewG)
        sheetB.add_sheet_view("Miata",sviewB)

        # To change the activation matrix so "Activity" plot_group
        # will be different.
        sheetR.activity = self.ra
        sheetG.activity = self.ga
        sheetB.activity = self.ba

        self.s.add(sheetR)<commit_msg>Directly access the Sheet.sheet_view_dict, instead of the add_sheet_view function the SheetViews. The function add_sheet_view will be soon deleted when all similar calls (in other files) will have been replaced.<commit_after>"""
Unit test for PlotGroupPanel
$Id$
"""
__version__='$Revision$'

import unittest, os
import topo
from topo.sheets.generatorsheet import *
from topo.tkgui import *
from topo.base.patterngenerator import *
from topo.base.simulator import *
from PIL import Image
from topo.base.sheetview import *
from topo.plotting.bitmap import *
import topo.tkgui.topoconsole 
import topo.tkgui.plotgrouppanel
import Tkinter
from topo.sheets.cfsom import CFSOM
from math import pi
from topo.base.parameter import Dynamic
import random
import pdb #debugger
import topo.patterns.basic

class TestPlotGroupPanel(unittest.TestCase):

    def setUp(self):
        """
        Create a Simulator that has a couple of sheets within it that
        have data within them that can then be used by the GUI tests.
        Two objects created after completion:
            self.s   Sample simulation with a couple of sheets
        """
        GeneratorSheet.period = 1.0
        GeneratorSheet.density = 30
#        base.print_level = topo.base.topoobject.WARNING
#        GeneratorSheet.print_level = topo.base.topoobject.WARNING
        
        topo.patterns.basic.Gaussian.x = Dynamic(lambda : random.uniform(-0.5,0.5))
        topo.patterns.basic.Gaussian.y = Dynamic(lambda : random.uniform(-0.5,0.5))
        topo.patterns.basic.Gaussian.orientation = Dynamic(lambda :random.uniform(-pi,pi))

        width = 0.02
        height = 0.9
        topo.patterns.basic.Gaussian.size = height
        topo.patterns.basic.Gaussian.aspect_ratio = width/height
        topo.patterns.basic.Gaussian.bounds = BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))

        ###########################################
        # build simulation
        
#        topo.base.topoobject.min_print_level = topo.base.topoobject.WARNING
        
        self.s = Simulator()
        self.s.verbose("Creating simulation objects...")

        # Uses testbitmap.jpg.
        # Converts a JPG to a triple of arrays of [0 <= i <= 1].
        miata = Image.open('topo/tests/testbitmap.jpg')
        miata = miata.resize((miata.size[0]/2,miata.size[1]/2))
        self.rIm, self.gIm, self.bIm = miata.split()
        self.rseq = self.rIm.getdata()
        self.gseq = self.gIm.getdata()
        self.bseq = self.bIm.getdata()
        self.rar = Numeric.array(self.rseq)
        self.gar = Numeric.array(self.gseq)
        self.bar = Numeric.array(self.bseq)
        self.ra = Numeric.reshape(self.rar,miata.size) / 255.0
        self.ga = Numeric.reshape(self.gar,miata.size) / 255.0
        self.ba = Numeric.reshape(self.bar,miata.size) / 255.0

        sheetR = Sheet()
        sheetG = Sheet()
        sheetB = Sheet()
        retina = GeneratorSheet(input_generator=topo.patterns.basic.Gaussian())
        retina.print_level = topo.base.topoobject.WARNING

        # For a new sheet_group named Miata:
        sviewR = SheetView((self.ra,BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))))
        sviewG = SheetView((self.ga,BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))))
        sviewB = SheetView((self.ba,BoundingBox(points=((-0.8,-0.8),(0.8,0.8)))))
        sheetR.sheet_view_dict["Miata"]=sviewR
        sheetG.sheet_view_dict["Miata"]=sviewG
        sheetB.sheet_view_dict["Miata"]=sviewB

        # To change the activation matrix so "Activity" plot_group
        # will be different.
        sheetR.activity = self.ra
        sheetG.activity = self.ga
        sheetB.activity = self.ba

        self.s.add(sheetR)
{'fraction_non_alphanumeric': 0.13177322746900683, 'fraction_numerical': 0.018665552305335006, 'mean_word_length': 2.708677685950413, 'pattern_counts': {'":': 0, '<': 7, '<?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': '116276', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2339, 'n_words': 473}