def to_frb(self, width, resolution, height=None, periodic=False): r"""This function returns a FixedResolutionBuffer generated from this object. An ObliqueFixedResolutionBuffer is an object that accepts a variable-resolution 2D object and transforms it into an NxM bitmap that can be plotted, examined or processed. This is a convenience function to return an FRB directly from an existing 2D data object. Unlike the corresponding to_frb function for other YTSelectionContainer2D objects, this does not accept a 'center' parameter as it is assumed to be centered at the center of the cutting plane. Parameters ---------- width : width specifier This can either be a floating point value, in the native domain units of the simulation, or a tuple of the (value, unit) style. This will be the width of the FRB. height : height specifier, optional This will be the height of the FRB, by default it is equal to width. resolution : int or tuple of ints The number of pixels on a side of the final FRB. periodic : boolean This can be true or false, and governs whether the pixelization will span the domain boundaries. Returns ------- frb : :class:`~yt.visualization.fixed_resolution.ObliqueFixedResolutionBuffer` A fixed resolution buffer, which can be queried for fields. Examples -------- >>> v, c = ds.find_max("density") >>> sp = ds.sphere(c, (100.0, 'au')) >>> L = sp.quantities.angular_momentum_vector() >>> cutting = ds.cutting(L, c) >>> frb = cutting.to_frb( (1.0, 'pc'), 1024) >>> write_image(np.log10(frb["Density"]), 'density_1pc.png') """ if is_sequence(width): validate_width_tuple(width) width = self.ds.quan(width[0], width[1]) if height is None: height = width elif is_sequence(height): validate_width_tuple(height) height = self.ds.quan(height[0], height[1]) if not is_sequence(resolution): resolution = (resolution, resolution) from yt.visualization.fixed_resolution import FixedResolutionBuffer bounds = (-width / 2.0, width / 2.0, -height / 2.0, height / 2.0) frb = FixedResolutionBuffer(self, bounds, resolution, periodic=periodic) return frb
def sanitize_depth(self, depth): if iterable(depth): validate_width_tuple(depth) depth = (self.ds.quan(depth[0], fix_unitary(depth[1])), ) elif isinstance(depth, Number): depth = (self.ds.quan(depth, 'code_length', registry=self.ds.unit_registry), ) elif isinstance(depth, YTQuantity): depth = (depth, ) else: raise YTInvalidWidthError(depth) return depth
def validate_iterable_width(width, ds, unit=None): if isinstance(width[0], tuple) and isinstance(width[1], tuple): validate_width_tuple(width[0]) validate_width_tuple(width[1]) return ( ds.quan(width[0][0], fix_unitary(width[0][1])), ds.quan(width[1][0], fix_unitary(width[1][1])), ) elif isinstance(width[0], Number) and isinstance(width[1], Number): return (ds.quan(width[0], "code_length"), ds.quan(width[1], "code_length")) elif isinstance(width[0], YTQuantity) and isinstance(width[1], YTQuantity): return (ds.quan(width[0]), ds.quan(width[1])) else: validate_width_tuple(width) # If width and unit are both valid width tuples, we # assume width controls x and unit controls y try: validate_width_tuple(unit) return ( ds.quan(width[0], fix_unitary(width[1])), ds.quan(unit[0], fix_unitary(unit[1])), ) except YTInvalidWidthError: return ( ds.quan(width[0], fix_unitary(width[1])), ds.quan(width[0], fix_unitary(width[1])), )