Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _header_to_properties(header: dict):
length = header['udist'] * plonk_units('cm')
time = header['utime'] * plonk_units('s')
mass = header['umass'] * plonk_units('g')
magnetic_field = (
header['umagfd']
* plonk_units('g ** (1/2) / cm ** (1/2) / s')
* np.sqrt(plonk_units.magnetic_constant / (4 * np.pi))
).to_base_units()
units = generate_units_dictionary(length, mass, time, magnetic_field)
prop = dict()
prop['time'] = header['time'] * units['time']
prop['smoothing_length_factor'] = header['hfact']
prop['adiabatic_index'] = header['gamma']
prop['polytropic_constant'] = 2 / 3 * header['RK2']
ieos = header['ieos']
def str_to_units(quantity, extent, projection):
"""Convert string to plonk units.
Parameters
----------
quantity
The units string for the quantity.
extent
The units string for the plot extent.
projection
The units string for projection interpolation.
"""
if isinstance(quantity, str):
quantity = plonk_units(quantity)
elif isinstance(quantity, Quantity):
pass
else:
raise ValueError(f'Cannot determine quantity unit')
if isinstance(extent, str):
extent = plonk_units(extent)
elif isinstance(extent, Quantity):
pass
else:
raise ValueError(f'Cannot determine extent unit')
if isinstance(projection, str):
projection = plonk_units(projection)
elif isinstance(projection, Quantity):
pass
else:
raise ValueError(f'Cannot determine projection unit')
----------
quantity
The units string for the quantity.
extent
The units string for the plot extent.
projection
The units string for projection interpolation.
"""
if isinstance(quantity, str):
quantity = plonk_units(quantity)
elif isinstance(quantity, Quantity):
pass
else:
raise ValueError(f'Cannot determine quantity unit')
if isinstance(extent, str):
extent = plonk_units(extent)
elif isinstance(extent, Quantity):
pass
else:
raise ValueError(f'Cannot determine extent unit')
if isinstance(projection, str):
projection = plonk_units(projection)
elif isinstance(projection, Quantity):
pass
else:
raise ValueError(f'Cannot determine projection unit')
if extent.dimensionality != plonk_units('cm').dimensionality:
raise ValueError('extent has incorrect dimensions')
if projection.dimensionality != plonk_units('cm').dimensionality:
raise ValueError('projection has incorrect dimensions')
def _header_to_properties(header: dict):
length = header['udist'] * plonk_units('cm')
time = header['utime'] * plonk_units('s')
mass = header['umass'] * plonk_units('g')
magnetic_field = (
header['umagfd']
* plonk_units('g ** (1/2) / cm ** (1/2) / s')
* np.sqrt(plonk_units.magnetic_constant / (4 * np.pi))
).to_base_units()
units = generate_units_dictionary(length, mass, time, magnetic_field)
prop = dict()
prop['time'] = header['time'] * units['time']
prop['smoothing_length_factor'] = header['hfact']
prop['adiabatic_index'] = header['gamma']
prop['polytropic_constant'] = 2 / 3 * header['RK2']
ieos = header['ieos']
if ieos == 1:
if isinstance(extent, str):
extent = plonk_units(extent)
elif isinstance(extent, Quantity):
pass
else:
raise ValueError(f'Cannot determine extent unit')
if isinstance(projection, str):
projection = plonk_units(projection)
elif isinstance(projection, Quantity):
pass
else:
raise ValueError(f'Cannot determine projection unit')
if extent.dimensionality != plonk_units('cm').dimensionality:
raise ValueError('extent has incorrect dimensions')
if projection.dimensionality != plonk_units('cm').dimensionality:
raise ValueError('projection has incorrect dimensions')
return {'quantity': quantity, 'extent': extent, 'projection': projection}
def _header_to_properties(header: dict):
length = header['udist'] * plonk_units('cm')
time = header['utime'] * plonk_units('s')
mass = header['umass'] * plonk_units('g')
magnetic_field = (
header['umagfd']
* plonk_units('g ** (1/2) / cm ** (1/2) / s')
* np.sqrt(plonk_units.magnetic_constant / (4 * np.pi))
).to_base_units()
units = generate_units_dictionary(length, mass, time, magnetic_field)
prop = dict()
prop['time'] = header['time'] * units['time']
prop['smoothing_length_factor'] = header['hfact']
prop['adiabatic_index'] = header['gamma']
prop['polytropic_constant'] = 2 / 3 * header['RK2']
The units string for projection interpolation.
"""
if isinstance(quantity, str):
quantity = plonk_units(quantity)
elif isinstance(quantity, Quantity):
pass
else:
raise ValueError(f'Cannot determine quantity unit')
if isinstance(extent, str):
extent = plonk_units(extent)
elif isinstance(extent, Quantity):
pass
else:
raise ValueError(f'Cannot determine extent unit')
if isinstance(projection, str):
projection = plonk_units(projection)
elif isinstance(projection, Quantity):
pass
else:
raise ValueError(f'Cannot determine projection unit')
if extent.dimensionality != plonk_units('cm').dimensionality:
raise ValueError('extent has incorrect dimensions')
if projection.dimensionality != plonk_units('cm').dimensionality:
raise ValueError('projection has incorrect dimensions')
return {'quantity': quantity, 'extent': extent, 'projection': projection}
def set_gravitational_parameter(self, sink_idx: Union[int, List[int]]):
"""Set standard gravitational parameter.
Calculate the standard gravitational parameter (G M) given a
sink index, or list of sink indices for multiple systems, etc,
and set snap.properties['gravitational_parameter']. This is
required to calculate orbital quantities such as eccentricity
or Stokes number.
Parameters
----------
sink_idx
The sink index or list of indices.
"""
G = plonk_units.newtonian_constant_of_gravitation
if isinstance(sink_idx, (int, list)):
M = self.sinks['mass'][sink_idx]
else:
raise ValueError('Cannot determine gravitational parameter')
if self._physical_units:
G = (G * M).to_base_units()
else:
G = (G * self.units['mass'] * M).to_base_units()
self.properties['gravitational_parameter'] = G