本文整理汇总了Python中Stoner.Data.filename方法的典型用法代码示例。如果您正苦于以下问题:Python Data.filename方法的具体用法?Python Data.filename怎么用?Python Data.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stoner.Data
的用法示例。
在下文中一共展示了Data.filename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_grouping
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import filename [as 别名]
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")
示例2: test_saving
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import filename [as 别名]
def test_saving(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()
newdir=tempfile.mkdtemp()
fldr4.save(newdir)
fldr5=SF.DataFolder(newdir)
self.assertEqual(fldr4.shape,fldr5.shape,"Saved DataFolder and loaded DataFolder have different shapes")