Ejemplo n.º 1
0
 def test_truncated_read_binary_values_raises_eof_error(self, seg_y_type, num_items, endian, data):
     assume(seg_y_type != SegYType.IBM)
     ctype = SEG_Y_TYPE_TO_CTYPE[seg_y_type]
     c_format = ''.join(map(str, (endian, num_items, ctype)))
     py_type = PY_TYPES[seg_y_type]
     min_value, max_value = LIMITS[seg_y_type]
     items_written = data.draw(st.lists(
         elements=NUMBER_STRATEGY[py_type](min_value=min_value, max_value=max_value),
         min_size=num_items, max_size=num_items))
     buffer = struct.pack(c_format, *items_written)
     truncate_pos = data.draw(st.integers(min_value=0, max_value=max(0, len(buffer) - 1)))
     truncated_buffer = buffer[:truncate_pos]
     with BytesIO(truncated_buffer) as fh:
         with raises(EOFError):
             toolkit.read_binary_values(fh, 0, seg_y_type, num_items, endian)
Ejemplo n.º 2
0
 def test_read_binary_values_successfully(self, seg_y_type, num_items, endian, data):
     assume(seg_y_type != SegYType.IBM)
     ctype = SEG_Y_TYPE_TO_CTYPE[seg_y_type]
     c_format = ''.join(map(str, (endian, num_items, ctype)))
     py_type = PY_TYPES[seg_y_type]
     min_value, max_value = LIMITS[seg_y_type]
     items_written = data.draw(st.lists(
         elements=NUMBER_STRATEGY[py_type](min_value=min_value, max_value=max_value),
         min_size=num_items, max_size=num_items))
     buffer = struct.pack(c_format, *items_written)
     with BytesIO(buffer) as fh:
         items_read = toolkit.read_binary_values(fh, 0, seg_y_type, num_items, endian)
         assert all(a == b for a, b in zip_longest(items_read, items_read))
Ejemplo n.º 3
0
    def trace_samples(self, trace_index, start=None, stop=None):
        """Read a specific trace_samples.

        Args:
            trace_index: An integer in the range zero to num_traces() - 1

            start: Optional zero-based start sample index. The default
                is to read from the first (i.e. zeroth) sample.

            stop: Optional zero-based stop sample index. Following Python
                slice convention this is one beyond the end.

        Returns:
            A sequence of numeric trace_samples samples.

        Example:

            first_trace_samples = segy_reader.trace_samples(0)
            part_of_second_trace_samples = segy_reader.trace_samples(1, 1000, 2000)
        """
        if not (0 <= trace_index < self.num_traces()):
            raise ValueError("Trace index out of range.")

        num_samples_in_trace = self.num_trace_samples(trace_index)

        start_sample = start if start is not None else 0
        stop_sample = stop if stop is not None else num_samples_in_trace

        if not (0 <= stop_sample <= num_samples_in_trace):
            raise ValueError(
                "trace_samples(): stop value {} out of range 0 to {}".format(
                    stop, num_samples_in_trace))

        if not (0 <= start_sample <= stop_sample):
            raise ValueError(
                "trace_samples(): start value {} out of range 0 to {}".format(
                    start, stop_sample))

        dsf = self._binary_reel_header.data_sample_format
        seg_y_type = DATA_SAMPLE_FORMAT_TO_SEG_Y_TYPE[dsf]
        start_pos = (
            self._trace_offset_catalog[trace_index] + TRACE_HEADER_NUM_BYTES +
            start_sample * size_in_bytes(SEG_Y_TYPE_TO_CTYPE[seg_y_type]))
        num_samples_to_read = stop_sample - start_sample

        trace_values = read_binary_values(self._fh, start_pos, seg_y_type,
                                          num_samples_to_read, self._endian)
        return trace_values
Ejemplo n.º 4
0
    def trace_samples(self, trace_index, start=None, stop=None):
        """Read a specific trace_samples.

        Args:
            trace_index: An integer in the range zero to num_traces() - 1

            start: Optional zero-based start sample index. The default
                is to read from the first (i.e. zeroth) sample.

            stop: Optional zero-based stop sample index. Following Python
                slice convention this is one beyond the end.

        Returns:
            A sequence of numeric trace_samples samples.

        Example:

            first_trace_samples = segy_reader.trace_samples(0)
            part_of_second_trace_samples = segy_reader.trace_samples(1, 1000, 2000)
        """
        if not (0 <= trace_index < self.num_traces()):
            raise ValueError("Trace index out of range.")

        num_samples_in_trace = self.num_trace_samples(trace_index)

        start_sample = start if start is not None else 0
        stop_sample = stop if stop is not None else num_samples_in_trace

        if not (0 <= stop_sample <= num_samples_in_trace):
            raise ValueError("trace_samples(): stop value {} out of range 0 to {}"
                             .format(stop, num_samples_in_trace))

        if not (0 <= start_sample <= stop_sample):
            raise ValueError("trace_samples(): start value {} out of range 0 to {}"
                             .format(start, stop_sample))

        dsf = self._binary_reel_header.data_sample_format
        seg_y_type = DATA_SAMPLE_FORMAT_TO_SEG_Y_TYPE[dsf]
        start_pos = (self._trace_offset_catalog[trace_index]
                     + TRACE_HEADER_NUM_BYTES
                     + start_sample * size_in_bytes(SEG_Y_TYPE_TO_CTYPE[seg_y_type]))
        num_samples_to_read = stop_sample - start_sample

        trace_values = read_binary_values(
            self._fh, start_pos, seg_y_type, num_samples_to_read, self._endian)
        return trace_values
Ejemplo n.º 5
0
 def test_read_binary_values_successfully(self, seg_y_type, num_items,
                                          endian, data):
     assume(seg_y_type != SegYType.IBM)
     ctype = SEG_Y_TYPE_TO_CTYPE[seg_y_type]
     c_format = ''.join(map(str, (endian, num_items, ctype)))
     py_type = PY_TYPES[seg_y_type]
     min_value, max_value = LIMITS[seg_y_type]
     items_written = data.draw(
         st.lists(elements=NUMBER_STRATEGY[py_type](min_value=min_value,
                                                    max_value=max_value),
                  min_size=num_items,
                  max_size=num_items))
     buffer = struct.pack(c_format, *items_written)
     with BytesIO(buffer) as fh:
         items_read = toolkit.read_binary_values(fh, 0, seg_y_type,
                                                 num_items, endian)
         assert all(a == b for a, b in zip_longest(items_read, items_read))