Exemple #1
0
    def test_time_shifting_special_case(self):
        """
        Sometimes actually changing the time value is necessary. This works but
        is considered experimental and thus emits a warning. Therefore Python
        >= 2.6 only.
        """
        output_filename = NamedTemporaryFile().name
        # This file was created only for testing purposes.
        filename = os.path.join(self.path, 'data',
            "one_record_already_applied_time_correction.mseed")
        with warnings.catch_warnings(record=True):
            warnings.simplefilter('error', UserWarning)
            self.assertRaises(UserWarning, util.shiftTimeOfFile,
                              input_file=filename, output_file=output_filename,
                              timeshift=123400)
            # Now ignore the warnings and test the default values.
            warnings.simplefilter('ignore', UserWarning)
            util.shiftTimeOfFile(input_file=filename,
                                 output_file=output_filename, timeshift=123400)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 12.34
        self.assertEqual(st_before, st_after)

        # Test negative shifts.
        with warnings.catch_warnings(record=True):
            warnings.simplefilter('ignore', UserWarning)
            util.shiftTimeOfFile(input_file=filename,
                                 output_file=output_filename, timeshift=-22222)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime -= 2.2222
        self.assertEqual(st_before, st_after)

        os.remove(output_filename)
Exemple #2
0
    def test_time_shifting(self):
        """
        Tests the shiftTimeOfFile() function.
        """
        output_filename = NamedTemporaryFile().name
        # Test a normal file first.
        filename = os.path.join(self.path, 'data',
                                "BW.BGLD.__.EHE.D.2008.001.first_10_records")
        # Shift by one second.
        util.shiftTimeOfFile(filename, output_filename, 10000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 1
        self.assertEqual(st_before, st_after)
        # Shift by 22 seconds in the other direction.
        util.shiftTimeOfFile(filename, output_filename, -220000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime -= 22
        self.assertEqual(st_before, st_after)
        # Shift by 11.33 seconds.
        util.shiftTimeOfFile(filename, output_filename, 113300)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 11.33
        self.assertEqual(st_before, st_after)

        # Test a special case with the time correction applied flag set but no
        # actual time correction in the field.
        filename = os.path.join(
            self.path, 'data',
            "one_record_time_corr_applied_but_time_corr_is_zero.mseed")
        # Positive shift.
        util.shiftTimeOfFile(filename, output_filename, 22000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 2.2
        self.assertEqual(st_before, st_after)
        # Negative shift.
        util.shiftTimeOfFile(filename, output_filename, -333000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime -= 33.3
        self.assertEqual(st_before, st_after)

        # Remove the file after everything it done.
        os.remove(output_filename)
Exemple #3
0
    def test_time_shifting(self):
        """
        Tests the shiftTimeOfFile() function.
        """
        output_filename = NamedTemporaryFile().name
        # Test a normal file first.
        filename = os.path.join(self.path, 'data',
                                "BW.BGLD.__.EHE.D.2008.001.first_10_records")
        # Shift by one second.
        util.shiftTimeOfFile(filename, output_filename, 10000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 1
        self.assertEqual(st_before, st_after)
        # Shift by 22 seconds in the other direction.
        util.shiftTimeOfFile(filename, output_filename, -220000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime -= 22
        self.assertEqual(st_before, st_after)
        # Shift by 11.33 seconds.
        util.shiftTimeOfFile(filename, output_filename, 113300)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 11.33
        self.assertEqual(st_before, st_after)

        # Test a special case with the time correction applied flag set but no
        # actual time correction in the field.
        filename = os.path.join(self.path, 'data',
                    "one_record_time_corr_applied_but_time_corr_is_zero.mseed")
        # Positive shift.
        util.shiftTimeOfFile(filename, output_filename, 22000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 2.2
        self.assertEqual(st_before, st_after)
        # Negative shift.
        util.shiftTimeOfFile(filename, output_filename, -333000)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime -= 33.3
        self.assertEqual(st_before, st_after)

        # Remove the file after everything it done.
        os.remove(output_filename)
Exemple #4
0
    def test_time_shifting_special_case(self):
        """
        Sometimes actually changing the time value is necessary. This works but
        is considered experimental and thus emits a warning. Therefore Python
        >= 2.6 only.
        """
        output_filename = NamedTemporaryFile().name
        # This file was created only for testing purposes.
        filename = os.path.join(
            self.path, 'data',
            "one_record_already_applied_time_correction.mseed")
        with warnings.catch_warnings(record=True):
            warnings.simplefilter('error', UserWarning)
            self.assertRaises(UserWarning,
                              util.shiftTimeOfFile,
                              input_file=filename,
                              output_file=output_filename,
                              timeshift=123400)
            # Now ignore the warnings and test the default values.
            warnings.simplefilter('ignore', UserWarning)
            util.shiftTimeOfFile(input_file=filename,
                                 output_file=output_filename,
                                 timeshift=123400)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime += 12.34
        self.assertEqual(st_before, st_after)

        # Test negative shifts.
        with warnings.catch_warnings(record=True):
            warnings.simplefilter('ignore', UserWarning)
            util.shiftTimeOfFile(input_file=filename,
                                 output_file=output_filename,
                                 timeshift=-22222)
        st_before = readMSEED(filename)
        st_after = readMSEED(output_filename)
        st_before[0].stats.starttime -= 2.2222
        self.assertEqual(st_before, st_after)

        os.remove(output_filename)