Beispiel #1
0
    def testSerialization(self):
        from lazyflow.operator import Operator
        from tsdl.data import OpPickleCache
        d = {"class": Operator,
             "cache": {"class": OpPickleCache},
             "answer": 42,
             "a_list": [OpPickleCache, {"class": OpPickleCache,
                                        "tuple_in_dict": (1, 2, 3)}],
             "a_tuple": (OpPickleCache, {"class": OpPickleCache}),
             "nested": (1, [2, (3, 4, 5)]),
             "subdict": {"a": 1},
             "a_string": "asdf"}
        s = dumps(d)
        from pprint import pprint
        pprint(d)
        print("serialized to: \n{}".format(s))
        d2 = loads(s)
        print("")
        pprint(d2)
        assert d == d2

        class Custom(object):
            A = 1

        d = {"key": Custom()}
        with self.assertRaises(TypeError):
            dumps(d)
Beispiel #2
0
    def execute(self, slot, subindex, roi, result):
        assert len(self.All) == 2, "need prediction and ground truth"
        report = _DictReport()

        self._get_report(report)

        filename = os.path.join(self.WorkingDir.value, "report.json")
        with open(filename, 'w') as file_:
            file_.write(dumps(report.get_report()))
            file_.write("\n")

        result[:] = True
Beispiel #3
0
    def _pre_run(self):
        """
        prepare everything for the next run
        """
        assert self._config is not None,\
            "workflow not configured - did you run build()?"
        # write config file
        config_string = dumps(self._config, indent=4, sort_keys=True)
        filename = os.path.join(self._workingdir, "config.json")
        with open(filename, "w") as file_:
            file_.write(config_string)
            file_.write("\n")

        # perform sanity checks, terminate early if incompatible
        try:
            self._sanity_check()
        except IncompatibleTargets:
            self._cleanup()
            raise

        # keep time for reporting
        self._start_time = datetime.datetime.now()