<html><body>
<p>1 new commit in yt:</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/2d7b93e59428/">https://bitbucket.org/yt_analysis/yt/commits/2d7b93e59428/</a> Changeset: 2d7b93e59428 Branch: yt User: atmyers Date: 2016-04-29 19:39:05+00:00 Summary: Merged in xarthisius/yt (pull request #2117)</p>
<p>Optimize creation of masks and hdf5 reads during creation of ionization tables for OWLS. Closes #1206 Affected #: 2 files</p>
<p>diff -r 3f50767dec553868bf966a8e027f308f545e84c2 -r 2d7b93e59428f2dc6d4cde5030cacc4b113c6ea4 yt/frontends/owls/fields.py --- a/yt/frontends/owls/fields.py +++ b/yt/frontends/owls/fields.py @@ -222,41 +222,40 @@</p>
<pre> """ returns a function that calculates the ion density of a particle.
"""
</pre>
<ul><li><p>def _ion_density(field, data):</p></li></ul>
<p>+ def get_owls_ion_density_field(ion, ftype, itab): + def _func(field, data):</p>
<ul><li><p># get element symbol from ion string. ion string will</p></li>
<li><p># be a member of the tuple _ions (i.e. si13)</p></li>
<li><p>#--------------------------------------------------------</p></li>
<li><p>if ion[0:2].isalpha():</p></li>
<li><p>symbol = ion[0:2].capitalize()</p></li>
<li><p>else:</p></li>
<li><p>symbol = ion[0:1].capitalize()</p></li></ul>
<p>+ # get element symbol from ion string. ion string will + # be a member of the tuple _ions (i.e. si13) + #-------------------------------------------------------- + if ion[0:2].isalpha(): + symbol = ion[0:2].capitalize() + else: + symbol = ion[0:1].capitalize()</p>
<ul><li><p># mass fraction for the element</p></li>
<li><p>#--------------------------------------------------------</p></li>
<li><p>m_frac = data[ftype, symbol+"_fraction"]</p></li></ul>
<p>+ # mass fraction for the element + #-------------------------------------------------------- + m_frac = data[ftype, symbol+"_fraction"]</p>
<ul><li><p># get nH and T for lookup</p></li>
<li><p>#--------------------------------------------------------</p></li>
<li><p>log_nH = np.log10( data["PartType0", “H_number_density”] )</p></li>
<li><p>log_T = np.log10( data["PartType0", “Temperature”] )</p></li></ul>
<p>+ # get nH and T for lookup + #-------------------------------------------------------- + log_nH = np.log10( data["PartType0", “H_number_density”] ) + log_T = np.log10( data["PartType0", “Temperature”] )</p>
<ul><li><p># get name of owls_ion_file for given ion</p></li>
<li><p>#--------------------------------------------------------</p></li>
<li><p>owls_ion_path = self._get_owls_ion_data_dir()</p></li>
<li><p>fname = os.path.join( owls_ion_path, ion+".hdf5" )</p></li></ul>
<p>+ # get name of owls_ion_file for given ion + #-------------------------------------------------------- + itab.set_iz( data.ds.current_redshift )</p>
<ul><li><p># create ionization table for this redshift</p></li>
<li><p>#--------------------------------------------------------</p></li>
<li><p>itab = oit.IonTableOWLS( fname )</p></li>
<li><p>itab.set_iz( data.ds.current_redshift )</p></li></ul>
<p>–</p>
<ul><li><p># find ion balance using log nH and log T</p></li>
<li><p>#--------------------------------------------------------</p></li>
<li><p>i_frac = itab.interp( log_nH, log_T )</p></li>
<li><p>return data[ftype,"Density"] * m_frac * i_frac</p></li></ul>
<p>–</p>
<ul><li><p>return _ion_density</p></li></ul>
<p>+ # find ion balance using log nH and log T + #-------------------------------------------------------- + i_frac = itab.interp( log_nH, log_T ) + return data[ftype,"Density"] * m_frac * i_frac + return _func + + ion_path = self._get_owls_ion_data_dir() + fname = os.path.join( ion_path, ion+".hdf5" ) + itab = oit.IonTableOWLS( fname ) + return get_owls_ion_density_field(ion, ftype, itab)</p>
<p>diff -r 3f50767dec553868bf966a8e027f308f545e84c2 -r 2d7b93e59428f2dc6d4cde5030cacc4b113c6ea4 yt/frontends/owls/owls_ion_tables.py --- a/yt/frontends/owls/owls_ion_tables.py +++ b/yt/frontends/owls/owls_ion_tables.py @@ -1,8 +1,8 @@ -""" +"""</p>
<pre>OWLS ion tables
A module to handle the HM01 UV background spectra and ionization data from the</pre>
<p>-OWLS photoionization equilibrium lookup tables. +OWLS photoionization equilibrium lookup tables.</p>
<p>@@ -17,27 +17,28 @@</p>
<pre>#-----------------------------------------------------------------------------
from yt.utilities.on_demand_imports import _h5py as h5py</pre>
<p>+import yt.extern.six as six</p>
<pre>import numpy as np
</pre>
<p>-def h5rd( fname, path, dtype=None ): +def h5rd(fname, path, dtype=None):</p>
<pre>""" Read Data. Return a dataset located at <path> in file <fname> as</pre>
<ul><li><p>a numpy array.</p></li></ul>
<p>+ a numpy array.</p>
<pre> e.g. rd( fname, '/PartType0/Coordinates' ). """
data = None</pre>
<ul><li><p>with h5py.File( fname, ‘r’ ) as h5f:</p></li>
<li><p>ds = h5f[path]</p></li>
<li><p>if dtype is None:</p></li>
<li><p>dtype = ds.dtype</p></li>
<li><p>data = np.zeros( ds.shape, dtype=dtype )</p></li>
<li><p>data = ds.value</p></li></ul>
<p>+ fid = h5py.h5f.open(six.b(fname), h5py.h5f.ACC_RDONLY) + dg = h5py.h5d.open(fid, path.encode('ascii')) + if dtype is None: + dtype = dg.dtype + data = np.zeros(dg.shape, dtype=dtype) + dg.read(h5py.h5s.ALL, h5py.h5s.ALL, data) + fid.close()</p>
<pre> return data
</pre>
<p>–</p>
<pre>class IonTableSpectrum:
""" A class to handle the HM01 spectra in the OWLS ionization tables. """</pre>
<p>@@ -45,17 +46,16 @@</p>
<pre> def __init__(self, ion_file):
where = '/header/spectrum/gammahi'</pre>
<ul><li><p>self.GH1 = h5rd( ion_file, where ) # GH1[1/s]</p></li></ul>
<p>+ self.GH1 = h5rd(ion_file, where) # GH1[1/s]</p>
<pre>where = '/header/spectrum/logenergy_ryd'</pre>
<ul><li><p>self.logryd = h5rd( ion_file, where ) # E[ryd]</p></li></ul>
<p>+ self.logryd = h5rd(ion_file, where) # E[ryd]</p>
<pre>where = '/header/spectrum/logflux'</pre>
<ul><li><p>self.logflux = h5rd( ion_file, where ) # J[ergs/s/Hz/Sr/cm^2]</p></li></ul>
<p>+ self.logflux = h5rd(ion_file, where) # J[ergs/s/Hz/Sr/cm^2]</p>
<pre>where = '/header/spectrum/redshift'</pre>
<ul><li><p>self.z = h5rd( ion_file, where ) # z</p></li></ul>
<p>– + self.z = h5rd(ion_file, where) # z</p>
<pre>def return_table_GH1_at_z(self,z):</pre>
<p>@@ -68,9 +68,9 @@</p>
<pre> else:
i_zhi = i_zlo
i_zlo = i_zlo - 1</pre>
<p>– +</p>
<pre>z_frac = (z - self.z[i_zlo]) / (self.z[i_zhi] - self.z[i_zlo])</pre>
<p>– +</p>
<pre># find GH1 from table
#-----------------------------------------------------------------
logGH1_all = np.log10( self.GH1 )</pre>
<p>@@ -80,8 +80,6 @@</p>
<pre> GH1_table = 10.0**logGH1_table
return GH1_table</pre>
<p>– –</p>
<pre>class IonTableOWLS:</pre>
<p>@@ -90,7 +88,7 @@</p>
<pre>DELTA_nH = 0.25
DELTA_T = 0.1</pre>
<p>– +</p>
<pre> def __init__(self, ion_file):
self.ion_file = ion_file</pre>
<p>@@ -104,13 +102,13 @@</p>
<pre># read the ionization fractions
# linear values stored in file so take log here</pre>
<ul><li><p># ionbal is the ionization balance (i.e. fraction)</p></li></ul>
<p>+ # ionbal is the ionization balance (i.e. fraction)</p>
<pre>#---------------------------------------------------------------</pre>
<ul><li><p>self.ionbal = h5rd( ion_file, ‘/ionbal’ ).astype(np.float64)</p></li></ul>
<p>+ self.ionbal = h5rd( ion_file, ‘/ionbal’ ).astype(np.float64)</p>
<pre> self.ionbal_orig = self.ionbal.copy()
</pre>
<ul><li><p>ipositive = np.where( self.ionbal > 0.0 )</p></li>
<li><p>izero = np.where( self.ionbal <= 0.0 )</p></li></ul>
<p>+ ipositive = self.ionbal > 0.0 + izero = np.logical_not(ipositive)</p>
<pre> self.ionbal[izero] = self.ionbal[ipositive].min()
self.ionbal = np.log10( self.ionbal )</pre>
<p>@@ -118,7 +116,7 @@</p>
<pre># load in background spectrum
#---------------------------------------------------------------</pre>
<ul><li><p>self.spectrum = IonTableSpectrum( ion_file )</p></li></ul>
<p>+ self.spectrum = IonTableSpectrum( ion_file )</p>
<pre># calculate the spacing along each dimension
#---------------------------------------------------------------</pre>
<p>@@ -129,9 +127,6 @@</p>
<pre> self.order_str = '[log nH, log T, z]'
</pre>
<p>– – –</p>
<pre># sets iz and fz
#-----------------------------------------------------
def set_iz( self, z ):</pre>
<p>@@ -149,11 +144,11 @@</p>
<pre> self.fz = ( z - self.z[iz] ) / self.dz[iz]
break
</pre>
<p>– +</p>
<pre># interpolate the table at a fixed redshift for the input</pre>
<ul><li><p># values of nH and T ( input should be log ). A simple</p></li>
<li><p># tri-linear interpolation is used.</p></li></ul>
<p>+ # values of nH and T ( input should be log ). A simple + # tri-linear interpolation is used.</p>
<pre> #-----------------------------------------------------
def interp( self, nH, T ):
</pre>
<p>@@ -162,7 +157,7 @@</p>
<pre> if nH.size != T.size:
raise ValueError(' owls_ion_tables: array size mismatch !!! ')</pre>
<p>– +</p>
<pre> # field discovery will have nH.size == 1 and T.size == 1
# in that case we simply return 1.0
</pre>
<p>@@ -185,14 +180,14 @@</p>
<pre>x_T_clip = np.clip( x_T, 0.0, self.T.size-1.001 )
fT,iT = np.modf( x_T_clip )
iT = iT.astype( np.int32 )</pre>
<p>– +</p>
<pre> # short names for previously calculated iz and fz
#-----------------------------------------------------
iz = self.iz
fz = self.fz
</pre>
<p>– +</p>
<pre># calculate interpolated value
# use tri-linear interpolation on the log values
#-----------------------------------------------------</pre>
<p>Repository URL: <a href="https://bitbucket.org/yt_analysis/yt/">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-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27BV1QL1226GMWXdPyLfER-2BBmLNOrHZ4aR5Tkyev58vfUASXKuM9Q-2BXeqdyFJQG0dgCYVI590-2BTyTDGSBEIgTwP-2BXbMfZr2AiGrwf0NV75E7PIV6VIApsY1DtZI0PvPFeMPuil80QiweNTTpOH2r6WbSPgykkcHBV6cOWepcVvxmez4A1-2Bw4kw7dogbZQdp2qII-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>