Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def volume(self):
"""The abstract volume associated with this VolumeSource
This object does the heavy lifting to access data in an efficient manner
using a KDTree
"""
if self._volume is None:
mylog.info("Creating volume")
volume = AMRKDTree(self.data_source.ds, data_source=self.data_source)
self._volume = volume
return self._volume
if cosmology is None:
hubble = getattr(ds, "hubble_constant", None)
omega_m = getattr(ds, "omega_matter", None)
omega_l = getattr(ds, "omega_lambda", None)
if hubble == 0: hubble = None
if hubble is not None and \
omega_m is not None and \
omega_l is not None:
cosmo = Cosmology(hubble_constant=hubble,
omega_matter=omega_m,
omega_lambda=omega_l)
else:
cosmo = Cosmology()
else:
cosmo = cosmology
mylog.info("Cosmology: h = %g, omega_matter = %g, omega_lambda = %g" %
(cosmo.hubble_constant, cosmo.omega_matter, cosmo.omega_lambda))
if dist is None:
D_A = cosmo.angular_diameter_distance(0.0,redshift).in_units("Mpc")
else:
D_A = parse_value(dist, "Mpc")
redshift = 0.0
if center in ("center", "c"):
parameters["center"] = ds.domain_center
elif center in ("max", "m"):
parameters["center"] = ds.find_max("density")[-1]
elif iterable(center):
if isinstance(center, YTArray):
parameters["center"] = center.in_units("code_length")
elif isinstance(center, tuple):
if center[0] == "min":
def get_data(self, fields):
mylog.info("Getting %s using ParticleIO" % str(fields))
fields = ensure_list(fields)
if not self.ds.index.io._particle_reader:
mylog.info("not self.ds.index.io._particle_reader")
return self.source.get_data(fields)
rtype, args = self._get_args()
count_list, grid_list = [], []
for grid in self.source._grids:
if grid.NumberOfParticles == 0: continue
grid_list.append(grid)
if self.source._is_fully_enclosed(grid):
count_list.append(grid.NumberOfParticles)
else:
count_list.append(-1)
# region type, left_edge, right_edge, periodic, grid_list
fields_to_read = []
conv_factors = []
def _validate_parent_children_relationship(self):
mylog.info('Validating the parent-children relationship ...')
father_list = self._handle["Tree/Father"].value
for grid in self.grids:
# parent->children == itself
if grid.Parent is not None:
assert grid in grid.Parent.Children, \
'Grid %d, Parent %d, Parent->Children[0] %d' % \
(grid.id, grid.Parent.id, grid.Parent.Children[0].id)
# children->parent == itself
for c in grid.Children:
assert c.Parent is grid, \
'Grid %d, Children %d, Children->Parent %d' % \
(grid.id, c.id, c.Parent.id)
A :class:`yt.data_objects.image_array.ImageArray` instance containing
the current rendering image.
Examples
--------
>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>>
>>> sc = yt.create_scene(ds)
>>> # Modify camera, sources, etc...
>>> im = sc.render()
>>> sc.save(sigma_clip=4.0)
"""
mylog.info("Rendering scene (Can take a while).")
if camera is None:
camera = self.camera
assert(camera is not None)
self._validate()
bmp = self.composite(camera=camera)
self._last_render = bmp
return bmp
if isinstance(rs.field, string_types):
field = rs.field
else:
field = rs.field[-1]
fname = "%s_Render_%s.png" % (basename, field)
# if no volume source present, use a default filename
else:
fname = "Render_opaque.png"
suffix = get_image_suffix(fname)
if suffix == '':
suffix = '.png'
fname = '%s%s' % (fname, suffix)
self.render()
mylog.info("Saving render %s", fname)
# We can render pngs natively but for other formats we defer to
# matplotlib.
if suffix == '.png':
self._last_render.write_png(fname, sigma_clip=sigma_clip)
else:
from matplotlib.figure import Figure
from matplotlib.backends.backend_pdf import \
FigureCanvasPdf
from matplotlib.backends.backend_ps import \
FigureCanvasPS
shape = self._last_render.shape
fig = Figure((shape[0]/100., shape[1]/100.))
if suffix == '.pdf':
canvas = FigureCanvasPdf(fig)
elif suffix in ('.eps', '.ps'):
canvas = FigureCanvasPS(fig)
Examples
--------
>>> import yt
>>> ds = yt.load("Enzo_64/DD0046/DD0046")
>>> sc = yt.create_scene(ds)
"""
data_source = data_source_or_all(data_source)
sc = Scene()
if field is None:
field = data_source.ds.default_field
if field not in data_source.ds.derived_field_list:
raise YTSceneFieldNotFound("""Could not find field '%s' in %s.
Please specify a field in create_scene()""" % (field, data_source.ds))
mylog.info('Setting default field to %s' % field.__repr__())
if hasattr(data_source.ds.index, "meshes"):
source = MeshSource(data_source, field=field)
else:
source = VolumeSource(data_source, field=field)
sc.add_source(source)
sc.add_camera(data_source=data_source, lens_type=lens_type)
return sc
def build_memmap(self):
assert(self.size != -1)
mylog.info('Building memmap with offset: %i and size %i' % (self._offset, self.size))
self.handle = self.HTTPArray(self.filename, dtype=self.dtype,
shape=self.size, offset=self._offset)
for k in self.dtype.names:
self.data[k] = RedirectArray(self.handle, k)
def _open_stream(self, data_file, field):
# This does not actually stream yet!
ftype, fname = field
s = "%s/%s/%s/%s" % (self._url,
data_file.file_id, ftype, fname)
mylog.info("Loading URL %s", s)
requests = get_requests()
resp = requests.get(s)
if resp.status_code != 200:
raise RuntimeError
self.total_bytes += len(resp.content)
return resp.content
" this, change one of the BTYPE header keywords.")
fname += "_%d" % (dup_field_index[fname])
for k in range(naxis4):
if naxis4 > 1:
fname += "_%s_%d" % (hdu.header["CTYPE4"], k+1)
self._axis_map[fname] = k
self._file_map[fname] = fits_file
self._ext_map[fname] = j
self._scale_map[fname] = [0.0, 1.0]
if "bzero" in hdu.header:
self._scale_map[fname][0] = hdu.header["bzero"]
if "bscale" in hdu.header:
self._scale_map[fname][1] = hdu.header["bscale"]
self.field_list.append(("fits", fname))
self.dataset.field_units[fname] = units
mylog.info("Adding field %s to the list of fields." % (fname))
if units == "dimensionless":
mylog.warning("Could not determine dimensions for field %s, " % (fname) +
"setting to dimensionless.")
else:
mylog.warning("Image block %s does not have " % (hdu.name.lower()) +
"the same dimensions as the primary and will not be " +
"available as a field.")