<html><body>
<p>9 new commits in yt:</p>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUKWP7hJaQRDneQXEEIV3Bk04U9Waslcrw2ZJ0nExPTW4-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyN7a6PdXRAgTZR6KIY1ic5xtzINnDMJ2OVQyBYaBvyhmKana-2Fx0XzqePySGSGqDZnQ-2BiXK-2BsmWjM5Wow6pigRV2IIrrh0Yw9n2jSmRRUkhsRc5JkEcjDXN9MulCImYDNurX0tQXbkB7qwydZvS22yKQ-3D">https://bitbucket.org/yt_analysis/yt/commits/e1d4435ed014/</a> Changeset:   e1d4435ed014 Branch:      yt User:        chummels Date:        2015-11-30 07:13:11+00:00 Summary:     Adding observing_redshift kwarg to make_spectrum() Affected #:  1 file</p>
<p>diff -r 03a54b627189e63eaee9f2bc1d4a36c3ab6b9637 -r e1d4435ed014f2d6205d25b8166c3fd22af333bc yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -118,7 +118,8 @@</p>
<pre>     def make_spectrum(self, input_file, output_file=None,
line_list_file=None, output_absorbers_file=None,
use_peculiar_velocity=True,</pre>
<ul><li><p>subgrid_resolution=10, njobs="auto"):</p></li></ul>
<p>+                      subgrid_resolution=10, observing_redshift=0., +                      njobs="auto"):</p>
<pre>        """
        Make spectrum from ray data using the line list.
</pre>
<p>@@ -153,6 +154,10 @@</p>
<pre>but is more expensive.  A value of 10 yields accuracy to the 4th
significant digit in tau.
Default: 10</pre>
<p>+        observing_redshift : optional, float +           This is the redshift at which the observer is observing +           the absorption spectrum. +           Default: 0</p>
<pre>         njobs : optional, int or "auto"
the number of process groups into which the loop over
absorption lines will be divided.  If set to -1, each</pre>
<p>@@ -179,6 +184,11 @@</p>
<pre>input_fields.append('redshift_eff')
field_units["velocity_los"] = "cm/s"
field_units["redshift_eff"] = ""</pre>
<p>+        if observing_redshift != 0.: +            input_fields.append('redshift_dopp') +            input_fields.append('redshift') +            field_units["redshift_dopp"] = "" +            field_units["redshift"] = ""</p>
<pre>         for feature in self.line_list + self.continuum_list:
if not feature['field_name'] in input_fields:
    input_fields.append(feature['field_name'])</pre>
<p>@@ -219,7 +229,8 @@</p>
<pre>        del field_data
        return (self.lambda_field, self.flux_field)
</pre>
<ul><li><p>def _add_continua_to_spectrum(self, field_data, use_peculiar_velocity):</p></li></ul>
<p>+    def _add_continua_to_spectrum(self, field_data, use_peculiar_velocity, +                                  observing_redshift):</p>
<pre>"""
Add continuum features to the spectrum.
"""</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUFjKpxeiedxvHZU15Y1MwXHbaydVNeuwNAmGdjgHhdis-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyNP4dYHe5-2BPcEKWB6D-2F-2Bv2dCoeXujzbjbB2Anmay3SqRSeOfD1ZmaH2e9G-2BLaGzzVsW71RJqx92r6zDvsZMkBRzRxJ9w220JwHwi-2BsVjXGzeb0pjwysJPfWzn-2Bop8lryLnEVN2DqfQ54y4Sn0sXKkms-3D">https://bitbucket.org/yt_analysis/yt/commits/4be2c32b5c0a/</a> Changeset:   4be2c32b5c0a Branch:      yt User:        chummels Date:        2015-12-05 18:28:45+00:00 Summary:     Adding observing_redshift to AbsorptionSpectrum analysis module. Affected #:  1 file</p>
<p>diff -r e1d4435ed014f2d6205d25b8166c3fd22af333bc -r 4be2c32b5c0afe1e64279728e0ed788cf5cb60fe yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -118,7 +118,7 @@</p>
<pre>     def make_spectrum(self, input_file, output_file=None,
line_list_file=None, output_absorbers_file=None,
use_peculiar_velocity=True,</pre>
<ul><li><p>subgrid_resolution=10, observing_redshift=0.,</p></li></ul>
<p>+                      subgrid_resolution=10, observing_redshift=0.,</p>
<pre>njobs="auto"):
         """
         Make spectrum from ray data using the line list.</pre>
<p>@@ -140,7 +140,9 @@</p>
<pre>is recommended to set to None in such circumstances.
Default: None
         use_peculiar_velocity : optional, bool</pre>
<ul><li><p>if True, include line of sight velocity for shifting lines.</p></li></ul>
<p>+           if True, include peculiar velocity for calculating doppler redshift +           to shift lines.  Requires similar flag to be set in LightRay +           generation.</p>
<pre>Default: True
         subgrid_resolution : optional, int
When a line is being added that is unresolved (ie its thermal</pre>
<p>@@ -186,9 +188,7 @@</p>
<pre>field_units["redshift_eff"] = ""
         if observing_redshift != 0.:
input_fields.append('redshift_dopp')</pre>
<ul><li><p>input_fields.append('redshift') field_units["redshift_dopp"] = ""</p></li>
<li><p>field_units["redshift"] = ""</p></li></ul>
<pre>         for feature in self.line_list + self.continuum_list:
if not feature['field_name'] in input_fields:
    input_fields.append(feature['field_name'])</pre>
<p>@@ -210,8 +210,10 @@</p>
<pre>         self._add_lines_to_spectrum(field_data, use_peculiar_velocity,
output_absorbers_file,
subgrid_resolution=subgrid_resolution,</pre>
<p>+                                    observing_redshift=observing_redshift,</p>
<pre>njobs=njobs)</pre>
<ul><li><p>self._add_continua_to_spectrum(field_data, use_peculiar_velocity)</p></li></ul>
<p>+        self._add_continua_to_spectrum(field_data, use_peculiar_velocity, +                                       observing_redshift=observing_redshift)</p>
<pre>        self.flux_field = np.exp(-self.tau_field)
</pre>
<p>@@ -230,7 +232,7 @@</p>
<pre>        return (self.lambda_field, self.flux_field)

    def _add_continua_to_spectrum(self, field_data, use_peculiar_velocity,</pre>
<ul><li><p>observing_redshift):</p></li></ul>
<p>+                                  observing_redshift=0.):</p>
<pre>"""
Add continuum features to the spectrum.
"""</pre>
<p>@@ -239,11 +241,32 @@</p>
<pre>         for continuum in self.continuum_list:
column_density = field_data[continuum['field_name']] * field_data['dl']</pre>
<p>+            if observing_redshift == 0.: +                # This is already assumed in the generation of the LightRay +                redshift = field_data['redshift'] +                if use_peculiar_velocity: +                    redshift_eff = field_data['redshift_eff'] +            else: +                # The intermediate redshift that is seen by an observer +                # at a redshift other than z=0 is z12, where z1 is the +                # observing redshift and z2 is the emitted photon's redshift +                # Hogg (2000) eq. 13: +                # 1 + z12 = (1 + z2) / (1 + z1) +                redshift = ((1 + field_data['redshift']) / \ +                            (1 + observing_redshift)) – 1. +                # Combining cosmological redshift and doppler redshift +                # into an effective redshift is found in Peacock's +                # Cosmological Physics eqn 3.75: +                # 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler) +                if use_peculiar_velocity: +                    redshift_eff = ((1 + redshift) * \ +                                    (1 + field_data['redshift_dopp'])) – 1. +</p>
<pre># redshift_eff field combines cosmological and velocity redshifts
if use_peculiar_velocity:</pre>
<ul><li><p>delta_lambda = continuum['wavelength'] * field_data['redshift_eff']</p></li></ul>
<p>+                delta_lambda = continuum['wavelength'] * redshift_eff</p>
<pre>else:</pre>
<ul><li><p>delta_lambda = continuum['wavelength'] * field_data['redshift']</p></li></ul>
<p>+                delta_lambda = continuum['wavelength'] * redshift</p>
<pre>this_wavelength = delta_lambda + continuum['wavelength']
right_index = np.digitize(this_wavelength, self.lambda_field).clip(0, self.n_lambda)
left_index = np.digitize((this_wavelength *</pre>
<p>@@ -267,7 +290,7 @@</p>
<pre>     def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,
output_absorbers_file, subgrid_resolution=10,</pre>
<ul><li><p>njobs=-1):</p></li></ul>
<p>+                               observing_redshift=0., njobs=-1):</p>
<pre>"""
Add the absorption lines to the spectrum.
"""</pre>
<p>@@ -281,13 +304,34 @@</p>
<pre>        for line in parallel_objects(self.line_list, njobs=njobs):
            column_density = field_data[line['field_name']] * field_data['dl']
</pre>
<p>+            if observing_redshift == 0.: +                # This is already assumed in the generation of the LightRay +                redshift = field_data['redshift'] +                if use_peculiar_velocity: +                    redshift_eff = field_data['redshift_eff'] +            else: +                # The intermediate redshift that is seen by an observer +                # at a redshift other than z=0 is z12, where z1 is the +                # observing redshift and z2 is the emitted photon's redshift +                # Hogg (2000) eq. 13: +                # 1 + z12 = (1 + z2) / (1 + z1) +                redshift = ((1 + field_data['redshift']) / \ +                            (1 + observing_redshift)) – 1. +                # Combining cosmological redshift and doppler redshift +                # into an effective redshift is found in Peacock's +                # Cosmological Physics eqn 3.75: +                # 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler) +                if use_peculiar_velocity: +                    redshift_eff = ((1 + redshift) * \ +                                    (1 + field_data['redshift_dopp'])) – 1. +</p>
<pre># redshift_eff field combines cosmological and velocity redshifts
# so delta_lambda gives the offset in angstroms from the rest frame
# wavelength to the observed wavelength of the transition
if use_peculiar_velocity:</pre>
<ul><li><p>delta_lambda = line['wavelength'] * field_data['redshift_eff']</p></li></ul>
<p>+                delta_lambda = line['wavelength'] * redshift_eff</p>
<pre>else:</pre>
<ul><li><p>delta_lambda = line['wavelength'] * field_data['redshift']</p></li></ul>
<p>+                delta_lambda = line['wavelength'] * redshift</p>
<pre># lambda_obs is central wavelength of line after redshift
lambda_obs = line['wavelength'] + delta_lambda
# bin index in lambda_field of central wavelength of line after z</pre>
<p>@@ -413,8 +457,8 @@</p>
<pre>'wavelength': (lambda_0 + dlambda[i]),
'column_density': column_density[i],
'b_thermal': thermal_b[i],</pre>
<ul><li><p>‘redshift’: field_data['redshift'][i],</p></li>
<li><p>‘redshift_eff’: field_data['redshift_eff'][i],</p></li></ul>
<p>+                                                ‘redshift’: redshift[i], +                                                ‘redshift_eff’: redshift_eff[i],</p>
<pre>                                    'v_pec': peculiar_velocity})
    pbar.update(i)
pbar.finish()</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUCQS-2B1vQtPU6nDXAEwrcCzyEW8xo-2BqAOCkbMt5SLpDZw-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyMtyMTU7dJ-2BkY0AdATV6GVKwvAtB8RPvcAP9ULnitIrFKXFNxTTVWtqGeQBFq9Q8XnXGPbB-2F5yCePIRtjqnvSpjtbBFoF4PcJyly6u-2FX4aqGnWLnW5pxT8u9WNdHobted1ffNOmqVfuPHX58h1YOdFg-3D">https://bitbucket.org/yt_analysis/yt/commits/02417c5a8f7f/</a> Changeset:   02417c5a8f7f Branch:      yt User:        chummels Date:        2016-03-15 23:43:42+00:00 Summary:     Cleaning up code. Affected #:  1 file</p>
<p>diff -r 4be2c32b5c0afe1e64279728e0ed788cf5cb60fe -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -52,7 +52,7 @@</p>
<pre>def __init__(self, lambda_min, lambda_max, n_lambda):
    self.n_lambda = n_lambda
    # lambda, flux, and tau are wavelength, flux, and optical depth</pre>
