How to use the plonk._logging.logger.debug 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
def physical_units(self) -> Snap:
        """Set physical units.

        Returns
        -------
        Snap
        """
        if self._physical_units:
            logger.info('Physical units already set: snap.unset(units=True) to unset.')
        logger.debug(f'Setting physical units: {self.file_path.name}')
        for arr in self.loaded_arrays():
            self._arrays[arr] = self._arrays[arr] * self.get_array_unit(arr)
        for arr in self.loaded_arrays(sinks=True):
            self._sinks[arr] = self._sinks[arr] * self.get_array_unit(arr)
        self._physical_units = True

        return self
github dmentipl / plonk / plonk / snap / snap.py View on Github external
Returns
        -------
        Snap
            The rotated Snap. Note that the rotation operation is
            in-place.

        Examples
        --------
        Rotate a Snap by π/3 around [1, 1, 0].

        >>> rot = np.array([1, 1, 0])
        >>> rot = rot * np.pi / 3 * np.linalg.norm(rot)
        >>> snap.rotate(rot)
        """
        logger.debug(f'Rotating snapshot: {self.file_path.name}')
        if isinstance(rotation, (list, tuple, ndarray)):
            rotation = Rotation.from_rotvec(rotation)
        for arr in self._vector_arrays:
            if arr in self.loaded_arrays():
                self._arrays[arr] = rotation.apply(self._arrays[arr])
            if arr in self.loaded_arrays(sinks=True):
                self._sinks[arr] = rotation.apply(self._sinks[arr])
        for arr in self._vector_component_arrays:
            if arr in self.loaded_arrays():
                del self._arrays[arr]
            if arr in self.loaded_arrays(sinks=True):
                del self._sinks[arr]

        if self.rotation is None:
            self.rotation = rotation
        else:
github dmentipl / plonk / plonk / snap / snap.py View on Github external
def extra_quantities(self):
        """Make extra quantities available."""
        if self._extra_quantities:
            logger.info('Extra quantities already available')
        logger.debug(f'Loading extra quantities: {self.file_path.name}')
        extra_quantities(snap=self)
        self._extra_quantities = True
        return self
github dmentipl / plonk / plonk / snap / snap.py View on Github external
Parameters
        ----------
        translation
            The translation as a (3,) ndarray like (x, y, z).

        Returns
        -------
        Snap
            The translated Snap. Note that the translation operation is
            in-place.
        """
        translation = np.array(translation)
        if translation.shape != (3,):
            raise ValueError('translation must be like (x, y, z)')
        logger.debug(f'Translating snapshot: {self.file_path.name}')
        if 'position' in self.loaded_arrays():
            self._arrays['position'] += translation
        if 'position' in self.loaded_arrays(sinks=True):
            self._sinks['position'] += translation

        if self.translation is None:
            self.translation = translation
        else:
            self.translation += translation

        return self
github dmentipl / plonk / plonk / snap / readers / phantom.py View on Github external
def generate_snap_from_file(filename: Union[str, Path]) -> Snap:
    """Generate a Snap object from a Phantom HDF5 file.

    Parameters
    ----------
    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']
github dmentipl / plonk / plonk / analysis / profile.py View on Github external
def load_profile(
    snap: SnapLike,
    ndim: Optional[int] = 2,
    radius_min: Optional[Any] = None,
    radius_max: Optional[Any] = None,
    n_bins: int = 100,
    aggregation: str = 'average',
    spacing: str = 'linear',
    coordinate: str = 'x',
    ignore_accreted: bool = True,
) -> Profile:
    logger.debug(f'Loading profile: {snap.file_path.name}')
    return Profile(
        snap=snap,
        ndim=ndim,
        radius_min=radius_min,
        radius_max=radius_max,
        n_bins=n_bins,
        aggregation=aggregation,
        spacing=spacing,
        coordinate=coordinate,
        ignore_accreted=ignore_accreted,
    )
github dmentipl / plonk / plonk / simulation / simulation.py View on Github external
is 'Phantom'.
        """
        if not isinstance(prefix, str):
            raise TypeError('prefix must be str')

        if data_source not in _data_sources:
            raise ValueError(f'Data source not available: try {_data_sources}')
        self.data_source = data_source

        if directory is None:
            directory = '.'
        else:
            if not isinstance(directory, (str, Path)):
                raise TypeError('directory must be str or pathlib.Path')

        logger.debug(f'Loading {data_source} simulation: {prefix} at {directory}')
        self.prefix = prefix
        self.paths = {
            'directory': Path(directory).expanduser().resolve(),
        }

        if not list(self.paths['directory'].glob(self.prefix + '*')):
            raise FileNotFoundError(f'No files with prefix: {prefix}')

        self._snap_file_extension = self._get_snap_file_extension()

        self.paths['snaps'] = self._get_snap_files()
        self.paths['global_quantities'] = self._get_global_ev_files()
        self.paths['sink_quantities'] = self._get_sink_ev_files()

        return self