def convert_particles_to_pynbody_data(particles, length_unit=units.kpc, pynbody_unit="kpc"): if not HAS_PYNBODY: raise AmuseException("Couldn't find pynbody") if hasattr(particles, "u"): pynbody_data = _new(gas=len(particles)) else: pynbody_data = _new(dm=len(particles)) pynbody_data._filename = "AMUSE" if hasattr(particles, "mass"): pynbody_data['mass'] = SimArray(particles.mass.value_in(units.MSun), "Msol") if hasattr(particles, "position"): pynbody_data['x'] = SimArray(particles.x.value_in(length_unit), pynbody_unit) pynbody_data['y'] = SimArray(particles.y.value_in(length_unit), pynbody_unit) pynbody_data['z'] = SimArray(particles.z.value_in(length_unit), pynbody_unit) if hasattr(particles, "velocity"): pynbody_data['vx'] = SimArray(particles.vx.value_in(units.km / units.s), "km s^-1") pynbody_data['vy'] = SimArray(particles.vy.value_in(units.km / units.s), "km s^-1") pynbody_data['vz'] = SimArray(particles.vz.value_in(units.km / units.s), "km s^-1") if hasattr(particles, "h_smooth"): pynbody_data['smooth'] = SimArray(particles.h_smooth.value_in(length_unit), pynbody_unit) if hasattr(particles, "rho"): pynbody_data['rho'] = SimArray(particles.rho.value_in(units.g / units.cm**3), "g cm^-3") if hasattr(particles, "temp"): pynbody_data['temp'] = SimArray(particles.temp.value_in(units.K), "K") elif hasattr(particles, "u"): # pynbody_data['u'] = SimArray(particles.u.value_in(units.km**2 / units.s**2), "km^2 s^-2") temp = 2.0/3.0 * particles.u * mu() / constants.kB pynbody_data['temp'] = SimArray(temp.value_in(units.K), "K") return pynbody_data
def __init__(self, **kwargs): self.__profile = kwargs.get('profile', density_profiles.alphabetagamma) self.__drhodr = kwargs.get('drhodr', density_profiles.dalphabetagammadr) self.__d2rhodr2 = kwargs.get('d2rhodr2', density_profiles.d2alphabetagammadr2) self.__pars = kwargs.get('pars', { 'alpha': 1., 'beta': 3., 'gamma': 1., 'c': 10., 'factor': 0.1 }) if self.__profile == density_profiles.alphabetagamma and self.__pars[ 'beta'] <= 3.: if 'factor' not in self.__pars.keys(): self.__pars['factor'] = 0.1 self.__m_vir = kwargs.get('m_vir', '1e12 Msol') self.__m_vir = units.Unit(self.__m_vir) self.__h = kwargs.get('h', 0.7) self.__overden = kwargs.get('overden', 200.) self.__r_vir = tools.calc_r_vir(self.__m_vir, self.__h, self.__overden) self.__r_s = self.__r_vir / self.__pars['c'] self.__n_particles = int(kwargs.get('n_particles', 1e5)) self.__logxmax_rho = np.log10(self.__pars['c']) + 2. # Make sure to sample well inside the gravitational softening self.__logxmin_rho = self.__logxmax_rho - .5 * np.log10( self.__n_particles) - 3. self.__logxmax_dist_func = np.log10(self.__pars['c']) + 13. self.__logxmin_dist_func = self.__logxmax_dist_func - .5 * np.log10( self.__n_particles) self.__logxmin_dist_func -= 14. self.__n_sample_rho = int(kwargs.get('n_sample_rho', 1e4)) self.__n_sample_dist_func = int(kwargs.get('n_sample_dist_func', 1e2)) self.__n_sample_dist_func_rho = int( kwargs.get('n_sample_dist_func_rho', 1e4)) self.__random_seed = kwargs.get('random_seed', 4) if 'prng' in kwargs.keys(): self.__prng = kwargs['prng'] else: self.__prng = np.random.RandomState(self.__random_seed) self.__spline_order = kwargs.get('spline_order', 3) self.__progress_bar = kwargs.get('progress_bar', False) self.__no_bulk_vel = kwargs.get('no_bulk_vel', True) self.__x_rho = np.logspace(self.__logxmin_rho, self.__logxmax_rho, self.__n_sample_rho) self.__do_velocities = kwargs.get('do_velocities', True) self.__gas = kwargs.get('gas', False) if 'snap' in kwargs.keys(): self.sim = kwargs['snap'] elif self.__gas: self.sim = snapshot._new(gas=self.__n_particles) else: self.sim = snapshot._new(self.__n_particles)
def __init__(self, **kwargs): self.__profile = kwargs.get('profile', density_profiles.alphabetagamma) self.__drhodr = kwargs.get('drhodr', density_profiles.dalphabetagammadr) self.__d2rhodr2 = kwargs.get('d2rhodr2', density_profiles.d2alphabetagammadr2) self.__pars = kwargs.get('pars', {'alpha': 1., 'beta': 3., 'gamma': 1., 'c': 10., 'factor': 0.1}) if self.__profile == density_profiles.alphabetagamma and self.__pars['beta'] <= 3.: if 'factor' not in self.__pars.keys(): self.__pars['factor'] = 0.1 self.__m_vir = kwargs.get('m_vir', '1e12 Msol') self.__m_vir = units.Unit(self.__m_vir) self.__h = kwargs.get('h', 0.7) self.__overden = kwargs.get('overden', 200.) self.__r_vir = tools.calc_r_vir(self.__m_vir, self.__h, self.__overden) self.__r_s = self.__r_vir/self.__pars['c'] self.__n_particles = int(kwargs.get('n_particles', 1e5)) self.__logxmax_rho = np.log10(self.__pars['c']) + 2. # Make sure to sample well inside the gravitational softening self.__logxmin_rho = self.__logxmax_rho - .5*np.log10(self.__n_particles) - 3. self.__logxmax_dist_func = np.log10(self.__pars['c']) + 13. self.__logxmin_dist_func = self.__logxmax_dist_func - .5*np.log10(self.__n_particles) self.__logxmin_dist_func -= 14. self.__n_sample_rho = int(kwargs.get('n_sample_rho', 1e4)) self.__n_sample_dist_func = int(kwargs.get('n_sample_dist_func', 1e2)) self.__n_sample_dist_func_rho = int(kwargs.get('n_sample_dist_func_rho', 1e4)) self.__random_seed = kwargs.get('random_seed', 4) if 'prng' in kwargs.keys(): self.__prng = kwargs['prng'] else: self.__prng = np.random.RandomState(self.__random_seed) self.__spline_order = kwargs.get('spline_order', 3) self.__progress_bar = kwargs.get('progress_bar', False) self.__no_bulk_vel = kwargs.get('no_bulk_vel', True) self.__x_rho = np.logspace(self.__logxmin_rho, self.__logxmax_rho, self.__n_sample_rho) self.__do_velocities = kwargs.get('do_velocities', True) self.__gas = kwargs.get('gas', False) if 'snap' in kwargs.keys(): self.sim = kwargs['snap'] elif self.__gas: self.sim = snapshot._new(gas=self.__n_particles) else: self.sim = snapshot._new(self.__n_particles)