예제 #1
0
파일: catalog.py 프로젝트: Abushalaa/segpy
    def _create_catalog_1(self):
        """Create a catalog for one-dimensional integer keys (i.e. scalars)
        """
        index_min = self._catalog[0][0]
        index_max = self._catalog[-1][0]
        index_stride = measure_stride(index for index, value in self._catalog)
        assert index_stride != 0

        value_start = self._catalog[0][1]
        value_stop = self._catalog[-1][1]
        value_stride = measure_stride(value for index, value in self._catalog)

        if index_stride is None and value_stride is None:
            # Dictionary strategy - arbitrary keys and values
            return DictionaryCatalog(self._catalog)

        if index_stride is not None and value_stride == 0:
            assert value_start == value_stop
            return RegularConstantCatalog(index_min,
                                          index_max,
                                          index_stride,
                                          value_start)

        if index_stride is None and value_stride == 0:
            assert value_start == value_stop
            return ConstantCatalog(
                    (index for index, value in self._catalog),
                    value_start)

        if index_stride is not None and value_stride is None:
            # Regular index - regular keys and arbitrary values
            return RegularCatalog(index_min,
                                  index_max,
                                  index_stride,
                                  (value for index, value in self._catalog))

        if (index_stride is not None) and (value_stride is not None):
            assert value_stride != 0
            return LinearRegularCatalog(index_min,
                                        index_max,
                                        index_stride,
                                        value_start,
                                        value_stop,
                                        value_stride)

        return DictionaryCatalog(self._catalog)
예제 #2
0
    def _create_catalog_1(self):
        """Create a catalog for one-dimensional integer keys (i.e. scalars)
        """
        index_min = self._catalog[0][0]
        index_max = self._catalog[-1][0]
        index_stride = measure_stride(index for index, value in self._catalog)

        if index_stride is None:
            # Dictionary strategy - arbitrary keys and values
            return DictionaryCatalog(self._catalog)

        self._catalog.sort(key=lambda index_value: index_value[1])
        value_min = self._catalog[0][1]
        value_max = self._catalog[-1][1]
        value_stride = measure_stride(value for index, value in self._catalog)

        if index_stride is not None and value_stride == 0:
            assert value_min == value_max
            return RegularConstantCatalog(index_min,
                                          index_max,
                                          index_stride,
                                          value_min)

        if index_stride is None and value_stride == 0:
            assert value_min == value_max
            return ConstantCatalog(
                    (index for index, value in self._catalog),
                    value_min)

        if index_stride is not None and value_stride is None:
            # Regular index - regular keys and arbitrary values
            return RegularCatalog(index_min,
                                  index_max,
                                  index_stride,
                                  (value for index, value in self._catalog))

        assert (index_stride is not None) and (value_stride is not None)
        catalog = LinearRegularCatalog(index_min,
                                       index_max,
                                       index_stride,
                                       value_min,
                                       value_max,
                                       value_stride)
        return catalog
예제 #3
0
    def _create_catalog_1(self):
        """Create a catalog for one-dimensional integer keys (i.e. scalars)
        """
        index_min = self._catalog[0][0]
        index_max = self._catalog[-1][0]
        index_stride = measure_stride(index for index, value in self._catalog)

        if index_stride is None:
            # Dictionary strategy - arbitrary keys and values
            return DictionaryCatalog(self._catalog)

        self._catalog.sort(key=lambda index_value: index_value[1])
        value_min = self._catalog[0][1]
        value_max = self._catalog[-1][1]
        value_stride = measure_stride(value for index, value in self._catalog)

        if index_stride is not None and value_stride == 0:
            assert value_min == value_max
            return RegularConstantCatalog(index_min,
                                          index_max,
                                          index_stride,
                                          value_min)

        if index_stride is None and value_stride == 0:
            assert value_min == value_max
            return ConstantCatalog(
                    (index for index, value in self._catalog),
                    value_min)

        if index_stride is not None and value_stride is None:
            # Regular index - regular keys and arbitrary values
            return RegularCatalog(index_min,
                                  index_max,
                                  index_stride,
                                  (value for index, value in self._catalog))

        assert (index_stride is not None) and (value_stride is not None)
        catalog = LinearRegularCatalog(index_min,
                                       index_max,
                                       index_stride,
                                       value_min,
                                       value_max,
                                       value_stride)
        return catalog
예제 #4
0
파일: catalog.py 프로젝트: wassname/segpy
    def _create_catalog_1(self):
        """Create a catalog for one-dimensional integer keys (i.e. scalars)
        """
        index_min = self._catalog[0][0]
        index_max = self._catalog[-1][0]
        index_stride = measure_stride(index for index, value in self._catalog)
        assert index_stride != 0

        value_start = self._catalog[0][1]
        value_stop = self._catalog[-1][1]
        value_stride = measure_stride(value for index, value in self._catalog)

        if index_stride is None and value_stride is None:
            # Dictionary strategy - arbitrary keys and values
            return DictionaryCatalog(self._catalog)

        if index_stride is not None and value_stride == 0:
            assert value_start == value_stop
            return RegularConstantCatalog(index_min, index_max, index_stride,
                                          value_start)

        if index_stride is None and value_stride == 0:
            assert value_start == value_stop
            return ConstantCatalog((index for index, value in self._catalog),
                                   value_start)

        if index_stride is not None and value_stride is None:
            # Regular index - regular keys and arbitrary values
            return RegularCatalog(index_min, index_max, index_stride,
                                  (value for index, value in self._catalog))

        if (index_stride is not None) and (value_stride is not None):
            assert value_stride != 0
            return LinearRegularCatalog(index_min, index_max, index_stride,
                                        value_start, value_stop, value_stride)

        return DictionaryCatalog(self._catalog)
예제 #5
0
파일: test_util.py 프로젝트: yzchs7/segpy
 def test_stride_of_empty_sequence_is_none(self, s):
     assert measure_stride(s) is None
예제 #6
0
파일: test_util.py 프로젝트: yzchs7/segpy
 def test_measure_list_stride_irregular(self, r):
     t = list(r) + list(r)
     s = measure_stride(t)
     assert s is None
예제 #7
0
파일: test_util.py 프로젝트: yzchs7/segpy
 def test_measure_list_stride_regular(self, r):
     t = list(r)
     s = measure_stride(t)
     assert s == r.step
예제 #8
0
파일: test_util.py 프로젝트: yzchs7/segpy
 def test_measure_range_stride(self, r):
     s = measure_stride(r)
     assert s == r.step
예제 #9
0
파일: test_util.py 프로젝트: abingham/segpy
 def test_stride_of_empty_sequence_is_none(self, s):
     assert measure_stride(s) is None
예제 #10
0
파일: test_util.py 프로젝트: abingham/segpy
 def test_measure_list_stride_irregular(self, r):
     t = list(r) + list(r)
     s = measure_stride(t)
     assert s is None
예제 #11
0
파일: test_util.py 프로젝트: abingham/segpy
 def test_measure_list_stride_regular(self, r):
     t = list(r)
     s = measure_stride(t)
     assert s == r.step
예제 #12
0
파일: test_util.py 프로젝트: abingham/segpy
 def test_measure_range_stride(self, r):
     s = measure_stride(r)
     assert s == r.step