[Yt-svn] yt: 2 new changesets
hg at spacepope.org
hg at spacepope.org
Tue Jun 29 16:35:44 PDT 2010
hg Repository: yt
details: yt/rev/0ac7531358e0
changeset: 1842:0ac7531358e0
user: J.S. Oishi <jsoishi at gmail.com>
date:
Tue Jun 29 16:28:03 2010 -0700
description:
added callback for magnetic field
hg Repository: yt
details: yt/rev/7450ce6a5059
changeset: 1843:7450ce6a5059
user: J.S. Oishi <jsoishi at gmail.com>
date:
Tue Jun 29 16:30:33 2010 -0700
description:
merged
diffstat:
yt/extensions/StarAnalysis.py | 41 ++++++++++++++++++++++-------------------
yt/lagos/HierarchyType.py | 24 ++++++++++++++++--------
yt/lagos/TwoPointFunctions.py | 16 ++++++++++++----
yt/raven/Callbacks.py | 20 ++++++++++++++++++++
yt/raven/plot_collection.py | 2 +-
5 files changed, 71 insertions(+), 32 deletions(-)
diffs (229 lines):
diff -r 9731ae6284b4 -r 7450ce6a5059 yt/extensions/StarAnalysis.py
--- a/yt/extensions/StarAnalysis.py Tue Jun 29 10:38:55 2010 -0700
+++ b/yt/extensions/StarAnalysis.py Tue Jun 29 16:30:33 2010 -0700
@@ -128,22 +128,24 @@
def write_out(self, name="StarFormationRate.out"):
r"""Write out the star analysis to a text file *name*. The columns are in
- order:
- 1) Time (yrs)
- 2) Look-back time (yrs)
- 3) Redshift
- 4) Star formation rate in this bin per year (Msol/yr)
- 5) Star formation rate in this bin per year per Mpc**3 (Msol/yr/Mpc**3)
- 6) Stars formed in this time bin (Msol)
- 7) Cumulative stars formed up to this time bin (Msol)
+ order.
+
+ The columns in the output file are:
+ 1. Time (yrs)
+ 2. Look-back time (yrs)
+ 3. Redshift
+ 4. Star formation rate in this bin per year (Msol/yr)
+ 5. Star formation rate in this bin per year per Mpc**3 (Msol/yr/Mpc**3)
+ 6. Stars formed in this time bin (Msol)
+ 7. Cumulative stars formed up to this time bin (Msol)
Parameters
- ---------
+ ----------
name : String
The name of the file to write to. Default = StarFormationRate.out.
Examples
- -------
+ --------
>>> sfr.write_out("stars-SFR.out")
"""
fp = open(name, "w")
@@ -226,7 +228,7 @@
'salpeter'. Default = 'chabrier'.
Examples
- -------
+ --------
>>> pf = load("RedshiftOutput0000")
>>> spec = SpectrumBuilder(pf, "/home/user/bc/", model="salpeter")
"""
@@ -276,7 +278,7 @@
avg_metal: Average metallicity of all the stars.
Parameters
- ---------
+ ----------
data_source : AMRRegion object, optional
The region from which stars are extracted for analysis. If this is
not specified, the next three parameters must be supplied.
@@ -420,10 +422,11 @@
def write_out(self, name="sum_flux.out"):
- r"""Write out the summed flux to a file. The file has two columns:
- 1) Wavelength (Angstrom)
- 2) Flux (Luminosity per unit wavelength, L_sun Ang^-1,
- L_sun = 3.826 * 10^33 ergs s^-1.)
+ r"""Write out the summed flux to a file.
+
+ The output file from this function has two columns: Wavelength
+ (Angstrom) and Flux (Luminosity per unit wavelength, L_sun Ang^-1,
+ L_sun = 3.826 * 10^33 ergs s^-1.).
Parameters
----------
@@ -431,7 +434,7 @@
Name of file to write to. Default = "sum_flux.out"
Examples
- -------
+ --------
>>> spec.write_out("spec.out")
"""
fp = open(name, 'w')
@@ -448,7 +451,7 @@
identical to the disk output.
Parameters
- ---------
+ ----------
name : String
Name of file to write to. Default = "sum_SED.out"
flux_norm : Float
@@ -456,7 +459,7 @@
Default = 5200 Ang.
Examples
- -------
+ --------
>>> spec.write_out_SED(name = "SED.out", flux_norm = 6000.)
"""
# find the f_nu closest to flux_norm
diff -r 9731ae6284b4 -r 7450ce6a5059 yt/lagos/HierarchyType.py
--- a/yt/lagos/HierarchyType.py Tue Jun 29 10:38:55 2010 -0700
+++ b/yt/lagos/HierarchyType.py Tue Jun 29 16:30:33 2010 -0700
@@ -144,16 +144,24 @@
fn = os.path.join(self.directory,
"%s.yt" % self.parameter_file.basename)
dir_to_check = os.path.dirname(fn)
- if os.path.isfile(fn):
- writable = os.access(fn, os.W_OK)
+ # We have four options:
+ # Writeable, does not exist : create, open as append
+ # Writeable, does exist : open as append
+ # Not writeable, does not exist : do not attempt to open
+ # Not writeable, does exist : open as read-only
+ exists = os.path.isfile(fn)
+ if not exists:
+ writeable = os.access(dir_to_check, os.W_OK)
else:
- writable = os.access(dir_to_check, os.W_OK)
- if ytcfg.getboolean('lagos','onlydeserialize') or not writable:
- self._data_mode = mode = 'r'
+ writeable = os.access(fn, os.W_OK)
+ writeable = writeable and not ytcfg.getboolean('lagos','onlydeserialize')
+ # We now have our conditional stuff
+ if not writeable and not exists: return
+ if writeable:
+ self._data_mode = 'a'
+ if not exists: self.__create_data_file(fn)
else:
- self._data_mode = mode = 'a'
-
- self.__create_data_file(fn)
+ self._data_mode = 'r'
self.__data_filename = fn
self._data_file = h5py.File(fn, self._data_mode)
diff -r 9731ae6284b4 -r 7450ce6a5059 yt/lagos/TwoPointFunctions.py
--- a/yt/lagos/TwoPointFunctions.py Tue Jun 29 10:38:55 2010 -0700
+++ b/yt/lagos/TwoPointFunctions.py Tue Jun 29 16:30:33 2010 -0700
@@ -586,7 +586,7 @@
directory.
Examples
- -------
+ --------
>>> tpf.write_out_means()
"""
for fset in self._fsets:
@@ -618,7 +618,7 @@
'function_name.txt' and saved in the current working directory.
Examples
- -------
+ --------
>>> tpf.write_out_arrays()
"""
if self.mine == 0:
@@ -702,6 +702,7 @@
A pair of values giving the range for the bins.
A pair of floats (a list), or a list of pairs for N-dim binning.
Default = None.
+
Examples
--------
>>> f1.set_pdf_params(bin_type='log', bin_range=[5e4, 5.5e13],
@@ -795,7 +796,14 @@
for d1 in range(dim):
multi *= self.bin_edges[d1].size
if dim == 0 and len(self.out_labels)==1:
- digi = na.digitize(results, self.bin_edges[dim])
+ try:
+ digi = na.digitize(results, self.bin_edges[dim])
+ except ValueError:
+ # The user probably did something like
+ # return a * b rather than
+ # return a[0] * b[0], which will only happen
+ # for single field functions.
+ digi = na.digitize(results[0], self.bin_edges[dim])
else:
digi = na.digitize(results[:,dim], self.bin_edges[dim])
too_low = (digi == 0)
@@ -843,4 +851,4 @@
for length in self.tpf.lengths:
xi[length] = -1 + na.sum(self.length_bin_hits[length] * \
self.bin_edges[0][:-1]) / self.corr_norm
- return xi
\ No newline at end of file
+ return xi
diff -r 9731ae6284b4 -r 7450ce6a5059 yt/raven/Callbacks.py
--- a/yt/raven/Callbacks.py Tue Jun 29 10:38:55 2010 -0700
+++ b/yt/raven/Callbacks.py Tue Jun 29 16:30:33 2010 -0700
@@ -74,6 +74,26 @@
qcb = QuiverCallback(xv, yv, self.factor)
return qcb(plot)
+class MagFieldCallback(PlotCallback):
+ _type_name = "magnetic_field"
+ def __init__(self, factor=16):
+ """
+ Adds a 'quiver' plot of magnetic field to the plot, skipping all but
+ every *factor* datapoint
+ """
+ PlotCallback.__init__(self)
+ self.factor = factor
+
+ def __call__(self, plot):
+ # Instantiation of these is cheap
+ if plot._type_name == "CuttingPlane":
+ print "WARNING: Magnetic field on Cutting Plane Not implemented."
+ else:
+ xv = "B%s" % (lagos.x_names[plot.data.axis])
+ yv = "B%s" % (lagos.y_names[plot.data.axis])
+ qcb = QuiverCallback(xv, yv, self.factor)
+ return qcb(plot)
+
class QuiverCallback(PlotCallback):
_type_name = "quiver"
def __init__(self, field_x, field_y, factor):
diff -r 9731ae6284b4 -r 7450ce6a5059 yt/raven/plot_collection.py
--- a/yt/raven/plot_collection.py Tue Jun 29 10:38:55 2010 -0700
+++ b/yt/raven/plot_collection.py Tue Jun 29 16:30:33 2010 -0700
@@ -1123,7 +1123,7 @@
if center is None: center = self.c
r = radius/self.pf[unit]
data_source = self.pf.hierarchy.sphere(center, r)
- p = add_phase_object(self, data_source, fields, cmap,
+ p = self.add_phase_object(data_source, fields, cmap,
weight, accumulation,
x_bins, x_log, x_bounds,
y_bins, y_log, y_bounds,
More information about the yt-svn
mailing list