def __init__(self, points, ds=None, field_parameters=None, data_source=None): validate_object(ds, Dataset) validate_object(field_parameters, dict) validate_object(data_source, YTSelectionContainer) validate_object(points, YTArray) points = fix_length(points, ds) if len(points) < 2: raise YTException( "Not enough points. Expected at least 2, got %s" % len(points)) mylog.debug('Building minimal sphere around points.') mb = _miniball.Miniball(points) if not mb.is_valid(): raise YTException("Could not build valid sphere around points.") center = ds.arr(mb.center(), points.units) radius = ds.quan(np.sqrt(mb.squared_radius()), points.units) super(YTMinimalSphere, self).__init__(center, ds, field_parameters, data_source) self.set_field_parameter('radius', radius) self.set_field_parameter("center", self.center) self.radius = radius
def _validate_unit_vectors(normal_vector, north_vector): # Make sure vectors are unitless if north_vector is not None: north_vector = YTArray(north_vector, "", dtype='float64') if normal_vector is not None: normal_vector = YTArray(normal_vector, "", dtype='float64') if not np.dot(normal_vector, normal_vector) > 0: raise YTException("normal_vector cannot be the zero vector.") if north_vector is not None and _aligned(north_vector, normal_vector): raise YTException("normal_vector and north_vector cannot be aligned.") return normal_vector, north_vector
def _read_field_names(self, grid): if grid.filename is None: return [] f = h5py.File(grid.filename, "r") try: group = f[grid.block_name] except KeyError: raise YTException(message="Grid %s is missing from data file %s." % (grid.block_name, grid.filename), ds=self.ds) fields = [] dtypes = set([]) for name, v in iteritems(group): if not hasattr(v, "shape") or v.dtype == "O": continue # mesh fields are "field <name>" if name.startswith("field"): dummy, fname = name.split(" ", 1) fields.append(("enzop", fname)) dtypes.add(v.dtype) # particle fields are "particle <type> <name>" else: dummy, ftype, fname = name.split(" ", 2) fields.append((ftype, fname)) if len(dtypes) == 1: # Now, if everything we saw was the same dtype, we can go ahead and # set it here. We do this because it is a HUGE savings for 32 bit # floats, since our numpy copying/casting is way faster than # h5py's, for some reason I don't understand. This does *not* need # to be correct -- it will get fixed later -- it just needs to be # okay for now. self._field_dtype = list(dtypes)[0] f.close() return fields
def _parse_parameter_file(self): handle = h5py.File(self.parameter_filename, mode="r") hvals = {} hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items()) hvals["NumFiles"] = hvals["NumFilesPerSnapshot"] hvals["Massarr"] = hvals["MassTable"] self.dimensionality = 3 self.refine_by = 2 self.unique_identifier = \ int(os.stat(self.parameter_filename)[stat.ST_CTIME]) # Set standard values self.current_time = self.quan( hvals["Time_GYR"] * sec_conversion["Gyr"], "s") self.domain_left_edge = np.zeros(3, "float64") self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"] nz = 1 << self.over_refine_factor self.domain_dimensions = np.ones(3, "int32") * nz self.cosmological_simulation = 1 self.periodicity = (True, True, True) self.current_redshift = hvals["Redshift"] self.omega_lambda = hvals["OmegaLambda"] self.omega_matter = hvals["Omega0"] self.hubble_constant = hvals["HubbleParam"] self.parameters = hvals prefix = os.path.abspath( os.path.join( os.path.dirname(self.parameter_filename), os.path.basename(self.parameter_filename).split(".", 1)[0])) suffix = self.parameter_filename.rsplit(".", 1)[-1] self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix) self.file_count = len(glob.glob(prefix + "*" + self._suffix)) if self.file_count == 0: raise YTException(message="No data files found.", ds=self) self.particle_types = ("FOF", "SUBFIND") self.particle_types_raw = ("FOF", "SUBFIND") # To avoid having to open files twice self._unit_base = {} self._unit_base.update( (str(k), v) for k, v in handle["/Units"].attrs.items()) handle.close()
def _parse_parameter_file(self): handle = h5py.File(self.parameter_filename, mode="r") hvals = {} hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items()) hvals["NumFiles"] = hvals["NumFiles"] self.dimensionality = 3 self.refine_by = 2 self.unique_identifier = \ int(os.stat(self.parameter_filename)[stat.ST_CTIME]) # Set standard values self.domain_left_edge = np.zeros(3, "float64") self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"] nz = 1 << self.over_refine_factor self.domain_dimensions = np.ones(3, "int32") * nz self.cosmological_simulation = 1 self.periodicity = (True, True, True) self.current_redshift = hvals["Redshift"] self.omega_lambda = hvals["OmegaLambda"] self.omega_matter = hvals["Omega0"] self.hubble_constant = hvals["HubbleParam"] cosmology = Cosmology(hubble_constant=self.hubble_constant, omega_matter=self.omega_matter, omega_lambda=self.omega_lambda) self.current_time = cosmology.t_from_z(self.current_redshift) self.parameters = hvals prefix = os.path.abspath( os.path.join( os.path.dirname(self.parameter_filename), os.path.basename(self.parameter_filename).split(".", 1)[0])) suffix = self.parameter_filename.rsplit(".", 1)[-1] self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix) self.file_count = len(glob.glob(prefix + "*" + self._suffix)) if self.file_count == 0: raise YTException(message="No data files found.", ds=self) self.particle_types = ("Group", "Subhalo") self.particle_types_raw = ("Group", "Subhalo") handle.close()