Commit 6143cce2 authored by Javier Quinteros's avatar Javier Quinteros

Bugfix: Merge Traces with same IDs in tests

Better comparison of numpy arrrays
parent 2f96d7d9
......@@ -20,6 +20,7 @@ any later version.
import sys
from datetime import datetime
from datetime import timedelta
import numpy as np
import unittest
from unittestTools import WITestRunner
from obspy import Trace
......@@ -50,9 +51,7 @@ class ConversionTests(unittest.TestCase):
aux = Trace(data=data[0], header=data[1])
conv = Stream([aux])
# print(orig[0].stats)
# print(conv[0].stats)
self.assertTrue((orig[0].data == conv[0].data).all(), 'Wrong comparison for one record and one channel!')
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for one record and one channel!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testOneChannel2(self):
......@@ -72,9 +71,31 @@ class ConversionTests(unittest.TestCase):
aux = Trace(data=data[0], header=data[1])
conv = Stream([aux])
# print(orig[0].stats)
# print(conv[0].stats)
self.assertTrue((orig[0].data == conv[0].data).all(), 'Wrong comparison for one record and one channel!')
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for one record and one channel!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testTwoFiles(self):
"""One record from one channel originally split in two files"""
directory = '/Users/javier/Nextcloud/share_Philippe'
# Start of the time window close to the beginning of the file
stt = datetime(2018, 9, 5, 9, 54, 3)
# Take only 250 samples
ett = stt + timedelta(seconds=1)
orig = read('testTwoFiles.mseed')
t = TDMS('PDN_1km', directory, chstart=99, chstop=99, starttime=stt, endtime=ett)
with t:
conv = Stream()
for data in t:
aux = Trace(data=data[0], header=data[1])
conv += aux
# Merge all Traces with same NSLC code
conv.merge()
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for channel 99!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testTwoChannels(self):
......@@ -95,8 +116,9 @@ class ConversionTests(unittest.TestCase):
aux = Trace(data=data[0], header=data[1])
conv += aux
self.assertTrue((orig[0].data == conv[0].data).all(), 'Wrong comparison for channel 100!')
self.assertTrue((orig[1].data == conv[1].data).all(), 'Wrong comparison for channel 101!')
# TODO Improve error message replacing the number for the ID in Trace.stats
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for channel 100!')
self.assertTrue(np.array_equal(orig[1].data, conv[1].data), 'Wrong comparison for channel 101!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testTwoChannels2(self):
......@@ -117,8 +139,8 @@ class ConversionTests(unittest.TestCase):
aux = Trace(data=data[0], header=data[1])
conv += aux
self.assertTrue((orig[0].data == conv[0].data).all(), 'Wrong comparison for channel 100!')
self.assertTrue((orig[1].data == conv[1].data).all(), 'Wrong comparison for channel 101!')
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for channel 100!')
self.assertTrue(np.array_equal(orig[1].data, conv[1].data), 'Wrong comparison for channel 101!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testTwoRecords(self):
......@@ -139,7 +161,10 @@ class ConversionTests(unittest.TestCase):
aux = Trace(data=data[0], header=data[1])
conv += aux
self.assertTrue((orig[0].data == conv[0].data).all(), 'Wrong comparison for channel 100!')
# Merge all Traces with same NSLC code
conv.merge()
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for channel 100!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment