Ejemplo n.º 1
0
    def dict_to_object(self, obj):
        for k, v in obj.items():
            if isinstance(v, str):
                try:
                    obj[k] = iso8601(v)
                    continue
                except ValueError:
                    pass

                try:
                    obj[k] = str_to_dtype(v)
                    continue
                except ValueError:
                    pass

        if "__class__" not in obj:
            LOG.warning(
                "No '__class__' element in JSON file. Using BaseP2GObject by default for now."
            )
            obj["__class__"] = "BaseP2GObject"
            return BaseP2GObject(**obj)

        cls = self._jsonclass_to_pyclass(obj["__class__"])
        inst = cls(**obj)
        return inst
Ejemplo n.º 2
0
def _parse_binary_info(parts):
    from polar2grid.core.dtype import str_to_dtype
    fn = parts[0]
    if not os.path.exists(fn):
        raise ValueError("File '%s' does not exist" % (fn, ))

    dtype = str_to_dtype(parts[1])
    rows = int(parts[2])
    cols = int(parts[3])
    fill = float(parts[4])
    arr = numpy.memmap(fn, dtype=dtype, mode='r', shape=(rows, cols))
    return (fn, numpy.ma.masked_array(arr, numpy.isnan(arr) | (arr == fill)))
Ejemplo n.º 3
0
def _parse_binary_info(parts):
    from polar2grid.core.dtype import str_to_dtype
    fn = parts[0]
    if not os.path.exists(fn):
        raise ValueError("File '%s' does not exist" % (fn,))

    dtype = str_to_dtype(parts[1])
    rows = int(parts[2])
    cols = int(parts[3])
    fill = float(parts[4])
    arr = numpy.memmap(fn, dtype=dtype, mode='r', shape=(rows, cols))
    return fn, numpy.ma.masked_array(arr, numpy.isnan(arr) | (arr == fill))
Ejemplo n.º 4
0
    def dict_to_object(self, obj):
        for k, v in obj.items():
            if isinstance(v, (str, unicode)):
                try:
                    obj[k] = iso8601(v)
                    continue
                except ValueError:
                    pass

                try:
                    obj[k] = str_to_dtype(v)
                    continue
                except StandardError:
                    pass

        if "__class__" not in obj:
            LOG.warning("No '__class__' element in JSON file. Using BaseP2GObject by default for now.")
            obj["__class__"] = "BaseP2GObject"
            return BaseP2GObject(**obj)

        cls = self._jsonclass_to_pyclass(obj["__class__"])
        inst = cls(**obj)
        return inst