[yt-svn] commit/yt: ngoldbaum: Merged in brittonsmith/yt (pull request #1295)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Nov 6 14:40:09 PST 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/6c93e5b1dc99/
Changeset:   6c93e5b1dc99
Branch:      yt
User:        ngoldbaum
Date:        2014-11-06 22:39:58+00:00
Summary:     Merged in brittonsmith/yt (pull request #1295)

Adding setup_function to LightRay.
Affected #:  2 files

diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 doc/source/cookbook/fit_spectrum.py
--- a/doc/source/cookbook/fit_spectrum.py
+++ b/doc/source/cookbook/fit_spectrum.py
@@ -3,14 +3,19 @@
 from yt.analysis_modules.absorption_spectrum.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
+# Define a field to simulate OVI based on a constant relationship to HI
 # Do *NOT* use this for science, because this is not how OVI actually behaves;
 # it is just an example.
 
- at yt.derived_field(name='O_p5_number_density', units='cm**-3')
 def _OVI_number_density(field, data):
     return data['H_number_density']*2.0
 
+# Define a function that will accept a ds and add the new field 
+# defined above.  This will be given to the LightRay below.
+def setup_ds(ds):
+    ds.add_field("O_p5_number_density", 
+                 function=_OVI_number_density,
+                 units="cm**-3")
 
 # Define species and associated parameters to add to continuum
 # Parameters used for both adding the transition to the spectrum
@@ -65,7 +70,7 @@
 lr.make_light_ray(seed=123456780,
                   solution_filename='lightraysolution.txt',
                   data_filename='lightray.h5',
-                  fields=fields,
+                  fields=fields, setup_function=setup_ds,
                   get_los_velocity=True,
                   njobs=-1)
 

diff -r b4e9e508e03145fd0788ff6514c1ab9c6f029fae -r 6c93e5b1dc99bd3e0a1b01bfa1b1711413f0d1a4 yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
@@ -210,7 +210,7 @@
     def make_light_ray(self, seed=None,
                        start_position=None, end_position=None,
                        trajectory=None,
-                       fields=None,
+                       fields=None, setup_function=None,
                        solution_filename=None, data_filename=None,
                        get_los_velocity=True,
                        njobs=-1):
@@ -241,6 +241,11 @@
         fields : list
             A list of fields for which to get data.
             Default: None.
+        setup_function : callable, accepts a ds
+            This function will be called on each dataset that is loaded 
+            to create the light ray.  For, example, this can be used to 
+            add new derived fields.
+            Default: None.
         solution_filename : string
             Path to a text file where the trajectories of each
             subray is written out.
@@ -299,6 +304,10 @@
 
             # Load dataset for segment.
             ds = load(my_segment['filename'])
+
+            if setup_function is not None:
+                setup_function(ds)
+            
             my_segment["start"] = ds.domain_width * my_segment["start"] + \
                 ds.domain_left_edge
             my_segment["end"] = ds.domain_width * my_segment["end"] + \

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