當前位置: 首頁>>代碼示例>>Python>>正文


Python ThunderContext.loadParams方法代碼示例

本文整理匯總了Python中thunder.ThunderContext.loadParams方法的典型用法代碼示例。如果您正苦於以下問題:Python ThunderContext.loadParams方法的具體用法?Python ThunderContext.loadParams怎麽用?Python ThunderContext.loadParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在thunder.ThunderContext的用法示例。


在下文中一共展示了ThunderContext.loadParams方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestContextLoading

# 需要導入模塊: from thunder import ThunderContext [as 別名]
# 或者: from thunder.ThunderContext import loadParams [as 別名]

#.........這裏部分代碼省略.........
        del pilImg, tmpAry

        rangeSeries = self.tsc.loadImagesAsSeries(self.outputdir, inputFormat="tif-stack")
        assert_equals('float16', rangeSeries._dtype)
        rangeSeriesAry = rangeSeries.pack()
        rangeSeriesAry_xpose = rangeSeries.pack(transpose=True)

        assert_equals((60, 120), rangeSeries.dims.count)  # 2d tif now loaded as 2d image; was 3d with singleton z dim
        assert_equals((2, 60, 120), rangeSeriesAry.shape)
        assert_equals((2, 120, 60), rangeSeriesAry_xpose.shape)
        assert_equals('float16', str(rangeSeriesAry.dtype))
        assert_true(array_equal(rangeAry, rangeSeriesAry[0]))
        assert_true(array_equal(rangeAry2, rangeSeriesAry[1]))
        assert_true(array_equal(rangeAry.T, rangeSeriesAry_xpose[0]))
        assert_true(array_equal(rangeAry2.T, rangeSeriesAry_xpose[1]))

    @unittest.skipIf(not _have_image, "PIL/pillow not installed or not functional")
    def test_loadMultipleMultipointTifsAsSeries(self):
        testResourcesDir = TestContextLoading._findTestResourcesDir()
        imagesPath = os.path.join(testResourcesDir, "multilayer_tif", "dotdotdot_lzw*.tif")

        # load only one file, second is a copy of this one
        testimg_pil = Image.open(os.path.join(testResourcesDir, "multilayer_tif", "dotdotdot_lzw.tif"))
        testimg_arys = [array(testimg_pil)]
        for idx in xrange(1, 3):
            testimg_pil.seek(idx)
            testimg_arys.append(array(testimg_pil))

        rangeSeries = self.tsc.loadImagesAsSeries(imagesPath, inputFormat="tif-stack", nplanes=1)
        assert_equals((70, 75), rangeSeries.dims.count)

        rangeSeriesAry = rangeSeries.pack()
        assert_equals((6, 70, 75), rangeSeriesAry.shape)
        for idx in xrange(6):
            assert_true(array_equal(testimg_arys[idx % 3], rangeSeriesAry[idx]))

    @staticmethod
    def _tempFileWithPaths(f, blob):
        f.write(blob)
        f.flush()
        return f.name

    def test_loadParams(self):

        params = json.dumps({"name": "test1", "value": [1, 2, 3]})

        f = tempfile.NamedTemporaryFile()
        path = TestContextLoading._tempFileWithPaths(f, params)

        d = self.tsc.loadParams(path)

        assert(d.names() == ["test1"])
        assert(array_equal(d.values(), [1, 2, 3]))

        params = json.dumps([{"name": "test0", "value": [1, 2, 3]},
                             {"name": "test1", "value": [4, 5, 6]}])

        f = tempfile.NamedTemporaryFile()
        path = TestContextLoading._tempFileWithPaths(f, params)
        d = self.tsc.loadParams(path)

        assert(d.names() == ["test0", "test1"])
        assert(array_equal(d.values(), [[1, 2, 3], [4, 5, 6]]))
        assert(array_equal(d.values("test0"), [1, 2, 3]))

    def test_loadSeriesFromArray(self):

        target = array([[0, 1], [0, 2]])
        d1 = self.tsc.loadSeriesFromArray([[0, 1], [0, 2]])
        d2 = self.tsc.loadSeriesFromArray(array([[0, 1], [0, 2]]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect(), [(0,), (1,)])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect(), [(0,), (1,)])

        target = array([[0, 1]])
        d1 = self.tsc.loadSeriesFromArray([0, 1])
        d2 = self.tsc.loadSeriesFromArray(array([0, 1]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect(), [(0,)])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect(), [(0,)])

    def test_loadImagesFromArray(self):

        target = array([[[0, 1], [0, 2]]])
        d1 = self.tsc.loadImagesFromArray([[0, 1], [0, 2]])
        d2 = self.tsc.loadImagesFromArray(array([[0, 1], [0, 2]]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect() == [0])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect() == [0])

        target = array([[[0, 1], [0, 2]], [[0, 1], [0, 2]]])
        d1 = self.tsc.loadImagesFromArray([[[0, 1], [0, 2]], [[0, 1], [0, 2]]])
        d2 = self.tsc.loadImagesFromArray(array([[[0, 1], [0, 2]], [[0, 1], [0, 2]]]))
        assert(array_equal(d1.collectValuesAsArray(), target))
        assert(d1.keys().collect() == [0, 1])
        assert(array_equal(d2.collectValuesAsArray(), target))
        assert(d2.keys().collect() == [0, 1])
開發者ID:Peichao,項目名稱:thunder,代碼行數:104,代碼來源:test_context.py


注:本文中的thunder.ThunderContext.loadParams方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。