def __init__(self, data: Union[str, Path, AmsetData, dict]): if isinstance(data, (str, Path)): # guess the mesh filename data = loadfn(data) elif isinstance(data, AmsetData): data = data.to_dict(include_mesh=True) elif isinstance(data, dict): data = data else: raise ValueError("Unrecognised data format") self._data = cast_dict_ndarray(data)
def __init__(self, data: Union[str, Path, AmsetData, dict]): if isinstance(data, (str, Path)): data = loadfn(data) elif isinstance(data, AmsetData): data = data.to_dict(include_mesh=True) elif isinstance(data, dict): data = data else: raise ValueError("Unrecognised data format") self._data = cast_dict_ndarray(data) self.spins = list(self.energies.keys()) self.has_mesh = "energies" in data
def __init__(self, mesh_data: Union[str, Path, AmsetData, dict]): if isinstance(mesh_data, (str, Path)): if "h5" not in mesh_data: raise ValueError( "mesh.h5 file needed for plot. Run AMSET with write_mesh=True" ) mesh_data = load_mesh(mesh_data) elif isinstance(mesh_data, AmsetData): mesh_data = mesh_data.to_dict(include_mesh=True)["mesh"] elif not isinstance(mesh_data, dict): raise ValueError("Unrecognised data format") self._data = cast_dict_ndarray(mesh_data) self.spins = list(self.energies.keys())
def test_cast_dict_ndarray(value, expected): def compare(a, b): if isinstance(a, dict) and isinstance(b, dict): all_keys = list(a.keys()) + list(b.keys()) for k in all_keys: compare(a[k], b[k]) elif isinstance(a, dict) or isinstance(b, dict): assert False else: if isinstance(a, np.ndarray) and isinstance(b, np.ndarray): a = a.tolist() b = b.tolist() elif isinstance(a, np.ndarray) or isinstance(b, np.ndarray): # both not numpy arrays assert False assert a == b compare(cast_dict_ndarray(value), expected)
def __init__(self, data: List[Union[str, Path, AmsetData, dict, list]]): if not isinstance(data, (tuple, list)): data = [data] if isinstance(data, tuple): data = list(data) if len(data) < 2: raise ValueError("More than 2 transport data needed for plotting") new_data = [] for d in data: if isinstance(d, (str, Path)): # guess the mesh filename d = loadfn(d) elif isinstance(d, AmsetData): d = d.to_dict(include_mesh=True) elif isinstance(d, dict): d = d else: raise ValueError("Unrecognised data format") new_data.append(cast_dict_ndarray(d)) temperatures = set(new_data[0]["temperatures"]) doping = set(new_data[0]["doping"]) for d in new_data[1:]: if set(d["temperatures"]) != temperatures or set( d["doping"]) != doping: raise ValueError( "Transport data contain inconsistent doping or temperatures" ) self.temperatures = new_data[0]["temperatures"] self.doping = new_data[0]["doping"] self.n = len(new_data) self._data = new_data