[yt-svn] commit/yt: 5 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue May 6 06:36:08 PDT 2014
5 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/9ae0344be0b3/
Changeset: 9ae0344be0b3
Branch: yt-3.0
User: smumford
Date: 2014-05-02 18:25:32
Summary: 3.0 style changes and some fixes to cookbook.
I changed most pf to ds and pep8 linted the code.
Affected #: 13 files
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/aligned_cutting_plane.py
--- a/doc/source/cookbook/aligned_cutting_plane.py
+++ b/doc/source/cookbook/aligned_cutting_plane.py
@@ -1,18 +1,18 @@
-from yt.mods import *
+import yt
# Load the dataset.
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
# Create a 1 kpc radius sphere, centered on the max density. Note that this
# sphere is very small compared to the size of our final plot, and it has a
# non-axially aligned L vector.
-sp = pf.sphere("center", (15.0, "kpc"))
+sp = ds.sphere("center", (15.0, "kpc"))
# Get the angular momentum vector for the sphere.
L = sp.quantities.angular_momentum_vector()
-print "Angular momentum vector: %s" % (L)
+print "Angular momentum vector: {0}".format(L)
# Create an OffAxisSlicePlot on the object with the L vector as its normal
-p = OffAxisSlicePlot(pf, L, "density", sp.center, (25, "kpc"))
+p = yt.OffAxisSlicePlot(ds, L, "density", sp.center, (25, "kpc"))
p.save()
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/amrkdtree_downsampling.py
--- a/doc/source/cookbook/amrkdtree_downsampling.py
+++ b/doc/source/cookbook/amrkdtree_downsampling.py
@@ -1,26 +1,28 @@
-## Using AMRKDTree Homogenized Volumes to examine large datasets at lower resolution.
+# Using AMRKDTree Homogenized Volumes to examine large datasets
+# at lower resolution.
# In this example we will show how to use the AMRKDTree to take a simulation
# with 8 levels of refinement and only use levels 0-3 to render the dataset.
# We begin by loading up yt, and importing the AMRKDTree
+import numpy as np
-from yt.mods import *
+import yt
from yt.utilities.amr_kdtree.api import AMRKDTree
# Load up a data and print out the maximum refinement level
-pf = load('IsolatedGalaxy/galaxy0030/galaxy0030')
+ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
-kd = AMRKDTree(pf)
+kd = AMRKDTree(ds)
# Print out the total volume of all the bricks
print kd.count_volume()
# Print out the number of cells
print kd.count_cells()
-tf = ColorTransferFunction((-30, -22))
-cam = pf.h.camera([0.5, 0.5, 0.5], [0.2, 0.3, 0.4], 0.10, 256,
- tf, volume=kd)
-tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5], colormap = 'RdBu_r')
+tf = yt.ColorTransferFunction((-30, -22))
+cam = ds.h.camera([0.5, 0.5, 0.5], [0.2, 0.3, 0.4], 0.10, 256,
+ tf, volume=kd)
+tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5], colormap='RdBu_r')
cam.snapshot("v1.png", clip_ratio=6.0)
# This rendering is okay, but lets say I'd like to improve it, and I don't want
@@ -28,7 +30,7 @@
# generate a low resolution version of the AMRKDTree and pass that in to the
# camera. We do this by specifying a maximum refinement level of 3.
-kd_low_res = AMRKDTree(pf, l_max=3)
+kd_low_res = AMRKDTree(ds, max_level=3)
print kd_low_res.count_volume()
print kd_low_res.count_cells()
@@ -42,21 +44,21 @@
# rendering until we find something we like.
tf.clear()
-tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
- alpha=np.ones(4,dtype='float64'), colormap = 'RdBu_r')
+tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5],
+ alpha=np.ones(4, dtype='float64'), colormap='RdBu_r')
cam.snapshot("v2.png", clip_ratio=6.0)
# This looks better. Now let's try turning on opacity.
-tf.grey_opacity=True
+tf.grey_opacity = True
cam.snapshot("v4.png", clip_ratio=6.0)
# That seemed to pick out som interesting structures. Now let's bump up the
# opacity.
tf.clear()
-tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
- alpha=10.0*np.ones(4,dtype='float64'), colormap = 'RdBu_r')
+tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5],
+ alpha=10.0 * np.ones(4, dtype='float64'), colormap='RdBu_r')
cam.snapshot("v3.png", clip_ratio=6.0)
# This looks pretty good, now lets go back to the full resolution AMRKDTree
@@ -65,4 +67,3 @@
cam.snapshot("v4.png", clip_ratio=6.0)
# This looks great!
-
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/average_value.py
--- a/doc/source/cookbook/average_value.py
+++ b/doc/source/cookbook/average_value.py
@@ -1,12 +1,12 @@
-from yt.mods import *
+import yt
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
field = "temperature" # The field to average
-weight = "cell_mass" # The weight for the average
+weight = "cell_mass" # The weight for the average
-dd = pf.h.all_data() # This is a region describing the entire box,
- # but note it doesn't read anything in yet!
+dd = ds.h.all_data() # This is a region describing the entire box,
+ # but note it doesn't read anything in yet!
# We now use our 'quantities' call to get the average quantity
average_value = dd.quantities["WeightedAverageQuantity"](field, weight)
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/boolean_data_objects.py
--- a/doc/source/cookbook/boolean_data_objects.py
+++ b/doc/source/cookbook/boolean_data_objects.py
@@ -1,23 +1,23 @@
-from yt.mods import * # set up our namespace
+import yt
-pf = load("Enzo_64/DD0043/data0043") # load data
+ds = yt.load("Enzo_64/DD0043/data0043") # load data
# Make a few data ojbects to start.
-re1 = pf.region([0.5, 0.5, 0.5], [0.4, 0.4, 0.4], [0.6, 0.6, 0.6])
-re2 = pf.region([0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6])
-sp1 = pf.sphere([0.5, 0.5, 0.5], 0.05)
-sp2 = pf.sphere([0.1, 0.2, 0.3], 0.1)
+re1 = ds.region([0.5, 0.5, 0.5], [0.4, 0.4, 0.4], [0.6, 0.6, 0.6])
+re2 = ds.region([0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6])
+sp1 = ds.sphere([0.5, 0.5, 0.5], 0.05)
+sp2 = ds.sphere([0.1, 0.2, 0.3], 0.1)
# The "AND" operator. This will make a region identical to re2.
-bool1 = pf.boolean([re1, "AND", re2])
+bool1 = ds.boolean([re1, "AND", re2])
xp = bool1["particle_position_x"]
# The "OR" operator. This will make a region identical to re1.
-bool2 = pf.boolean([re1, "OR", re2])
+bool2 = ds.boolean([re1, "OR", re2])
# The "NOT" operator. This will make a region like re1, but with the corner
# that re2 covers cut out.
-bool3 = pf.boolean([re1, "NOT", re2])
+bool3 = ds.boolean([re1, "NOT", re2])
# Disjoint regions can be combined with the "OR" operator.
-bool4 = pf.boolean([sp1, "OR", sp2])
+bool4 = ds.boolean([sp1, "OR", sp2])
# Find oddly-shaped overlapping regions.
-bool5 = pf.boolean([re2, "AND", sp1])
+bool5 = ds.boolean([re2, "AND", sp1])
# Nested logic with parentheses.
# This is re1 with the oddly-shaped region cut out.
-bool6 = pf.boolean([re1, "NOT", "(", re1, "AND", sp1, ")"])
+bool6 = ds.boolean([re1, "NOT", "(", re1, "AND", sp1, ")"])
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/camera_movement.py
--- a/doc/source/cookbook/camera_movement.py
+++ b/doc/source/cookbook/camera_movement.py
@@ -1,43 +1,43 @@
-from yt.mods import * # set up our namespace
+import numpy as np
+
+import yt
# Follow the simple_volume_rendering cookbook for the first part of this.
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
-dd = pf.h.all_data()
-mi, ma = dd.quantities["Extrema"]("density")[0]
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
+dd = ds.all_data()
+mi, ma = dd.quantities["Extrema"]("density")
# Set up transfer function
-tf = ColorTransferFunction((np.log10(mi), np.log10(ma)))
+tf = yt.ColorTransferFunction((np.log10(mi), np.log10(ma)))
tf.add_layers(6, w=0.05)
# Set up camera paramters
-c = [0.5, 0.5, 0.5] # Center
-L = [1, 1, 1] # Normal Vector
-W = 1.0 # Width
-Nvec = 512 # Pixels on a side
+c = [0.5, 0.5, 0.5] # Center
+L = [1, 1, 1] # Normal Vector
+W = 1.0 # Width
+Nvec = 512 # Pixels on a side
# Specify a north vector, which helps with rotations.
-north_vector = [0.,0.,1.]
+north_vector = [0., 0., 1.]
# Find the maximum density location, store it in max_c
-v,max_c = pf.h.find_max('density')
+v, max_c = ds.find_max('density')
# Initialize the Camera
-cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf, north_vector=north_vector)
+cam = ds.camera(c, L, W, (Nvec, Nvec), tf, north_vector=north_vector)
frame = 0
# Do a rotation over 5 frames
-for i, snapshot in enumerate(cam.rotation(np.pi, 5, clip_ratio = 8.0)):
+for i, snapshot in enumerate(cam.rotation(np.pi, 5, clip_ratio=8.0)):
snapshot.write_png('camera_movement_%04i.png' % frame)
frame += 1
# Move to the maximum density location over 5 frames
-for i, snapshot in enumerate(cam.move_to(max_c, 5, clip_ratio = 8.0)):
+for i, snapshot in enumerate(cam.move_to(max_c, 5, clip_ratio=8.0)):
snapshot.write_png('camera_movement_%04i.png' % frame)
frame += 1
# Zoom in by a factor of 10 over 5 frames
-for i, snapshot in enumerate(cam.zoomin(10.0, 5, clip_ratio = 8.0)):
+for i, snapshot in enumerate(cam.zoomin(10.0, 5, clip_ratio=8.0)):
snapshot.write_png('camera_movement_%04i.png' % frame)
- frame += 1
-
-
+ frame += 1
\ No newline at end of file
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/contours_on_slice.py
--- a/doc/source/cookbook/contours_on_slice.py
+++ b/doc/source/cookbook/contours_on_slice.py
@@ -1,13 +1,13 @@
-from yt.mods import * # set up our namespace
+import yt
# first add density contours on a density slice
-pf = load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
-p = SlicePlot(pf, "x", "density")
+pf = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
+p = yt.SlicePlot(pf, "x", "density")
p.annotate_contour("density")
p.save()
# then add temperature contours on the same densty slice
-pf = load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
-p = SlicePlot(pf, "x", "density")
+pf = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
+p = yt.SlicePlot(pf, "x", "density")
p.annotate_contour("temperature")
p.save(str(pf)+'_T_contour')
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/extract_fixed_resolution_data.py
--- a/doc/source/cookbook/extract_fixed_resolution_data.py
+++ b/doc/source/cookbook/extract_fixed_resolution_data.py
@@ -1,25 +1,25 @@
-from yt.mods import *
+import yt
# For this example we will use h5py to write to our output file.
import h5py
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
level = 2
-dims = pf.domain_dimensions * pf.refine_by**level
+dims = ds.domain_dimensions * ds.refine_by**level
# Now, we construct an object that describes the data region and structure we
# want
-cube = pf.covering_grid(2, # The level we are willing to extract to; higher
- # levels than this will not contribute to the data!
- left_edge=[0.0, 0.0, 0.0],
- # And any fields to preload (this is optional!)
- dims = dims,
- fields=["density"])
+cube = ds.covering_grid(2, # The level we are willing to extract to; higher
+ # levels than this will not contribute to the data!
+ left_edge=[0.0, 0.0, 0.0],
+ # And any fields to preload (this is optional!)
+ dims=dims,
+ fields=["density"])
# Now we open our output file using h5py
# Note that we open with 'w' which will overwrite existing files!
-f = h5py.File("my_data.h5", "w")
+f = h5py.File("my_data.h5", "w")
# We create a dataset at the root note, calling it density...
f.create_dataset("/density", data=cube["density"])
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/find_clumps.py
--- a/doc/source/cookbook/find_clumps.py
+++ b/doc/source/cookbook/find_clumps.py
@@ -1,26 +1,30 @@
-# set up our namespace
-from yt.mods import *
-from yt.analysis_modules.level_sets.api import *
+import numpy as np
-fn = "IsolatedGalaxy/galaxy0030/galaxy0030" # parameter file to load
-field = "density" # this is the field we look for contours over -- we could do
- # this over anything. Other common choices are 'AveragedDensity'
- # and 'Dark_Matter_Density'.
-step = 2.0 # This is the multiplicative interval between contours.
+import yt
+from yt.analysis_modules.level_sets.api import (Clump, find_clumps,
+ get_lowest_clumps)
-pf = load(fn) # load data
+fn = "IsolatedGalaxy/galaxy0030/galaxy0030" # parameter file to load
+# this is the field we look for contours over -- we could do
+# this over anything. Other common choices are 'AveragedDensity'
+# and 'Dark_Matter_Density'.
+field = "density"
+
+step = 2.0 # This is the multiplicative interval between contours.
+
+ds = yt.load(fn) # load data
# We want to find clumps over the entire dataset, so we'll just grab the whole
# thing! This is a convenience parameter that prepares an object that covers
# the whole domain. Note, though, that it will load on demand and not before!
-data_source = pf.disk([0.5, 0.5, 0.5], [0., 0., 1.],
- 8./pf.units['kpc'], 1./pf.units['kpc'])
+data_source = ds.disk([0.5, 0.5, 0.5], [0., 0., 1.],
+ (8., 'kpc'), (1., 'kpc'))
# Now we set some sane min/max values between which we want to find contours.
# This is how we tell the clump finder what to look for -- it won't look for
# contours connected below or above these threshold values.
-c_min = 10**np.floor(np.log10(data_source[field]).min() )
-c_max = 10**np.floor(np.log10(data_source[field]).max()+1)
+c_min = 10**np.floor(np.log10(data_source[field]).min())
+c_max = 10**np.floor(np.log10(data_source[field]).max() + 1)
# keep only clumps with at least 20 cells
function = 'self.data[\'%s\'].size > 20' % field
@@ -38,13 +42,13 @@
# As it goes, it appends the information about all the sub-clumps to the
# master-clump. Among different ways we can examine it, there's a convenience
# function for outputting the full index to a file.
-f = open('%s_clump_index.txt' % pf,'w')
-amods.level_sets.write_clump_index(master_clump,0,f)
+f = open('%s_clump_index.txt' % ds, 'w')
+yt.amods.level_sets.write_clump_index(master_clump, 0, f)
f.close()
# We can also output some handy information, as well.
-f = open('%s_clumps.txt' % pf,'w')
-amods.level_sets.write_clumps(master_clump,0,f)
+f = open('%s_clumps.txt' % ds, 'w')
+yt.amods.level_sets.write_clumps(master_clump, 0, f)
f.close()
# We can traverse the clump index to get a list of all of the 'leaf' clumps
@@ -52,7 +56,7 @@
# If you'd like to visualize these clumps, a list of clumps can be supplied to
# the "clumps" callback on a plot. First, we create a projection plot:
-prj = ProjectionPlot(pf, 2, field, center='c', width=(20,'kpc'))
+prj = yt.ProjectionPlot(ds, 2, field, center='c', width=(20, 'kpc'))
# Next we annotate the plot with contours on the borders of the clumps
prj.annotate_clumps(leaf_clumps)
@@ -62,7 +66,7 @@
# We can also save the clump object to disk to read in later so we don't have
# to spend a lot of time regenerating the clump objects.
-pf.h.save_object(master_clump, 'My_clumps')
+ds.h.save_object(master_clump, 'My_clumps')
# Later, we can read in the clump object like so,
-master_clump = pf.h.load_object('My_clumps')
+master_clump = ds.load_object('My_clumps')
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/fit_spectrum.py
--- a/doc/source/cookbook/fit_spectrum.py
+++ b/doc/source/cookbook/fit_spectrum.py
@@ -1,25 +1,19 @@
-import os
-import sys
-import h5py
+import yt
+from yt.analysis_modules.cosmological_observation.light_ray.api import LightRay
+from yt.analysis_modules.api import AbsorptionSpectrum
+from yt.analysis_modules.absorption_spectrum.api import generate_total_fit
-from yt.mods import *
-from yt.analysis_modules.cosmological_observation.light_ray.api import \
- LightRay
-from yt.analysis_modules.api import AbsorptionSpectrum
-from yt.analysis_modules.absorption_spectrum.api import \
- generate_total_fit
+# Define and add a field to simulate OVI based on a constant relationship to HI
+def _OVI_NumberDensity(field, data):
+ return data['HI_NumberDensity']
-# Define and add a field to simulate OVI based on
-# a constant relationship to HI
-def _OVI_NumberDensity(field,data):
- return data['HI_NumberDensity']
def _convertOVI(data):
return 4.9E-4*.2
-add_field('my_OVI_NumberDensity',
- function=_OVI_NumberDensity,
- convert_function=_convertOVI)
+yt.add_field('my_OVI_NumberDensity',
+ function=_OVI_NumberDensity,
+ convert_function=_convertOVI)
# Define species andi associated parameters to add to continuum
@@ -29,33 +23,33 @@
# (as in the OVI doublet), 'numLines' will be equal to the number
# of lines, and f,gamma, and wavelength will have multiple values.
-HI_parameters = {'name':'HI',
- 'field' : 'HI_NumberDensity',
- 'f': [.4164],
- 'Gamma':[6.265E8],
- 'wavelength':[1215.67],
- 'mass': 1.00794,
- 'numLines':1,
- 'maxN': 1E22, 'minN':1E11,
- 'maxb': 300, 'minb':1,
- 'maxz': 6, 'minz':0,
- 'init_b':30,
- 'init_N':1E14}
+HI_parameters = {'name': 'HI',
+ 'field': 'HI_NumberDensity',
+ 'f': [.4164],
+ 'Gamma': [6.265E8],
+ 'wavelength': [1215.67],
+ 'mass': 1.00794,
+ 'numLines': 1,
+ 'maxN': 1E22, 'minN': 1E11,
+ 'maxb': 300, 'minb': 1,
+ 'maxz': 6, 'minz': 0,
+ 'init_b': 30,
+ 'init_N': 1E14}
-OVI_parameters = {'name':'OVI',
- 'field' : 'my_OVI_NumberDensity',
- 'f':[.1325,.06580],
- 'Gamma':[4.148E8,4.076E8],
- 'wavelength':[1031.9261,1037.6167],
- 'mass': 15.9994,
- 'numLines':2,
- 'maxN':1E17,'minN':1E11,
- 'maxb':300, 'minb':1,
- 'maxz':6, 'minz':0,
- 'init_b':20,
- 'init_N':1E12}
+OVI_parameters = {'name': 'OVI',
+ 'field': 'my_OVI_NumberDensity',
+ 'f': [.1325, .06580],
+ 'Gamma': [4.148E8, 4.076E8],
+ 'wavelength': [1031.9261, 1037.6167],
+ 'mass': 15.9994,
+ 'numLines': 2,
+ 'maxN': 1E17, 'minN': 1E11,
+ 'maxb': 300, 'minb': 1,
+ 'maxz': 6, 'minz': 0,
+ 'init_b': 20,
+ 'init_N': 1E12}
-species_dicts = {'HI':HI_parameters,'OVI':OVI_parameters}
+species_dicts = {'HI': HI_parameters, 'OVI': OVI_parameters}
# Create a LightRay object extending from z = 0 to z = 0.1
# and use only the redshift dumps.
@@ -63,7 +57,7 @@
'Enzo', 0.0, 0.1,
use_minimum_datasets=True,
time_data=False
- )
+ )
# Get all fields that need to be added to the light ray
fields = ['temperature']
@@ -80,34 +74,32 @@
get_los_velocity=True,
njobs=-1)
-# Create an AbsorptionSpectrum object extending from
+# Create an AbsorptionSpectrum object extending from
# lambda = 900 to lambda = 1800, with 10000 pixels
sp = AbsorptionSpectrum(900.0, 1400.0, 50000)
# Iterate over species
-for s,params in species_dicts.iteritems():
-
- #Iterate over transitions for a single species
+for s, params in species_dicts.iteritems():
+ # Iterate over transitions for a single species
for i in range(params['numLines']):
-
- #Add the lines to the spectrum
- sp.add_line(s, params['field'],
- params['wavelength'][i], params['f'][i],
- params['Gamma'][i], params['mass'],
- label_threshold=1.e10)
+ # Add the lines to the spectrum
+ sp.add_line(s, params['field'],
+ params['wavelength'][i], params['f'][i],
+ params['Gamma'][i], params['mass'],
+ label_threshold=1.e10)
# Make and save spectrum
-wavelength, flux = sp.make_spectrum('lightray.h5',
- output_file='spectrum.h5',
- line_list_file='lines.txt',
- use_peculiar_velocity=True)
+wavelength, flux = sp.make_spectrum('lightray.h5',
+ output_file='spectrum.h5',
+ line_list_file='lines.txt',
+ use_peculiar_velocity=True)
-#Define order to fit species in
-order_fits = ['OVI','HI']
+# Define order to fit species in
+order_fits = ['OVI', 'HI']
# Fit spectrum and save fit
fitted_lines, fitted_flux = generate_total_fit(wavelength,
- flux, order_fits, species_dicts,
- output_file='spectrum_fit.h5')
+ flux, order_fits, species_dicts,
+ output_file='spectrum_fit.h5')
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/free_free_field.py
--- a/doc/source/cookbook/free_free_field.py
+++ b/doc/source/cookbook/free_free_field.py
@@ -1,40 +1,42 @@
-from yt.mods import *
-from yt.utilities.physical_constants import mp # Need to grab the proton mass from the
- # constants database
+import numpy as np
+import yt
+# Need to grab the proton mass from the constants database
+from yt.utilities.physical_constants import mp
# Define the emission field
-keVtoerg = 1.602e-9 # Convert energy in keV to energy in erg
-KtokeV = 8.617e-08 # Convert degrees Kelvin to degrees keV
+keVtoerg = 1.602e-9 # Convert energy in keV to energy in erg
+KtokeV = 8.617e-08 # Convert degrees Kelvin to degrees keV
sqrt3 = np.sqrt(3.)
-expgamma = 1.78107241799 # Exponential of Euler's constant
+expgamma = 1.78107241799 # Exponential of Euler's constant
-def _FreeFree_Emission(field, data) :
- if data.has_field_parameter("Z") :
+def _FreeFree_Emission(field, data):
+
+ if data.has_field_parameter("Z"):
Z = data.get_field_parameter("Z")
- else :
- Z = 1.077 # Primordial H/He plasma
+ else:
+ Z = 1.077 # Primordial H/He plasma
- if data.has_field_parameter("mue") :
+ if data.has_field_parameter("mue"):
mue = data.get_field_parameter("mue")
- else :
- mue = 1./0.875 # Primordial H/He plasma
+ else:
+ mue = 1./0.875 # Primordial H/He plasma
- if data.has_field_parameter("mui") :
+ if data.has_field_parameter("mui"):
mui = data.get_field_parameter("mui")
- else :
- mui = 1./0.8125 # Primordial H/He plasma
+ else:
+ mui = 1./0.8125 # Primordial H/He plasma
- if data.has_field_parameter("Ephoton") :
+ if data.has_field_parameter("Ephoton"):
Ephoton = data.get_field_parameter("Ephoton")
- else :
- Ephoton = 1.0 # in keV
+ else:
+ Ephoton = 1.0 # in keV
- if data.has_field_parameter("photon_emission") :
+ if data.has_field_parameter("photon_emission"):
photon_emission = data.get_field_parameter("photon_emission")
- else :
- photon_emission = False # Flag for energy or photon emission
+ else:
+ photon_emission = False # Flag for energy or photon emission
n_e = data["density"]/(mue*mp)
n_i = data["density"]/(mui*mp)
@@ -50,24 +52,25 @@
eps_E = 1.64e-20*Z*Z*n_e*n_i/np.sqrt(data["temperature"]) * \
np.exp(-Ephoton/kT)*g_ff
- if photon_emission: eps_E /= (Ephoton*keVtoerg)
+ if photon_emission:
+ eps_E /= (Ephoton*keVtoerg)
return eps_E
-add_field("FreeFree_Emission", function=_FreeFree_Emission)
+yt.add_field("FreeFree_Emission", function=_FreeFree_Emission)
# Define the luminosity derived quantity
-
-def _FreeFreeLuminosity(data) :
+def _FreeFreeLuminosity(data):
return (data["FreeFree_Emission"]*data["cell_volume"]).sum()
-def _combFreeFreeLuminosity(data, luminosity) :
+
+def _combFreeFreeLuminosity(data, luminosity):
return luminosity.sum()
-add_quantity("FreeFree_Luminosity", function=_FreeFreeLuminosity,
- combine_function=_combFreeFreeLuminosity, n_ret = 1)
+yt.add_quantity("FreeFree_Luminosity", function=_FreeFreeLuminosity,
+ combine_function=_combFreeFreeLuminosity, n_ret=1)
-pf = load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
+pf = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
sphere = pf.sphere(pf.domain_center, (100., "kpc"))
@@ -75,8 +78,8 @@
print "L_E (1 keV, primordial) = ", sphere.quantities["FreeFree_Luminosity"]()
-# The defaults for the field assume a H/He primordial plasma. Let's set the appropriate
-# parameters for a pure hydrogen plasma.
+# The defaults for the field assume a H/He primordial plasma.
+# Let's set the appropriate parameters for a pure hydrogen plasma.
sphere.set_field_parameter("mue", 1.0)
sphere.set_field_parameter("mui", 1.0)
@@ -90,10 +93,9 @@
print "L_E (10 keV, pure hydrogen) = ", sphere.quantities["FreeFree_Luminosity"]()
-# Finally, let's set the flag for photon emission, to get the total number of photons
-# emitted at this energy:
+# Finally, let's set the flag for photon emission, to get the total number
+# of photons emitted at this energy:
sphere.set_field_parameter("photon_emission", True)
print "L_ph (10 keV, pure hydrogen) = ", sphere.quantities["FreeFree_Luminosity"]()
-
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/global_phase_plots.py
--- a/doc/source/cookbook/global_phase_plots.py
+++ b/doc/source/cookbook/global_phase_plots.py
@@ -1,14 +1,14 @@
-from yt.mods import * # set up our namespace
+import yt
# load the dataset
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
# This is an object that describes the entire box
-ad = pf.h.all_data()
+ad = ds.h.all_data()
-# We plot the average VelocityMagnitude (mass-weighted) in our object
+# We plot the average VelocityMagnitude (mass-weighted) in our object
# as a function of Density and temperature
-plot = PhasePlot(ad, "density","temperature","velocity_magnitude")
+plot = yt.PhasePlot(ad, "density", "temperature", "velocity_magnitude")
# save the plot
plot.save()
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/halo_finding.py
--- a/doc/source/cookbook/halo_finding.py
+++ b/doc/source/cookbook/halo_finding.py
@@ -2,9 +2,9 @@
This script shows the simplest way of getting halo information. For more
information, see :ref:`halo_finding`.
"""
-from yt.mods import * # set up our namespace
+import yt
-pf = load("Enzo_64/DD0043/data0043")
+ds = yt.load("Enzo_64/DD0043/data0043")
-halos = HaloFinder(pf)
-halos.write_out("%s_halos.txt" % pf)
+halos = yt.HaloFinder(ds)
+halos.write_out("%s_halos.txt" % ds)
diff -r 8afbcadd70e3649e77886a9b29c3886f2969b22f -r 9ae0344be0b321d7bc0dda396b3932df89585e20 doc/source/cookbook/hse_field.py
--- a/doc/source/cookbook/hse_field.py
+++ b/doc/source/cookbook/hse_field.py
@@ -1,121 +1,134 @@
-from yt.mods import *
+import numpy as np
+import yt
-# Define the components of the gravitational acceleration vector field by taking the
-# gradient of the gravitational potential
+# Define the components of the gravitational acceleration vector field by
+# taking the gradient of the gravitational potential
-def _Grav_Accel_x(field, data) :
+
+def _Grav_Accel_x(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dx = div_fac * data['dx'].flat[0]
- gx = data["Grav_Potential"][sl_right,1:-1,1:-1]/dx
- gx -= data["Grav_Potential"][sl_left, 1:-1,1:-1]/dx
+ gx = data["gravitational_potential"][sl_right, 1:-1, 1:-1]/dx
+ gx -= data["gravitational_potential"][sl_left, 1:-1, 1:-1]/dx
- new_field = np.zeros(data["Grav_Potential"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = -gx
+ new_field = np.zeros(data["gravitational_potential"].shape,
+ dtype='float64')
+ new_field[1:-1, 1:-1, 1:-1] = -gx
return new_field
-def _Grav_Accel_y(field, data) :
+
+def _Grav_Accel_y(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dy = div_fac * data['dy'].flat[0]
- gy = data["Grav_Potential"][1:-1,sl_right,1:-1]/dy
- gy -= data["Grav_Potential"][1:-1,sl_left ,1:-1]/dy
+ gy = data["gravitational_potential"][1:-1, sl_right, 1:-1]/dy
+ gy -= data["gravitational_potential"][1:-1, sl_left, 1:-1]/dy
- new_field = np.zeros(data["Grav_Potential"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = -gy
+ new_field = np.zeros(data["gravitational_potential"].shape,
+ dtype='float64')
+ new_field[1:-1, 1:-1, 1:-1] = -gy
return new_field
-def _Grav_Accel_z(field, data) :
+
+def _Grav_Accel_z(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dz = div_fac * data['dz'].flat[0]
- gz = data["Grav_Potential"][1:-1,1:-1,sl_right]/dz
- gz -= data["Grav_Potential"][1:-1,1:-1,sl_left ]/dz
+ gz = data["gravitational_potential"][1:-1, 1:-1, sl_right]/dz
+ gz -= data["gravitational_potential"][1:-1, 1:-1, sl_left]/dz
- new_field = np.zeros(data["Grav_Potential"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = -gz
+ new_field = np.zeros(data["gravitational_potential"].shape,
+ dtype='float64')
+ new_field[1:-1, 1:-1, 1:-1] = -gz
return new_field
+
# Define the components of the pressure gradient field
-def _Grad_Pressure_x(field, data) :
+
+def _Grad_Pressure_x(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dx = div_fac * data['dx'].flat[0]
- px = data["pressure"][sl_right,1:-1,1:-1]/dx
- px -= data["pressure"][sl_left, 1:-1,1:-1]/dx
+ px = data["pressure"][sl_right, 1:-1, 1:-1]/dx
+ px -= data["pressure"][sl_left, 1:-1, 1:-1]/dx
new_field = np.zeros(data["pressure"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = px
+ new_field[1:-1, 1:-1, 1:-1] = px
return new_field
-def _Grad_Pressure_y(field, data) :
+
+def _Grad_Pressure_y(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dy = div_fac * data['dy'].flat[0]
- py = data["pressure"][1:-1,sl_right,1:-1]/dy
- py -= data["pressure"][1:-1,sl_left ,1:-1]/dy
+ py = data["pressure"][1:-1, sl_right, 1:-1]/dy
+ py -= data["pressure"][1:-1, sl_left, 1:-1]/dy
new_field = np.zeros(data["pressure"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = py
+ new_field[1:-1, 1:-1, 1:-1] = py
return new_field
-def _Grad_Pressure_z(field, data) :
+
+def _Grad_Pressure_z(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dz = div_fac * data['dz'].flat[0]
- pz = data["pressure"][1:-1,1:-1,sl_right]/dz
- pz -= data["pressure"][1:-1,1:-1,sl_left ]/dz
+ pz = data["pressure"][1:-1, 1:-1, sl_right]/dz
+ pz -= data["pressure"][1:-1, 1:-1, sl_left]/dz
new_field = np.zeros(data["pressure"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = pz
+ new_field[1:-1, 1:-1, 1:-1] = pz
return new_field
+
# Define the "degree of hydrostatic equilibrium" field
-def _HSE(field, data) :
+
+def _HSE(field, data):
gx = data["density"]*data["Grav_Accel_x"]
gy = data["density"]*data["Grav_Accel_y"]
@@ -131,36 +144,37 @@
# Now add the fields to the database
-add_field("Grav_Accel_x", function=_Grav_Accel_x, take_log=False,
- validators=[ValidateSpatial(1,["Grav_Potential"])])
+yt.add_field("Grav_Accel_x", function=_Grav_Accel_x, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["gravitational_potential"])])
-add_field("Grav_Accel_y", function=_Grav_Accel_y, take_log=False,
- validators=[ValidateSpatial(1,["Grav_Potential"])])
+yt.add_field("Grav_Accel_y", function=_Grav_Accel_y, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["gravitational_potential"])])
-add_field("Grav_Accel_z", function=_Grav_Accel_z, take_log=False,
- validators=[ValidateSpatial(1,["Grav_Potential"])])
+yt.add_field("Grav_Accel_z", function=_Grav_Accel_z, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["gravitational_potential"])])
-add_field("Grad_Pressure_x", function=_Grad_Pressure_x, take_log=False,
- validators=[ValidateSpatial(1,["pressure"])])
+yt.add_field("Grad_Pressure_x", function=_Grad_Pressure_x, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["pressure"])])
-add_field("Grad_Pressure_y", function=_Grad_Pressure_y, take_log=False,
- validators=[ValidateSpatial(1,["pressure"])])
+yt.add_field("Grad_Pressure_y", function=_Grad_Pressure_y, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["pressure"])])
-add_field("Grad_Pressure_z", function=_Grad_Pressure_z, take_log=False,
- validators=[ValidateSpatial(1,["pressure"])])
+yt.add_field("Grad_Pressure_z", function=_Grad_Pressure_z, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["pressure"])])
-add_field("HSE", function=_HSE, take_log=False)
+yt.add_field("HSE", function=_HSE, take_log=False)
-# Open two files, one at the beginning and the other at a later time when there's a
-# lot of sloshing going on.
+# Open two files, one at the beginning and the other at a later time when
+# there's a lot of sloshing going on.
-pfi = load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0000")
-pff = load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0350")
+dsi = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0000")
+dsf = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0350")
-# Sphere objects centered at the cluster potential minimum with a radius of 200 kpc
+# Sphere objects centered at the cluster potential minimum with a radius
+# of 200 kpc
-sphere_i = pfi.h.sphere(pfi.domain_center, (200, "kpc"))
-sphere_f = pff.h.sphere(pff.domain_center, (200, "kpc"))
+sphere_i = dsi.h.sphere(dsi.domain_center, (200, "kpc"))
+sphere_f = dsf.h.sphere(dsf.domain_center, (200, "kpc"))
# Average "degree of hydrostatic equilibrium" in these spheres
@@ -170,10 +184,13 @@
print "Degree of hydrostatic equilibrium initially: ", hse_i
print "Degree of hydrostatic equilibrium later: ", hse_f
-# Just for good measure, take slices through the center of the domain of the two files
+# Just for good measure, take slices through the center of the domains
+# of the two files
-slc_i = SlicePlot(pfi, 2, ["density","HSE"], center=pfi.domain_center, width=(1.0, "mpc"))
-slc_f = SlicePlot(pff, 2, ["density","HSE"], center=pff.domain_center, width=(1.0, "mpc"))
+slc_i = yt.SlicePlot(dsi, 2, ["density", "HSE"], center=dsi.domain_center,
+ width=(1.0, "mpc"))
+slc_f = yt.SlicePlot(dsf, 2, ["density", "HSE"], center=dsf.domain_center,
+ width=(1.0, "mpc"))
slc_i.save("initial")
slc_f.save("final")
https://bitbucket.org/yt_analysis/yt/commits/57502d10c2fd/
Changeset: 57502d10c2fd
Branch: yt-3.0
User: smumford
Date: 2014-05-03 19:48:03
Summary: Allow the user to override StreamlineCallback's x and y positions.
Allow plot_args to override the automatically generated x and y arrays
that are inputted to mpl.streamplot().
Affected #: 1 file
diff -r 9ae0344be0b321d7bc0dda396b3932df89585e20 -r 57502d10c2fdd23010e466de263ded110d898ccd yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -496,8 +496,10 @@
(x0, x1, y0, y1),).transpose()
X,Y = (np.linspace(xx0,xx1,nx,endpoint=True),
np.linspace(yy0,yy1,ny,endpoint=True))
- plot._axes.streamplot(X,Y, pixX, pixY, density = self.dens,
- **self.plot_args)
+ streamplot_args = {'x': X, 'y': Y, 'u':pixX, 'v': pixY,
+ 'density': self.dens}
+ streamplot_args.update(self.plot_args)
+ plot._axes.streamplot(**self.streamplot_args)
plot._axes.set_xlim(xx0,xx1)
plot._axes.set_ylim(yy0,yy1)
plot._axes.hold(False)
https://bitbucket.org/yt_analysis/yt/commits/d8f094635164/
Changeset: d8f094635164
Branch: yt-3.0
User: smumford
Date: 2014-05-03 23:06:13
Summary: First pass at making _frb frb
Affected #: 1 file
diff -r 57502d10c2fdd23010e466de263ded110d898ccd -r d8f094635164d037231e27a98db0008f7fb2eee0 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -264,7 +264,7 @@
including the margins but not the colorbar.
"""
- _frb = None
+ frb = None
def __init__(self, data_source, bounds, buff_size=(800,800), antialias=True,
periodic=True, origin='center-window', oblique=False,
window_size=8.0, fields=None, fontsize=18, setup=False):
@@ -294,7 +294,7 @@
range(len(self.data_source.center))
if i != self.data_source.axis]
self.set_center(center)
- for field in self._frb.data.keys():
+ for field in self.frb.data.keys():
finfo = self.data_source.pf._get_field_info(*field)
if finfo.take_log:
self._field_transform[field] = log_transform
@@ -322,27 +322,27 @@
def _recreate_frb(self):
old_fields = None
- if self._frb is not None:
- old_fields = self._frb.keys()
- old_units = [str(self._frb[of].units) for of in old_fields]
+ if self.frb is not None:
+ old_fields = self.frb.keys()
+ old_units = [str(self.frb[of].units) for of in old_fields]
if hasattr(self,'zlim'):
bounds = self.xlim+self.ylim+self.zlim
else:
bounds = self.xlim+self.ylim
if self._frb_generator is ObliqueFixedResolutionBuffer:
bounds = np.array(bounds)
- self._frb = self._frb_generator(self.data_source,
+ self.frb = self._frb_generator(self.data_source,
bounds, self.buff_size,
self.antialias,
periodic=self._periodic)
if old_fields is None:
- self._frb._get_data_source_fields()
+ self.frb._get_data_source_fields()
else:
for key, unit in zip(old_fields, old_units):
- self._frb[key]
- self._frb[key].convert_to_units(unit)
+ self.frb[key]
+ self.frb[key].convert_to_units(unit)
for key in self.override_fields:
- self._frb[key]
+ self.frb[key]
self._data_valid = True
@property
@@ -442,7 +442,7 @@
"Field list {} and unit "
"list {} are incompatible".format(field, new_unit))
for f, u in zip(field, new_unit):
- self._frb[f].convert_to_units(u)
+ self.frb[f].convert_to_units(u)
return self
@invalidate_data
@@ -513,7 +513,7 @@
axes_unit = get_axes_unit(width, self.pf)
- width = get_sanitized_width(self._frb.axis, width, None, self.pf)
+ width = get_sanitized_width(self.frb.axis, width, None, self.pf)
centerx = (self.xlim[1] + self.xlim[0])/2.
centery = (self.ylim[1] + self.ylim[0])/2.
@@ -744,7 +744,7 @@
else:
zlim = (None, None)
- image = self._frb[f]
+ image = self.frb[f]
if image.max() == image.min():
if self._field_transform[f] == log_transform:
@@ -828,7 +828,7 @@
colorbar_label = image.info['label']
# Determine the units of the data
- units = Unit(self._frb[f].units, registry=self.pf.unit_registry)
+ units = Unit(self.frb[f].units, registry=self.pf.unit_registry)
units = units.latex_representation()
if units is None or units == '':
@@ -1373,14 +1373,14 @@
addl_keys = {'type': 'widget_payload',
'widget_id': self._ext_widget_id}
else:
- fields = self._frb.data.keys()
+ fields = self.frb.data.keys()
addl_keys = {}
if self._colorbar_valid == False:
addl_keys['colorbar_image'] = self._get_cbar_image()
self._colorbar_valid = True
min_zoom = 200*self.pf.index.get_smallest_dx() * self.pf['unitary']
for field in fields:
- to_plot = apply_colormap(self._frb[field],
+ to_plot = apply_colormap(self.frb[field],
func = self._field_transform[field],
cmap_name = self._colormaps[field])
pngs = self._apply_modifications(to_plot)
@@ -1429,8 +1429,8 @@
field, number, colors, logit = self._contour_info
if colors is not None: plot_args['colors'] = colors
- raw_data = self._frb.data_source
- b = self._frb.bounds
+ raw_data = self.frb.data_source
+ b = self.frb.bounds
xi, yi = np.mgrid[b[0]:b[1]:(vi / 8) * 1j,
b[2]:b[3]:(vj / 8) * 1j]
x = raw_data['px']
@@ -1445,15 +1445,15 @@
if self._vector_info is None: return
skip, scale = self._vector_info
- nx = self._frb.buff_size[0]/skip
- ny = self._frb.buff_size[1]/skip
- new_frb = FixedResolutionBuffer(self._frb.data_source,
- self._frb.bounds, (nx,ny))
+ nx = self.frb.buff_size[0]/skip
+ ny = self.frb.buff_size[1]/skip
+ new_frb = FixedResolutionBuffer(self.frb.data_source,
+ self.frb.bounds, (nx,ny))
- axis = self._frb.data_source.axis
- xax = self._frb.data_source.pf.coordinates.x_axis[axis]
- yax = self._frb.data_source.pf.coordinates.y_axis[axis]
- axis_names = self._frb.data_source.pf.coordinates.axis_name
+ axis = self.frb.data_source.axis
+ xax = self.frb.data_source.pf.coordinates.x_axis[axis]
+ yax = self.frb.data_source.pf.coordinates.y_axis[axis]
+ axis_names = self.frb.data_source.pf.coordinates.axis_name
fx = "velocity_%s" % (axis_names[xax])
fy = "velocity_%x" % (axis_names[yax])
px = new_frb[fx][::-1,:]
@@ -1471,7 +1471,7 @@
# This will eventually change to work with non-logged fields
ticks = []
transform = self._field_transform[field]
- mi, ma = self._frb[field].min(), self._frb[field].max()
+ mi, ma = self.frb[field].min(), self.frb[field].max()
tick_locs = transform.ticks(mi, ma)
mi, ma = transform((mi, ma))
for v1,v2 in zip(tick_locs, transform(tick_locs)):
@@ -1509,7 +1509,7 @@
self.set_center((new_x, new_y))
def get_field_units(self, field, strip_mathml = True):
- ds = self._frb.data_source
+ ds = self.frb.data_source
pf = self.pf
field = self._check_field(field)
finfo = self.data_source.pf._get_field_info(*field)
@@ -1527,7 +1527,7 @@
return units
def get_metadata(self, field, strip_mathml = True, return_string = True):
- fval = self._frb[field]
+ fval = self.frb[field]
mi = fval.min()
ma = fval.max()
x_width = self.xlim[1] - self.xlim[0]
@@ -1538,10 +1538,10 @@
else:
unit = self._axes_unit_names
units = self.get_field_units(field, strip_mathml)
- center = getattr(self._frb.data_source, "center", None)
- xax = self.pf.coordinates.x_axis[self._frb.axis]
- yax = self.pf.coordinates.y_axis[self._frb.axis]
- if center is None or self._frb.axis == 4:
+ center = getattr(self.frb.data_source, "center", None)
+ xax = self.pf.coordinates.x_axis[self.frb.axis]
+ yax = self.pf.coordinates.y_axis[self.frb.axis]
+ if center is None or self.frb.axis == 4:
xc, yc, zc = -999, -999, -999
else:
center[xax] = 0.5 * (
@@ -1580,7 +1580,7 @@
def set_current_field(self, field):
field = self._check_field(field)
self._current_field = field
- self._frb[field]
+ self.frb[field]
finfo = self.data_source.pf._get_field_info(*field)
if finfo.take_log:
self._field_transform[field] = log_transform
https://bitbucket.org/yt_analysis/yt/commits/35643555863a/
Changeset: 35643555863a
Branch: yt-3.0
User: smumford
Date: 2014-05-03 23:14:30
Summary: More frb fixes
Affected #: 1 file
diff -r d8f094635164d037231e27a98db0008f7fb2eee0 -r 35643555863a276233803a7803842f6f2fdfc160 yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -270,15 +270,15 @@
return self.plots[item]
def run_callbacks(self, f):
- keys = self._frb.keys()
+ keys = self.frb.keys()
for name, (args, kwargs) in self._callbacks:
- cbw = CallbackWrapper(self, self.plots[f], self._frb, f)
+ cbw = CallbackWrapper(self, self.plots[f], self.frb, f)
CallbackMaker = callback_registry[name]
callback = CallbackMaker(*args[1:], **kwargs)
callback(cbw)
- for key in self._frb.keys():
+ for key in self.frb.keys():
if key not in keys:
- del self._frb[key]
+ del self.frb[key]
@invalidate_plot
@invalidate_figure
https://bitbucket.org/yt_analysis/yt/commits/aa2ce117afc7/
Changeset: aa2ce117afc7
Branch: yt-3.0
User: MatthewTurk
Date: 2014-05-06 15:36:00
Summary: Merged in smumford/yt/yt-3.0 (pull request #865)
3.0 style changes and some fixes to cookbook.
Affected #: 14 files
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/aligned_cutting_plane.py
--- a/doc/source/cookbook/aligned_cutting_plane.py
+++ b/doc/source/cookbook/aligned_cutting_plane.py
@@ -1,18 +1,18 @@
-from yt.mods import *
+import yt
# Load the dataset.
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
# Create a 1 kpc radius sphere, centered on the max density. Note that this
# sphere is very small compared to the size of our final plot, and it has a
# non-axially aligned L vector.
-sp = pf.sphere("center", (15.0, "kpc"))
+sp = ds.sphere("center", (15.0, "kpc"))
# Get the angular momentum vector for the sphere.
L = sp.quantities.angular_momentum_vector()
-print "Angular momentum vector: %s" % (L)
+print "Angular momentum vector: {0}".format(L)
# Create an OffAxisSlicePlot on the object with the L vector as its normal
-p = OffAxisSlicePlot(pf, L, "density", sp.center, (25, "kpc"))
+p = yt.OffAxisSlicePlot(ds, L, "density", sp.center, (25, "kpc"))
p.save()
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/amrkdtree_downsampling.py
--- a/doc/source/cookbook/amrkdtree_downsampling.py
+++ b/doc/source/cookbook/amrkdtree_downsampling.py
@@ -1,26 +1,28 @@
-## Using AMRKDTree Homogenized Volumes to examine large datasets at lower resolution.
+# Using AMRKDTree Homogenized Volumes to examine large datasets
+# at lower resolution.
# In this example we will show how to use the AMRKDTree to take a simulation
# with 8 levels of refinement and only use levels 0-3 to render the dataset.
# We begin by loading up yt, and importing the AMRKDTree
+import numpy as np
-from yt.mods import *
+import yt
from yt.utilities.amr_kdtree.api import AMRKDTree
# Load up a data and print out the maximum refinement level
-pf = load('IsolatedGalaxy/galaxy0030/galaxy0030')
+ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
-kd = AMRKDTree(pf)
+kd = AMRKDTree(ds)
# Print out the total volume of all the bricks
print kd.count_volume()
# Print out the number of cells
print kd.count_cells()
-tf = ColorTransferFunction((-30, -22))
-cam = pf.h.camera([0.5, 0.5, 0.5], [0.2, 0.3, 0.4], 0.10, 256,
- tf, volume=kd)
-tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5], colormap = 'RdBu_r')
+tf = yt.ColorTransferFunction((-30, -22))
+cam = ds.h.camera([0.5, 0.5, 0.5], [0.2, 0.3, 0.4], 0.10, 256,
+ tf, volume=kd)
+tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5], colormap='RdBu_r')
cam.snapshot("v1.png", clip_ratio=6.0)
# This rendering is okay, but lets say I'd like to improve it, and I don't want
@@ -28,7 +30,7 @@
# generate a low resolution version of the AMRKDTree and pass that in to the
# camera. We do this by specifying a maximum refinement level of 3.
-kd_low_res = AMRKDTree(pf, l_max=3)
+kd_low_res = AMRKDTree(ds, max_level=3)
print kd_low_res.count_volume()
print kd_low_res.count_cells()
@@ -42,21 +44,21 @@
# rendering until we find something we like.
tf.clear()
-tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
- alpha=np.ones(4,dtype='float64'), colormap = 'RdBu_r')
+tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5],
+ alpha=np.ones(4, dtype='float64'), colormap='RdBu_r')
cam.snapshot("v2.png", clip_ratio=6.0)
# This looks better. Now let's try turning on opacity.
-tf.grey_opacity=True
+tf.grey_opacity = True
cam.snapshot("v4.png", clip_ratio=6.0)
# That seemed to pick out som interesting structures. Now let's bump up the
# opacity.
tf.clear()
-tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
- alpha=10.0*np.ones(4,dtype='float64'), colormap = 'RdBu_r')
+tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5],
+ alpha=10.0 * np.ones(4, dtype='float64'), colormap='RdBu_r')
cam.snapshot("v3.png", clip_ratio=6.0)
# This looks pretty good, now lets go back to the full resolution AMRKDTree
@@ -65,4 +67,3 @@
cam.snapshot("v4.png", clip_ratio=6.0)
# This looks great!
-
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/average_value.py
--- a/doc/source/cookbook/average_value.py
+++ b/doc/source/cookbook/average_value.py
@@ -1,12 +1,12 @@
-from yt.mods import *
+import yt
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
field = "temperature" # The field to average
-weight = "cell_mass" # The weight for the average
+weight = "cell_mass" # The weight for the average
-dd = pf.h.all_data() # This is a region describing the entire box,
- # but note it doesn't read anything in yet!
+dd = ds.h.all_data() # This is a region describing the entire box,
+ # but note it doesn't read anything in yet!
# We now use our 'quantities' call to get the average quantity
average_value = dd.quantities["WeightedAverageQuantity"](field, weight)
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/boolean_data_objects.py
--- a/doc/source/cookbook/boolean_data_objects.py
+++ b/doc/source/cookbook/boolean_data_objects.py
@@ -1,23 +1,23 @@
-from yt.mods import * # set up our namespace
+import yt
-pf = load("Enzo_64/DD0043/data0043") # load data
+ds = yt.load("Enzo_64/DD0043/data0043") # load data
# Make a few data ojbects to start.
-re1 = pf.region([0.5, 0.5, 0.5], [0.4, 0.4, 0.4], [0.6, 0.6, 0.6])
-re2 = pf.region([0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6])
-sp1 = pf.sphere([0.5, 0.5, 0.5], 0.05)
-sp2 = pf.sphere([0.1, 0.2, 0.3], 0.1)
+re1 = ds.region([0.5, 0.5, 0.5], [0.4, 0.4, 0.4], [0.6, 0.6, 0.6])
+re2 = ds.region([0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6])
+sp1 = ds.sphere([0.5, 0.5, 0.5], 0.05)
+sp2 = ds.sphere([0.1, 0.2, 0.3], 0.1)
# The "AND" operator. This will make a region identical to re2.
-bool1 = pf.boolean([re1, "AND", re2])
+bool1 = ds.boolean([re1, "AND", re2])
xp = bool1["particle_position_x"]
# The "OR" operator. This will make a region identical to re1.
-bool2 = pf.boolean([re1, "OR", re2])
+bool2 = ds.boolean([re1, "OR", re2])
# The "NOT" operator. This will make a region like re1, but with the corner
# that re2 covers cut out.
-bool3 = pf.boolean([re1, "NOT", re2])
+bool3 = ds.boolean([re1, "NOT", re2])
# Disjoint regions can be combined with the "OR" operator.
-bool4 = pf.boolean([sp1, "OR", sp2])
+bool4 = ds.boolean([sp1, "OR", sp2])
# Find oddly-shaped overlapping regions.
-bool5 = pf.boolean([re2, "AND", sp1])
+bool5 = ds.boolean([re2, "AND", sp1])
# Nested logic with parentheses.
# This is re1 with the oddly-shaped region cut out.
-bool6 = pf.boolean([re1, "NOT", "(", re1, "AND", sp1, ")"])
+bool6 = ds.boolean([re1, "NOT", "(", re1, "AND", sp1, ")"])
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/camera_movement.py
--- a/doc/source/cookbook/camera_movement.py
+++ b/doc/source/cookbook/camera_movement.py
@@ -1,43 +1,43 @@
-from yt.mods import * # set up our namespace
+import numpy as np
+
+import yt
# Follow the simple_volume_rendering cookbook for the first part of this.
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
-dd = pf.h.all_data()
-mi, ma = dd.quantities["Extrema"]("density")[0]
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
+dd = ds.all_data()
+mi, ma = dd.quantities["Extrema"]("density")
# Set up transfer function
-tf = ColorTransferFunction((np.log10(mi), np.log10(ma)))
+tf = yt.ColorTransferFunction((np.log10(mi), np.log10(ma)))
tf.add_layers(6, w=0.05)
# Set up camera paramters
-c = [0.5, 0.5, 0.5] # Center
-L = [1, 1, 1] # Normal Vector
-W = 1.0 # Width
-Nvec = 512 # Pixels on a side
+c = [0.5, 0.5, 0.5] # Center
+L = [1, 1, 1] # Normal Vector
+W = 1.0 # Width
+Nvec = 512 # Pixels on a side
# Specify a north vector, which helps with rotations.
-north_vector = [0.,0.,1.]
+north_vector = [0., 0., 1.]
# Find the maximum density location, store it in max_c
-v,max_c = pf.h.find_max('density')
+v, max_c = ds.find_max('density')
# Initialize the Camera
-cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf, north_vector=north_vector)
+cam = ds.camera(c, L, W, (Nvec, Nvec), tf, north_vector=north_vector)
frame = 0
# Do a rotation over 5 frames
-for i, snapshot in enumerate(cam.rotation(np.pi, 5, clip_ratio = 8.0)):
+for i, snapshot in enumerate(cam.rotation(np.pi, 5, clip_ratio=8.0)):
snapshot.write_png('camera_movement_%04i.png' % frame)
frame += 1
# Move to the maximum density location over 5 frames
-for i, snapshot in enumerate(cam.move_to(max_c, 5, clip_ratio = 8.0)):
+for i, snapshot in enumerate(cam.move_to(max_c, 5, clip_ratio=8.0)):
snapshot.write_png('camera_movement_%04i.png' % frame)
frame += 1
# Zoom in by a factor of 10 over 5 frames
-for i, snapshot in enumerate(cam.zoomin(10.0, 5, clip_ratio = 8.0)):
+for i, snapshot in enumerate(cam.zoomin(10.0, 5, clip_ratio=8.0)):
snapshot.write_png('camera_movement_%04i.png' % frame)
- frame += 1
-
-
+ frame += 1
\ No newline at end of file
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/contours_on_slice.py
--- a/doc/source/cookbook/contours_on_slice.py
+++ b/doc/source/cookbook/contours_on_slice.py
@@ -1,13 +1,13 @@
-from yt.mods import * # set up our namespace
+import yt
# first add density contours on a density slice
-pf = load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
-p = SlicePlot(pf, "x", "density")
+pf = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
+p = yt.SlicePlot(pf, "x", "density")
p.annotate_contour("density")
p.save()
# then add temperature contours on the same densty slice
-pf = load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
-p = SlicePlot(pf, "x", "density")
+pf = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") # load data
+p = yt.SlicePlot(pf, "x", "density")
p.annotate_contour("temperature")
p.save(str(pf)+'_T_contour')
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/extract_fixed_resolution_data.py
--- a/doc/source/cookbook/extract_fixed_resolution_data.py
+++ b/doc/source/cookbook/extract_fixed_resolution_data.py
@@ -1,25 +1,25 @@
-from yt.mods import *
+import yt
# For this example we will use h5py to write to our output file.
import h5py
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
level = 2
-dims = pf.domain_dimensions * pf.refine_by**level
+dims = ds.domain_dimensions * ds.refine_by**level
# Now, we construct an object that describes the data region and structure we
# want
-cube = pf.covering_grid(2, # The level we are willing to extract to; higher
- # levels than this will not contribute to the data!
- left_edge=[0.0, 0.0, 0.0],
- # And any fields to preload (this is optional!)
- dims = dims,
- fields=["density"])
+cube = ds.covering_grid(2, # The level we are willing to extract to; higher
+ # levels than this will not contribute to the data!
+ left_edge=[0.0, 0.0, 0.0],
+ # And any fields to preload (this is optional!)
+ dims=dims,
+ fields=["density"])
# Now we open our output file using h5py
# Note that we open with 'w' which will overwrite existing files!
-f = h5py.File("my_data.h5", "w")
+f = h5py.File("my_data.h5", "w")
# We create a dataset at the root note, calling it density...
f.create_dataset("/density", data=cube["density"])
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/find_clumps.py
--- a/doc/source/cookbook/find_clumps.py
+++ b/doc/source/cookbook/find_clumps.py
@@ -1,26 +1,30 @@
-# set up our namespace
-from yt.mods import *
-from yt.analysis_modules.level_sets.api import *
+import numpy as np
-fn = "IsolatedGalaxy/galaxy0030/galaxy0030" # parameter file to load
-field = "density" # this is the field we look for contours over -- we could do
- # this over anything. Other common choices are 'AveragedDensity'
- # and 'Dark_Matter_Density'.
-step = 2.0 # This is the multiplicative interval between contours.
+import yt
+from yt.analysis_modules.level_sets.api import (Clump, find_clumps,
+ get_lowest_clumps)
-pf = load(fn) # load data
+fn = "IsolatedGalaxy/galaxy0030/galaxy0030" # parameter file to load
+# this is the field we look for contours over -- we could do
+# this over anything. Other common choices are 'AveragedDensity'
+# and 'Dark_Matter_Density'.
+field = "density"
+
+step = 2.0 # This is the multiplicative interval between contours.
+
+ds = yt.load(fn) # load data
# We want to find clumps over the entire dataset, so we'll just grab the whole
# thing! This is a convenience parameter that prepares an object that covers
# the whole domain. Note, though, that it will load on demand and not before!
-data_source = pf.disk([0.5, 0.5, 0.5], [0., 0., 1.],
- 8./pf.units['kpc'], 1./pf.units['kpc'])
+data_source = ds.disk([0.5, 0.5, 0.5], [0., 0., 1.],
+ (8., 'kpc'), (1., 'kpc'))
# Now we set some sane min/max values between which we want to find contours.
# This is how we tell the clump finder what to look for -- it won't look for
# contours connected below or above these threshold values.
-c_min = 10**np.floor(np.log10(data_source[field]).min() )
-c_max = 10**np.floor(np.log10(data_source[field]).max()+1)
+c_min = 10**np.floor(np.log10(data_source[field]).min())
+c_max = 10**np.floor(np.log10(data_source[field]).max() + 1)
# keep only clumps with at least 20 cells
function = 'self.data[\'%s\'].size > 20' % field
@@ -38,13 +42,13 @@
# As it goes, it appends the information about all the sub-clumps to the
# master-clump. Among different ways we can examine it, there's a convenience
# function for outputting the full index to a file.
-f = open('%s_clump_index.txt' % pf,'w')
-amods.level_sets.write_clump_index(master_clump,0,f)
+f = open('%s_clump_index.txt' % ds, 'w')
+yt.amods.level_sets.write_clump_index(master_clump, 0, f)
f.close()
# We can also output some handy information, as well.
-f = open('%s_clumps.txt' % pf,'w')
-amods.level_sets.write_clumps(master_clump,0,f)
+f = open('%s_clumps.txt' % ds, 'w')
+yt.amods.level_sets.write_clumps(master_clump, 0, f)
f.close()
# We can traverse the clump index to get a list of all of the 'leaf' clumps
@@ -52,7 +56,7 @@
# If you'd like to visualize these clumps, a list of clumps can be supplied to
# the "clumps" callback on a plot. First, we create a projection plot:
-prj = ProjectionPlot(pf, 2, field, center='c', width=(20,'kpc'))
+prj = yt.ProjectionPlot(ds, 2, field, center='c', width=(20, 'kpc'))
# Next we annotate the plot with contours on the borders of the clumps
prj.annotate_clumps(leaf_clumps)
@@ -62,7 +66,7 @@
# We can also save the clump object to disk to read in later so we don't have
# to spend a lot of time regenerating the clump objects.
-pf.h.save_object(master_clump, 'My_clumps')
+ds.h.save_object(master_clump, 'My_clumps')
# Later, we can read in the clump object like so,
-master_clump = pf.h.load_object('My_clumps')
+master_clump = ds.load_object('My_clumps')
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/fit_spectrum.py
--- a/doc/source/cookbook/fit_spectrum.py
+++ b/doc/source/cookbook/fit_spectrum.py
@@ -1,25 +1,19 @@
-import os
-import sys
-import h5py
+import yt
+from yt.analysis_modules.cosmological_observation.light_ray.api import LightRay
+from yt.analysis_modules.api import AbsorptionSpectrum
+from yt.analysis_modules.absorption_spectrum.api import generate_total_fit
-from yt.mods import *
-from yt.analysis_modules.cosmological_observation.light_ray.api import \
- LightRay
-from yt.analysis_modules.api import AbsorptionSpectrum
-from yt.analysis_modules.absorption_spectrum.api import \
- generate_total_fit
+# Define and add a field to simulate OVI based on a constant relationship to HI
+def _OVI_NumberDensity(field, data):
+ return data['HI_NumberDensity']
-# Define and add a field to simulate OVI based on
-# a constant relationship to HI
-def _OVI_NumberDensity(field,data):
- return data['HI_NumberDensity']
def _convertOVI(data):
return 4.9E-4*.2
-add_field('my_OVI_NumberDensity',
- function=_OVI_NumberDensity,
- convert_function=_convertOVI)
+yt.add_field('my_OVI_NumberDensity',
+ function=_OVI_NumberDensity,
+ convert_function=_convertOVI)
# Define species andi associated parameters to add to continuum
@@ -29,33 +23,33 @@
# (as in the OVI doublet), 'numLines' will be equal to the number
# of lines, and f,gamma, and wavelength will have multiple values.
-HI_parameters = {'name':'HI',
- 'field' : 'HI_NumberDensity',
- 'f': [.4164],
- 'Gamma':[6.265E8],
- 'wavelength':[1215.67],
- 'mass': 1.00794,
- 'numLines':1,
- 'maxN': 1E22, 'minN':1E11,
- 'maxb': 300, 'minb':1,
- 'maxz': 6, 'minz':0,
- 'init_b':30,
- 'init_N':1E14}
+HI_parameters = {'name': 'HI',
+ 'field': 'HI_NumberDensity',
+ 'f': [.4164],
+ 'Gamma': [6.265E8],
+ 'wavelength': [1215.67],
+ 'mass': 1.00794,
+ 'numLines': 1,
+ 'maxN': 1E22, 'minN': 1E11,
+ 'maxb': 300, 'minb': 1,
+ 'maxz': 6, 'minz': 0,
+ 'init_b': 30,
+ 'init_N': 1E14}
-OVI_parameters = {'name':'OVI',
- 'field' : 'my_OVI_NumberDensity',
- 'f':[.1325,.06580],
- 'Gamma':[4.148E8,4.076E8],
- 'wavelength':[1031.9261,1037.6167],
- 'mass': 15.9994,
- 'numLines':2,
- 'maxN':1E17,'minN':1E11,
- 'maxb':300, 'minb':1,
- 'maxz':6, 'minz':0,
- 'init_b':20,
- 'init_N':1E12}
+OVI_parameters = {'name': 'OVI',
+ 'field': 'my_OVI_NumberDensity',
+ 'f': [.1325, .06580],
+ 'Gamma': [4.148E8, 4.076E8],
+ 'wavelength': [1031.9261, 1037.6167],
+ 'mass': 15.9994,
+ 'numLines': 2,
+ 'maxN': 1E17, 'minN': 1E11,
+ 'maxb': 300, 'minb': 1,
+ 'maxz': 6, 'minz': 0,
+ 'init_b': 20,
+ 'init_N': 1E12}
-species_dicts = {'HI':HI_parameters,'OVI':OVI_parameters}
+species_dicts = {'HI': HI_parameters, 'OVI': OVI_parameters}
# Create a LightRay object extending from z = 0 to z = 0.1
# and use only the redshift dumps.
@@ -63,7 +57,7 @@
'Enzo', 0.0, 0.1,
use_minimum_datasets=True,
time_data=False
- )
+ )
# Get all fields that need to be added to the light ray
fields = ['temperature']
@@ -80,34 +74,32 @@
get_los_velocity=True,
njobs=-1)
-# Create an AbsorptionSpectrum object extending from
+# Create an AbsorptionSpectrum object extending from
# lambda = 900 to lambda = 1800, with 10000 pixels
sp = AbsorptionSpectrum(900.0, 1400.0, 50000)
# Iterate over species
-for s,params in species_dicts.iteritems():
-
- #Iterate over transitions for a single species
+for s, params in species_dicts.iteritems():
+ # Iterate over transitions for a single species
for i in range(params['numLines']):
-
- #Add the lines to the spectrum
- sp.add_line(s, params['field'],
- params['wavelength'][i], params['f'][i],
- params['Gamma'][i], params['mass'],
- label_threshold=1.e10)
+ # Add the lines to the spectrum
+ sp.add_line(s, params['field'],
+ params['wavelength'][i], params['f'][i],
+ params['Gamma'][i], params['mass'],
+ label_threshold=1.e10)
# Make and save spectrum
-wavelength, flux = sp.make_spectrum('lightray.h5',
- output_file='spectrum.h5',
- line_list_file='lines.txt',
- use_peculiar_velocity=True)
+wavelength, flux = sp.make_spectrum('lightray.h5',
+ output_file='spectrum.h5',
+ line_list_file='lines.txt',
+ use_peculiar_velocity=True)
-#Define order to fit species in
-order_fits = ['OVI','HI']
+# Define order to fit species in
+order_fits = ['OVI', 'HI']
# Fit spectrum and save fit
fitted_lines, fitted_flux = generate_total_fit(wavelength,
- flux, order_fits, species_dicts,
- output_file='spectrum_fit.h5')
+ flux, order_fits, species_dicts,
+ output_file='spectrum_fit.h5')
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/free_free_field.py
--- a/doc/source/cookbook/free_free_field.py
+++ b/doc/source/cookbook/free_free_field.py
@@ -1,40 +1,42 @@
-from yt.mods import *
-from yt.utilities.physical_constants import mp # Need to grab the proton mass from the
- # constants database
+import numpy as np
+import yt
+# Need to grab the proton mass from the constants database
+from yt.utilities.physical_constants import mp
# Define the emission field
-keVtoerg = 1.602e-9 # Convert energy in keV to energy in erg
-KtokeV = 8.617e-08 # Convert degrees Kelvin to degrees keV
+keVtoerg = 1.602e-9 # Convert energy in keV to energy in erg
+KtokeV = 8.617e-08 # Convert degrees Kelvin to degrees keV
sqrt3 = np.sqrt(3.)
-expgamma = 1.78107241799 # Exponential of Euler's constant
+expgamma = 1.78107241799 # Exponential of Euler's constant
-def _FreeFree_Emission(field, data) :
- if data.has_field_parameter("Z") :
+def _FreeFree_Emission(field, data):
+
+ if data.has_field_parameter("Z"):
Z = data.get_field_parameter("Z")
- else :
- Z = 1.077 # Primordial H/He plasma
+ else:
+ Z = 1.077 # Primordial H/He plasma
- if data.has_field_parameter("mue") :
+ if data.has_field_parameter("mue"):
mue = data.get_field_parameter("mue")
- else :
- mue = 1./0.875 # Primordial H/He plasma
+ else:
+ mue = 1./0.875 # Primordial H/He plasma
- if data.has_field_parameter("mui") :
+ if data.has_field_parameter("mui"):
mui = data.get_field_parameter("mui")
- else :
- mui = 1./0.8125 # Primordial H/He plasma
+ else:
+ mui = 1./0.8125 # Primordial H/He plasma
- if data.has_field_parameter("Ephoton") :
+ if data.has_field_parameter("Ephoton"):
Ephoton = data.get_field_parameter("Ephoton")
- else :
- Ephoton = 1.0 # in keV
+ else:
+ Ephoton = 1.0 # in keV
- if data.has_field_parameter("photon_emission") :
+ if data.has_field_parameter("photon_emission"):
photon_emission = data.get_field_parameter("photon_emission")
- else :
- photon_emission = False # Flag for energy or photon emission
+ else:
+ photon_emission = False # Flag for energy or photon emission
n_e = data["density"]/(mue*mp)
n_i = data["density"]/(mui*mp)
@@ -50,24 +52,25 @@
eps_E = 1.64e-20*Z*Z*n_e*n_i/np.sqrt(data["temperature"]) * \
np.exp(-Ephoton/kT)*g_ff
- if photon_emission: eps_E /= (Ephoton*keVtoerg)
+ if photon_emission:
+ eps_E /= (Ephoton*keVtoerg)
return eps_E
-add_field("FreeFree_Emission", function=_FreeFree_Emission)
+yt.add_field("FreeFree_Emission", function=_FreeFree_Emission)
# Define the luminosity derived quantity
-
-def _FreeFreeLuminosity(data) :
+def _FreeFreeLuminosity(data):
return (data["FreeFree_Emission"]*data["cell_volume"]).sum()
-def _combFreeFreeLuminosity(data, luminosity) :
+
+def _combFreeFreeLuminosity(data, luminosity):
return luminosity.sum()
-add_quantity("FreeFree_Luminosity", function=_FreeFreeLuminosity,
- combine_function=_combFreeFreeLuminosity, n_ret = 1)
+yt.add_quantity("FreeFree_Luminosity", function=_FreeFreeLuminosity,
+ combine_function=_combFreeFreeLuminosity, n_ret=1)
-pf = load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
+pf = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
sphere = pf.sphere(pf.domain_center, (100., "kpc"))
@@ -75,8 +78,8 @@
print "L_E (1 keV, primordial) = ", sphere.quantities["FreeFree_Luminosity"]()
-# The defaults for the field assume a H/He primordial plasma. Let's set the appropriate
-# parameters for a pure hydrogen plasma.
+# The defaults for the field assume a H/He primordial plasma.
+# Let's set the appropriate parameters for a pure hydrogen plasma.
sphere.set_field_parameter("mue", 1.0)
sphere.set_field_parameter("mui", 1.0)
@@ -90,10 +93,9 @@
print "L_E (10 keV, pure hydrogen) = ", sphere.quantities["FreeFree_Luminosity"]()
-# Finally, let's set the flag for photon emission, to get the total number of photons
-# emitted at this energy:
+# Finally, let's set the flag for photon emission, to get the total number
+# of photons emitted at this energy:
sphere.set_field_parameter("photon_emission", True)
print "L_ph (10 keV, pure hydrogen) = ", sphere.quantities["FreeFree_Luminosity"]()
-
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/global_phase_plots.py
--- a/doc/source/cookbook/global_phase_plots.py
+++ b/doc/source/cookbook/global_phase_plots.py
@@ -1,14 +1,14 @@
-from yt.mods import * # set up our namespace
+import yt
# load the dataset
-pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
# This is an object that describes the entire box
-ad = pf.h.all_data()
+ad = ds.h.all_data()
-# We plot the average VelocityMagnitude (mass-weighted) in our object
+# We plot the average VelocityMagnitude (mass-weighted) in our object
# as a function of Density and temperature
-plot = PhasePlot(ad, "density","temperature","velocity_magnitude")
+plot = yt.PhasePlot(ad, "density", "temperature", "velocity_magnitude")
# save the plot
plot.save()
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/halo_finding.py
--- a/doc/source/cookbook/halo_finding.py
+++ b/doc/source/cookbook/halo_finding.py
@@ -2,9 +2,9 @@
This script shows the simplest way of getting halo information. For more
information, see :ref:`halo_finding`.
"""
-from yt.mods import * # set up our namespace
+import yt
-pf = load("Enzo_64/DD0043/data0043")
+ds = yt.load("Enzo_64/DD0043/data0043")
-halos = HaloFinder(pf)
-halos.write_out("%s_halos.txt" % pf)
+halos = yt.HaloFinder(ds)
+halos.write_out("%s_halos.txt" % ds)
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 doc/source/cookbook/hse_field.py
--- a/doc/source/cookbook/hse_field.py
+++ b/doc/source/cookbook/hse_field.py
@@ -1,121 +1,134 @@
-from yt.mods import *
+import numpy as np
+import yt
-# Define the components of the gravitational acceleration vector field by taking the
-# gradient of the gravitational potential
+# Define the components of the gravitational acceleration vector field by
+# taking the gradient of the gravitational potential
-def _Grav_Accel_x(field, data) :
+
+def _Grav_Accel_x(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dx = div_fac * data['dx'].flat[0]
- gx = data["Grav_Potential"][sl_right,1:-1,1:-1]/dx
- gx -= data["Grav_Potential"][sl_left, 1:-1,1:-1]/dx
+ gx = data["gravitational_potential"][sl_right, 1:-1, 1:-1]/dx
+ gx -= data["gravitational_potential"][sl_left, 1:-1, 1:-1]/dx
- new_field = np.zeros(data["Grav_Potential"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = -gx
+ new_field = np.zeros(data["gravitational_potential"].shape,
+ dtype='float64')
+ new_field[1:-1, 1:-1, 1:-1] = -gx
return new_field
-def _Grav_Accel_y(field, data) :
+
+def _Grav_Accel_y(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dy = div_fac * data['dy'].flat[0]
- gy = data["Grav_Potential"][1:-1,sl_right,1:-1]/dy
- gy -= data["Grav_Potential"][1:-1,sl_left ,1:-1]/dy
+ gy = data["gravitational_potential"][1:-1, sl_right, 1:-1]/dy
+ gy -= data["gravitational_potential"][1:-1, sl_left, 1:-1]/dy
- new_field = np.zeros(data["Grav_Potential"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = -gy
+ new_field = np.zeros(data["gravitational_potential"].shape,
+ dtype='float64')
+ new_field[1:-1, 1:-1, 1:-1] = -gy
return new_field
-def _Grav_Accel_z(field, data) :
+
+def _Grav_Accel_z(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dz = div_fac * data['dz'].flat[0]
- gz = data["Grav_Potential"][1:-1,1:-1,sl_right]/dz
- gz -= data["Grav_Potential"][1:-1,1:-1,sl_left ]/dz
+ gz = data["gravitational_potential"][1:-1, 1:-1, sl_right]/dz
+ gz -= data["gravitational_potential"][1:-1, 1:-1, sl_left]/dz
- new_field = np.zeros(data["Grav_Potential"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = -gz
+ new_field = np.zeros(data["gravitational_potential"].shape,
+ dtype='float64')
+ new_field[1:-1, 1:-1, 1:-1] = -gz
return new_field
+
# Define the components of the pressure gradient field
-def _Grad_Pressure_x(field, data) :
+
+def _Grad_Pressure_x(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dx = div_fac * data['dx'].flat[0]
- px = data["pressure"][sl_right,1:-1,1:-1]/dx
- px -= data["pressure"][sl_left, 1:-1,1:-1]/dx
+ px = data["pressure"][sl_right, 1:-1, 1:-1]/dx
+ px -= data["pressure"][sl_left, 1:-1, 1:-1]/dx
new_field = np.zeros(data["pressure"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = px
+ new_field[1:-1, 1:-1, 1:-1] = px
return new_field
-def _Grad_Pressure_y(field, data) :
+
+def _Grad_Pressure_y(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dy = div_fac * data['dy'].flat[0]
- py = data["pressure"][1:-1,sl_right,1:-1]/dy
- py -= data["pressure"][1:-1,sl_left ,1:-1]/dy
+ py = data["pressure"][1:-1, sl_right, 1:-1]/dy
+ py -= data["pressure"][1:-1, sl_left, 1:-1]/dy
new_field = np.zeros(data["pressure"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = py
+ new_field[1:-1, 1:-1, 1:-1] = py
return new_field
-def _Grad_Pressure_z(field, data) :
+
+def _Grad_Pressure_z(field, data):
# We need to set up stencils
- sl_left = slice(None,-2,None)
- sl_right = slice(2,None,None)
+ sl_left = slice(None, -2, None)
+ sl_right = slice(2, None, None)
div_fac = 2.0
dz = div_fac * data['dz'].flat[0]
- pz = data["pressure"][1:-1,1:-1,sl_right]/dz
- pz -= data["pressure"][1:-1,1:-1,sl_left ]/dz
+ pz = data["pressure"][1:-1, 1:-1, sl_right]/dz
+ pz -= data["pressure"][1:-1, 1:-1, sl_left]/dz
new_field = np.zeros(data["pressure"].shape, dtype='float64')
- new_field[1:-1,1:-1,1:-1] = pz
+ new_field[1:-1, 1:-1, 1:-1] = pz
return new_field
+
# Define the "degree of hydrostatic equilibrium" field
-def _HSE(field, data) :
+
+def _HSE(field, data):
gx = data["density"]*data["Grav_Accel_x"]
gy = data["density"]*data["Grav_Accel_y"]
@@ -131,36 +144,37 @@
# Now add the fields to the database
-add_field("Grav_Accel_x", function=_Grav_Accel_x, take_log=False,
- validators=[ValidateSpatial(1,["Grav_Potential"])])
+yt.add_field("Grav_Accel_x", function=_Grav_Accel_x, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["gravitational_potential"])])
-add_field("Grav_Accel_y", function=_Grav_Accel_y, take_log=False,
- validators=[ValidateSpatial(1,["Grav_Potential"])])
+yt.add_field("Grav_Accel_y", function=_Grav_Accel_y, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["gravitational_potential"])])
-add_field("Grav_Accel_z", function=_Grav_Accel_z, take_log=False,
- validators=[ValidateSpatial(1,["Grav_Potential"])])
+yt.add_field("Grav_Accel_z", function=_Grav_Accel_z, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["gravitational_potential"])])
-add_field("Grad_Pressure_x", function=_Grad_Pressure_x, take_log=False,
- validators=[ValidateSpatial(1,["pressure"])])
+yt.add_field("Grad_Pressure_x", function=_Grad_Pressure_x, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["pressure"])])
-add_field("Grad_Pressure_y", function=_Grad_Pressure_y, take_log=False,
- validators=[ValidateSpatial(1,["pressure"])])
+yt.add_field("Grad_Pressure_y", function=_Grad_Pressure_y, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["pressure"])])
-add_field("Grad_Pressure_z", function=_Grad_Pressure_z, take_log=False,
- validators=[ValidateSpatial(1,["pressure"])])
+yt.add_field("Grad_Pressure_z", function=_Grad_Pressure_z, take_log=False,
+ validators=[yt.ValidateSpatial(1, ["pressure"])])
-add_field("HSE", function=_HSE, take_log=False)
+yt.add_field("HSE", function=_HSE, take_log=False)
-# Open two files, one at the beginning and the other at a later time when there's a
-# lot of sloshing going on.
+# Open two files, one at the beginning and the other at a later time when
+# there's a lot of sloshing going on.
-pfi = load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0000")
-pff = load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0350")
+dsi = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0000")
+dsf = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0350")
-# Sphere objects centered at the cluster potential minimum with a radius of 200 kpc
+# Sphere objects centered at the cluster potential minimum with a radius
+# of 200 kpc
-sphere_i = pfi.h.sphere(pfi.domain_center, (200, "kpc"))
-sphere_f = pff.h.sphere(pff.domain_center, (200, "kpc"))
+sphere_i = dsi.h.sphere(dsi.domain_center, (200, "kpc"))
+sphere_f = dsf.h.sphere(dsf.domain_center, (200, "kpc"))
# Average "degree of hydrostatic equilibrium" in these spheres
@@ -170,10 +184,13 @@
print "Degree of hydrostatic equilibrium initially: ", hse_i
print "Degree of hydrostatic equilibrium later: ", hse_f
-# Just for good measure, take slices through the center of the domain of the two files
+# Just for good measure, take slices through the center of the domains
+# of the two files
-slc_i = SlicePlot(pfi, 2, ["density","HSE"], center=pfi.domain_center, width=(1.0, "mpc"))
-slc_f = SlicePlot(pff, 2, ["density","HSE"], center=pff.domain_center, width=(1.0, "mpc"))
+slc_i = yt.SlicePlot(dsi, 2, ["density", "HSE"], center=dsi.domain_center,
+ width=(1.0, "mpc"))
+slc_f = yt.SlicePlot(dsf, 2, ["density", "HSE"], center=dsf.domain_center,
+ width=(1.0, "mpc"))
slc_i.save("initial")
slc_f.save("final")
diff -r 513b0df9cdaf57c16feafa25521a00f93fa6d46f -r aa2ce117afc797ccbea2a157621a590880ad7c00 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -498,8 +498,10 @@
(x0, x1, y0, y1),).transpose()
X,Y = (np.linspace(xx0,xx1,nx,endpoint=True),
np.linspace(yy0,yy1,ny,endpoint=True))
- plot._axes.streamplot(X,Y, pixX, pixY, density = self.dens,
- **self.plot_args)
+ streamplot_args = {'x': X, 'y': Y, 'u':pixX, 'v': pixY,
+ 'density': self.dens}
+ streamplot_args.update(self.plot_args)
+ plot._axes.streamplot(**self.streamplot_args)
plot._axes.set_xlim(xx0,xx1)
plot._axes.set_ylim(yy0,yy1)
plot._axes.hold(False)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list