def animate_map_2d_helper(input_data, output_file=None, label=None, feature=None, variable=None, **kwargs): """ Animate 2D maps. Arguments: input_data (tramway.core.analyses.base.Analyses or str): analysis tree or path to rwa file. output_file (str): path to .mp4 file; if None, the video stream is dumped into a temporary file that is deleted after being played. label (str or list): path to the maps as a (comma-separated) list of labels. feature/variable (str): name of the mapped feature to be rendered. The other keyword arguments are passed to :func:`~tramway.plot.animation.map.animate_map_2d`. """ from tramway.core.analyses import find_artefacts from tramway.tessellation.base import Partition from tramway.inference.base import Maps from tramway.plot.animation.map import animate_map_2d if isinstance(input_data, Analyses): analyses = input_data else: from tramway.core.hdf5 import load_rwa input_file = os.path.expanduser(input_data) if not os.path.isfile(input_file): raise OSError("file '{}' not found".format(input_file)) analyses = load_rwa(input_file, lazy=True) if isinstance(label, str): _label = [] for _l in label.split(","): try: _l = int(_l) except (TypeError, ValueError): pass _label.append(_l) label = _label cells, maps = find_artefacts(analyses, (Partition, Maps), label) if feature is None: feature = variable if feature is None: if maps.features[1:]: raise ValueError("multiple mapped features found: {}".format( maps.features)) feature = maps.features[0] _map = maps[feature] animate_map_2d(_map, cells, output_file, **kwargs)
def new_file(self, *args, **kwargs): self.analysis.set("") self.analyses = None self.map_labels = None self.disable_widgets() map_file = self.input_file.filepath.get() try: self.analyses = load_rwa(map_file) except KeyError: try: # old format store = HDF5Store(map_file, "r") store.lazy = False maps = peek_maps(store, store.store) finally: store.close() if self.analyses is None: try: tess_file = maps.rwa_file except AttributeError: # even older tess_file = maps.imt_file maps = maps.maps if not isinstance(tess_file, str): tess_file = tess_file.decode("utf-8") tess_file = os.path.join(os.path.dirname(map_file), tess_file) try: store = HDF5Store(tess_file, "r") store.lazy = False try: cells = store.peek("cells") except: raise else: if cells.tessellation is None: cells._tessellation = store.peek( "_tesselation", store.store["cells"] ) self.editor.cells = cells finally: store.close() except: print(traceback.format_exc()) print("cells not found") self.set_maps(maps) else: self.map_labels = [ " - ".join(str(a) for a in path) for path in label_paths(self.analyses, Maps) ] self.analysis_input["values"] = self.map_labels if not self.map_labels: raise ValueError("no analyses found") if not self.map_labels[1:]: self.analysis.set(self.map_labels[0]) self.enable_widgets()
def animate_trajectories_2d_helper(input_data, *args, **kwargs): """ Animate 2D trajectories. Arguments: input_data (pandas.DataFrame or tramway.core.analyses.base.Analyses or str): nxyt data, or analysis tree, or path to xyt file. columns (str or list): (comma-separated) list of column names if input data are to be loaded; keyworded-only; see also :func:`~tramway.core.xyt.load_xyt`. The other arguments are passed to :func:`~tramway.plot.animation.xyt.animate_trajectories_2d`. """ from tramway.plot.animation.xyt import animate_trajectories_2d import pandas as pd columns = kwargs.pop("columns", None) if isinstance(input_data, pd.DataFrame): xyt = input_data elif isinstance(input_data, Analyses): xyt = input_data.data else: input_file = os.path.expanduser(input_data) if not os.path.isfile(input_file): raise OSError("file '{}' not found".format(input_file)) load_kwargs = {} if columns is not None: if isinstance(columns, str): columns = columns.split(",") load_kwargs["columns"] = columns from tramway.core.xyt import load_xyt try: xyt = load_xyt(input_file, **load_kwargs) except (SystemExit, KeyboardInterrupt): raise except: from tramway.core.hdf5 import load_rwa xyt = load_rwa(input_file, lazy=True).data animate_trajectories_2d(xyt, *args, **kwargs)