37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
"""Independent analytic data checks for offline estimands, no CFD context."""
|
|
import unittest
|
|
import numpy as np
|
|
from research.fig2_collection.analyze import frequency, native_summary, compare_selected
|
|
|
|
|
|
class AnalysisTests(unittest.TestCase):
|
|
def test_frequency_units_and_no_dc(self):
|
|
dt=.005/40;n=640000
|
|
t=np.arange(n)*dt
|
|
result=frequency(4+np.sin(2*np.pi*.2*t),dt)
|
|
self.assertAlmostEqual(result['f_D_U'],.2)
|
|
self.assertAlmostEqual(result['bin_width_D_U'],1/80)
|
|
self.assertIsNone(frequency(np.ones(20),dt))
|
|
|
|
def test_motion_and_native_rhs_are_distinct_from_node_impulse(self):
|
|
a=np.zeros((10,18));a[:,0]=np.arange(1,11);a[:,1]=40*np.tile([.5,-.5],5)
|
|
a[:,3]=.001;a[:,6]=.002;a[:,9]=999
|
|
result=native_summary(a,'taylor')
|
|
self.assertEqual(result['motion']['centered_rms'],.5)
|
|
self.assertEqual(result['motion']['half_range'],.5)
|
|
self.assertAlmostEqual(result['structural_RHS_Cy_RMS'],6.)
|
|
self.assertEqual(result['window_D_U'],[0.,10*.005/40])
|
|
|
|
def test_selected_vector_error_uses_common_roi_and_actual_flags(self):
|
|
shape=(1,712,2162)
|
|
target=dict(ux=np.zeros(shape,np.float32),uy=np.zeros(shape,np.float32),flags=np.ones(shape,np.uint16))
|
|
current={k:v.copy() for k,v in target.items()}
|
|
current['ux'][:,311:711,1360:2161]=.003
|
|
current['uy'][:,311:711,1360:2161]=.004
|
|
self.assertAlmostEqual(compare_selected(target,current)['aggregate_E'],1.,places=6)
|
|
current['flags'][0,400,1500]=2
|
|
with self.assertRaises(ValueError):compare_selected(target,current)
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|