Ejemplo n.º 1
0
 def test_read_and_write_textual_file_header(self):
     """
     Reading and writing should not change the textual file header.
     """
     for file, attribs in self.files.items():
         endian = attribs['endian']
         header_enc = attribs['textual_header_enc']
         file = os.path.join(self.path, file)
         # Read the file.
         with open(file, 'rb') as f:
             org_header = f.read(3200)
             f.seek(0, 0)
             # Initialize an empty SEGY object and set certain attributes.
             segy = SEGYFile()
             segy.endian = endian
             segy.file = f
             segy.textual_header_encoding = None
             # Read the textual header.
             segy._read_textual_header()
             # Assert the encoding and compare with known values.
             self.assertEqual(segy.textual_header_encoding, header_enc)
         # The header writes to a file like object.
         new_header = io.BytesIO()
         with warnings.catch_warnings(record=True):
             segy._write_textual_header(new_header)
         new_header.seek(0, 0)
         new_header = new_header.read()
         # Assert the correct length.
         self.assertEqual(len(new_header), 3200)
         # Patch both headers to not worry about the automatically set
         # values.
         org_header = _patch_header(org_header)
         new_header = _patch_header(new_header)
         # Assert the actual header.
         self.assertEqual(org_header, new_header)
Ejemplo n.º 2
0
    def test_reading_and_writing_with_unset_dates(self):
        f = SEGYFile()
        f.binary_file_header = SEGYBinaryFileHeader()
        s = SEGYTrace()
        f.traces = [s]
        s.data = np.ones(10, dtype=np.float32)

        # Create a dummy file with only the year set.
        s.header.year_data_recorded = 2015
        with io.BytesIO() as buf:
            f.write(buf, data_encoding=5)
            buf.seek(0, 0)
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                st = read(buf, format="segy")
        # Should result in the correct year.
        self.assertEqual(st[0].stats.starttime, UTCDateTime(2015, 1, 1))
        self.assertEqual(len(w), 1)
        self.assertEqual(
            w[0].message.args[0],
            "Trace starttime does not store a proper date (day of year is "
            "zero). Using January 1st 00:00 as trace start time.")

        # No date set at all.
        s.header.year_data_recorded = 0
        with io.BytesIO() as buf:
            f.write(buf, data_encoding=5)
            buf.seek(0, 0)
            st = read(buf, format="segy")
        # Results in 1970, 1, 1
        self.assertEqual(st[0].stats.starttime, UTCDateTime(0))
Ejemplo n.º 3
0
 def test_read_and_write_textual_file_header(self):
     """
     Reading and writing should not change the textual file header.
     """
     for file, attribs in self.files.items():
         endian = attribs['endian']
         header_enc = attribs['textual_header_enc']
         file = os.path.join(self.path, file)
         # Read the file.
         with open(file, 'rb') as f:
             org_header = f.read(3200)
             f.seek(0, 0)
             # Initialize an empty SEGY object and set certain attributes.
             segy = SEGYFile()
             segy.endian = endian
             segy.file = f
             segy.textual_header_encoding = None
             # Read the textual header.
             segy._read_textual_header()
             # Assert the encoding and compare with known values.
             self.assertEqual(segy.textual_header_encoding, header_enc)
         # The header writes to a file like object.
         new_header = io.BytesIO()
         with warnings.catch_warnings(record=True):
             segy._write_textual_header(new_header)
         new_header.seek(0, 0)
         new_header = new_header.read()
         # Assert the correct length.
         self.assertEqual(len(new_header), 3200)
         # Patch both headers to not worry about the automatically set
         # values.
         org_header = _patch_header(org_header)
         new_header = _patch_header(new_header)
         # Assert the actual header.
         self.assertEqual(org_header, new_header)
Ejemplo n.º 4
0
    def test_reading_and_writing_with_unset_dates(self):
        f = SEGYFile()
        f.binary_file_header = SEGYBinaryFileHeader()
        s = SEGYTrace()
        f.traces = [s]
        s.data = np.ones(10, dtype=np.float32)

        # Create a dummy file with only the year set.
        s.header.year_data_recorded = 2015
        with io.BytesIO() as buf:
            f.write(buf, data_encoding=5)
            buf.seek(0, 0)
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                st = read(buf, format="segy")
        # Should result in the correct year.
        self.assertEqual(st[0].stats.starttime, UTCDateTime(2015, 1, 1))
        self.assertEqual(len(w), 1)
        self.assertEqual(
            w[0].message.args[0],
            "Trace starttime does not store a proper date (day of year is "
            "zero). Using January 1st 00:00 as trace start time.")

        # No date set at all.
        s.header.year_data_recorded = 0
        with io.BytesIO() as buf:
            f.write(buf, data_encoding=5)
            buf.seek(0, 0)
            st = read(buf, format="segy")
        # Results in 1970, 1, 1
        self.assertEqual(st[0].stats.starttime, UTCDateTime(0))