Ejemplo n.º 1
0
    def save_field(self, field_i, _save_debug=True, **kwargs):
        """
        When using parallel field maps we can not save into the result
        because that will not be serialized back to the main thread.
        Rather, use temporary files and gather at save()

        Note that there is no guarantee of the order these are created.
        """

        # CONVERT raw_mask_rects to a DataFrame
        # rows = [
        #     (field_i, ch, cy, rect[0], rect[1], rect[2], rect[3])
        #     for ch, cy_rects in enumerate(kwargs.pop("raw_mask_rects"))
        #     for cy, rects in enumerate(cy_rects)
        #     for i, rect in enumerate(rects)
        # ]
        # kwargs["mask_rects_df"] = pd.DataFrame(
        #     rows, columns=["field_i", "channel_i", "cycle_i", "l", "r", "w", "h"]
        # )

        non_debug_kwargs = {
            k: v
            for k, v in kwargs.items() if not k.startswith("_")
        }
        utils.indexed_pickler_dump(
            non_debug_kwargs, self._field_filename(field_i, is_debug=False))

        if _save_debug:
            debug_kwargs = {
                k: v
                for k, v in kwargs.items() if k.startswith("_")
            }
            utils.indexed_pickler_dump(
                debug_kwargs, self._field_filename(field_i, is_debug=True))
Ejemplo n.º 2
0
 def it_creates_an_indexed_pickle_and_reloads_it_on_all_properties():
     path = "/tmp/__test.ipkl"
     testme_orig = PropertiesClass()
     utils.indexed_pickler_dump(testme_orig, path)
     testme_new = PropertiesClass.__new__(PropertiesClass)
     utils.indexed_pickler_load(path, None, testme_new)
     for prop in ["a", "b", "c"]:
         assert getattr(testme_orig, prop) == getattr(testme_new, prop)
     os.unlink(path)
Ejemplo n.º 3
0
 def it_creates_an_indexed_pickle_and_reloads_it():
     path = "/tmp/__test.ipkl"
     prop_list = ["a", "b"]
     testme_orig = PropertiesClass()
     utils.indexed_pickler_dump(testme_orig, path, prop_list)
     testme_new = PropertiesClass.__new__(PropertiesClass)
     utils.indexed_pickler_load(path, prop_list, testme_new)
     for prop in prop_list:
         assert getattr(testme_orig, prop) == getattr(testme_new, prop)
     assert hasattr(testme_orig, "c")
     assert not hasattr(testme_new, "c")
     os.unlink(path)
Ejemplo n.º 4
0
    def save(self):
        """
        The default behavior is to simply pickle the entire object.

        Some sub-classes might choose to defer to some non-pickle files
        for debugging information or other.

        kwargs are added into to the save if specified.
        """

        # Sanity check that required fields are present
        for prop, type_ in self.required_props.items():
            if prop not in self:
                raise ValueError(f"Required property '{prop}' not found")
            if not isinstance(self[prop], type_):
                raise ValueError(
                    f"Property '{prop}' of wrong type; expected '{type_}' found '{type(self[prop])}'"
                )

        # Note, self.filename is a class member set in the subclass
        utils.indexed_pickler_dump(self, self._folder / self.filename)