Exemple #1
0
 def test_grouping(self):
     fldr4=SF.DataFolder()
     x=np.linspace(-np.pi,np.pi,181)
     for phase in np.linspace(0,1.0,5):
         for amplitude in np.linspace(1,2,6):
             for frequency in np.linspace(1,2,5):
                 y=amplitude*np.sin(frequency*x+phase*np.pi)
                 d=Data(x,y,setas="xy",column_headers=["X","Y"])
                 d["frequency"]=frequency
                 d["amplitude"]=amplitude
                 d["phase"]=phase
                 d["params"]=[phase,frequency,amplitude]
                 d.filename="test/{amplitude}/{phase}/{frequency}.dat".format(**d)
                 fldr4+=d
     fldr4.unflatten()
     self.assertEqual(fldr4.mindepth,3,"Unflattened DataFolder had wrong mindepth.")
     self.assertEqual(fldr4.shape, (~~fldr4).shape,"Datafodler changed shape on flatten/unflatten")
     fldr5=fldr4.select(amplitude=1.4,recurse=True)
     fldr5.prune()
     pruned=(0,
             {'test': (0,
                {'1.4': (0,
                  {'0.0': (5, {}),
                   '0.25': (5, {}),
                   '0.5': (5, {}),
                   '0.75': (5, {}),
                   '1.0': (5, {})})})})
     selected=(0,
             {'test': (0,
                {'1.4': (0,
                  {'0.25': (1, {}), '0.5': (1, {}), '0.75': (1, {}), '1.0': (1, {})})})})
     self.assertEqual(fldr5.shape,pruned,"Folder pruning gave an unxpected shape.")
     self.assertEqual(fldr5[("test","1.4","0.5",0,"phase")],0.5,"Multilevel indexing of tree failed.")
     shape=(~(~fldr4).select(amplitude=1.4).select(frequency=1).select(phase__gt=0.2)).shape
     self.fldr4=fldr4
     self.assertEqual(shape, selected,"Multi selects and inverts failed.")
     g=(~fldr4)/10
     self.assertEqual(g.shape,(0,{'Group 0': (15, {}),'Group 1': (15, {}),'Group 2': (15, {}),'Group 3': (15, {}),'Group 4': (15, {}),
                                  'Group 5': (15, {}),'Group 6': (15, {}),'Group 7': (15, {}),'Group 8': (15, {}),'Group 9': (15, {})}),"Dive by int failed.")
     g["Group 6"]-=5
     self.assertEqual(g.shape,(0,{'Group 0': (15, {}),'Group 1': (15, {}),'Group 2': (15, {}),'Group 3': (15, {}),'Group 4': (15, {}),
                                  'Group 5': (15, {}),'Group 6': (14, {}),'Group 7': (15, {}),'Group 8': (15, {}),'Group 9': (15, {})}),"Sub by int failed.")
     remove=g["Group 3"][4]
     g["Group 3"]-=remove
     self.assertEqual(g.shape,(0,{'Group 0': (15, {}),'Group 1': (15, {}),'Group 2': (15, {}),'Group 3': (14, {}),'Group 4': (15, {}),
                                  'Group 5': (15, {}),'Group 6': (14, {}),'Group 7': (15, {}),'Group 8': (15, {}),'Group 9': (15, {})}),"Sub by object failed.")
     d=fldr4["test",1.0,1.0].gather(0,1)
     self.assertEqual(d.shape,(181,6),"Gather seems have failed.")
     self.assertTrue(np.all(fldr4["test",1.0,1.0].slice_metadata("phase")==
                            np.ones(5)),"Slice metadata failure.")
     d=(~fldr4).extract("phase","frequency","amplitude","params")
     self.assertEqual(d.shape,(150,6),"Extract failed to produce data of correct shape.")
     self.assertEqual(d.column_headers,['phase', 'frequency', 'amplitude', 'params', 'params', 'params'],"Exctract failed to get correct column headers.")
     p=fldr4["test",1.0,1.0]
     p=SF.PlotFolder(p)
     p.plot()
     self.assertEqual(len(plt.get_fignums()),1,"Failed to generate a single plot for PlotFolder.")
     plt.close("all")
Exemple #2
0
 def test_attr_access(self):
     self.fldr=SF.PlotFolder(path.join(self.datadir,"NLIV"),pattern="*.txt",setas="yx")