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
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)))
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))
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