How to use the plonk.snap.snap.Snap function in plonk

To help you get started, we’ve selected a few plonk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmentipl / plonk / plonk / snap / snap.py View on Github external
"""Sink particle arrays."""
        return self.base.sinks

    def __repr__(self):
        """Dunder repr method."""
        return self.__str__()

    def __str__(self):
        """Dunder str method."""
        return self.base.__str__().replace('Snap', 'SubSnap')

    def _get_array(self, name: str, sinks: bool = False) -> ndarray:
        return self.base._get_array(name, sinks)[self.indices]


SnapLike = Union[Snap, SubSnap]


def _str_is_int(string):
    try:
        int(string)
        return True
    except ValueError:
        return False
github dmentipl / plonk / plonk / visualize / plot.py View on Github external
"""Plot helper functions."""

from typing import Any, Dict, Optional, Tuple, Union

from numpy import ndarray

from ..snap.snap import Snap, SubSnap
from .interpolation import scalar_interpolation
from .visualization import Visualization

SnapLike = Union[Snap, SubSnap]

_number_of_pixels = (512, 512)


def plot(
    *,
    snap: SnapLike,
    scalar_data: Optional[Union[str, ndarray]] = None,
    vector_data: Optional[Union[str, ndarray]] = None,
    x_coordinate: Optional[Union[str, ndarray]] = None,
    y_coordinate: Optional[Union[str, ndarray]] = None,
    z_coordinate: Optional[Union[str, ndarray]] = None,
    extent: Optional[Tuple[float, float, float, float]] = None,
    axis: Optional[Any] = None,
    scalar_options: Optional[Dict[str, Any]] = None,
    vector_options: Optional[Dict[str, Any]] = None,
github dmentipl / plonk / plonk / snap / readers / phantom.py View on Github external
----------
    filename
        The path to the file.

    Returns
    -------
    Snap
        A Snap object.
    """
    logger.debug(f'Loading Phantom snapshot: {filename}')
    file_path = pathlib.Path(filename).expanduser()
    if not file_path.is_file():
        raise FileNotFoundError('Cannot find snapshot file')
    file_handle = h5py.File(file_path, mode='r')

    snap = Snap()
    snap.data_source = 'Phantom'
    snap.file_path = file_path
    snap._file_pointer = file_handle

    header = {key: val[()] for key, val in file_handle['header'].items()}
    snap.properties, snap.units = _header_to_properties(header)

    arrays = list(file_handle['particles'])
    ndustsmall = header['ndustsmall']
    ndustlarge = header['ndustlarge']
    array_registry = _populate_particle_array_registry(
        arrays=arrays,
        name_map=_particle_array_name_map,
        ndustsmall=ndustsmall,
        ndustlarge=ndustlarge,
    )
github dmentipl / plonk / plonk / simulation / simulation.py View on Github external
def __init__(self):

        self.data_source: str
        self.prefix: str
        self.paths: Dict[str, Any]

        self._snaps: List[Snap] = None
        self._properties: Dict[str, Any] = None
        self._units: Dict[str, Any] = None
        self._global_quantities: DataFrame = None
        self._sink_quantities: List[DataFrame] = None

        self._snap_file_extension = ''
        self._len = -1
github dmentipl / plonk / plonk / snap / snap.py View on Github external
return self.available_arrays()

    def __len__(self):
        """Length as number of particles."""
        return self.num_particles

    def __repr__(self):
        """Dunder repr method."""
        return self.__str__()

    def __str__(self):
        """Dunder str method."""
        return f''


class SubSnap(Snap):
    """A Snap subset of particles.

    The sub-snap is generated via an index array.

    Parameters
    ----------
    base
        The base snapshot.
    indices
        A (N,) array of particle indices to include in the sub-snap.
    """

    def __init__(self, base: Snap, indices: ndarray):
        super().__init__()

        # Attributes different to Snap
github dmentipl / plonk / plonk / snap / snap.py View on Github external
def add_alias(name: str, alias: str) -> None:
        """Add alias to array.

        Parameters
        ----------
        name
            The name of the array.
        alias
            The alias to reference the array.
        """
        Snap._array_name_mapper[alias] = name