Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
Snap
The Snap object.
"""
if data_source not in _data_sources:
raise ValueError(
f'Unknown data source. Available data sources:\n{_data_sources}'
)
if data_source == 'Phantom':
try:
return read_phantom(filename)
except FileNotFoundError as e:
logger.error(f'File not found: {filename}')
raise e
except OSError as e:
# Catch errors raised by h5py due to file corruption
logger.error(f'File likely corrupted: {filename}')
raise e
raise RuntimeError('Cannot load snap')
----------
interpolated_data_cartesian
The interpolated data on a Cartesian grid.
extent_cartesian
The extent in Cartesian space as (xmin, xmax, ymin, ymax). It
must be square.
Returns
-------
interpolated_data_polar
The interpolated data on a polar grid (R, phi).
extent_polar
The extent on a polar grid (0, Rmax, 0, 2π).
"""
if transform is None:
logger.error(
'cartesian_to_polar requires skimage (scikit-image) which is unavailable\n'
'try pip install skimage --or-- conda install skimage'
)
data, extent = interpolated_data_cartesian, extent_cartesian
if not np.allclose(extent[1] - extent[0], extent[3] - extent[2]):
raise ValueError('Bad polar plot: x and y have different scales')
number_of_pixels = data.shape
radius_pix = 0.5 * data.shape[0]
data = transform.warp_polar(data, radius=radius_pix)
radius = 0.5 * (extent[1] - extent[0])
extent_polar = (0, radius, 0, 2 * np.pi)
array: ndarray = self.snap[array_name]
if array.ndim == 1:
self._profiles[name] = self.particles_to_binned_quantity(
aggregation, array
)
return self._profiles[name]
raise ValueError(
'Requested profile has array dimension > 1.\nTo access x-, y-, or '
'z-components, or magnitude of vector quantities,\ntry, for '
'example, prof["velocity_x"] or prof["momentum_magnitude"].\nTo '
'access dust profiles, try, for example, prof["stopping_time_001"] '
'or\nprof["dust_mass_sum"].'
)
except ValueError:
if self.snap._extra_quantities:
logger.error('Profile unavailable.')
else:
logger.error(
'Profile unavailable. Try calling extra_quantities method on Snap.'
)
self._profiles[name] = self.particles_to_binned_quantity(
aggregation, array
)
return self._profiles[name]
raise ValueError(
'Requested profile has array dimension > 1.\nTo access x-, y-, or '
'z-components, or magnitude of vector quantities,\ntry, for '
'example, prof["velocity_x"] or prof["momentum_magnitude"].\nTo '
'access dust profiles, try, for example, prof["stopping_time_001"] '
'or\nprof["dust_mass_sum"].'
)
except ValueError:
if self.snap._extra_quantities:
logger.error('Profile unavailable.')
else:
logger.error(
'Profile unavailable. Try calling extra_quantities method on Snap.'
)
| (particle_type == istar)
| (particle_type == idarkmatter)
| (particle_type == ibulge)
] = 0
sub_type[particle_type == iboundary] = 0
idust = _get_dataset('idust', 'header')(snap)
ndustlarge = _get_dataset('ndustlarge', 'header')(snap)
for idx in range(idust, idust + ndustlarge):
sub_type[particle_type == idx] = idx - idust + 1
try:
idustbound = _get_dataset('idustbound', 'header')(snap)
for idx in range(idustbound, idustbound + ndustlarge):
sub_type[particle_type == idx] = idx - idustbound + 1
except KeyError:
if np.any(particle_type >= idust + ndustlarge):
logger.error('Cannot determine dust boundary particles')
return sub_type
# Dark matter | 5 | 5
# Bulge | 6 | 6
idust = _get_dataset('idust', 'header')(snap)
ndustlarge = _get_dataset('ndustlarge', 'header')(snap)
particle_type = np.abs(_get_dataset('itype', 'particles')(snap))
particle_type[
(particle_type >= idust) & (particle_type < idust + ndustlarge)
] = snap.particle_type['dust']
try:
idustbound = _get_dataset('idustbound', 'header')(snap)
particle_type[
(particle_type >= idustbound) & (particle_type < idustbound + ndustlarge)
] = snap.particle_type['boundary']
except KeyError:
if np.any(particle_type >= idust + ndustlarge):
logger.error('Cannot determine dust boundary particles')
return particle_type
The Snap object.
"""
if data_source not in _data_sources:
raise ValueError(
f'Unknown data source. Available data sources:\n{_data_sources}'
)
if data_source == 'Phantom':
try:
return read_phantom(filename)
except FileNotFoundError as e:
logger.error(f'File not found: {filename}')
raise e
except OSError as e:
# Catch errors raised by h5py due to file corruption
logger.error(f'File likely corrupted: {filename}')
raise e
raise RuntimeError('Cannot load snap')