<ul><li><p>self.lambda_field = YTArray(np.linspace(lambda_min, lambda_max,</p></li></ul>
<p>+        self.lambda_field = YTArray(np.linspace(lambda_min, lambda_max,</p>
<pre>n_lambda), "angstrom")
         self.tau_field = None
         self.flux_field = None</pre>
<p>@@ -117,7 +117,7 @@</p>
<pre>     def make_spectrum(self, input_file, output_file=None,
line_list_file=None, output_absorbers_file=None,</pre>
<ul><li><p>use_peculiar_velocity=True,</p></li></ul>
<p>+                      use_peculiar_velocity=True,</p>
<pre>subgrid_resolution=10, observing_redshift=0.,
njobs="auto"):
         """</pre>
<p>@@ -129,36 +129,37 @@</p>
<pre>         input_file : string or dataset
path to input ray data or a loaded ray dataset
         output_file : optional, string</pre>
<ul><li><p>Option to save a file containing the wavelength, flux, and optical</p></li>
<li><p>depth fields.  File formats are chosen based on the filename extension.</p></li>
<li><p>``.h5`` for hdf5, ``.fits`` for fits, and everything else is ASCII.</p></li></ul>
<p>+           Option to save a file containing the wavelength, flux, and optical +           depth fields.  File formats are chosen based on the filename +           extension. ``.h5`` for hdf5, ``.fits`` for fits, and everything +           else is ASCII.</p>
<pre>Default: None
         output_absorbers_file : optional, string</pre>
<ul><li><p>Option to save a text file containing all of the absorbers and</p></li></ul>
<p>+           Option to save a text file containing all of the absorbers and</p>
<pre>corresponding wavelength and redshift information.
For parallel jobs, combining the lines lists can be slow so it
is recommended to set to None in such circumstances.
Default: None
         use_peculiar_velocity : optional, bool
if True, include peculiar velocity for calculating doppler redshift</pre>
<ul><li><p>to shift lines.  Requires similar flag to be set in LightRay</p></li></ul>
<p>+           to shift lines.  Requires similar flag to be set in LightRay</p>
<pre>generation.
Default: True
         subgrid_resolution : optional, int
When a line is being added that is unresolved (ie its thermal
width is less than the spectral bin width), the voigt profile of</pre>
<ul><li><p>the line is deposited into an array of virtual wavelength bins at</p></li>
<li><p>higher resolution.  The optical depth from these virtual bins is</p></li>
<li><p>integrated and then added to the coarser spectral wavelength bin.</p></li>
<li><p>The subgrid_resolution value determines the ratio between the</p></li>
<li><p>thermal width and the bin width of the virtual bins.  Increasing</p></li>
<li><p>this value yields smaller virtual bins, which increases accuracy,</p></li>
<li><p>but is more expensive.  A value of 10 yields accuracy to the 4th</p></li></ul>
<p>+           the line is deposited into an array of virtual wavelength bins at +           higher resolution.  The optical depth from these virtual bins is +           integrated and then added to the coarser spectral wavelength bin. +           The subgrid_resolution value determines the ratio between the +           thermal width and the bin width of the virtual bins.  Increasing +           this value yields smaller virtual bins, which increases accuracy, +           but is more expensive.  A value of 10 yields accuracy to the 4th</p>
<pre>significant digit in tau.
Default: 10
         observing_redshift : optional, float
This is the redshift at which the observer is observing</pre>
<ul><li><p>the absorption spectrum.</p></li></ul>
<p>+           the absorption spectrum.</p>
<pre>Default: 0
         njobs : optional, int or "auto"
the number of process groups into which the loop over</pre>
<p>@@ -248,14 +249,14 @@</p>
<pre>        redshift_eff = field_data['redshift_eff']
else:
    # The intermediate redshift that is seen by an observer</pre>
<ul><li><p># at a redshift other than z=0 is z12, where z1 is the</p></li></ul>
<p>+                # at a redshift other than z=0 is z12, where z1 is the</p>
<pre># observing redshift and z2 is the emitted photon's redshift
# Hogg (2000) eq. 13:
# 1 + z12 = (1 + z2) / (1 + z1)
redshift = ((1 + field_data['redshift']) / \
            (1 + observing_redshift)) - 1.</pre>
<ul><li><p># Combining cosmological redshift and doppler redshift</p></li>
<li><p># into an effective redshift is found in Peacock's</p></li></ul>
<p>+                # Combining cosmological redshift and doppler redshift +                # into an effective redshift is found in Peacock's</p>
<pre># Cosmological Physics eqn 3.75:
# 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler)
if use_peculiar_velocity:</pre>
<p>@@ -289,13 +290,13 @@</p>
<pre>            pbar.finish()

    def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,</pre>
<ul><li><p>output_absorbers_file, subgrid_resolution=10,</p></li></ul>
<p>+                               output_absorbers_file, subgrid_resolution=10,</p>
<pre>observing_redshift=0., njobs=-1):
         """
         Add the absorption lines to the spectrum.
         """</pre>
<ul><li><p># Widen wavelength window until optical depth falls below this tau</p></li>
<li><p># value at the ends to assure that the wings of a line have been</p></li></ul>
<p>+        # Widen wavelength window until optical depth falls below this tau +        # value at the ends to assure that the wings of a line have been</p>
<pre>        # fully resolved.
        min_tau = 1e-3
</pre>
<p>@@ -311,14 +312,14 @@</p>
<pre>        redshift_eff = field_data['redshift_eff']
else:
    # The intermediate redshift that is seen by an observer</pre>
<ul><li><p># at a redshift other than z=0 is z12, where z1 is the</p></li></ul>
<p>+                # at a redshift other than z=0 is z12, where z1 is the</p>
<pre># observing redshift and z2 is the emitted photon's redshift
# Hogg (2000) eq. 13:
# 1 + z12 = (1 + z2) / (1 + z1)
redshift = ((1 + field_data['redshift']) / \
            (1 + observing_redshift)) - 1.</pre>
<ul><li><p># Combining cosmological redshift and doppler redshift</p></li>
<li><p># into an effective redshift is found in Peacock's</p></li></ul>
<p>+                # Combining cosmological redshift and doppler redshift +                # into an effective redshift is found in Peacock's</p>
<pre># Cosmological Physics eqn 3.75:
# 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler)
if use_peculiar_velocity:</pre>
<p>@@ -327,7 +328,7 @@</p>
<pre># redshift_eff field combines cosmological and velocity redshifts
# so delta_lambda gives the offset in angstroms from the rest frame</pre>
<ul><li><p># wavelength to the observed wavelength of the transition</p></li></ul>
<p>+            # wavelength to the observed wavelength of the transition</p>
<pre>if use_peculiar_velocity:
    delta_lambda = line['wavelength'] * redshift_eff
else:</pre>
<p>@@ -343,7 +344,7 @@</p>
<pre>                                  line['atomic_mass'])

            # the actual thermal width of the lines</pre>
<ul><li><p>thermal_width = (lambda_obs * thermal_b /</p></li></ul>
<p>+            thermal_width = (lambda_obs * thermal_b /</p>
<pre>                             speed_of_light_cgs).convert_to_units("angstrom")

            # Sanitize units for faster runtime of the tau_profile machinery.</pre>
<p>@@ -356,25 +357,25 @@</p>
<pre># When we actually deposit the voigt profile, sometimes we will
# have underresolved lines (ie lines with smaller widths than</pre>
<ul><li><p># the spectral bin size).  Here, we create virtual wavelength bins</p></li>
<li><p># small enough in width to well resolve each line, deposit the</p></li>
<li><p># voigt profile into them, then numerically integrate their tau</p></li>
<li><p># values and sum them to redeposit them into the actual spectral</p></li></ul>
<p>+            # the spectral bin size).  Here, we create virtual wavelength bins +            # small enough in width to well resolve each line, deposit the +            # voigt profile into them, then numerically integrate their tau +            # values and sum them to redeposit them into the actual spectral</p>
<pre>            # bins.

            # virtual bins (vbins) will be:
            # 1) <= the bin_width; assures at least as good as spectral bins
            # 2) <= 1/10th the thermal width; assures resolving voigt profiles
            #   (actually 1/subgrid_resolution value, default is 1/10)</pre>
<ul><li><p># 3) a bin width will be divisible by vbin_width times a power of</p></li></ul>
<p>+            # 3) a bin width will be divisible by vbin_width times a power of</p>
<pre>#    10; this will assure we don't get spikes in the deposited
#    spectra from uneven numbers of vbins per bin</pre>
<ul><li><p>resolution = thermal_width / self.bin_width</p></li></ul>
<p>+            resolution = thermal_width / self.bin_width</p>
<pre>            vbin_width = self.bin_width / \
                         10**(np.ceil(np.log10(subgrid_resolution/resolution)).clip(0, np.inf))
            vbin_width = vbin_width.in_units('angstrom').d
</pre>
<ul><li><p># the virtual window into which the line is deposited initially</p></li></ul>
<p>+            # the virtual window into which the line is deposited initially</p>
<pre># spans a region of 5 thermal_widths, but this may expand
n_vbins = np.ceil(5*thermal_width.d/vbin_width)
vbin_window_width = n_vbins*vbin_width</pre>
<p>@@ -382,7 +383,7 @@</p>
<pre>if (thermal_width < self.bin_width).any():
    mylog.info(("%d out of %d line components will be " + \
                "deposited as unresolved lines.") %</pre>
<ul><li><p>((thermal_width < self.bin_width).sum(),</p></li></ul>
<p>+                           ((thermal_width < self.bin_width).sum(),</p>
<pre>                            thermal_width.size))

            valid_lines = np.arange(len(thermal_width))</pre>
<p>@@ -390,7 +391,7 @@</p>
<pre>                            (line['label'], line['wavelength']),
                            thermal_width.size)
</pre>
<ul><li><p># for a given transition, step through each location in the</p></li></ul>
<p>+            # for a given transition, step through each location in the</p>
<pre># observed spectrum where it occurs and deposit a voigt profile
for i in parallel_objects(valid_lines, njobs=-1):
    my_vbin_window_width = vbin_window_width[i]</pre>
<p>@@ -400,7 +401,7 @@</p>
<pre>while True:
    vbins = \
        np.linspace(lambda_1[i]-my_vbin_window_width/2.,</pre>
<ul><li><p>lambda_1[i]+my_vbin_window_width/2.,</p></li></ul>
<p>+                                    lambda_1[i]+my_vbin_window_width/2.,</p>
<pre>                                    my_n_vbins, endpoint=False)

                    vbins, vtau = \</pre>
<p>@@ -410,8 +411,8 @@</p>
<pre>                            lambda_bins=vbins)

                    # If tau has not dropped below min tau threshold by the</pre>
<ul><li><p># edges (ie the wings), then widen the wavelength</p></li>
<li><p># window and repeat process.</p></li></ul>
<p>+                    # edges (ie the wings), then widen the wavelength +                    # window and repeat process.</p>
<pre>if (vtau[0] < min_tau and vtau[-1] < min_tau):
    break
my_vbin_window_width *= 2</pre>
<p>@@ -427,10 +428,10 @@</p>
<pre># run digitize to identify which vbins are deposited into which
# global lambda bins.</pre>
<ul><li><p># shift global lambda bins over by half a bin width;</p></li>
<li><p># this has the effect of assuring np.digitize will place</p></li></ul>
<p>+                # shift global lambda bins over by half a bin width; +                # this has the effect of assuring np.digitize will place</p>
<pre># the vbins in the closest bin center.</pre>
<ul><li><p>binned = np.digitize(vbins,</p></li></ul>
<p>+                binned = np.digitize(vbins,</p>
<pre>                                     self.lambda_field[left_index:right_index] \
                                     + (0.5 * self.bin_width))
</pre>
<p>@@ -443,7 +444,7 @@</p>
<pre>                self.tau_field[left_index:right_index] += EW

                # write out absorbers to file if the column density of</pre>
<ul><li><p># an absorber is greater than the specified “label_threshold”</p></li></ul>
<p>+                # an absorber is greater than the specified “label_threshold”</p>
<pre># of that absorption line
if output_absorbers_file and \
   line['label_threshold'] is not None and \</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUoxeWxrfr5snrg5pwhBexnvWlnPWIjuGMSgtzK6Ts-2Bno-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyLwlHgNeSHdhE6L-2FD3lFxqhgiSfJmJjNQRWwn4Ymmq0EBs66lv7JSVjzsI-2BHyKyr8bOD-2F6DJVWKqvpp8d-2BVHX5wx2LShTtXRox1RPwoVgA5tCXI2CTT2GnV0je-2FbBCbncdT01lH2yMxTSgXfi9NnnTE-3D">https://bitbucket.org/yt_analysis/yt/commits/8ac0f630b3f0/</a> Changeset:   8ac0f630b3f0 Branch:      yt User:        chummels Date:        2016-03-15 23:54:32+00:00 Summary:     Merging. Affected #:  463 files</p>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 .hgchurn --- a/.hgchurn +++ b/.hgchurn @@ -22,4 +22,21 @@</p>
<pre>ngoldbau@ucsc.edu = goldbaum@ucolick.org
biondo@wisc.edu = Biondo@wisc.edu
samgeen@googlemail.com = samgeen@gmail.com</pre>
<p>-fbogert = fbogert@ucsc.edu \ No newline at end of file +fbogert = fbogert@ucsc.edu +bwoshea = oshea@msu.edu +mornkr@slac.stanford.edu = me@jihoonkim.org +kbarrow = kssbarrow@gatech.edu +kssbarrow@gmail.com = kssbarrow@gatech.edu +kassbarrow@gmail.com = kssbarrow@gatech.edu +antoine.strugarek@cea.fr = strugarek@astro.umontreal.ca +rosen@ucolick.org = alrosen@ucsc.edu +jzuhone = jzuhone@gmail.com +karraki@nmsu.edu = karraki@gmail.com +hckr@eml.cc = astrohckr@gmail.com +julian3@illinois.edu = astrohckr@gmail.com +cosmosquark = bthompson2090@gmail.com +chris.m.malone@lanl.gov = chris.m.malone@gmail.com +jnaiman@ucolick.org = jnaiman +migueld.deval = miguel@archlinux.net +slevy@ncsa.illinois.edu = salevy@illinois.edu +malzraa@gmail.com = kellerbw@mcmaster.ca \ No newline at end of file</p>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 .hgignore --- a/.hgignore +++ b/.hgignore @@ -28,31 +28,34 @@</p>
<pre>yt/utilities/spatial/ckdtree.c
yt/utilities/lib/alt_ray_tracers.c
yt/utilities/lib/amr_kdtools.c</pre>
<p>+yt/utilities/lib/basic_octree.c</p>
<pre>yt/utilities/lib/bitarray.c</pre>
<p>-yt/utilities/lib/CICDeposit.c -yt/utilities/lib/ContourFinding.c -yt/utilities/lib/DepthFirstOctree.c +yt/utilities/lib/bounding_volume_hierarchy.c +yt/utilities/lib/contour_finding.c +yt/utilities/lib/depth_first_octree.c</p>
<pre>yt/utilities/lib/element_mappings.c</pre>
<p>-yt/utilities/lib/FixedInterpolator.c</p>
<pre>yt/utilities/lib/fortran_reader.c
yt/utilities/lib/freetype_writer.c
yt/utilities/lib/geometry_utils.c
yt/utilities/lib/image_utilities.c</pre>
<p>-yt/utilities/lib/Interpolators.c +yt/utilities/lib/interpolators.c</p>
<pre>yt/utilities/lib/kdtree.c
yt/utilities/lib/line_integral_convolution.c</pre>
<p>+yt/utilities/lib/mesh_construction.cpp +yt/utilities/lib/mesh_intersection.cpp +yt/utilities/lib/mesh_samplers.cpp +yt/utilities/lib/mesh_traversal.cpp</p>
<pre>yt/utilities/lib/mesh_utilities.c
yt/utilities/lib/misc_utilities.c</pre>
<p>-yt/utilities/lib/Octree.c -yt/utilities/lib/GridTree.c +yt/utilities/lib/particle_mesh_operations.c</p>
<pre>yt/utilities/lib/origami.c</pre>
<p>+yt/utilities/lib/particle_mesh_operations.c</p>
<pre>yt/utilities/lib/pixelization_routines.c
yt/utilities/lib/png_writer.c</pre>
<p>-yt/utilities/lib/PointsInVolume.c -yt/utilities/lib/QuadTree.c -yt/utilities/lib/RayIntegrators.c +yt/utilities/lib/points_in_volume.c +yt/utilities/lib/quad_tree.c +yt/utilities/lib/ray_integrators.c</p>
<pre>yt/utilities/lib/ragged_arrays.c</pre>
<p>-yt/utilities/lib/VolumeIntegrator.c</p>
<pre>yt/utilities/lib/grid_traversal.c
yt/utilities/lib/marching_cubes.c
yt/utilities/lib/png_writer.h</pre>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 CONTRIBUTING.rst --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -795,8 +795,8 @@</p>
<pre>  rather than explicitly. Ex: ``super(SpecialGridSubclass, self).__init__()``
  rather than ``SpecialGrid.__init__()``.
* Docstrings should describe input, output, behavior, and any state changes</pre>
<ul><li><p>that occur on an object.  See the file ``doc/docstring_example.txt`` for a</p></li>
<li><p>fiducial example of a docstring.</p></li></ul>
<p>+   that occur on an object.  See :ref:`docstrings` below for a fiducial example +   of a docstring.</p>
<pre>* Use only one top-level import per line. Unless there is a good reason not to,
  imports should happen at the top of the file, after the copyright blurb.
* Never compare with ``True`` or ``False`` using ``==`` or ``!=``, always use</pre>
<p>@@ -843,7 +843,7 @@</p>
<pre>   be avoided, they must be explained, even if they are only to be passed on to
   a nested function.
</pre>
<p>-.. _docstrings +.. _docstrings:</p>
<pre>Docstrings
----------</pre>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 CREDITS --- a/CREDITS +++ b/CREDITS @@ -4,20 +4,30 @@</p>
<pre>Tom Abel (tabel@stanford.edu)
Gabriel Altay (gabriel.altay@gmail.com)
Kenza Arraki (karraki@gmail.com)</pre>
<p>+                Kirk Barrow (kssbarrow@gatech.edu) +                Ricarda Beckmann (Ricarda.Beckmann@astro.ox.ac.uk)</p>
<pre>Elliott Biondo (biondo@wisc.edu)
Alex Bogert (fbogert@ucsc.edu)</pre>
<p>+                André-Patrick Bubel (code@andre-bubel.de)</p>
<pre>Pengfei Chen (madcpf@gmail.com)
David Collins (dcollins4096@gmail.com)
Brian Crosby (crosby.bd@gmail.com)
Andrew Cunningham (ajcunn@gmail.com)
Miguel de Val-Borro (miguel.deval@gmail.com)</pre>
<p>+                Bili Dong (qobilidop@gmail.com) +                Nicholas Earl (nchlsearl@gmail.com)</p>
<pre>Hilary Egan (hilaryye@gmail.com)</pre>
<p>+                Daniel Fenn (df11c@my.fsu.edu)</p>
<pre>John Forces (jforbes@ucolick.org)</pre>
<p>+                Adam Ginsburg (keflavich@gmail.com)</p>
<pre>Sam Geen (samgeen@gmail.com)
Nathan Goldbaum (goldbaum@ucolick.org)</pre>
<p>+                William Gray (graywilliamj@gmail.com)</p>
<pre>Markus Haider (markus.haider@uibk.ac.at)
Eric Hallman (hallman13@gmail.com)
Cameron Hummels (chummels@gmail.com)</pre>
<p>+                Anni Järvenpää (anni.jarvenpaa@gmail.com) +                Allyson Julian (astrohckr@gmail.com)</p>
<pre>Christian Karch (chiffre@posteo.de)
Ben W. Keller (kellerbw@mcmaster.ca)
Ji-hoon Kim (me@jihoonkim.org)</pre>
<p>@@ -25,11 +35,15 @@</p>
<pre>Kacper Kowalik (xarthisius.kk@gmail.com)
Mark Krumholz (mkrumhol@ucsc.edu)
Michael Kuhlen (mqk@astro.berkeley.edu)</pre>
<p>+                Meagan Lang (langmm.astro@gmail.com) +                Doris Lee (dorislee@berkeley.edu)</p>
<pre>Eve Lee (elee@cita.utoronto.ca)
Sam Leitner (sam.leitner@gmail.com)</pre>
<p>+                Stuart Levy (salevy@illinois.edu)</p>
<pre>Yuan Li (yuan@astro.columbia.edu)
Chris Malone (chris.m.malone@gmail.com)
Josh Maloney (joshua.moloney@colorado.edu)</pre>
<p>+                Jonah Miller (jonah.maxwell.miller@gmail.com)</p>
<pre>Chris Moody (cemoody@ucsc.edu)
Stuart Mumford (stuart@mumford.me.uk)
Andrew Myers (atmyers@astro.berkeley.edu)</pre>
<p>@@ -44,6 +58,7 @@</p>
<pre>Mark Richardson (Mark.L.Richardson@asu.edu)
Thomas Robitaille (thomas.robitaille@gmail.com)
Anna Rosen (rosen@ucolick.org)</pre>
<p>+                Chuck Rozhon (rozhon2@illinois.edu)</p>
<pre>Douglas Rudd (drudd@uchicago.edu)
Anthony Scopatz (scopatz@gmail.com)
Noel Scudder (noel.scudder@stonybrook.edu)</pre>
<p>@@ -59,6 +74,7 @@</p>
<pre>Ji Suoqing (jisuoqing@gmail.com)
Elizabeth Tasker (tasker@astro1.sci.hokudai.ac.jp)
Benjamin Thompson (bthompson2090@gmail.com)</pre>
<p>+                Robert Thompson (rthompsonj@gmail.com)</p>
<pre>Stephanie Tonnesen (stonnes@gmail.com)
Matthew Turk (matthewturk@gmail.com)
Rich Wagner (rwagner@physics.ucsd.edu)</pre>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 MANIFEST.in --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include README* CREDITS COPYING.txt CITATION requirements.txt optional-requirements.txt +include README* CREDITS COPYING.txt CITATION requirements.txt optional-requirements.txt setupext.py</p>
<pre>include yt/visualization/mapserver/html/map_index.html
include yt/visualization/mapserver/html/leaflet/*.css
include yt/visualization/mapserver/html/leaflet/*.js</pre>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 clean.sh --- a/clean.sh +++ b/clean.sh @@ -1,4 +1,1 @@ -find . -name “*.so” -exec rm -v {} \; -find . -name “*.pyc” -exec rm -v {} \; -find . -name “__config__.py” -exec rm -v {} \; -rm -rvf build dist +hg --config extensions.purge= purge --all yt</p>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 doc/extensions/notebook_sphinxext.py --- a/doc/extensions/notebook_sphinxext.py +++ /dev/null @@ -1,241 +0,0 @@ -import errno -import os -import shutil -import string -import re -import tempfile -import uuid -from sphinx.util.compat import Directive -from docutils import nodes -from docutils.parsers.rst import directives -from IPython.config import Config -from IPython.nbconvert import html, python -from IPython.nbformat import current as nbformat -from runipy.notebook_runner import NotebookRunner, NotebookError – -class NotebookDirective(Directive):</p>
<ul><li><p>"""Insert an evaluated notebook into a document</p></li></ul>
<p>–</p>
<ul><li><p>This uses runipy and nbconvert to transform a path to an unevaluated notebook</p></li>
<li><p>into html suitable for embedding in a Sphinx document.</p></li>
<li><p>"""</p></li>
<li><p>required_arguments = 1</p></li>
<li><p>optional_arguments = 1</p></li>
<li><p>option_spec = {'skip_exceptions': directives.flag}</p></li>
<li><p>final_argument_whitespace = True</p></li></ul>
<p>–</p>
<ul><li><p>def run(self): # check if there are spaces in the notebook name</p></li>
<li><p>nb_path = self.arguments[0]</p></li>
<li><p>if ' ' in nb_path: raise ValueError(</p></li>
<li><p>"Due to issues with docutils stripping spaces from links, white "</p></li>
<li><p>"space is not allowed in notebook filenames '{0}'".format(nb_path))</p></li>
<li><p># check if raw html is supported</p></li>
<li><p>if not self.state.document.settings.raw_enabled:</p></li>
<li><p>raise self.warning('"%s" directive disabled.' % self.name)</p></li></ul>
<p>–</p>
<ul><li><p>cwd = os.getcwd()</p></li>
<li><p>tmpdir = tempfile.mkdtemp()</p></li>
<li><p>os.chdir(tmpdir)</p></li></ul>
<p>–</p>
<ul><li><p># get path to notebook</p></li>
<li><p>nb_filename = self.arguments[0]</p></li>
<li><p>nb_basename = os.path.basename(nb_filename)</p></li>
<li><p>rst_file = self.state_machine.document.attributes['source']</p></li>
<li><p>rst_dir = os.path.abspath(os.path.dirname(rst_file))</p></li>
<li><p>nb_abs_path = os.path.abspath(os.path.join(rst_dir, nb_filename))</p></li></ul>
<p>–</p>
<ul><li><p># Move files around.</p></li>
<li><p>rel_dir = os.path.relpath(rst_dir, setup.confdir)</p></li>
<li><p>dest_dir = os.path.join(setup.app.builder.outdir, rel_dir)</p></li>
<li><p>dest_path = os.path.join(dest_dir, nb_basename)</p></li></ul>
<p>–</p>
<ul><li><p>image_dir, image_rel_dir = make_image_dir(setup, rst_dir)</p></li></ul>
<p>–</p>
<ul><li><p># Ensure desination build directory exists</p></li>
<li><p>thread_safe_mkdir(os.path.dirname(dest_path))</p></li></ul>
<p>–</p>
<ul><li><p># Copy unevaluated notebook</p></li>
<li><p>shutil.copyfile(nb_abs_path, dest_path)</p></li></ul>
<p>–</p>
<ul><li><p># Construct paths to versions getting copied over</p></li>
<li><p>dest_path_eval = string.replace(dest_path, ‘.ipynb’, ‘_evaluated.ipynb’)</p></li>
<li><p>dest_path_script = string.replace(dest_path, ‘.ipynb’, ‘.py’)</p></li>
<li><p>rel_path_eval = string.replace(nb_basename, ‘.ipynb’, ‘_evaluated.ipynb’)</p></li>
<li><p>rel_path_script = string.replace(nb_basename, ‘.ipynb’, ‘.py’)</p></li></ul>
<p>–</p>
<ul><li><p># Create python script vesion</p></li>
<li><p>script_text = nb_to_python(nb_abs_path)</p></li>
<li><p>f = open(dest_path_script, ‘w’)</p></li>
<li><p>f.write(script_text.encode('utf8'))</p></li>
<li><p>f.close()</p></li></ul>
<p>–</p>
<ul><li><p>skip_exceptions = ‘skip_exceptions’ in self.options</p></li></ul>
<p>–</p>
<ul><li><p>ret = evaluate_notebook(</p></li>
<li><p>nb_abs_path, dest_path_eval, skip_exceptions=skip_exceptions)</p></li></ul>
<p>–</p>
<ul><li><p>try:</p></li>
<li><p>evaluated_text, resources = ret</p></li>
<li><p>evaluated_text = write_notebook_output(</p></li>
<li><p>resources, image_dir, image_rel_dir, evaluated_text)</p></li>
<li><p>except ValueError:</p></li>
<li><p># This happens when a notebook raises an unhandled exception</p></li>
<li><p>evaluated_text = ret</p></li></ul>
<p>–</p>
<ul><li><p># Create link to notebook and script files</p></li>
<li><p>link_rst = “(” + \</p></li>
<li><p>formatted_link(nb_basename) + "; " + \</p></li>
<li><p>formatted_link(rel_path_eval) + "; " + \</p></li>
<li><p>formatted_link(rel_path_script) + \</p></li>
<li><p>“)”</p></li></ul>
<p>–</p>
<ul><li><p>self.state_machine.insert_input([link_rst], rst_file)</p></li></ul>
<p>–</p>
<ul><li><p># create notebook node</p></li>
<li><p>attributes = {'format': ‘html’, ‘source’: ‘nb_path’}</p></li>
<li><p>nb_node = notebook_node('', evaluated_text, **attributes)</p></li>
<li><p>(nb_node.source, nb_node.line) = \</p></li>
<li><p>self.state_machine.get_source_and_line(self.lineno)</p></li></ul>
<p>–</p>
<ul><li><p># add dependency</p></li>
<li><p>self.state.document.settings.record_dependencies.add(nb_abs_path)</p></li></ul>
<p>–</p>
<ul><li><p># clean up</p></li>
<li><p>os.chdir(cwd)</p></li>
<li><p>shutil.rmtree(tmpdir, True)</p></li></ul>
<p>–</p>
<ul><li><p>return [nb_node]</p></li></ul>
<p>– – -class notebook_node(nodes.raw):</p>
<ul><li><p>pass</p></li></ul>
<p>– -def nb_to_python(nb_path):</p>
<ul><li><p>"""convert notebook to python script"""</p></li>
<li><p>exporter = python.PythonExporter()</p></li>
<li><p>output, resources = exporter.from_filename(nb_path)</p></li>
<li><p>return output</p></li></ul>
<p>– -def nb_to_html(nb_path):</p>
<ul><li><p>"""convert notebook to html"""</p></li>
<li><p>c = Config({'ExtractOutputPreprocessor':{'enabled':True}})</p></li></ul>
<p>–</p>
<ul><li><p>exporter = html.HTMLExporter(template_file='full', config=c)</p></li>
<li><p>notebook = nbformat.read(open(nb_path), ‘json’)</p></li>
<li><p>output, resources = exporter.from_notebook_node(notebook)</p></li>
<li><p>header = output.split('<head>', 1)[1].split('</head>',1)[0]</p></li>
<li><p>body = output.split('<body>', 1)[1].split('</body>',1)[0]</p></li></ul>
<p>–</p>
<ul><li><p># <a href="http://link.bitbucket.org/wf/click?upn=5coGVbsfgQvfK24RVUKNw8OSruoxozfEBRYP6eKQOFg-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyOXPJTw7hPtiKVKQvB6MI-2Bg88v-2Fq67vGhWiBxLhGX9-2FwRPWdpJuQ6-2BFBJy57SFbYqWeqbVjlMhFHhfbU2TIQrDkNNX6xrcAMbkPmk-2B74NxvaNMtPcNxGTsk4KswtceYAxinABSJIm0Xq3FcKk9PNiUM-3D">http://imgur.com/eR9bMRH</a></p></li>
<li><p>header = header.replace('<style', ‘<style scoped="scoped"’)</p></li>
<li><p>header = header.replace('body {\n  overflow: visible;\n  padding: 8px;\n}\n',</p></li>
<li><p>'')</p></li>
<li><p>header = header.replace("code,pre{", “code{”)</p></li></ul>
<p>–</p>
<ul><li><p># Filter out styles that conflict with the sphinx theme.</p></li>
<li><p>filter_strings = [</p></li>
<li><p>‘navbar’,</p></li>
<li><p>‘body{’,</p></li>
<li><p>‘alert{’,</p></li>
<li><p>‘uneditable-input{’,</p></li>
<li><p>‘collapse{’,</p></li>
<li><p>]</p></li></ul>
<p>–</p>
<ul><li><p>filter_strings.extend(['h%s{' % (i+1) for i in range(6)])</p></li></ul>
<p>–</p>
<ul><li><p>line_begin = [</p></li>
<li><p>‘pre{’,</p></li>
<li><p>‘p{margin’</p></li>
<li><p>]</p></li></ul>
<p>–</p>
<ul><li><p>filterfunc = lambda x: not any([s in x for s in filter_strings])</p></li>
<li><p>header_lines = filter(filterfunc, header.split('\n'))</p></li></ul>
<p>–</p>
<ul><li><p>filterfunc = lambda x: not any([x.startswith(s) for s in line_begin])</p></li>
<li><p>header_lines = filter(filterfunc, header_lines)</p></li></ul>
<p>–</p>
<ul><li><p>header = '\n'.join(header_lines)</p></li></ul>
<p>–</p>
<ul><li><p># concatenate raw html lines</p></li>
<li><p>lines = ['<div class="ipynotebook">']</p></li>
<li><p>lines.append(header)</p></li>
<li><p>lines.append(body)</p></li>
<li><p>lines.append('</div>')</p></li>
<li><p>return '\n'.join(lines), resources</p></li></ul>
<p>– -def evaluate_notebook(nb_path, dest_path=None, skip_exceptions=False):</p>
<ul><li><p># Create evaluated version and save it to the dest path.</p></li>
<li><p>notebook = nbformat.read(open(nb_path), ‘json’)</p></li>
<li><p>nb_runner = NotebookRunner(notebook, pylab=False)</p></li>
<li><p>try:</p></li>
<li><p>nb_runner.run_notebook(skip_exceptions=skip_exceptions)</p></li>
<li><p>except NotebookError as e:</p></li>
<li><p>print('')</p></li>
<li><p>print(e)</p></li>
<li><p># Return the traceback, filtering out ANSI color codes.</p></li>
<li><p># <a href="http://link.bitbucket.org/wf/click?upn=h-2F4jTGrCxy1-2FSrs21iLYdOh8hrOIvk5pCG5VO-2Bd3YMJxbyA17GoK16BVkus0TpF-2BuIvBw8XikaR5dJK7Mvj9qbbateo1rllNu7dLpSSrXvq02zvYJ9WKUV-2BaFvSvJodw_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyIYmE8DNRHNs4k3QwcQ4nCPQqssj6sk3FrBF4RpwhUNdYE4Hb6NU-2FCb3kE-2BdEdtI-2BqDpNqTGBfRVXkMWJwfmIADkreOHZX3e75t9ozdrw9pghic2gvVnFMctyTNNuQxEChaqP-2FNPYnd3jFt9U8vwU-2F0-3D">http://stackoverflow.com/questions/13506033/filtering-out-ansi-escape-sequences</a></p></li>
<li><p>return "Notebook conversion failed with the " \</p></li>
<li><p>“following traceback: \n%s” % \</p></li>
<li><p>re.sub(r'\\033[\[\]]([0-9]{1,2}([;@][0-9]{0,2})*)*[mKP]?', '',</p></li>
<li><p>str(e))</p></li></ul>
<p>–</p>
<ul><li><p>if dest_path is None:</p></li>
<li><p>dest_path = ‘temp_evaluated.ipynb’</p></li>
<li><p>nbformat.write(nb_runner.nb, open(dest_path, ‘w'), 'json’)</p></li>
<li><p>ret = nb_to_html(dest_path)</p></li>
<li><p>if dest_path is ‘temp_evaluated.ipynb’:</p></li>
<li><p>os.remove(dest_path)</p></li>
<li><p>return ret</p></li></ul>
<p>– -def formatted_link(path):</p>
<ul><li><p>return “`%s <%s>`__” % (os.path.basename(path), path)</p></li></ul>
<p>– -def visit_notebook_node(self, node):</p>
<ul><li><p>self.visit_raw(node)</p></li></ul>
<p>– -def depart_notebook_node(self, node):</p>
<ul><li><p>self.depart_raw(node)</p></li></ul>
<p>– -def setup(app):</p>
<ul><li><p>setup.app = app</p></li>
<li><p>setup.config = app.config</p></li>
<li><p>setup.confdir = app.confdir</p></li></ul>
<p>–</p>
<ul><li><p>app.add_node(notebook_node,</p></li>
<li><p>html=(visit_notebook_node, depart_notebook_node))</p></li></ul>
<p>–</p>
<ul><li><p>app.add_directive('notebook', NotebookDirective)</p></li></ul>
<p>–</p>
<ul><li><p>retdict = dict(</p></li>
<li><p>version='0.1',</p></li>
<li><p>parallel_read_safe=True,</p></li>
<li><p>parallel_write_safe=True</p></li>
<li><p>)</p></li></ul>
<p>–</p>
<ul><li><p>return retdict</p></li></ul>
<p>– -def make_image_dir(setup, rst_dir):</p>
<ul><li><p>image_dir = setup.app.builder.outdir + os.path.sep + ‘_images’</p></li>
<li><p>rel_dir = os.path.relpath(setup.confdir, rst_dir)</p></li>
<li><p>image_rel_dir = rel_dir + os.path.sep + ‘_images’</p></li>
<li><p>thread_safe_mkdir(image_dir)</p></li>
<li><p>return image_dir, image_rel_dir</p></li></ul>
<p>– -def write_notebook_output(resources, image_dir, image_rel_dir, evaluated_text):</p>
<ul><li><p>my_uuid = uuid.uuid4().hex</p></li></ul>
<p>–</p>
<ul><li><p>for output in resources['outputs']:</p></li>
<li><p>new_name = image_dir + os.path.sep + my_uuid + output</p></li>
<li><p>new_relative_name = image_rel_dir + os.path.sep + my_uuid + output</p></li>
<li><p>evaluated_text = evaluated_text.replace(output, new_relative_name)</p></li>
<li><p>with open(new_name, ‘wb’) as f:</p></li>
<li><p>f.write(resources['outputs'][output])</p></li>
<li><p>return evaluated_text</p></li></ul>
<p>– -def thread_safe_mkdir(dirname):</p>
<ul><li><p>try:</p></li>
<li><p>os.makedirs(dirname)</p></li>
<li><p>except OSError as e:</p></li>
<li><p>if e.errno != errno.EEXIST:</p></li>
<li><p>raise</p></li>
<li><p>pass</p></li></ul>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 doc/extensions/notebookcell_sphinxext.py --- a/doc/extensions/notebookcell_sphinxext.py +++ /dev/null @@ -1,87 +0,0 @@ -import os -import shutil -import io -import tempfile -from sphinx.util.compat import Directive -from docutils.parsers.rst import directives -from IPython.nbformat import current -from notebook_sphinxext import \</p>
<ul><li><p>notebook_node, visit_notebook_node, depart_notebook_node, \</p></li>
<li><p>evaluate_notebook, make_image_dir, write_notebook_output</p></li></ul>
<p>– – -class NotebookCellDirective(Directive):</p>
<ul><li><p>"""Insert an evaluated notebook cell into a document</p></li></ul>
<p>–</p>
<ul><li><p>This uses runipy and nbconvert to transform an inline python</p></li>
<li><p>script into html suitable for embedding in a Sphinx document.</p></li>
<li><p>"""</p></li>
<li><p>required_arguments = 0</p></li>
<li><p>optional_arguments = 1</p></li>
<li><p>has_content = True</p></li>
<li><p>option_spec = {'skip_exceptions': directives.flag}</p></li></ul>
<p>–</p>
<ul><li><p>def run(self):</p></li>
<li><p># check if raw html is supported</p></li>
<li><p>if not self.state.document.settings.raw_enabled:</p></li>
<li><p>raise self.warning('"%s" directive disabled.' % self.name)</p></li></ul>
<p>–</p>
<ul><li><p>cwd = os.getcwd()</p></li>
<li><p>tmpdir = tempfile.mkdtemp()</p></li>
<li><p>os.chdir(tmpdir)</p></li></ul>
<p>–</p>
<ul><li><p>rst_file = self.state_machine.document.attributes['source']</p></li>
<li><p>rst_dir = os.path.abspath(os.path.dirname(rst_file))</p></li></ul>
<p>–</p>
<ul><li><p>image_dir, image_rel_dir = make_image_dir(setup, rst_dir)</p></li></ul>
<p>–</p>
<ul><li><p># Construct notebook from cell content</p></li>
<li><p>content = "\n".join(self.content)</p></li>
<li><p>with open("temp.py", “w”) as f:</p></li>
<li><p>f.write(content)</p></li></ul>
<p>–</p>
<ul><li><p>convert_to_ipynb('temp.py', ‘temp.ipynb’)</p></li></ul>
<p>–</p>
<ul><li><p>skip_exceptions = ‘skip_exceptions’ in self.options</p></li></ul>
<p>–</p>
<ul><li><p>evaluated_text, resources = evaluate_notebook(</p></li>
<li><p>‘temp.ipynb’, skip_exceptions=skip_exceptions)</p></li></ul>
<p>–</p>
<ul><li><p>evaluated_text = write_notebook_output(</p></li>
<li><p>resources, image_dir, image_rel_dir, evaluated_text)</p></li></ul>
<p>–</p>
<ul><li><p># create notebook node</p></li>
<li><p>attributes = {'format': ‘html’, ‘source’: ‘nb_path’}</p></li>
<li><p>nb_node = notebook_node('', evaluated_text, **attributes)</p></li>
<li><p>(nb_node.source, nb_node.line) = \</p></li>
<li><p>self.state_machine.get_source_and_line(self.lineno)</p></li></ul>
<p>–</p>
<ul><li><p># clean up</p></li>
<li><p>os.chdir(cwd)</p></li>
<li><p>shutil.rmtree(tmpdir, True)</p></li></ul>
<p>–</p>
<ul><li><p>return [nb_node]</p></li></ul>
<p>– -def setup(app):</p>
<ul><li><p>setup.app = app</p></li>
<li><p>setup.config = app.config</p></li>
<li><p>setup.confdir = app.confdir</p></li></ul>
<p>–</p>
<ul><li><p>app.add_node(notebook_node,</p></li>
<li><p>html=(visit_notebook_node, depart_notebook_node))</p></li></ul>
<p>–</p>
<ul><li><p>app.add_directive('notebook-cell', NotebookCellDirective)</p></li></ul>
<p>–</p>
<ul><li><p>retdict = dict(</p></li>
<li><p>version='0.1',</p></li>
<li><p>parallel_read_safe=True,</p></li>
<li><p>parallel_write_safe=True</p></li>
<li><p>)</p></li></ul>
<p>–</p>
<ul><li><p>return retdict</p></li></ul>
<p>– -def convert_to_ipynb(py_file, ipynb_file):</p>
<ul><li><p>with io.open(py_file, ‘r’, encoding='utf-8') as f:</p></li>
<li><p>notebook = current.reads(f.read(), format='py')</p></li>
<li><p>with io.open(ipynb_file, ‘w’, encoding='utf-8') as f:</p></li>
<li><p>current.write(notebook, f, format='ipynb')</p></li></ul>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 doc/extensions/numpydocmod/__init__.py --- a/doc/extensions/numpydocmod/__init__.py +++ /dev/null @@ -1,1 +0,0 @@ -from numpydoc import setup</p>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 doc/extensions/numpydocmod/comment_eater.py --- a/doc/extensions/numpydocmod/comment_eater.py +++ /dev/null @@ -1,158 +0,0 @@ -from cStringIO import StringIO -import compiler -import inspect -import textwrap -import tokenize – -from compiler_unparse import unparse – – -class Comment(object):</p>
<ul><li><p>""" A comment block.</p></li>
<li><p>"""</p></li>
<li><p>is_comment = True</p></li>
<li><p>def __init__(self, start_lineno, end_lineno, text):</p></li>
<li><p># int : The first line number in the block. 1-indexed.</p></li>
<li><p>self.start_lineno = start_lineno</p></li>
<li><p># int : The last line number. Inclusive!</p></li>
<li><p>self.end_lineno = end_lineno</p></li>
<li><p># str : The text block including ‘#’ character but not any leading spaces.</p></li>
<li><p>self.text = text</p></li></ul>
<p>–</p>
<ul><li><p>def add(self, string, start, end, line):</p></li>
<li><p>""" Add a new comment line.</p></li>
<li><p>"""</p></li>
<li><p>self.start_lineno = min(self.start_lineno, start[0])</p></li>
<li><p>self.end_lineno = max(self.end_lineno, end[0])</p></li>
<li><p>self.text += string</p></li></ul>
<p>–</p>
<ul><li><p>def __repr__(self):</p></li>
<li><p>return ‘%s(%r, %r, %r)’ % (self.__class__.__name__, self.start_lineno,</p></li>
<li><p>self.end_lineno, self.text)</p></li></ul>
<p>– – -class NonComment(object):</p>
<ul><li><p>""" A non-comment block of code.</p></li>
<li><p>"""</p></li>
<li><p>is_comment = False</p></li>
<li><p>def __init__(self, start_lineno, end_lineno):</p></li>
<li><p>self.start_lineno = start_lineno</p></li>
<li><p>self.end_lineno = end_lineno</p></li></ul>
<p>–</p>
<ul><li><p>def add(self, string, start, end, line):</p></li>
<li><p>""" Add lines to the block.</p></li>
<li><p>"""</p></li>
<li><p>if string.strip():</p></li>
<li><p># Only add if not entirely whitespace.</p></li>
<li><p>self.start_lineno = min(self.start_lineno, start[0])</p></li>
<li><p>self.end_lineno = max(self.end_lineno, end[0])</p></li></ul>
<p>–</p>
<ul><li><p>def __repr__(self):</p></li>
<li><p>return ‘%s(%r, %r)’ % (self.__class__.__name__, self.start_lineno,</p></li>
<li><p>self.end_lineno)</p></li></ul>
<p>– – -class CommentBlocker(object):</p>
<ul><li><p>""" Pull out contiguous comment blocks.</p></li>
<li><p>"""</p></li>
<li><p>def __init__(self):</p></li>
<li><p># Start with a dummy.</p></li>
<li><p>self.current_block = NonComment(0, 0)</p></li></ul>
<p>–</p>
<ul><li><p># All of the blocks seen so far.</p></li>
<li><p>self.blocks = []</p></li></ul>
<p>–</p>
<ul><li><p># The index mapping lines of code to their associated comment blocks.</p></li>
<li><p>self.index = {}</p></li></ul>
<p>–</p>
<ul><li><p>def process_file(self, file):</p></li>
<li><p>""" Process a file object.</p></li>
<li><p>"""</p></li>
<li><p>for token in tokenize.generate_tokens(file.next):</p></li>
<li><p>self.process_token(*token)</p></li>
<li><p>self.make_index()</p></li></ul>
<p>–</p>
<ul><li><p>def process_token(self, kind, string, start, end, line):</p></li>
<li><p>""" Process a single token.</p></li>
<li><p>"""</p></li>
<li><p>if self.current_block.is_comment:</p></li>
<li><p>if kind == tokenize.COMMENT:</p></li>
<li><p>self.current_block.add(string, start, end, line)</p></li>
<li><p>else:</p></li>
<li><p>self.new_noncomment(start[0], end[0])</p></li>
<li><p>else:</p></li>
<li><p>if kind == tokenize.COMMENT:</p></li>
<li><p>self.new_comment(string, start, end, line)</p></li>
<li><p>else:</p></li>
<li><p>self.current_block.add(string, start, end, line)</p></li></ul>
<p>–</p>
<ul><li><p>def new_noncomment(self, start_lineno, end_lineno):</p></li>
<li><p>""" We are transitioning from a noncomment to a comment.</p></li>
<li><p>"""</p></li>
<li><p>block = NonComment(start_lineno, end_lineno)</p></li>
<li><p>self.blocks.append(block)</p></li>
<li><p>self.current_block = block</p></li></ul>
<p>–</p>
<ul><li><p>def new_comment(self, string, start, end, line):</p></li>
<li><p>""" Possibly add a new comment.</p></li></ul>
<p>–</p>
<ul><li><p>Only adds a new comment if this comment is the only thing on the line.</p></li>
<li><p>Otherwise, it extends the noncomment block.</p></li>
<li><p>"""</p></li>
<li><p>prefix = line[:start[1]]</p></li>
<li><p>if prefix.strip():</p></li>
<li><p># Oops! Trailing comment, not a comment block.</p></li>
<li><p>self.current_block.add(string, start, end, line)</p></li>
<li><p>else:</p></li>
<li><p># A comment block.</p></li>
<li><p>block = Comment(start[0], end[0], string)</p></li>
<li><p>self.blocks.append(block)</p></li>
<li><p>self.current_block = block</p></li></ul>
<p>–</p>
<ul><li><p>def make_index(self):</p></li>
<li><p>""" Make the index mapping lines of actual code to their associated</p></li>
<li><p>prefix comments.</p></li>
<li><p>"""</p></li>
<li><p>for prev, block in zip(self.blocks[:-1], self.blocks[1:]):</p></li>
<li><p>if not block.is_comment:</p></li>
<li><p>self.index[block.start_lineno] = prev</p></li></ul>
<p>–</p>
<ul><li><p>def search_for_comment(self, lineno, default=None):</p></li>
<li><p>""" Find the comment block just before the given line number.</p></li></ul>
<p>–</p>
<ul><li><p>Returns None (or the specified default) if there is no such block.</p></li>
<li><p>"""</p></li>
<li><p>if not self.index:</p></li>
<li><p>self.make_index()</p></li>
<li><p>block = self.index.get(lineno, None)</p></li>
<li><p>text = getattr(block, ‘text’, default)</p></li>
<li><p>return text</p></li></ul>
<p>– – -def strip_comment_marker(text):</p>
<ul><li><p>""" Strip # markers at the front of a block of comment text.</p></li>
<li><p>"""</p></li>
<li><p>lines = []</p></li>
<li><p>for line in text.splitlines():</p></li>
<li><p>lines.append(line.lstrip('#'))</p></li>
<li><p>text = textwrap.dedent('\n'.join(lines))</p></li>
<li><p>return text</p></li></ul>
<p>– – -def get_class_traits(klass):</p>
<ul><li><p>""" Yield all of the documentation for trait definitions on a class object.</p></li>
<li><p>"""</p></li>
<li><p># FIXME: gracefully handle errors here or in the caller?</p></li>
<li><p>source = inspect.getsource(klass)</p></li>
<li><p>cb = CommentBlocker()</p></li>
<li><p>cb.process_file(StringIO(source))</p></li>
<li><p>mod_ast = compiler.parse(source)</p></li>
<li><p>class_ast = mod_ast.node.nodes[0]</p></li>
<li><p>for node in class_ast.code.nodes:</p></li>
<li><p># FIXME: handle other kinds of assignments?</p></li>
<li><p>if isinstance(node, compiler.ast.Assign):</p></li>
<li><p>name = node.nodes[0].name</p></li>
<li><p>rhs = unparse(node.expr).strip()</p></li>
<li><p>doc = strip_comment_marker(cb.search_for_comment(node.lineno, default=''))</p></li>
<li><p>yield name, rhs, doc</p></li></ul>
<p>–</p>
<p>diff -r 02417c5a8f7f2fad0bcd7f9f6fc3bd970c3712af -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 doc/extensions/numpydocmod/compiler_unparse.py --- a/doc/extensions/numpydocmod/compiler_unparse.py +++ /dev/null @@ -1,860 +0,0 @@ -""" Turn compiler.ast structures back into executable python code. –</p>
<ul><li><p>The unparse method takes a compiler.ast tree and transforms it back into</p></li>
<li><p>valid python code.  It is incomplete and currently only works for</p></li>
<li><p>import statements, function calls, function definitions, assignments, and</p></li>
<li><p>basic expressions.</p></li></ul>
<p>–</p>
<ul><li><p>Inspired by python-2.5-svn/Demo/parser/unparse.py</p></li></ul>
<p>–</p>
<ul><li><p>fixme: We may want to move to using _ast trees because the compiler for</p></li>
<li><p>them is about 6 times faster than compiler.compile.</p></li></ul>
<p>-""" – -import sys -import cStringIO -from compiler.ast import Const, Name, Tuple, Div, Mul, Sub, Add – -def unparse(ast, single_line_functions=False):</p>
<ul><li><p>s = cStringIO.StringIO()</p></li>
<li><p>UnparseCompilerAst(ast, s, single_line_functions)</p></li>
<li><p>return s.getvalue().lstrip()</p></li></ul>
<p>– -op_precedence = { 'compiler.ast.Power':3, 'compiler.ast.Mul':2, 'compiler.ast.Div':2,</p>
<ul><li><p>'compiler.ast.Add':1, 'compiler.ast.Sub':1 }</p></li></ul>
<p>– -class UnparseCompilerAst:</p>
<ul><li><p>""" Methods in this class recursively traverse an AST and</p></li>
<li><p>output source code for the abstract syntax; original formatting</p></li>
<li><p>is disregarged.</p></li>
<li><p>"""</p></li></ul>
<p>–</p>
<ul><li><p>#########################################################################</p></li>
<li><p># object interface.</p></li>
<li><p>#########################################################################</p></li></ul>
<p>–</p>
<ul><li><p>def __init__(self, tree, file = sys.stdout, single_line_functions=False):</p></li>
<li><p>""" Unparser(tree, file=sys.stdout) -> None.</p></li></ul>
<p>–</p>
<ul><li><p>Print the source for tree to file.</p></li>
<li><p>"""</p></li>
<li><p>self.f = file</p></li>
<li><p>self._single_func = single_line_functions</p></li>
<li><p>self._do_indent = True</p></li>
<li><p>self._indent = 0</p></li>
<li><p>self._dispatch(tree)</p></li>
<li><p>self._write("\n")</p></li>
<li><p>self.f.flush()</p></li></ul>
<p>–</p>
<ul><li><p>#########################################################################</p></li>
<li><p># Unparser private interface.</p></li>
<li><p>#########################################################################</p></li></ul>
<p>–</p>
<ul><li><p>### format, output, and dispatch methods ################################</p></li></ul>
<p>–</p>
<ul><li><p>def _fill(self, text = ""):</p></li>
<li><p>“Indent a piece of text, according to the current indentation level”</p></li>
<li><p>if self._do_indent:</p></li>
<li><p>self._write("\n"+"    "*self._indent + text)</p></li>
<li><p>else:</p></li>
<li><p>self._write(text)</p></li></ul>
<p>–</p>
<ul><li><p>def _write(self, text):</p></li>
<li><p>“Append a piece of text to the current line.”</p></li>
<li><p>self.f.write(text)</p></li></ul>
<p>–</p>
<ul><li><p>def _enter(self):</p></li>
<li><p>“Print ‘:’, and increase the indentation.”</p></li>
<li><p>self._write(": ")</p></li>
<li><p>self._indent += 1</p></li></ul>
<p>–</p>
<ul><li><p>def _leave(self):</p></li>
<li><p>“Decrease the indentation level.”</p></li>
<li><p>self._indent -= 1</p></li></ul>
<p>–</p>
<ul><li><p>def _dispatch(self, tree):</p></li>
<li><p>“_dispatcher function, _dispatching tree type T to method _T.”</p></li>
<li><p>if isinstance(tree, list):</p></li>
<li><p>for t in tree:</p></li>
<li><p>self._dispatch(t)</p></li>
<li><p>return</p></li>
<li><p>meth = getattr(self, "_"+tree.__class__.__name__)</p></li>
<li><p>if tree.__class__.__name__ == ‘NoneType’ and not self._do_indent:</p></li>
<li><p>return</p></li>
<li><p>meth(tree)</p></li></ul>
<p>– –</p>
<ul><li><p>#########################################################################</p></li>
<li><p># compiler.ast unparsing methods.</p></li>
<li><p>#</p></li>
<li><p># There should be one method per concrete grammar type. They are</p></li>
<li><p># organized in alphabetical order.</p></li>
<li><p>#########################################################################</p></li></ul>
<p>–</p>
<ul><li><p>def _Add(self, t):</p></li>
<li><p>self.__binary_op(t, ‘+’)</p></li></ul>
<p>–</p>
<ul><li><p>def _And(self, t):</p></li>
<li><p>self._write(" (")</p></li>
<li><p>for i, node in enumerate(t.nodes):</p></li>
<li><p>self._dispatch(node)</p></li>
<li><p>if i != len(t.nodes)-1:</p></li>
<li><p>self._write(") and (")</p></li>
<li><p>self._write(")")</p></li></ul>
<p>–</p>
<ul><li><p>def _AssAttr(self, t):</p></li>
<li><p>""" Handle assigning an attribute of an object</p></li>
<li><p>"""</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>self._write('.'+t.attrname)</p></li></ul>
<p>–</p>
<ul><li><p>def _Assign(self, t):</p></li>
<li><p>""" Expression Assignment such as “a = 1”.</p></li></ul>
<p>–</p>
<ul><li><p>This only handles assignment in expressions.  Keyword assignment</p></li>
<li><p>is handled separately.</p></li>
<li><p>"""</p></li>
<li><p>self._fill()</p></li>
<li><p>for target in t.nodes:</p></li>
<li><p>self._dispatch(target)</p></li>
<li><p>self._write(" = ")</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>if not self._do_indent:</p></li>
<li><p>self._write('; ')</p></li></ul>
<p>–</p>
<ul><li><p>def _AssName(self, t):</p></li>
<li><p>""" Name on left hand side of expression.</p></li></ul>
<p>–</p>
<ul><li><p>Treat just like a name on the right side of an expression.</p></li>
<li><p>"""</p></li>
<li><p>self._Name(t)</p></li></ul>
<p>–</p>
<ul><li><p>def _AssTuple(self, t):</p></li>
<li><p>""" Tuple on left hand side of an expression.</p></li>
<li><p>"""</p></li></ul>
<p>–</p>
<ul><li><p># _write each elements, separated by a comma.</p></li>
<li><p>for element in t.nodes[:-1]:</p></li>
<li><p>self._dispatch(element)</p></li>
<li><p>self._write(", ")</p></li></ul>
<p>–</p>
<ul><li><p># Handle the last one without writing comma</p></li>
<li><p>last_element = t.nodes[-1]</p></li>
<li><p>self._dispatch(last_element)</p></li></ul>
<p>–</p>
<ul><li><p>def _AugAssign(self, t):</p></li>
<li><p>""" +=,-=,*=,/=,**=, etc. operations</p></li>
<li><p>"""</p></li></ul>
<p>–</p>
<ul><li><p>self._fill()</p></li>
<li><p>self._dispatch(t.node)</p></li>
<li><p>self._write(' ‘+t.op+’ ')</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>if not self._do_indent:</p></li>
<li><p>self._write(';')</p></li></ul>
<p>–</p>
<ul><li><p>def _Bitand(self, t):</p></li>
<li><p>""" Bit and operation.</p></li>
<li><p>"""</p></li></ul>
<p>–</p>
<ul><li><p>for i, node in enumerate(t.nodes):</p></li>
<li><p>self._write("(")</p></li>
<li><p>self._dispatch(node)</p></li>
<li><p>self._write(")")</p></li>
<li><p>if i != len(t.nodes)-1:</p></li>
<li><p>self._write(" & ")</p></li></ul>
<p>–</p>
<ul><li><p>def _Bitor(self, t):</p></li>
<li><p>""" Bit or operation</p></li>
<li><p>"""</p></li></ul>
<p>–</p>
<ul><li><p>for i, node in enumerate(t.nodes):</p></li>
<li><p>self._write("(")</p></li>
<li><p>self._dispatch(node)</p></li>
<li><p>self._write(")")</p></li>
<li><p>if i != len(t.nodes)-1:</p></li>
<li><p>self._write(" | ")</p></li></ul>
<p>–</p>
<ul><li><p>def _CallFunc(self, t):</p></li>
<li><p>""" Function call.</p></li>
<li><p>"""</p></li>
<li><p>self._dispatch(t.node)</p></li>
<li><p>self._write("(")</p></li>
<li><p>comma = False</p></li>
<li><p>for e in t.args:</p></li>
<li><p>if comma: self._write(", ")</p></li>
<li><p>else: comma = True</p></li>
<li><p>self._dispatch(e)</p></li>
<li><p>if t.star_args:</p></li>
<li><p>if comma: self._write(", ")</p></li>
<li><p>else: comma = True</p></li>
<li><p>self._write("*")</p></li>
<li><p>self._dispatch(t.star_args)</p></li>
<li><p>if t.dstar_args:</p></li>
<li><p>if comma: self._write(", ")</p></li>
<li><p>else: comma = True</p></li>
<li><p>self._write("**")</p></li>
<li><p>self._dispatch(t.dstar_args)</p></li>
<li><p>self._write(")")</p></li></ul>
<p>–</p>
<ul><li><p>def _Compare(self, t):</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>for op, expr in t.ops:</p></li>
<li><p>self._write(" " + op + " ")</p></li>
<li><p>self._dispatch(expr)</p></li></ul>
<p>–</p>
<ul><li><p>def _Const(self, t):</p></li>
<li><p>""" A constant value such as an integer value, 3, or a string, “hello”.</p></li>
<li><p>"""</p></li>
<li><p>self._dispatch(t.value)</p></li></ul>
<p>–</p>
<ul><li><p>def _Decorators(self, t):</p></li>
<li><p>""" Handle function decorators (eg. @has_units)</p></li>
<li><p>"""</p></li>
<li><p>for node in t.nodes:</p></li>
<li><p>self._dispatch(node)</p></li></ul>
<p>–</p>
<ul><li><p>def _Dict(self, t):</p></li>
<li><p>self._write("{")</p></li>
<li><p>for  i, (k, v) in enumerate(t.items):</p></li>
<li><p>self._dispatch(k)</p></li>
<li><p>self._write(": ")</p></li>
<li><p>self._dispatch(v)</p></li>
<li><p>if i < len(t.items)-1:</p></li>
<li><p>self._write(", ")</p></li>
<li><p>self._write("}")</p></li></ul>
<p>–</p>
<ul><li><p>def _Discard(self, t):</p></li>
<li><p>""" Node for when return value is ignored such as in “foo(a)”.</p></li>
<li><p>"""</p></li>
<li><p>self._fill()</p></li>
<li><p>self._dispatch(t.expr)</p></li></ul>
<p>–</p>
<ul><li><p>def _Div(self, t):</p></li>
<li><p>self.__binary_op(t, ‘/’)</p></li></ul>
<p>–</p>
<ul><li><p>def _Ellipsis(self, t):</p></li>
<li><p>self._write("…")</p></li></ul>
<p>–</p>
<ul><li><p>def _From(self, t):</p></li>
<li><p>""" Handle “from xyz import foo, bar as baz”.</p></li>
<li><p>"""</p></li>
<li><p># fixme: Are From and ImportFrom handled differently?</p></li>
<li><p>self._fill("from ")</p></li>
<li><p>self._write(t.modname)</p></li>
<li><p>self._write(" import ")</p></li>
<li><p>for i, (name,asname) in enumerate(t.names):</p></li>
<li><p>if i != 0:</p></li>
<li><p>self._write(", ")</p></li>
<li><p>self._write(name)</p></li>
<li><p>if asname is not None:</p></li>
<li><p>self._write(" as "+asname)</p></li></ul>
<p>–</p>
<ul><li><p>def _Function(self, t):</p></li>
<li><p>""" Handle function definitions</p></li>
<li><p>"""</p></li>
<li><p>if t.decorators is not None:</p></li>
<li><p>self._fill("@")</p></li>
<li><p>self._dispatch(t.decorators)</p></li>
<li><p>self._fill("def “+t.name + "(”)</p></li>
<li><p>defaults = [None] * (len(t.argnames) – len(t.defaults)) + list(t.defaults)</p></li>
<li><p>for i, arg in enumerate(zip(t.argnames, defaults)):</p></li>
<li><p>self._write(arg[0])</p></li>
<li><p>if arg[1] is not None:</p></li>
<li><p>self._write('=')</p></li>
<li><p>self._dispatch(arg[1])</p></li>
<li><p>if i < len(t.argnames)-1:</p></li>
<li><p>self._write(', ')</p></li>
<li><p>self._write(")")</p></li>
<li><p>if self._single_func:</p></li>
<li><p>self._do_indent = False</p></li>
<li><p>self._enter()</p></li>
<li><p>self._dispatch(t.code)</p></li>
<li><p>self._leave()</p></li>
<li><p>self._do_indent = True</p></li></ul>
<p>–</p>
<ul><li><p>def _Getattr(self, t):</p></li>
<li><p>""" Handle getting an attribute of an object</p></li>
<li><p>"""</p></li>
<li><p>if isinstance(t.expr, (Div, Mul, Sub, Add)):</p></li>
<li><p>self._write('(')</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>self._write(')')</p></li>
<li><p>else:</p></li>
<li><p>self._dispatch(t.expr)</p></li></ul>
<p>–</p>
<ul><li><p>self._write('.'+t.attrname)</p></li></ul>
<p>–</p>
<ul><li><p>def _If(self, t):</p></li>
<li><p>self._fill()</p></li></ul>
<p>–</p>
<ul><li><p>for i, (compare,code) in enumerate(t.tests):</p></li>
<li><p>if i == 0:</p></li>
<li><p>self._write("if ")</p></li>
<li><p>else:</p></li>
<li><p>self._write("elif ")</p></li>
<li><p>self._dispatch(compare)</p></li>
<li><p>self._enter()</p></li>
<li><p>self._fill()</p></li>
<li><p>self._dispatch(code)</p></li>
<li><p>self._leave()</p></li>
<li><p>self._write("\n")</p></li></ul>
<p>–</p>
<ul><li><p>if t.else_ is not None:</p></li>
<li><p>self._write("else")</p></li>
<li><p>self._enter()</p></li>
<li><p>self._fill()</p></li>
<li><p>self._dispatch(t.else_)</p></li>
<li><p>self._leave()</p></li>
<li><p>self._write("\n")</p></li></ul>
<p>–</p>
<ul><li><p>def _IfExp(self, t):</p></li>
<li><p>self._dispatch(t.then)</p></li>
<li><p>self._write(" if ")</p></li>
<li><p>self._dispatch(t.test)</p></li></ul>
<p>–</p>
<ul><li><p>if t.else_ is not None:</p></li>
<li><p>self._write(" else (")</p></li>
<li><p>self._dispatch(t.else_)</p></li>
<li><p>self._write(")")</p></li></ul>
<p>–</p>
<ul><li><p>def _Import(self, t):</p></li>
<li><p>""" Handle “import xyz.foo”.</p></li>
<li><p>"""</p></li>
<li><p>self._fill("import ")</p></li></ul>
<p>–</p>
<ul><li><p>for i, (name,asname) in enumerate(t.names):</p></li>
<li><p>if i != 0:</p></li>
<li><p>self._write(", ")</p></li>
<li><p>self._write(name)</p></li>
<li><p>if asname is not None:</p></li>
<li><p>self._write(" as "+asname)</p></li></ul>
<p>–</p>
<ul><li><p>def _Keyword(self, t):</p></li>
<li><p>""" Keyword value assignment within function calls and definitions.</p></li>
<li><p>"""</p></li>
<li><p>self._write(t.name)</p></li>
<li><p>self._write("=")</p></li>
<li><p>self._dispatch(t.expr)</p></li></ul>
<p>–</p>
<ul><li><p>def _List(self, t):</p></li>
<li><p>self._write("[")</p></li>
<li><p>for  i,node in enumerate(t.nodes):</p></li>
<li><p>self._dispatch(node)</p></li>
<li><p>if i < len(t.nodes)-1:</p></li>
<li><p>self._write(", ")</p></li>
<li><p>self._write("]")</p></li></ul>
<p>–</p>
<ul><li><p>def _Module(self, t):</p></li>
<li><p>if t.doc is not None:</p></li>
<li><p>self._dispatch(t.doc)</p></li>
<li><p>self._dispatch(t.node)</p></li></ul>
<p>–</p>
<ul><li><p>def _Mul(self, t):</p></li>
<li><p>self.__binary_op(t, ‘*’)</p></li></ul>
<p>–</p>
<ul><li><p>def _Name(self, t):</p></li>
<li><p>self._write(t.name)</p></li></ul>
<p>–</p>
<ul><li><p>def _NoneType(self, t):</p></li>
<li><p>self._write("None")</p></li></ul>
<p>–</p>
<ul><li><p>def _Not(self, t):</p></li>
<li><p>self._write('not (')</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>self._write(')')</p></li></ul>
<p>–</p>
<ul><li><p>def _Or(self, t):</p></li>
<li><p>self._write(" (")</p></li>
<li><p>for i, node in enumerate(t.nodes):</p></li>
<li><p>self._dispatch(node)</p></li>
<li><p>if i != len(t.nodes)-1:</p></li>
<li><p>self._write(") or (")</p></li>
<li><p>self._write(")")</p></li></ul>
<p>–</p>
<ul><li><p>def _Pass(self, t):</p></li>
<li><p>self._write("pass\n")</p></li></ul>
<p>–</p>
<ul><li><p>def _Printnl(self, t):</p></li>
<li><p>self._fill("print ")</p></li>
<li><p>if t.dest:</p></li>
<li><p>self._write(">> ")</p></li>
<li><p>self._dispatch(t.dest)</p></li>
<li><p>self._write(", ")</p></li>
<li><p>comma = False</p></li>
<li><p>for node in t.nodes:</p></li>
<li><p>if comma: self._write(', ')</p></li>
<li><p>else: comma = True</p></li>
<li><p>self._dispatch(node)</p></li></ul>
<p>–</p>
<ul><li><p>def _Power(self, t):</p></li>
<li><p>self.__binary_op(t, ‘**’)</p></li></ul>
<p>–</p>
<ul><li><p>def _Return(self, t):</p></li>
<li><p>self._fill("return ")</p></li>
<li><p>if t.value:</p></li>
<li><p>if isinstance(t.value, Tuple):</p></li>
<li><p>text = ', '.join([ name.name for name in t.value.asList() ])</p></li>
<li><p>self._write(text)</p></li>
<li><p>else:</p></li>
<li><p>self._dispatch(t.value)</p></li>
<li><p>if not self._do_indent:</p></li>
<li><p>self._write('; ')</p></li></ul>
<p>–</p>
<ul><li><p>def _Slice(self, t):</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>self._write("[")</p></li>
<li><p>if t.lower:</p></li>
<li><p>self._dispatch(t.lower)</p></li>
<li><p>self._write(":")</p></li>
<li><p>if t.upper:</p></li>
<li><p>self._dispatch(t.upper)</p></li>
<li><p>#if t.step:</p></li>
<li><p>#    self._write(":")</p></li>
<li><p>#    self._dispatch(t.step)</p></li>
<li><p>self._write("]")</p></li></ul>
<p>–</p>
<ul><li><p>def _Sliceobj(self, t):</p></li>
<li><p>for i, node in enumerate(t.nodes):</p></li>
<li><p>if i != 0:</p></li>
<li><p>self._write(":")</p></li>
<li><p>if not (isinstance(node, Const) and node.value is None):</p></li>
<li><p>self._dispatch(node)</p></li></ul>
<p>–</p>
<ul><li><p>def _Stmt(self, tree):</p></li>
<li><p>for node in tree.nodes:</p></li>
<li><p>self._dispatch(node)</p></li></ul>
<p>–</p>
<ul><li><p>def _Sub(self, t):</p></li>
<li><p>self.__binary_op(t, ‘-’)</p></li></ul>
<p>–</p>
<ul><li><p>def _Subscript(self, t):</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>self._write("[")</p></li>
<li><p>for i, value in enumerate(t.subs):</p></li>
<li><p>if i != 0:</p></li>
<li><p>self._write(",")</p></li>
<li><p>self._dispatch(value)</p></li>
<li><p>self._write("]")</p></li></ul>
<p>–</p>
<ul><li><p>def _TryExcept(self, t):</p></li>
<li><p>self._fill("try")</p></li>
<li><p>self._enter()</p></li>
<li><p>self._dispatch(t.body)</p></li>
<li><p>self._leave()</p></li></ul>
<p>–</p>
<ul><li><p>for handler in t.handlers:</p></li>
<li><p>self._fill('except ')</p></li>
<li><p>self._dispatch(handler[0])</p></li>
<li><p>if handler[1] is not None:</p></li>
<li><p>self._write(', ')</p></li>
<li><p>self._dispatch(handler[1])</p></li>
<li><p>self._enter()</p></li>
<li><p>self._dispatch(handler[2])</p></li>
<li><p>self._leave()</p></li></ul>
<p>–</p>
<ul><li><p>if t.else_:</p></li>
<li><p>self._fill("else")</p></li>
<li><p>self._enter()</p></li>
<li><p>self._dispatch(t.else_)</p></li>
<li><p>self._leave()</p></li></ul>
<p>–</p>
<ul><li><p>def _Tuple(self, t):</p></li></ul>
<p>–</p>
<ul><li><p>if not t.nodes:</p></li>
<li><p># Empty tuple.</p></li>
<li><p>self._write("()")</p></li>
<li><p>else:</p></li>
<li><p>self._write("(")</p></li></ul>
<p>–</p>
<ul><li><p># _write each elements, separated by a comma.</p></li>
<li><p>for element in t.nodes[:-1]:</p></li>
<li><p>self._dispatch(element)</p></li>
<li><p>self._write(", ")</p></li></ul>
<p>–</p>
<ul><li><p># Handle the last one without writing comma</p></li>
<li><p>last_element = t.nodes[-1]</p></li>
<li><p>self._dispatch(last_element)</p></li></ul>
<p>–</p>
<ul><li><p>self._write(")")</p></li></ul>
<p>–</p>
<ul><li><p>def _UnaryAdd(self, t):</p></li>
<li><p>self._write("+")</p></li>
<li><p>self._dispatch(t.expr)</p></li></ul>
<p>–</p>
<ul><li><p>def _UnarySub(self, t):</p></li>
<li><p>self._write("-")</p></li>
<li><p>self._dispatch(t.expr)</p></li></ul>
<p>–</p>
<ul><li><p>def _With(self, t):</p></li>
<li><p>self._fill('with ')</p></li>
<li><p>self._dispatch(t.expr)</p></li>
<li><p>if t.vars:</p></li>
<li><p>self._write(' as ')</p></li>
<li><p>self._dispatch(t.vars.name)</p></li>
<li><p>self._enter()</p></li>
<li><p>self._dispatch(t.body)</p></li>
<li><p>self._leave()</p></li>
<li><p>self._write('\n')</p></li></ul>
<p>–</p>
<ul><li><p>def _int(self, t):</p></li>
<li><p>self._write(repr(t))</p></li></ul>
<p>–</p>
<ul><li><p>def __binary_op(self, t, symbol):</p></li>
<li><p># Check if parenthesis are needed on left side and then dispatch</p></li>
<li><p>has_paren = False</p></li>
<li><p>left_class = str(t.left.__class__)</p></li>
<li><p>if (left_class in op_precedence.keys() and</p></li>
<li><p>op_precedence[left_class] < op_precedence[str(t.__class__)]):</p></li>
<li><p>has_paren = True</p></li>
<li><p>if has_paren:</p></li>
<li><p>self._write('(')</p></li>
<li><p>self._dispatch(t.left)</p></li>
<li><p>if has_paren:</p></li>
<li><p>self._write(')')</p></li>
<li><p># Write the appropriate symbol for operator</p></li>
<li><p>self._write(symbol)</p></li>
<li><p># Check if parenthesis are needed on the right side and then dispatch</p></li>
<li><p>has_paren = False</p></li>
<li><p>right_class = str(t.right.__class__)</p></li>
<li><p>if (right_class in op_precedence.keys() and</p></li>
<li><p>op_precedence[right_class] < op_precedence[str(t.__class__)]):</p></li>
<li><p>has_paren = True</p></li>
<li><p>if has_paren:</p></li>
<li><p>self._write('(')</p></li>
<li><p>self._dispatch(t.right)</p></li>
<li><p>if has_paren:</p></li>
<li><p>self._write(')')</p></li></ul>
<p>–</p>
<ul><li><p>def _float(self, t):</p></li>
<li><p># if t is 0.1, str(t)->'0.1' while repr(t)->'0.1000000000001'</p></li>
<li><p># We prefer str here.</p></li>
<li><p>self._write(str(t))</p></li></ul>
<p>–</p>
<ul><li><p>def _str(self, t):</p></li>
<li><p>self._write(repr(t))</p></li></ul>
<p>–</p>
<ul><li><p>def _tuple(self, t):</p></li>
<li><p>self._write(str(t))</p></li></ul>
<p>–</p>
<ul><li><p>#########################################################################</p></li>
<li><p># These are the methods from the _ast modules unparse.</p></li>
<li><p>#</p></li>
<li><p># As our needs to handle more advanced code increase, we may want to</p></li>
<li><p># modify some of the methods below so that they work for compiler.ast.</p></li>
<li><p>#########################################################################</p></li></ul>
<p>– -#    # stmt -#    def <em>Expr(self, tree): -#        self._fill() -#        self._dispatch(tree.value) -# -#    def <em>Import(self, t): -#        self._fill("import “) -#        first = True -#        for a in t.names: -#            if first: -#                first = False -#            else: -#                self._write(”, “) -#            self._write(a.name) -#            if a.asname: -#                self._write(” as “+a.asname) -# -##    def _ImportFrom(self, t): -##        self._fill("from “) -##        self._write(t.module) -##        self._write(” import “) -##        for i, a in enumerate(t.names): -##            if i == 0: -##                self._write(”, “) -##            self._write(a.name) -##            if a.asname: -##                self._write(” as “+a.asname) -##        # XXX(jpe) what is level for? -## -# -#    def _Break(self, t): -#        self._fill("break”) -# -#    def _Continue(self, t): -#        self._fill("continue”) -# -#    def _Delete(self, t): -#        self._fill("del “) -#        self._dispatch(t.targets) -# -#    def _Assert(self, t): -#        self._fill("assert “) -#        self._dispatch(t.test) -#        if t.msg: -#            self._write(”, “) -#            self._dispatch(t.msg) -# -#    def _Exec(self, t): -#        self._fill("exec “) -#        self._dispatch(t.body) -#        if t.globals: -#            self._write(” in “) -#            self._dispatch(t.globals) -#        if t.locals: -#            self._write(”, “) -#            self._dispatch(t.locals) -# -#    def _Print(self, t): -#        self._fill("print “) -#        do_comma = False -#        if t.dest: -#            self._write(">>”) -#            self._dispatch(t.dest) -#            do_comma = True -#        for e in t.values: -#            if do_comma:self._write(”, “) -#            else:do_comma=True -#            self._dispatch(e) -#        if not t.nl: -#            self._write(",”) -# -#    def _Global(self, t): -#        self._fill("global”) -#        for i, n in enumerate(t.names): -#            if i != 0: -#                self._write(",”) -#            self._write(" " + n) -# -#    def _Yield(self, t): -#        self._fill("yield") -#        if t.value: -#            self._write(" (") -#            self._dispatch(t.value) -#            self._write(")") -# -#    def _Raise(self, t): -#        self._fill('raise ‘) -#        if t.type: -#            self._dispatch(t.type) -#        if t.inst: -#            self._write(", “) -#            self._dispatch(t.inst) -#        if t.tback: -#            self._write(”, “) -#            self._dispatch(t.tback) -# -# -#    def _TryFinally(self, t): -#        self._fill("try”) -#        self._enter() -#        self._dispatch(t.body) -#        self._leave() -# -#        self._fill("finally") -#        self._enter() -#        self._dispatch(t.finalbody) -#        self._leave() -# -#    def _excepthandler(self, t): -#        self._fill("except “) -#        if t.type: -#            self._dispatch(t.type) -#        if t.name: -#            self._write(”, “) -#            self._dispatch(t.name) -#        self._enter() -#        self._dispatch(t.body) -#        self._leave() -# -#    def _ClassDef(self, t): -#        self._write("\n”) -#        self._fill("class “+t.name) -#        if t.bases: -#            self._write("(”) -#            for a in t.bases: -#                self._dispatch(a) -#                self._write(", “) -#            self._write(")”) -#        self._enter() -#        self._dispatch(t.body) -#        self._leave() -# -#    def _FunctionDef(self, t): -#        self._write("\n") -#        for deco in t.decorators: -#            self._fill("@") -#            self._dispatch(deco) -#        self._fill("def “+t.name + “(”) -#        self._dispatch(t.args) -#        self._write(")”) -#        self._enter() -#        self._dispatch(t.body) -#        self._leave() -# -#    def _For(self, t): -#        self._fill("for “) -#        self._dispatch(t.target) -#        self._write(” in “) -#        self._dispatch(t.iter) -#        self._enter() -#        self._dispatch(t.body) -#        self._leave() -#        if t.orelse: -#            self._fill("else”) -#            self._enter() -#            self._dispatch(t.orelse) -#            self._leave -# -#    def _While(self, t): -#        self._fill("while “) -#        self._dispatch(t.test) -#        self._enter() -#        self._dispatch(t.body) -#        self._leave() -#        if t.orelse: -#            self._fill("else”) -#            self._enter() -#            self._dispatch(t.orelse) -#            self._leave -# -#    # expr -#    def _Str(self, tree): -#        self._write(repr(tree.s)) -## -#    def _Repr(self, t): -#        self._write("`") -#        self._dispatch(t.value) -#        self._write("`") -# -#    def _Num(self, t): -#        self._write(repr(t.n)) -# -#    def _ListComp(self, t): -#        self._write("[") -#        self._dispatch(t.elt) -#        for gen in t.generators: -#            self._dispatch(gen) -#        self._write("]") -# -#    def _GeneratorExp(self, t): -#        self._write("(") -#        self._dispatch(t.elt) -#        for gen in t.generators: -#            self._dispatch(gen) -#        self._write(")") -# -#    def _comprehension(self, t): -#        self._write(" for “) -#        self._dispatch(t.target) -#        self._write(” in “) -#        self._dispatch(t.iter) -#        for if_clause in t.ifs: -#            self._write(” if “) -#            self._dispatch(if_clause) -# -#    def _IfExp(self, t): -#        self._dispatch(t.body) -#        self._write(” if “) -#        self._dispatch(t.test) -#        if t.orelse: -#            self._write(” else “) -#            self._dispatch(t.orelse) -# -#    unop = {"Invert":"~”, “Not”: “not”, “UAdd":"+”, “USub":"-”} -#    def _UnaryOp(self, t): -#        self._write(self.unop[t.op.__class__.__name__]) -#        self._write("(") -#        self._dispatch(t.operand) -#        self._write(")") -# -#    binop = { “Add":"+”, “Sub":"-”, “Mult":"*”, “Div":"/”, “Mod":"%”, -#                    “LShift":">>”, “RShift":"<<”, “BitOr":"|”, “BitXor":"^”, “BitAnd":"&”, -#                    “FloorDiv":"//”, “Pow”: “**”} -#    def _BinOp(self, t): -#        self._write("(") -#        self._dispatch(t.left) -#        self._write(")" + self.binop[t.op.__class__.__name</em></em>] + “(”) -#        self._dispatch(t.right) -#        self._write(")") -# -#    boolops = {_ast.And: ‘and’, _ast.Or: ‘or’} -#    def _BoolOp(self, t): -#        self._write("(") -#        self._dispatch(t.values[0]) -#        for v in t.values[1:]: -#            self._write(" %s " % self.boolops[t.op.__class__]) -#            self._dispatch(v) -#        self._write(")") -# -#    def _Attribute(self,t): -#        self._dispatch(t.value) -#        self._write(".") -#        self._write(t.attr) -# -##    def _Call(self, t): -##        self._dispatch(t.func) -##        self._write("(") -##        comma = False -##        for e in t.args: -##            if comma: self._write(", “) -##            else: comma = True -##            self._dispatch(e) -##        for e in t.keywords: -##            if comma: self._write(”, “) -##            else: comma = True -##            self._dispatch(e) -##        if t.starargs: -##            if comma: self._write(”, “) -##            else: comma = True -##            self._write("*”) -##            self._dispatch(t.starargs) -##        if t.kwargs: -##            if comma: self._write(", “) -##            else: comma = True -##            self._write("**”) -##            self._dispatch(t.kwargs) -##        self._write(")") -# -#    # slice -#    def _Index(self, t): -#        self._dispatch(t.value) -# -#    def _ExtSlice(self, t): -#        for i, d in enumerate(t.dims): -#            if i != 0: -#                self._write(’: ') -#            self._dispatch(d) -# -#    # others -#    def _arguments(self, t): -#        first = True -#        nonDef = len(t.args)-len(t.defaults) -#        for a in t.args[0:nonDef]: -#            if first:first = False -#            else: self._write(", “) -#            self._dispatch(a) -#        for a,d in zip(t.args[nonDef:], t.defaults): -#            if first:first = False -#            else: self._write(”, “) -#            self._dispatch(a), -#            self._write("=”) -#            self._dispatch(d) -#        if t.vararg: -#            if first:first = False -#            else: self._write(", “) -#            self._write("*"+t.vararg) -#        if t.kwarg: -#            if first:first = False -#            else: self._write(”, “) -#            self._write("**"+t.kwarg) -# -##    def _keyword(self, t): -##        self._write(t.arg) -##        self._write("=”) -##        self._dispatch(t.value) -# -#    def _Lambda(self, t): -#        self._write("lambda “) -#        self._dispatch(t.args) -#        self._write(”: ") -#        self._dispatch(t.body) – – –</p>
<p>This diff is so big that we needed to truncate the remainder.</p>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUoZ8PHTVVR-2B7gkeeh01YmxMmeSqcpO5dmuhR1zW2hyus-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyK4FJUjmhSuO7aORtZTN3SvFXCb0b82jbSbjedhadBJ-2FhbGF2E48nOnJIl7N5SJkd69IPKpwCz9Vdzgp1Fvyd1uyLgDZq3dtqRyxV-2F29cFz53fRRJe1uFGPrgzzKsrp7DcmmON36y8258JWlxh2fJXU-3D">https://bitbucket.org/yt_analysis/yt/commits/8274418a9da0/</a> Changeset:   8274418a9da0 Branch:      yt User:        chummels Date:        2016-03-16 15:56:51+00:00 Summary:     Making observing_redshift loop happen in its own method. Affected #:  1 file</p>
<p>diff -r 8ac0f630b3f0b6c0d12f907a4efb384794b3d0d7 -r 8274418a9da017df6f69946c00f1fe04664b099d yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -237,31 +237,16 @@</p>
<pre>"""
Add continuum features to the spectrum.
"""</pre>
<p>+        # Change the redshifts of continuum sources to account for the +        # redshift at which the observer sits +        redshift, redshift_eff = self._apply_observing_redshift(field_data, +                                 use_peculiar_velocity, observing_redshift) +</p>
<pre>        # Only add continuum features down to tau of 1.e-4.
        min_tau = 1.e-3

        for continuum in self.continuum_list:
            column_density = field_data[continuum['field_name']] * field_data['dl']</pre>
<ul><li><p>if observing_redshift == 0.:</p></li>
<li><p># This is already assumed in the generation of the LightRay</p></li>
<li><p>redshift = field_data['redshift']</p></li>
<li><p>if use_peculiar_velocity:</p></li>
<li><p>redshift_eff = field_data['redshift_eff']</p></li>
<li><p>else:</p></li>
<li><p># The intermediate redshift that is seen by an observer</p></li>
<li><p># at a redshift other than z=0 is z12, where z1 is the</p></li>
<li><p># observing redshift and z2 is the emitted photon's redshift</p></li>
<li><p># Hogg (2000) eq. 13:</p></li>
<li><p># 1 + z12 = (1 + z2) / (1 + z1)</p></li>
<li><p>redshift = ((1 + field_data['redshift']) / \</p></li>
<li><p>(1 + observing_redshift)) – 1.</p></li>
<li><p># Combining cosmological redshift and doppler redshift</p></li>
<li><p># into an effective redshift is found in Peacock's</p></li>
<li><p># Cosmological Physics eqn 3.75:</p></li>
<li><p># 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler)</p></li>
<li><p>if use_peculiar_velocity:</p></li>
<li><p>redshift_eff = ((1 + redshift) * \</p></li>
<li><p>(1 + field_data['redshift_dopp'])) – 1.</p></li></ul>
<pre># redshift_eff field combines cosmological and velocity redshifts
if use_peculiar_velocity:</pre>
<p>@@ -289,12 +274,54 @@</p>
<pre>                pbar.update(i)
            pbar.finish()
</pre>
<p>+    def _apply_observing_redshift(self, field_data, use_peculiar_velocity, +                                 observing_redshift): +        """ +        Change the redshifts of individual absorbers to account for the +        redshift at which the observer sits. + +        The intermediate redshift that is seen by an observer +        at a redshift other than z=0 is z12, where z1 is the +        observing redshift and z2 is the emitted photon's redshift +        Hogg (2000) eq. 13: + +        1 + z12 = (1 + z2) / (1 + z1) +        """ +        if observing_redshift == 0.: +            # This is already assumed in the generation of the LightRay +            redshift = field_data['redshift'] +            if use_peculiar_velocity: +                redshift_eff = field_data['redshift_eff'] +        else: +            # The intermediate redshift that is seen by an observer +            # at a redshift other than z=0 is z12, where z1 is the +            # observing redshift and z2 is the emitted photon's redshift +            # Hogg (2000) eq. 13: +            # 1 + z12 = (1 + z2) / (1 + z1) +            redshift = ((1 + field_data['redshift']) / \ +                        (1 + observing_redshift)) – 1. +            # Combining cosmological redshift and doppler redshift +            # into an effective redshift is found in Peacock's +            # Cosmological Physics eqn 3.75: +            # 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler) +            if use_peculiar_velocity: +                redshift_eff = ((1 + redshift) * \ +                                (1 + field_data['redshift_dopp'])) – 1. + +        return redshift, redshift_eff +</p>
<pre>     def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,
output_absorbers_file, subgrid_resolution=10,
observing_redshift=0., njobs=-1):
         """
         Add the absorption lines to the spectrum.
         """</pre>
<p>+ +        # Change the redshifts of individual absorbers to account for the +        # redshift at which the observer sits +        redshift, redshift_eff = self._apply_observing_redshift(field_data, +                                 use_peculiar_velocity, observing_redshift) +</p>
<pre># Widen wavelength window until optical depth falls below this tau
# value at the ends to assure that the wings of a line have been
# fully resolved.</pre>
<p>@@ -305,27 +332,6 @@</p>
<pre>        for line in parallel_objects(self.line_list, njobs=njobs):
            column_density = field_data[line['field_name']] * field_data['dl']
</pre>
<ul><li><p>if observing_redshift == 0.:</p></li>
<li><p># This is already assumed in the generation of the LightRay</p></li>
<li><p>redshift = field_data['redshift']</p></li>
<li><p>if use_peculiar_velocity:</p></li>
<li><p>redshift_eff = field_data['redshift_eff']</p></li>
<li><p>else:</p></li>
<li><p># The intermediate redshift that is seen by an observer</p></li>
<li><p># at a redshift other than z=0 is z12, where z1 is the</p></li>
<li><p># observing redshift and z2 is the emitted photon's redshift</p></li>
<li><p># Hogg (2000) eq. 13:</p></li>
<li><p># 1 + z12 = (1 + z2) / (1 + z1)</p></li>
<li><p>redshift = ((1 + field_data['redshift']) / \</p></li>
<li><p>(1 + observing_redshift)) – 1.</p></li>
<li><p># Combining cosmological redshift and doppler redshift</p></li>
<li><p># into an effective redshift is found in Peacock's</p></li>
<li><p># Cosmological Physics eqn 3.75:</p></li>
<li><p># 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler)</p></li>
<li><p>if use_peculiar_velocity:</p></li>
<li><p>redshift_eff = ((1 + redshift) * \</p></li>
<li><p>(1 + field_data['redshift_dopp'])) – 1.</p></li></ul>
<p>–</p>
<pre># redshift_eff field combines cosmological and velocity redshifts
# so delta_lambda gives the offset in angstroms from the rest frame
# wavelength to the observed wavelength of the transition</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUMM-2B4Ak6BBeVYMIG6Y7Qc3pIjV2zvd9-2BRrjE-2BJ4e-2Blrg-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyPLfRx3TQ-2B3XFLJoLyzNnXL3QfOaOwXlE3wmfS5lXyEOX-2B7w0liOh7M9uFEHvI690XE0hDvCuJAESVtGq9X-2BsN4-2BnaydFNmSRqQFMf8sH-2FxyaIiPz91NJA2e2wZddoVdhGyELQtcSK7z-2BjwJK3EFdoc-3D">https://bitbucket.org/yt_analysis/yt/commits/ad805640beab/</a> Changeset:   ad805640beab Branch:      yt User:        chummels Date:        2016-03-16 18:46:45+00:00 Summary:     Merging with tip. Affected #:  13 files</p>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 doc/source/visualizing/plots.rst --- a/doc/source/visualizing/plots.rst +++ b/doc/source/visualizing/plots.rst @@ -415,9 +415,19 @@</p>
<pre>determined by the ``thresh`` parameter, which can be varied to make the lines thicker or
thinner.
</pre>
<p>+The above example all involve 8-node hexahedral mesh elements. Here is another example from +a dataset that uses 6-node wedge elements: + +.. python-script:: + +   import yt +   ds = yt.load("MOOSE_sample_data/wedge_out.e") +   sl = yt.SlicePlot(ds, 2, ('connect2', 'diffused')) +   sl.save() +</p>
<pre>Finally, slices can also be used to examine 2D unstructured mesh datasets, but the
slices must be taken to be normal to the ``'z'`` axis, or you'll get an error. Here is</pre>
<p>-an example using another MOOSE dataset: +an example using another MOOSE dataset that uses triangular mesh elements:</p>
<pre>.. python-script::
</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 doc/source/visualizing/unstructured_mesh_rendering.rst --- a/doc/source/visualizing/unstructured_mesh_rendering.rst +++ b/doc/source/visualizing/unstructured_mesh_rendering.rst @@ -214,6 +214,29 @@</p>
<pre>    # render and save
    sc.save()
</pre>
<p>+Here is an example using 6-node wedge elements: + +.. python-script:: + +   import yt + +   ds = yt.load("MOOSE_sample_data/wedge_out.e") + +   # create a default scene +   sc = yt.create_scene(ds, ('connect2', ‘diffused')) + +   # override the default colormap +   ms = sc.get_source(0) +   ms.cmap = ‘Eos A’ + +   # adjust the camera position and orientation +   cam = sc.camera +   cam.set_position(ds.arr([1.0, -1.0, 1.0], 'code_length')) +   cam.width = ds.arr([1.5, 1.5, 1.5], 'code_length’) + +   # render and save +   sc.save() +</p>
<pre>Another example, this time plotting the temperature field from a 20-node hex
MOOSE dataset:
</pre>
<p>@@ -273,7 +296,7 @@</p>
<pre># adjust the camera position and orientation
cam = sc.camera
camera_position = ds.arr([-1.0, 1.0, -0.5], 'code_length')</pre>
<ul><li><p>north_vector = ds.arr([0.0, 1.0, 1.0], ‘dimensionless’)</p></li></ul>
<p>+    north_vector = ds.arr([0.0, -1.0, -1.0], ‘dimensionless’)</p>
<pre>cam.width = ds.arr([0.05, 0.05, 0.05], 'code_length')
cam.set_position(camera_position, north_vector)
</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 tests/tests_2.7.yaml --- a/tests/tests_2.7.yaml +++ b/tests/tests_2.7.yaml @@ -39,12 +39,13 @@</p>
<pre>local_tipsy_270:
  - yt/frontends/tipsy/tests/test_outputs.py
</pre>
<ul><li><p>local_varia_270:</p></li></ul>
<p>+  local_varia_271:</p>
<pre>- yt/analysis_modules/radmc3d_export
- yt/frontends/moab/tests/test_c5.py
- yt/analysis_modules/photon_simulator/tests/test_spectra.py
- yt/analysis_modules/photon_simulator/tests/test_sloshing.py
- yt/visualization/volume_rendering/tests/test_vr_orientation.py</pre>
<p>+    – yt/visualization/volume_rendering/tests/test_mesh_render.py</p>
<pre>local_orion_270:
  - yt/frontends/boxlib/tests/test_orion.py</pre>
<p>@@ -55,7 +56,7 @@</p>
<pre>  local_ytdata_270:
    - yt/frontends/ytdata
</pre>
<ul><li><p>local_absorption_spectrum_270:</p></li></ul>
<p>+  local_absorption_spectrum_271:</p>
<pre>    - yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py:test_absorption_spectrum_non_cosmo
    - yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py:test_absorption_spectrum_cosmo
</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -52,7 +52,9 @@</p>
<pre>def __init__(self, lambda_min, lambda_max, n_lambda):
    self.n_lambda = n_lambda
    # lambda, flux, and tau are wavelength, flux, and optical depth</pre>
<ul><li><p>self.lambda_field = YTArray(np.linspace(lambda_min, lambda_max,</p></li></ul>
<p>+        self.lambda_min = lambda_min +        self.lambda_max = lambda_max +        self.lambda_field = YTArray(np.linspace(lambda_min, lambda_max,</p>
<pre>n_lambda), "angstrom")
         self.tau_field = None
         self.flux_field = None</pre>
<p>@@ -341,8 +343,24 @@</p>
<pre>    delta_lambda = line['wavelength'] * redshift
# lambda_obs is central wavelength of line after redshift
lambda_obs = line['wavelength'] + delta_lambda</pre>
<ul><li><p># bin index in lambda_field of central wavelength of line after z</p></li>
<li><p>center_index = np.digitize(lambda_obs, self.lambda_field)</p></li></ul>
<p>+            # the total number of absorbers per transition +            n_absorbers = len(lambda_obs) + +            # we want to know the bin index in the lambda_field array +            # where each line has its central wavelength after being +            # redshifted.  however, because we don't know a priori how wide +            # a line will be (ie DLAs), we have to include bin indices +            # <strong>outside</strong> the spectral range of the AbsorptionSpectrum +            # object.  Thus, we find the “equivalent” bin index, which +            # may be <0 or >the size of the array.  In the end, we deposit +            # the bins that actually overlap with the AbsorptionSpectrum's +            # range in lambda. + +            # this equation gives us the “equivalent” bin index for each line +            # if it were placed into the self.lambda_field array +            center_index = (lambda_obs.in_units('Angstrom').d – self.lambda_min) \ +                            / self.bin_width.d +            center_index = np.ceil(center_index).astype('int')</p>
<pre># thermal broadening b parameter
thermal_b =  np.sqrt((2 * boltzmann_constant_cgs *</pre>
<p>@@ -355,7 +373,6 @@</p>
<pre># Sanitize units for faster runtime of the tau_profile machinery.
lambda_0 = line['wavelength'].d  # line's rest frame; angstroms</pre>
<ul><li><p>lambda_1 = lambda_obs.d # line's observed frame; angstroms cdens = column_density.in_units("cm**-2").d # cm**-2 thermb = thermal_b.in_cgs().d  # thermal b coefficient; cm / s dlambda = delta_lambda.d  # lambda offset; angstroms</p></li></ul>
<p>@@ -377,77 +394,90 @@</p>
<pre>#    10; this will assure we don't get spikes in the deposited
#    spectra from uneven numbers of vbins per bin
resolution = thermal_width / self.bin_width</pre>
<ul><li><p>vbin_width = self.bin_width / \</p></li>
<li><p>10**(np.ceil(np.log10(subgrid_resolution/resolution)).clip(0, np.inf))</p></li>
<li><p>vbin_width = vbin_width.in_units('angstrom').d</p></li></ul>
<p>+            n_vbins_per_bin = 10**(np.ceil(np.log10(subgrid_resolution/resolution)).clip(0, np.inf)) +            vbin_width = self.bin_width.d / n_vbins_per_bin</p>
<ul><li><p># the virtual window into which the line is deposited initially</p></li>
<li><p># spans a region of 5 thermal_widths, but this may expand</p></li>
<li><p>n_vbins = np.ceil(5*thermal_width.d/vbin_width)</p></li>
<li><p>vbin_window_width = n_vbins*vbin_width</p></li></ul>
<p>– +            # a note to the user about which lines components are unresolved</p>
<pre>if (thermal_width < self.bin_width).any():
    mylog.info(("%d out of %d line components will be " + \
                "deposited as unresolved lines.") %
               ((thermal_width < self.bin_width).sum(),</pre>
<ul><li><p>thermal_width.size))</p></li></ul>
<p>+                            n_absorbers))</p>
<ul><li><p>valid_lines = np.arange(len(thermal_width))</p></li></ul>
<p>+            # provide a progress bar with information about lines processsed</p>
<pre>pbar = get_pbar("Adding line - %s [%f A]: " % \</pre>
<ul><li><p>(line['label'], line['wavelength']),</p></li>
<li><p>thermal_width.size)</p></li></ul>
<p>+                            (line['label'], line['wavelength']), n_absorbers)</p>
<pre># for a given transition, step through each location in the
# observed spectrum where it occurs and deposit a voigt profile</pre>
<ul><li><p>for i in parallel_objects(valid_lines, njobs=-1):</p></li>
<li><p>my_vbin_window_width = vbin_window_width[i]</p></li>
<li><p>my_n_vbins = n_vbins[i]</p></li>
<li><p>my_vbin_width = vbin_width[i]</p></li></ul>
<p>+            for i in parallel_objects(np.arange(n_absorbers), njobs=-1): + +                # the virtual window into which the line is deposited initially +                # spans a region of 2 coarse spectral bins +                # (one on each side of the center_index) but the window +                # can expand as necessary. +                # it will continue to expand until the tau value in the far +                # edge of the wings is less than the min_tau value or it +                # reaches the edge of the spectrum +                window_width_in_bins = 2</p>
<pre>while True:</pre>
<p>+                    left_index = (center_index[i] – window_width_in_bins/2) +                    right_index = (center_index[i] + window_width_in_bins/2) +                    n_vbins = (right_index – left_index) * n_vbins_per_bin[i] + +                   # the array of virtual bins in lambda space</p>
<pre>vbins = \</pre>
<ul><li><p>np.linspace(lambda_1[i]-my_vbin_window_width/2.,</p></li>
<li><p>lambda_1[i]+my_vbin_window_width/2.,</p></li>
<li><p>my_n_vbins, endpoint=False)</p></li></ul>
<p>+                        np.linspace(self.lambda_min + self.bin_width.d * left_index, +                                    self.lambda_min + self.bin_width.d * right_index, +                                    n_vbins, endpoint=False)</p>
<p>+                    # the virtual bins and their corresponding opacities</p>
<pre>vbins, vtau = \
    tau_profile(</pre>
<ul><li><p>lambda_0, line['f_value'], line['gamma'], thermb[i],</p></li>
<li><p>cdens[i], delta_lambda=dlambda[i],</p></li>
<li><p>lambda_bins=vbins)</p></li></ul>
<p>+                            lambda_0, line['f_value'], line['gamma'], +                            thermb[i], cdens[i], +                            delta_lambda=dlambda[i], lambda_bins=vbins)</p>
<pre># If tau has not dropped below min tau threshold by the
# edges (ie the wings), then widen the wavelength
# window and repeat process.
if (vtau[0] < min_tau and vtau[-1] < min_tau):
    break</pre>
<ul><li><p>my_vbin_window_width *= 2</p></li>
<li><p>my_n_vbins *= 2</p></li></ul>
<p>–</p>
<ul><li><p># identify the extrema of the vbin_window so as to speed</p></li>
<li><p># up searching over the entire lambda_field array</p></li>
<li><p>bins_from_center = np.ceil((my_vbin_window_width/2.) / \</p></li>
<li><p>self.bin_width.d) + 1</p></li>
<li><p>left_index = (center_index[i] – bins_from_center).clip(0, self.n_lambda)</p></li>
<li><p>right_index = (center_index[i] + bins_from_center).clip(0, self.n_lambda)</p></li>
<li><p>window_width = right_index – left_index</p></li></ul>
<p>–</p>
<ul><li><p># run digitize to identify which vbins are deposited into which</p></li>
<li><p># global lambda bins.</p></li>
<li><p># shift global lambda bins over by half a bin width;</p></li>
<li><p># this has the effect of assuring np.digitize will place</p></li>
<li><p># the vbins in the closest bin center.</p></li>
<li><p>binned = np.digitize(vbins,</p></li>
<li><p>self.lambda_field[left_index:right_index] \</p></li>
<li><p>+ (0.5 * self.bin_width))</p></li></ul>
<p>+                    window_width_in_bins *= 2</p>
<pre># numerically integrate the virtual bins to calculate a
# virtual equivalent width; then sum the virtual equivalent
# widths and deposit into each spectral bin</pre>
<ul><li><p>vEW = vtau * my_vbin_width</p></li>
<li><p>EW = [vEW[binned == j].sum() for j in np.arange(window_width)]</p></li>
<li><p>EW = np.array(EW)/self.bin_width.d</p></li>
<li><p>self.tau_field[left_index:right_index] += EW</p></li></ul>
<p>+                vEW = vtau * vbin_width[i] +                EW = np.zeros(right_index – left_index) +                EW_indices = np.arange(left_index, right_index) +                for k, val in enumerate(EW_indices): +                    EW[k] = vEW[n_vbins_per_bin[i] * k: \ +                                n_vbins_per_bin[i] * (k + 1)].sum() +                EW = EW/self.bin_width.d + +                # only deposit EW bins that actually intersect the original +                # spectral wavelength range (i.e. lambda_field) + +                # if EW bins don't intersect the original spectral range at all +                # then skip the deposition +                if ((left_index >= self.n_lambda) or \ +                    (right_index < 0)): +                    pbar.update(i) +                    continue + +                # otherwise, determine how much of the original spectrum +                # is intersected by the expanded line window to be deposited, +                # and deposit the Equivalent Width data into that intersecting +                # window in the original spectrum's tau +                else: +                    intersect_left_index = max(left_index, 0) +                    intersect_right_index = min(right_index, self.n_lambda-1) +                    self.tau_field[intersect_left_index:intersect_right_index] \ +                        += EW[(intersect_left_index – left_index): \ +                              (intersect_right_index – left_index)] +</p>
<pre># write out absorbers to file if the column density of
# an absorber is greater than the specified "label_threshold"</pre>
<p>@@ -471,9 +501,8 @@</p>
<pre>            pbar.finish()

            del column_density, delta_lambda, lambda_obs, center_index, \</pre>
<ul><li><p>thermal_b, thermal_width, lambda_1, cdens, thermb, dlambda, \</p></li>
<li><p>vlos, resolution, vbin_width, n_vbins, vbin_window_width, \</p></li>
<li><p>valid_lines, vbins, vtau, vEW</p></li></ul>
<p>+                thermal_b, thermal_width, cdens, thermb, dlambda, \ +                vlos, resolution, vbin_width, n_vbins, n_vbins_per_bin</p>
<pre>comm = _get_comm(())
self.tau_field = comm.mpi_allreduce(self.tau_field, op="sum")</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/tests/test_absorption_spectrum.py @@ -180,9 +180,9 @@</p>
<pre>wavelength, flux = sp.make_spectrum('lightray.h5')
total_tau.append((lambda_bin_width * sp.tau_field).sum())
</pre>
<ul><li><p># assure that the total tau values are all within 1e-5 of each other</p></li></ul>
<p>+    # assure that the total tau values are all within 1e-3 of each other</p>
<pre>for tau in total_tau:</pre>
<ul><li><p>assert_almost_equal(tau, total_tau[0], 5)</p></li></ul>
<p>+        assert_almost_equal(tau, total_tau[0], 3)</p>
<pre># clean up
os.chdir(curdir)</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 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 @@ -480,6 +480,9 @@</p>
<pre>sub_vel_mag = sub_ray['velocity_magnitude']
cos_theta = np.dot(line_of_sight, sub_vel) / sub_vel_mag</pre>
<p>+                    # Protect against stituations where velocity mag is exactly +                    # zero, in which case zero / zero = NaN. +                    cos_theta = np.nan_to_num(cos_theta)</p>
<pre>redshift_dopp = \
    (1 + sub_vel_mag * cos_theta / speed_of_light_cgs) / \
     np.sqrt(1 - sub_vel_mag**2 / speed_of_light_cgs**2) - 1</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/data_objects/static_output.py --- a/yt/data_objects/static_output.py +++ b/yt/data_objects/static_output.py @@ -451,6 +451,7 @@</p>
<pre>deps, unloaded = self.field_info.check_derived_fields()
self.field_dependencies.update(deps)
self.fields = FieldTypeContainer(self)</pre>
<p>+        self.index.field_list = sorted(self.field_list)</p>
<pre>def setup_deprecated_fields(self):
    from yt.fields.field_aliases import _field_name_aliases</pre>
<p>@@ -520,7 +521,10 @@</p>
<pre>self.particle_types += (union.name,)
self.particle_unions[union.name] = union
fields = [ (union.name, field) for field in fields]</pre>
<ul><li><p>self.field_list.extend(fields)</p></li></ul>
<p>+        new_fields = [_ for _ in fields if _ not in self.field_list] +        self.field_list.extend(new_fields) +        self.field_info.field_list.extend(new_fields) +        self.index.field_list = sorted(self.field_list)</p>
<pre># Give ourselves a chance to add them here, first, then...
# ...if we can't find them, we set them up as defaults.
new_fields = self._setup_particle_types([union.name])</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/frontends/boxlib/data_structures.py --- a/yt/frontends/boxlib/data_structures.py +++ b/yt/frontends/boxlib/data_structures.py @@ -41,6 +41,7 @@</p>
<pre>    MaestroFieldInfo, \
    CastroFieldInfo
</pre>
<p>+</p>
<pre># This is what we use to find scientific notation that might include d's
# instead of e's.
_scinot_finder = re.compile(r"[-+]?[0-9]*\.?[0-9]+([eEdD][-+]?[0-9]+)?")</pre>
<p>@@ -907,7 +908,7 @@</p>
<pre>        self._read_particle_header()

    def _read_particle_header(self):</pre>
<ul><li><p>if not self.ds.parameters["particles.write_in_plotfile"]:</p></li></ul>
<p>+        if not self.ds.parameters["particles"]:</p>
<pre>self.pgrid_info = np.zeros((self.num_grids, 3), dtype='int64')
return
         for fn in ['particle_position_%s' % ax for ax in 'xyz'] + \</pre>
<p>@@ -949,31 +950,48 @@</p>
<pre>@classmethod
def _is_valid(cls, *args, **kwargs):
    # fill our args</pre>
<ul><li><p>pname = args[0].rstrip("/")</p></li></ul>
<p>+        output_dir = args[0]</p>
<pre># boxlib datasets are always directories</pre>
<ul><li><p>if not os.path.isdir(pname): return False</p></li>
<li><p>dn = os.path.dirname(pname)</p></li>
<li><p>if len(args) > 1:</p></li>
<li><p>kwargs['paramFilename'] = args[1]</p></li></ul>
<p>–</p>
<ul><li><p>pfname = kwargs.get("paramFilename", os.path.join(dn, "inputs"))</p></li></ul>
<p>–</p>
<ul><li><p># @todo: new Nyx output.</p></li>
<li><p># We check for the job_info file's existence because this is currently</p></li>
<li><p># what distinguishes Nyx data from MAESTRO data.</p></li>
<li><p>pfn = os.path.join(pfname)</p></li>
<li><p>if not os.path.exists(pfn) or os.path.isdir(pfn): return False</p></li>
<li><p>nyx = any(("nyx." in line for line in open(pfn)))</p></li>
<li><p>return nyx</p></li></ul>
<p>+        if not os.path.isdir(output_dir): return False +        header_filename = os.path.join(output_dir, “Header”) +        jobinfo_filename = os.path.join(output_dir, “job_info”) +        if not os.path.exists(header_filename): +            # We <strong>know</strong> it's not boxlib if Header doesn't exist. +            return False +        if not os.path.exists(jobinfo_filename): +            return False +        # Now we check the job_info for the mention of maestro +        lines = open(jobinfo_filename).readlines() +        if any(line.startswith("Nyx  “) for line in lines): return True +        if any(line.startswith("nyx.”) for line in lines): return True +        return False</p>
<pre>def _parse_parameter_file(self):
    super(NyxDataset, self)._parse_parameter_file()</pre>
<ul><li><p># return</p></li></ul>
<p>+</p>
<pre># Nyx is always cosmological.
self.cosmological_simulation = 1</pre>
<ul><li><p>self.omega_lambda = self.parameters["comoving_OmL"]</p></li>
<li><p>self.omega_matter = self.parameters["comoving_OmM"]</p></li>
<li><p>self.hubble_constant = self.parameters["comoving_h"]</p></li></ul>
<p>+ +        jobinfo_filename = os.path.join(self.output_dir, “job_info”) +        line = "" +        with open(jobinfo_filename, “r”) as f: +            while not line.startswith(" Cosmology Information"): +                # get the code git hashes +                if “git hash” in line: +                    # line format: codename git hash:  the-hash +                    fields = line.split(":") +                    self.parameters[fields[0]] = fields[1].strip() +                line = next(f) + +            # get the cosmology +            for line in f: +                if “Omega_m (comoving)” in line: +                    self.omega_matter = float(line.split(":")[1]) +                elif “Omega_lambda (comoving)” in line: +                    self.omega_lambda = float(line.split(":")[1]) +                elif “h (comoving)” in line: +                    self.hubble_constant = float(line.split(":")[1]) +</p>
<pre># Read in the `comoving_a` file and parse the value. We should fix this
# in the new Nyx output format...</pre>
<p>@@ -987,7 +1005,9 @@</p>
<pre># alias
self.current_redshift = self.parameters["CosmologyCurrentRedshift"]</pre>
<ul><li><p>if self.parameters["particles.write_in_plotfile"]:</p></li></ul>
<p>+        if os.path.isdir(os.path.join(self.output_dir, “DM")): +            # we have particles +            self.parameters["particles”] = 1</p>
<pre>            self.particle_types = ("io",)
            self.particle_types_raw = self.particle_types
</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/frontends/exodus_ii/data_structures.py --- a/yt/frontends/exodus_ii/data_structures.py +++ b/yt/frontends/exodus_ii/data_structures.py @@ -354,6 +354,11 @@</p>
<pre>displaced_coords = self._apply_displacement(coords, mesh_id)
mi = np.minimum(displaced_coords.min(axis=0), mi)
ma = np.maximum(displaced_coords.max(axis=0), ma)</pre>
<p>+ +        # pad domain boundaries +        width = ma – mi +        mi -= 0.1 * width +        ma += 0.1 * width</p>
<pre>        return mi, ma

    @classmethod</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/visualization/volume_rendering/camera.py --- a/yt/visualization/volume_rendering/camera.py +++ b/yt/visualization/volume_rendering/camera.py @@ -133,11 +133,13 @@</p>
<pre>self.light = None
self.data_source = data_source_or_all(data_source)
self._resolution = (512, 512)</pre>
<p>+</p>
<pre>         if self.data_source is not None:
self.scene.set_new_unit_registry(self.data_source.ds.unit_registry)
self._focus = self.data_source.ds.domain_center
self._position = self.data_source.ds.domain_right_edge</pre>
<ul><li><p>self._width = 1.5*self.data_source.ds.domain_width</p></li></ul>
<p>+            self._width = self.data_source.ds.arr( +                [1.5*self.data_source.ds.domain_width.max()]*3)</p>
<pre>self._domain_center = self.data_source.ds.domain_center
self._domain_width = self.data_source.ds.domain_width
         else:</pre>
<p>@@ -175,7 +177,8 @@</p>
<pre>    raise RuntimeError(
        'Cannot set the camera focus and position to the same value')
self._position = position</pre>
<ul><li><p>self.switch_orientation()</p></li></ul>
<p>+            self.switch_orientation(normal_vector=self.focus – self._position, +                                    north_vector=None)</p>
<pre>         def fdel(self):
del self._position</pre>
<p>@@ -232,7 +235,8 @@</p>
<pre>    raise RuntimeError(
        'Cannot set the camera focus and position to the same value')
self._focus = focus</pre>
<ul><li><p>self.switch_orientation()</p></li></ul>
<p>+            self.switch_orientation(normal_vector=self.focus – self._position, +                                    north_vector=None)</p>
<pre>         def fdel(self):
del self._focus</pre>
<p>@@ -327,7 +331,7 @@</p>
<pre>         if not isinstance(width, YTArray):
width = data_source.ds.arr(width, input_units="code_length")
         if not isinstance(focus, YTArray):</pre>
<ul><li><p>focus = self.ds.arr(focus, input_units="code_length")</p></li></ul>
<p>+            focus = data_source.ds.arr(focus, input_units="code_length")</p>
<pre># We can't use the property setters yet, since they rely on attributes
# that will not be set up until the base class initializer is called.</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/visualization/volume_rendering/off_axis_projection.py --- a/yt/visualization/volume_rendering/off_axis_projection.py +++ b/yt/visualization/volume_rendering/off_axis_projection.py @@ -155,7 +155,7 @@</p>
<pre>camera.resolution = resolution
if not iterable(width):
    width = data_source.ds.arr([width]*3)</pre>
<ul><li><p>camera.position = center – width[2]*camera.normal_vector</p></li></ul>
<p>+    camera.position = center – width[2]*normal_vector</p>
<pre>camera.focus = center

# If north_vector is None, we set the default here.</pre>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/visualization/volume_rendering/tests/test_mesh_render.py --- a/yt/visualization/volume_rendering/tests/test_mesh_render.py +++ b/yt/visualization/volume_rendering/tests/test_mesh_render.py @@ -11,11 +11,18 @@</p>
<pre># The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
</pre>
<p>-from yt.testing import fake_tetrahedral_ds -from yt.testing import fake_hexahedral_ds -from yt.testing import requires_module -from yt.visualization.volume_rendering.render_source import MeshSource -from yt.visualization.volume_rendering.scene import Scene +from yt.testing import \ +    fake_tetrahedral_ds, \ +    fake_hexahedral_ds, \ +    requires_module +from yt.utilities.answer_testing.framework import \ +    requires_ds, \ +    data_dir_load, \ +    GenericImageTest +from yt.visualization.volume_rendering.api import \ +    MeshSource, \ +    Scene, \ +    create_scene</p>
<pre>@requires_module("pyembree")</pre>
<p>@@ -39,3 +46,101 @@</p>
<pre>        images.append(im)

    return images</pre>
<p>+ + +def compare(ds, im, test_prefix, decimals=12): +    def mesh_render_image_func(filename_prefix): +        return im.write_image(filename_prefix) + +    test = GenericImageTest(ds, mesh_render_image_func, decimals) +    test.prefix = test_prefix +    return test + +hex8 = “MOOSE_sample_data/out.e-s010” +hex8_fields = [('connect1', ‘diffused'), ('connect2’, ‘convected')] + +@requires_ds(hex8) +@requires_module("pyembree") +def test_hex8_render(): +    for field in hex8_fields: +        ds = data_dir_load(hex8, kwargs={'step':-1}) +        sc = create_scene(ds, field) +        im = sc.render() +        yield compare(ds, im, “render_answers_hex8_%s_%s” % field) + + +tet4 = “MOOSE_sample_data/high_order_elems_tet4_refine_out.e” +tet4_fields = [("connect1", “u")] + +@requires_ds(tet4) +@requires_module("pyembree”) +def test_tet4_render(): +    for field in tet4_fields: +        ds = data_dir_load(tet4, kwargs={'step':-1}) +        sc = create_scene(ds, field) +        im = sc.render() +        yield compare(ds, im, “render_answers_tet4_%s_%s” % field) + + +hex20 = “MOOSE_sample_data/mps_out.e” +hex20_fields = [('connect2’, ‘temp')] + +@requires_ds(hex20) +@requires_module("pyembree") +def test_hex20_render(): +    for field in hex20_fields: +        ds = data_dir_load(hex20, kwargs={'step':-1}) +        sc = create_scene(ds, field) +        im = sc.render() +        yield compare(ds, im, “render_answers_hex20_%s_%s” % field) + + +wedge6 = “MOOSE_sample_data/wedge_out.e” +wedge6_fields = [('connect1’, ‘diffused')] + +@requires_ds(wedge6) +@requires_module("pyembree") +def test_wedge6_render(): +    for field in wedge6_fields: +        ds = data_dir_load(wedge6, kwargs={'step':-1}) +        sc = create_scene(ds, field) +        im = sc.render() +        yield compare(ds, im, “render_answers_wedge6_%s_%s” % field) + + +@requires_ds(hex8) +@requires_module("pyembree") +def test_perspective_mesh_render(): +    ds = data_dir_load(hex8) +    sc = create_scene(ds, ("connect2", “diffused")) + +    cam = sc.add_camera(ds, lens_type='perspective’) +    cam.focus = ds.arr([0.0, 0.0, 0.0], ‘code_length’) +    cam_pos = ds.arr([-4.5, 4.5, -4.5], ‘code_length’) +    north_vector = ds.arr([0.0, -1.0, -1.0], ‘dimensionless’) +    cam.set_position(cam_pos, north_vector) +    cam.resolution = (800, 800) +    im = sc.render() +    yield compare(ds, im, “perspective_mesh_render”) + + +@requires_ds(hex8) +@requires_module("pyembree”) +def test_composite_mesh_render(): +    ds = data_dir_load(hex8) +    sc = Scene() +    cam = sc.add_camera(ds) +    cam.focus = ds.arr([0.0, 0.0, 0.0], ‘code_length’) +    cam.set_position(ds.arr([-3.0, 3.0, -3.0], ‘code_length'), +                     ds.arr([0.0, -1.0, 0.0], ‘dimensionless')) +    cam.set_width = ds.arr([8.0, 8.0, 8.0], ‘code_length’) +    cam.resolution = (800, 800) + +    ms1 = MeshSource(ds, ('connect1’, 'diffused')) +    ms2 = MeshSource(ds, ('connect2’, 'diffused')) + +    sc.add_source(ms1) +    sc.add_source(ms2) + +    im = sc.render() +    yield compare(ds, im, “composite_mesh_render”)</p>
<p>diff -r 8274418a9da017df6f69946c00f1fe04664b099d -r ad805640beab44a19be7d3e56ac39532d9dfb604 yt/visualization/volume_rendering/transfer_functions.py --- a/yt/visualization/volume_rendering/transfer_functions.py +++ b/yt/visualization/volume_rendering/transfer_functions.py @@ -29,7 +29,7 @@</p>
<pre>Transfer functions are defined by boundaries, bins, and the value that
governs transmission through that bin.  This is scaled between 0 and 1.</pre>
<ul><li><p>When integrating through a volume. the value through a given cell is</p></li></ul>
<p>+    When integrating through a volume the value through a given cell is</p>
<pre>    defined by the value calculated in the transfer function.

    Parameters</pre>
<p>@@ -38,7 +38,7 @@</p>
<pre>    The min and max for the transfer function.  Values below or above
    these values are discarded.
nbins : int</pre>
<ul><li><p>How many bins to calculate; in betwee, linear interpolation is</p></li></ul>
<p>+        How many bins to calculate; in between, linear interpolation is</p>
<pre>        used, so low values are typically fine.

    Notes</pre>
<p>@@ -63,7 +63,7 @@</p>
<pre>    def add_gaussian(self, location, width, height):
        r"""Add a Gaussian distribution to the transfer function.
</pre>
<ul><li><p>Typically, when rendering isocontours, a Guassian distribution is the</p></li></ul>
<p>+        Typically, when rendering isocontours, a Gaussian distribution is the</p>
<pre>        easiest way to draw out features.  The spread provides a softness.
        The values are calculated as :math:`f(x) = h \exp{-(x-x_0)^2 / w}`.
</pre>
<p>@@ -239,7 +239,7 @@</p>
<pre>class MultiVariateTransferFunction(object):
    r"""This object constructs a set of field tables that allow for</pre>
<ul><li><p>multiple field variables to control the integration through a volme.</p></li></ul>
<p>+    multiple field variables to control the integration through a volume.</p>
<pre>The integration through a volume typically only utilizes a single field
variable (for instance, Density) to set up and control the values</pre>
<p>@@ -825,7 +825,7 @@</p>
<pre>this transfer function should be used.  It will create a very simple
table that merely sums along each ray.  Note that the end product will
need to be scaled by the total width through which the rays were cast,</pre>
<ul><li><p>a piece of information inacessible to the transfer function.</p></li></ul>
<p>+    a piece of information inaccessible to the transfer function.</p>
<pre>Parameters
----------</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUu2SOyHSzpMOSQAZl9RumugpTkheyO-2Bk2r742rJYXSpc-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyF9CxJqfznWKbPk8bkRNudQBCry7JfigOnWUOTdoKiVPA-2BP8Y2BDcN4Py7DckhdjY4VcvqI3AfWqG-2BAw9z4kTP5PJ8j-2Fgs7igf2sNwqogIT-2BR5lCNfOiotDo-2BwG8M4Om-2FXaYKbMxg5EqdQ3n-2FLCGHQ0-3D">https://bitbucket.org/yt_analysis/yt/commits/0c002ab73f18/</a> Changeset:   0c002ab73f18 Branch:      yt User:        chummels Date:        2016-03-16 18:49:03+00:00 Summary:     Shifting absorption spectrum method order to retain logical grouping. Affected #:  1 file</p>
<p>diff -r ad805640beab44a19be7d3e56ac39532d9dfb604 -r 0c002ab73f180837a684aa1f86e18026b5bfa02f yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -234,6 +234,42 @@</p>
<pre>        del field_data
        return (self.lambda_field, self.flux_field)
</pre>
<p>+    def _apply_observing_redshift(self, field_data, use_peculiar_velocity, +                                 observing_redshift): +        """ +        Change the redshifts of individual absorbers to account for the +        redshift at which the observer sits. + +        The intermediate redshift that is seen by an observer +        at a redshift other than z=0 is z12, where z1 is the +        observing redshift and z2 is the emitted photon's redshift +        Hogg (2000) eq. 13: + +        1 + z12 = (1 + z2) / (1 + z1) +        """ +        if observing_redshift == 0.: +            # This is already assumed in the generation of the LightRay +            redshift = field_data['redshift'] +            if use_peculiar_velocity: +                redshift_eff = field_data['redshift_eff'] +        else: +            # The intermediate redshift that is seen by an observer +            # at a redshift other than z=0 is z12, where z1 is the +            # observing redshift and z2 is the emitted photon's redshift +            # Hogg (2000) eq. 13: +            # 1 + z12 = (1 + z2) / (1 + z1) +            redshift = ((1 + field_data['redshift']) / \ +                        (1 + observing_redshift)) – 1. +            # Combining cosmological redshift and doppler redshift +            # into an effective redshift is found in Peacock's +            # Cosmological Physics eqn 3.75: +            # 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler) +            if use_peculiar_velocity: +                redshift_eff = ((1 + redshift) * \ +                                (1 + field_data['redshift_dopp'])) – 1. + +        return redshift, redshift_eff +</p>
<pre>     def _add_continua_to_spectrum(self, field_data, use_peculiar_velocity,
observing_redshift=0.):
         """</pre>
<p>@@ -276,42 +312,6 @@</p>
<pre>                pbar.update(i)
            pbar.finish()
</pre>
<ul><li><p>def _apply_observing_redshift(self, field_data, use_peculiar_velocity,</p></li>
<li><p>observing_redshift):</p></li>
<li><p>"""</p></li>
<li><p>Change the redshifts of individual absorbers to account for the</p></li>
<li><p>redshift at which the observer sits.</p></li></ul>
<p>–</p>
<ul><li><p>The intermediate redshift that is seen by an observer</p></li>
<li><p>at a redshift other than z=0 is z12, where z1 is the</p></li>
<li><p>observing redshift and z2 is the emitted photon's redshift</p></li>
<li><p>Hogg (2000) eq. 13:</p></li></ul>
<p>–</p>
<ul><li><p>1 + z12 = (1 + z2) / (1 + z1)</p></li>
<li><p>"""</p></li>
<li><p>if observing_redshift == 0.:</p></li>
<li><p># This is already assumed in the generation of the LightRay</p></li>
<li><p>redshift = field_data['redshift']</p></li>
<li><p>if use_peculiar_velocity:</p></li>
<li><p>redshift_eff = field_data['redshift_eff']</p></li>
<li><p>else:</p></li>
<li><p># The intermediate redshift that is seen by an observer</p></li>
<li><p># at a redshift other than z=0 is z12, where z1 is the</p></li>
<li><p># observing redshift and z2 is the emitted photon's redshift</p></li>
<li><p># Hogg (2000) eq. 13:</p></li>
<li><p># 1 + z12 = (1 + z2) / (1 + z1)</p></li>
<li><p>redshift = ((1 + field_data['redshift']) / \</p></li>
<li><p>(1 + observing_redshift)) – 1.</p></li>
<li><p># Combining cosmological redshift and doppler redshift</p></li>
<li><p># into an effective redshift is found in Peacock's</p></li>
<li><p># Cosmological Physics eqn 3.75:</p></li>
<li><p># 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler)</p></li>
<li><p>if use_peculiar_velocity:</p></li>
<li><p>redshift_eff = ((1 + redshift) * \</p></li>
<li><p>(1 + field_data['redshift_dopp'])) – 1.</p></li></ul>
<p>–</p>
<ul><li><p>return redshift, redshift_eff</p></li></ul>
<p>–</p>
<pre>     def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,
output_absorbers_file, subgrid_resolution=10,
observing_redshift=0., njobs=-1):</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUGKYWZmy7muRqC0LhKWfJ-2BH60MvWOatmJaM7S4EW-2BFC0-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyHOMXlZBaLB6l9hv-2BxKoITPYUPSZ4rzrN1Gqad2I-2B0DllOUEUWx-2BO5V3ArBu-2Fp4YNpYgbVbqmZujzcm-2Bai9-2B1qjS8yCTYUDb325iCda7UnTTMqPNhwKypwy0X2-2BDe6ZbUhqKNDxb0-2F5ldsCnQFhI9E8-3D">https://bitbucket.org/yt_analysis/yt/commits/44cd6dd59d4f/</a> Changeset:   44cd6dd59d4f Branch:      yt User:        chummels Date:        2016-03-16 20:56:32+00:00 Summary:     Correcting pyflake issue with bad indentation. Affected #:  1 file</p>
<p>diff -r 0c002ab73f180837a684aa1f86e18026b5bfa02f -r 44cd6dd59d4f0b38313af14565aba9f4723a3b54 yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -426,7 +426,7 @@</p>
<pre>right_index = (center_index[i] + window_width_in_bins/2)
n_vbins = (right_index - left_index) * n_vbins_per_bin[i]
</pre>
<ul><li><p># the array of virtual bins in lambda space</p></li></ul>
<p>+                    # the array of virtual bins in lambda space</p>
<pre>vbins = \
    np.linspace(self.lambda_min + self.bin_width.d * left_index,
                self.lambda_min + self.bin_width.d * right_index,</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOURVLnwI9JFXOUwxpRdpSKLAcIhiHmOPDaWGUUyUZVytk-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyIikNZBe0bOc84y0piuZVyA080JVH-2BBZH1XntfG70QQxH0BlQ1rYEgfatGBZUKtcHAcz7B85sYA-2FeFFssthU8OxLFpJaEOiwjCWTpiCcuoY5rI-2BTNgJqE525VBMz7zjdx2Q5WIoMgTYzM-2FxHdpbSI-2Bw-3D">https://bitbucket.org/yt_analysis/yt/commits/b00711a542af/</a> Changeset:   b00711a542af Branch:      yt User:        ngoldbaum Date:        2016-03-23 20:50:32+00:00 Summary:     Merged in chummels/yt (pull request #2044)</p>
<p>Adding observing_redshift kwarg to AbsorptionSpectrum Affected #:  1 file</p>
<p>diff -r a58aff2c0219d6abd66ffc128fd82b3c6fbde296 -r b00711a542af2b45a03e6aec8ee35ee83b0d3ccc yt/analysis_modules/absorption_spectrum/absorption_spectrum.py --- a/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py +++ b/yt/analysis_modules/absorption_spectrum/absorption_spectrum.py @@ -119,8 +119,9 @@</p>
<pre>     def make_spectrum(self, input_file, output_file=None,
line_list_file=None, output_absorbers_file=None,</pre>
<ul><li><p>use_peculiar_velocity=True,</p></li>
<li><p>subgrid_resolution=10, njobs="auto"):</p></li></ul>
<p>+                      use_peculiar_velocity=True, +                      subgrid_resolution=10, observing_redshift=0., +                      njobs="auto"):</p>
<pre>        """
        Make spectrum from ray data using the line list.
</pre>
<p>@@ -130,33 +131,38 @@</p>
<pre>         input_file : string or dataset
path to input ray data or a loaded ray dataset
         output_file : optional, string</pre>
<ul><li><p>Option to save a file containing the wavelength, flux, and optical</p></li>
<li><p>depth fields.  File formats are chosen based on the filename extension.</p></li>
<li><p>``.h5`` for hdf5, ``.fits`` for fits, and everything else is ASCII.</p></li></ul>
<p>+           Option to save a file containing the wavelength, flux, and optical +           depth fields.  File formats are chosen based on the filename +           extension. ``.h5`` for hdf5, ``.fits`` for fits, and everything +           else is ASCII.</p>
<pre>Default: None
         output_absorbers_file : optional, string</pre>
<ul><li><p>Option to save a text file containing all of the absorbers and</p></li></ul>
<p>+           Option to save a text file containing all of the absorbers and</p>
<pre>corresponding wavelength and redshift information.
For parallel jobs, combining the lines lists can be slow so it
is recommended to set to None in such circumstances.
Default: None
         use_peculiar_velocity : optional, bool
if True, include peculiar velocity for calculating doppler redshift</pre>
<ul><li><p>to shift lines.  Requires similar flag to be set in LightRay</p></li></ul>
<p>+           to shift lines.  Requires similar flag to be set in LightRay</p>
<pre>generation.
Default: True
         subgrid_resolution : optional, int
When a line is being added that is unresolved (ie its thermal
width is less than the spectral bin width), the voigt profile of</pre>
<ul><li><p>the line is deposited into an array of virtual wavelength bins at</p></li>
<li><p>higher resolution.  The optical depth from these virtual bins is</p></li>
<li><p>integrated and then added to the coarser spectral wavelength bin.</p></li>
<li><p>The subgrid_resolution value determines the ratio between the</p></li>
<li><p>thermal width and the bin width of the virtual bins.  Increasing</p></li>
<li><p>this value yields smaller virtual bins, which increases accuracy,</p></li>
<li><p>but is more expensive.  A value of 10 yields accuracy to the 4th</p></li></ul>
<p>+           the line is deposited into an array of virtual wavelength bins at +           higher resolution.  The optical depth from these virtual bins is +           integrated and then added to the coarser spectral wavelength bin. +           The subgrid_resolution value determines the ratio between the +           thermal width and the bin width of the virtual bins.  Increasing +           this value yields smaller virtual bins, which increases accuracy, +           but is more expensive.  A value of 10 yields accuracy to the 4th</p>
<pre>significant digit in tau.
Default: 10</pre>
<p>+        observing_redshift : optional, float +           This is the redshift at which the observer is observing +           the absorption spectrum. +           Default: 0</p>
<pre>         njobs : optional, int or "auto"
the number of process groups into which the loop over
absorption lines will be divided.  If set to -1, each</pre>
<p>@@ -183,6 +189,9 @@</p>
<pre>input_fields.append('redshift_eff')
field_units["velocity_los"] = "cm/s"
field_units["redshift_eff"] = ""</pre>
<p>+        if observing_redshift != 0.: +            input_fields.append('redshift_dopp') +            field_units["redshift_dopp"] = ""</p>
<pre>         for feature in self.line_list + self.continuum_list:
if not feature['field_name'] in input_fields:
    input_fields.append(feature['field_name'])</pre>
<p>@@ -204,8 +213,10 @@</p>
<pre>         self._add_lines_to_spectrum(field_data, use_peculiar_velocity,
output_absorbers_file,
subgrid_resolution=subgrid_resolution,</pre>
<p>+                                    observing_redshift=observing_redshift,</p>
<pre>njobs=njobs)</pre>
<ul><li><p>self._add_continua_to_spectrum(field_data, use_peculiar_velocity)</p></li></ul>
<p>+        self._add_continua_to_spectrum(field_data, use_peculiar_velocity, +                                       observing_redshift=observing_redshift)</p>
<pre>        self.flux_field = np.exp(-self.tau_field)
</pre>
<p>@@ -223,20 +234,63 @@</p>
<pre>        del field_data
        return (self.lambda_field, self.flux_field)
</pre>
<ul><li><p>def _add_continua_to_spectrum(self, field_data, use_peculiar_velocity):</p></li></ul>
<p>+    def _apply_observing_redshift(self, field_data, use_peculiar_velocity, +                                 observing_redshift): +        """ +        Change the redshifts of individual absorbers to account for the +        redshift at which the observer sits. + +        The intermediate redshift that is seen by an observer +        at a redshift other than z=0 is z12, where z1 is the +        observing redshift and z2 is the emitted photon's redshift +        Hogg (2000) eq. 13: + +        1 + z12 = (1 + z2) / (1 + z1) +        """ +        if observing_redshift == 0.: +            # This is already assumed in the generation of the LightRay +            redshift = field_data['redshift'] +            if use_peculiar_velocity: +                redshift_eff = field_data['redshift_eff'] +        else: +            # The intermediate redshift that is seen by an observer +            # at a redshift other than z=0 is z12, where z1 is the +            # observing redshift and z2 is the emitted photon's redshift +            # Hogg (2000) eq. 13: +            # 1 + z12 = (1 + z2) / (1 + z1) +            redshift = ((1 + field_data['redshift']) / \ +                        (1 + observing_redshift)) – 1. +            # Combining cosmological redshift and doppler redshift +            # into an effective redshift is found in Peacock's +            # Cosmological Physics eqn 3.75: +            # 1 + z_eff = (1 + z_cosmo) * (1 + z_doppler) +            if use_peculiar_velocity: +                redshift_eff = ((1 + redshift) * \ +                                (1 + field_data['redshift_dopp'])) – 1. + +        return redshift, redshift_eff + +    def _add_continua_to_spectrum(self, field_data, use_peculiar_velocity, +                                  observing_redshift=0.):</p>
<pre>"""
Add continuum features to the spectrum.
"""</pre>
<p>+        # Change the redshifts of continuum sources to account for the +        # redshift at which the observer sits +        redshift, redshift_eff = self._apply_observing_redshift(field_data, +                                 use_peculiar_velocity, observing_redshift) +</p>
<pre>        # Only add continuum features down to tau of 1.e-4.
        min_tau = 1.e-3

        for continuum in self.continuum_list:
            column_density = field_data[continuum['field_name']] * field_data['dl']</pre>
<p>+</p>
<pre># redshift_eff field combines cosmological and velocity redshifts
if use_peculiar_velocity:</pre>
<ul><li><p>delta_lambda = continuum['wavelength'] * field_data['redshift_eff']</p></li></ul>
<p>+                delta_lambda = continuum['wavelength'] * redshift_eff</p>
<pre>else:</pre>
<ul><li><p>delta_lambda = continuum['wavelength'] * field_data['redshift']</p></li></ul>
<p>+                delta_lambda = continuum['wavelength'] * redshift</p>
<pre>this_wavelength = delta_lambda + continuum['wavelength']
right_index = np.digitize(this_wavelength, self.lambda_field).clip(0, self.n_lambda)
left_index = np.digitize((this_wavelength *</pre>
<p>@@ -259,13 +313,19 @@</p>
<pre>            pbar.finish()

    def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,</pre>
<ul><li><p>output_absorbers_file, subgrid_resolution=10,</p></li>
<li><p>njobs=-1):</p></li></ul>
<p>+                               output_absorbers_file, subgrid_resolution=10, +                               observing_redshift=0., njobs=-1):</p>
<pre>"""
Add the absorption lines to the spectrum.
"""</pre>
<ul><li><p># Widen wavelength window until optical depth falls below this tau</p></li>
<li><p># value at the ends to assure that the wings of a line have been</p></li></ul>
<p>+ +        # Change the redshifts of individual absorbers to account for the +        # redshift at which the observer sits +        redshift, redshift_eff = self._apply_observing_redshift(field_data, +                                 use_peculiar_velocity, observing_redshift) + +        # Widen wavelength window until optical depth falls below this tau +        # value at the ends to assure that the wings of a line have been</p>
<pre>        # fully resolved.
        min_tau = 1e-3
</pre>
<p>@@ -276,11 +336,11 @@</p>
<pre># redshift_eff field combines cosmological and velocity redshifts
# so delta_lambda gives the offset in angstroms from the rest frame</pre>
<ul><li><p># wavelength to the observed wavelength of the transition</p></li></ul>
<p>+            # wavelength to the observed wavelength of the transition</p>
<pre>if use_peculiar_velocity:</pre>
<ul><li><p>delta_lambda = line['wavelength'] * field_data['redshift_eff']</p></li></ul>
<p>+                delta_lambda = line['wavelength'] * redshift_eff</p>
<pre>else:</pre>
<ul><li><p>delta_lambda = line['wavelength'] * field_data['redshift']</p></li></ul>
<p>+                delta_lambda = line['wavelength'] * redshift</p>
<pre># lambda_obs is central wavelength of line after redshift
lambda_obs = line['wavelength'] + delta_lambda
# the total number of absorbers per transition</pre>
<p>@@ -308,7 +368,7 @@</p>
<pre>                                  line['atomic_mass'])

            # the actual thermal width of the lines</pre>
<ul><li><p>thermal_width = (lambda_obs * thermal_b /</p></li></ul>
<p>+            thermal_width = (lambda_obs * thermal_b /</p>
<pre>                             speed_of_light_cgs).convert_to_units("angstrom")

            # Sanitize units for faster runtime of the tau_profile machinery.</pre>
<p>@@ -320,20 +380,20 @@</p>
<pre># When we actually deposit the voigt profile, sometimes we will
# have underresolved lines (ie lines with smaller widths than</pre>
<ul><li><p># the spectral bin size).  Here, we create virtual wavelength bins</p></li>
<li><p># small enough in width to well resolve each line, deposit the</p></li>
<li><p># voigt profile into them, then numerically integrate their tau</p></li>
<li><p># values and sum them to redeposit them into the actual spectral</p></li></ul>
<p>+            # the spectral bin size).  Here, we create virtual wavelength bins +            # small enough in width to well resolve each line, deposit the +            # voigt profile into them, then numerically integrate their tau +            # values and sum them to redeposit them into the actual spectral</p>
<pre>            # bins.

            # virtual bins (vbins) will be:
            # 1) <= the bin_width; assures at least as good as spectral bins
            # 2) <= 1/10th the thermal width; assures resolving voigt profiles
            #   (actually 1/subgrid_resolution value, default is 1/10)</pre>
<ul><li><p># 3) a bin width will be divisible by vbin_width times a power of</p></li></ul>
<p>+            # 3) a bin width will be divisible by vbin_width times a power of</p>
<pre>#    10; this will assure we don't get spikes in the deposited
#    spectra from uneven numbers of vbins per bin</pre>
<ul><li><p>resolution = thermal_width / self.bin_width</p></li></ul>
<p>+            resolution = thermal_width / self.bin_width</p>
<pre>            n_vbins_per_bin = 10**(np.ceil(np.log10(subgrid_resolution/resolution)).clip(0, np.inf))
            vbin_width = self.bin_width.d / n_vbins_per_bin
</pre>
<p>@@ -341,17 +401,17 @@</p>
<pre>if (thermal_width < self.bin_width).any():
    mylog.info(("%d out of %d line components will be " + \
                "deposited as unresolved lines.") %</pre>
<ul><li><p>((thermal_width < self.bin_width).sum(),</p></li></ul>
<p>+                           ((thermal_width < self.bin_width).sum(),</p>
<pre>                            n_absorbers))

            # provide a progress bar with information about lines processsed
            pbar = get_pbar("Adding line - %s [%f A]: " % \
                            (line['label'], line['wavelength']), n_absorbers)
</pre>
<ul><li><p># for a given transition, step through each location in the</p></li></ul>
<p>+            # for a given transition, step through each location in the</p>
<pre># observed spectrum where it occurs and deposit a voigt profile
for i in parallel_objects(np.arange(n_absorbers), njobs=-1):</pre>
<p>– +</p>
<pre># the virtual window into which the line is deposited initially
# spans a region of 2 coarse spectral bins
# (one on each side of the center_index) but the window</pre>
<p>@@ -362,12 +422,9 @@</p>
<pre>                window_width_in_bins = 2

                while True:</pre>
<ul><li><p>left_index = (center_index[i] – \</p></li>
<li><p>window_width_in_bins/2)</p></li>
<li><p>right_index = (center_index[i] + \</p></li>
<li><p>window_width_in_bins/2)</p></li>
<li><p>n_vbins = (right_index – left_index) * \</p></li>
<li><p>n_vbins_per_bin[i]</p></li></ul>
<p>+                    left_index = (center_index[i] – window_width_in_bins/2) +                    right_index = (center_index[i] + window_width_in_bins/2) +                    n_vbins = (right_index – left_index) * n_vbins_per_bin[i]</p>
<pre># the array of virtual bins in lambda space
vbins = \</pre>
<p>@@ -384,8 +441,8 @@</p>
<pre># If tau has not dropped below min tau threshold by the
# edges (ie the wings), then widen the wavelength</pre>
<ul><li><p># window and repeat process.</p></li>
<li><p>if ((vtau[0] < min_tau) and (vtau[-1] < min_tau)):</p></li></ul>
<p>+                    # window and repeat process. +                    if (vtau[0] < min_tau and vtau[-1] < min_tau):</p>
<pre>                        break
                    window_width_in_bins *= 2
</pre>
<p>@@ -421,8 +478,9 @@</p>
<pre>                        += EW[(intersect_left_index - left_index): \
                              (intersect_right_index - left_index)]
</pre>
<p>+</p>
<pre># write out absorbers to file if the column density of</pre>
<ul><li><p># an absorber is greater than the specified “label_threshold”</p></li></ul>
<p>+                # an absorber is greater than the specified “label_threshold”</p>
<pre># of that absorption line
if output_absorbers_file and \
   line['label_threshold'] is not None and \</pre>
<p>@@ -436,15 +494,15 @@</p>
<pre>'wavelength': (lambda_0 + dlambda[i]),
'column_density': column_density[i],
'b_thermal': thermal_b[i],</pre>
<ul><li><p>‘redshift’: field_data['redshift'][i],</p></li>
<li><p>‘redshift_eff’: field_data['redshift_eff'][i],</p></li></ul>
<p>+                                                ‘redshift’: redshift[i], +                                                ‘redshift_eff’: redshift_eff[i],</p>
<pre>                                                'v_pec': peculiar_velocity})
                pbar.update(i)
            pbar.finish()

            del column_density, delta_lambda, lambda_obs, center_index, \
                thermal_b, thermal_width, cdens, thermb, dlambda, \</pre>
<ul><li><p>vlos, resolution, vbin_width, n_vbins_per_bin</p></li></ul>
<p>+                vlos, resolution, vbin_width, n_vbins, n_vbins_per_bin</p>
<pre>comm = _get_comm(())
self.tau_field = comm.mpi_allreduce(self.tau_field, op="sum")</pre>
<p>Repository URL: <a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BI0v8SbQq-2B8-2FZaaHaJT85r_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyPS5-2F1mCX4lQhFfQt6o3vgH74oq1DFAhfwncszq6mHK9-2Be1uVZmQ18HvpD-2BpL7XOAehdwtDoH04NDLtPl070cK6xR04A8eJbc4SonHNIwbBX637nQLrzrejGcRgVokUNqnvHN-2BRoW4SOwgRUJvN7BHY-3D">https://bitbucket.org/yt_analysis/yt/</a></p>
<p>—</p>
<p>This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.</p>

<img src="http://link.bitbucket.org/wf/open?upn=ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Chp4tbBaYQJh-2BYFo0ahY91tgRPGfZuSCITApOp1Z-2FKyDAFMNY4hSJtK161is-2F5aeCVHoxxKnRg6h8RRvL4mDBEzCBqtVyQjl5vKoZcSiS5gJkUzkj6lE2gdWSjKUHCJNtToT8Xbj6E2hBmK3zTNgvgmPcjgfWTX5KOoRKcz-2F5jC2K0yyDF5sVl8m18g5507RM-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>