Skip to content

Commit

Permalink
Fix up SG_Filter and add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gb119 committed Oct 6, 2019
1 parent 7fd3d46 commit 9798b1a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Stoner/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def SG_Filter(
)
else:
header = [header] * (len(col) - 1)
for column, head in zip(r[:-1], header):
if r.shape[0] > len(header):
iterdata = r[: len(header)]
else:
iterdata = r
for column, head in zip(iterdata, header):
self.add_column(column.ravel(), header=head, index=result, replace=replace)
return self
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/Stoner/folders/test_Folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,6 @@ def test_saving(self):
if __name__=="__main__": # Run some tests manually to allow debugging
test=Folders_test("test_Folders")
test.setUp()
unittest.main()
#test.test_methods()
#unittest.main()
test.test_Base_Operators()

11 changes: 11 additions & 0 deletions tests/Stoner/test_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,19 @@ def test_integrate(self):
fx=d.interpolate(None)
self.assertEqual(fx(np.linspace(1,1500,101)).shape,(101,7),"Failed to get the interpolated shape right")

def test_sg_filter(self):
x=np.linspace(0,10*np.pi,1001)
y=np.sin(x)+np.random.normal(size=1001,scale=0.05)
d=Data(x,y,column_headers=["Time","Signal"],setas="xy")
d.SG_Filter(order=1,result=True)
d.setas="x.y"
d.y=d.y-np.cos(x)
self.assertAlmostEqual(d.y[5:-5].mean(), 0,places=2,msg="Failed to differentiate correctly")


if __name__=="__main__": # Run some tests manually to allow debugging
test=Analysis_test("test_functions")
test.setUp()
#test.test_peaks()
unittest.main()
#test.test_integrate()

0 comments on commit 9798b1a

Please sign in to comment.