[yt-svn] commit/yt: 22 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri May 10 10:34:07 PDT 2013
22 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/924fad86026c/
Changeset: 924fad86026c
Branch: yt
User: atmyers
Date: 2013-05-07 08:29:47
Summary: adding code to export yt dataset to radmcd3d
Affected #: 5 files
diff -r 34979d998227182ac38c2c51b876472755d650ff -r 924fad86026cb243c3110ad6279ad53842f7dcdd yt/analysis_modules/api.py
--- a/yt/analysis_modules/api.py
+++ b/yt/analysis_modules/api.py
@@ -117,3 +117,6 @@
from .two_point_functions.api import \
TwoPointFunctions, \
FcnSet
+
+from .radmc3d_export.api import \
+ RadMC3DWriter
diff -r 34979d998227182ac38c2c51b876472755d650ff -r 924fad86026cb243c3110ad6279ad53842f7dcdd yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- /dev/null
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -0,0 +1,259 @@
+"""
+Code to export from yt to RadMC3D
+
+Author: Andrew Myers
+Affiliation: UCB
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2013 Andrew Myers. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+from yt.mods import *
+
+class RadMC3DLayer:
+ '''
+
+ This class represents an AMR 'layer' of the style described in
+ the radmc3d manual. Unlike grids, layers may not have more
+ than one parent, so level L grids will need to be split up
+ if they straddle two or more level L - 1 grids.
+
+ '''
+ def __init__(self, level, parent, id, LE, RE, dim):
+ self.level = level
+ self.parent = parent
+ self.LeftEdge = LE
+ self.RightEdge = RE
+ self.ActiveDimensions = dim
+ self.id = id
+
+ def get_overlap_with(self, grid):
+ '''
+
+ Returns the overlapping region between two Layers,
+ or a layer and a grid. RE < LE means in any direction
+ means no overlap.
+
+ '''
+ LE = np.maximum(self.LeftEdge, grid.LeftEdge)
+ RE = np.minimum(self.RightEdge, grid.RightEdge)
+ return LE, RE
+
+ def overlaps(self, grid):
+ '''
+
+ Returns whether or not this layer overlaps a given grid
+
+ '''
+ LE, RE = self.get_overlap_with(grid)
+ if np.any(RE <= LE):
+ return False
+ else:
+ return True
+
+class RadMC3DWriter:
+ '''
+
+ This class provides a mechanism for writing out data files in a format
+ readable by radmc3d. Examples:
+
+ from yt.mods import *
+ from RadMC3DInterface import *
+
+ pf = load('../data.0199.3d.hdf5')
+ writer = RadMC3DWriter(pf)
+
+ writer.write_amr_grid()
+ writer.write_dust_data('dust-density', 'dust_data.inp')
+ writer.write_dust_data('dust-temperature', 'dust_temperature.inp')
+ writer.write_line_data('number-density-co', 'numberdens_co.inp')
+ writer.write_line_data('gas-temperature', 'gas_temperature.inp')
+ writer.write_line_data( ['x-velocity', 'y-velocity', 'z-velocity'], 'gas_velocity.inp')
+ '''
+
+ def __init__(self, pf, max_level=2):
+ self.max_level = max_level
+ self.cell_count = 0
+ self.layers = []
+ self.domain_dimensions = pf.domain_dimensions
+ self.domain_left_edge = pf.domain_left_edge
+ self.domain_right_edge = pf.domain_right_edge
+ self.grid_filename = 'amr_grid.inp'
+ self.pf = pf
+
+ base_layer = RadMC3DLayer(0, None, 0, \
+ self.domain_left_edge, \
+ self.domain_right_edge, \
+ self.domain_dimensions)
+
+ self.layers.append(base_layer)
+ self.cell_count += np.product(pf.domain_dimensions)
+
+ for grid in pf.h.grids:
+ if grid.Level <= self.max_level:
+ self._add_grid_to_layers(grid)
+
+ def _get_parents(self, grid):
+ parents = []
+ for potential_parent in self.layers:
+ if potential_parent.level == grid.Level - 1:
+ if potential_parent.overlaps(grid):
+ parents.append(potential_parent)
+ return parents
+
+ def _add_grid_to_layers(self, grid):
+ parents = self._get_parents(grid)
+ for parent in parents:
+ LE, RE = parent.get_overlap_with(grid)
+ N = (RE - LE) / grid.dds
+ N = np.array([int(n + 0.5) for n in N])
+ new_layer = RadMC3DLayer(grid.Level, parent.id, len(self.layers), \
+ LE, RE, N)
+ self.layers.append(new_layer)
+ self.cell_count += np.product(N)
+
+ def write_amr_grid(self):
+ '''
+ This routine writes the 'amr_grid.inp' file that describes the mesh radmc3d
+ will use.
+
+ '''
+ dims = self.domain_dimensions
+ left_edge = self.domain_left_edge
+ right_edge = self.domain_right_edge
+
+ # calculate cell wall positions
+ xs = [str(x) for x in np.linspace(left_edge[0], right_edge[0], dims[0]+1)]
+ ys = [str(y) for y in np.linspace(left_edge[1], right_edge[1], dims[1]+1)]
+ zs = [str(z) for z in np.linspace(left_edge[2], right_edge[2], dims[2]+1)]
+
+ # writer file header
+ grid_file = open(self.grid_filename, 'w')
+ grid_file.write('1 \n') # iformat is always 1
+ if self.max_level == 0:
+ grid_file.write('0 \n')
+ else:
+ grid_file.write('10 \n') # only layer-style AMR files are supported
+ grid_file.write('1 \n') # only cartesian coordinates are supported
+ grid_file.write('0 \n')
+ grid_file.write('{} {} {} \n'.format(1, 1, 1)) # assume 3D
+ grid_file.write('{} {} {} \n'.format(dims[0], dims[1], dims[2]))
+ if self.max_level != 0:
+ grid_file.write(str(self.max_level) + ' ' + str(len(self.layers)) + '\n')
+
+ # write base grid cell wall positions
+ for x in xs:
+ grid_file.write(x + ' ')
+ grid_file.write('\n')
+
+ for y in ys:
+ grid_file.write(y + ' ')
+ grid_file.write('\n')
+
+ for z in zs:
+ grid_file.write(z + ' ')
+ grid_file.write('\n')
+
+ # write information about fine layers, skipping the base layer:
+ for layer in self.layers[1:]:
+ p = layer.parent
+ dds = (layer.RightEdge - layer.LeftEdge) / (layer.ActiveDimensions)
+ if p == 0:
+ ind = (layer.LeftEdge - left_edge) / (2.0*dds) + 1
+ else:
+ LE = np.zeros(3)
+ for potential_parent in self.layers:
+ if potential_parent.id == p:
+ LE = potential_parent.LeftEdge
+ ind = (layer.LeftEdge - LE) / (2.0*dds) + 1
+ ix = int(ind[0])
+ iy = int(ind[1])
+ iz = int(ind[2])
+ nx, ny, nz = layer.ActiveDimensions / 2
+ grid_file.write('{} {} {} {} {} {} {} \n'.format(p, ix, iy, iz, nx, ny, nz))
+
+ grid_file.close()
+
+ def _write_layer_data_to_file(self, fhandle, field, level, LE, dim):
+ import pyximport; pyximport.install()
+ from write_array import write_3D_array, write_3D_vector_array
+
+ cg = self.pf.h.covering_grid(level, LE, dim)
+ if type(field) == type([]):
+ data_x = cg[field[0]]
+ data_y = cg[field[1]]
+ data_z = cg[field[2]]
+ write_3D_vector_array(data_x, data_y, data_x, fhandle)
+ else:
+ data = cg[field]
+ write_3D_array(data, fhandle)
+
+ def write_dust_file(self, field, filename):
+ '''
+ This method writes out fields in the format radmc3d needs to compute
+ thermal dust emission. In particular, if you have a field called
+ "dust-density", you can write out a dust_density.inp file.
+
+ '''
+ fhandle = open(filename, 'w')
+
+ # write header
+ fhandle.write('1 \n')
+ fhandle.write(str(self.cell_count) + ' \n')
+ fhandle.write('1 \n')
+
+ # now write fine layers:
+ for layer in self.layers:
+ lev = layer.level
+ if lev == 0:
+ LE = self.domain_left_edge
+ N = self.domain_dimensions
+ else:
+ LE = layer.LeftEdge
+ N = layer.ActiveDimensions
+
+ self._write_layer_data_to_file(fhandle, field, lev, LE, N)
+
+ fhandle.close()
+
+ def write_line_file(self, field, filename):
+ '''
+ This method writes out fields in the format radmc3d needs to compute
+ line emission.
+
+ '''
+ fhandle = open(filename, 'w')
+
+ # write header
+ fhandle.write('1 \n')
+ fhandle.write(str(self.cell_count) + ' \n')
+
+ # now write fine layers:
+ for layer in self.layers:
+ lev = layer.level
+ if lev == 0:
+ LE = self.domain_left_edge
+ N = self.domain_dimensions
+ else:
+ LE = layer.LeftEdge
+ N = layer.ActiveDimensions
+
+ self._write_layer_data_to_file(fhandle, field, lev, LE, N)
+
+ fhandle.close()
diff -r 34979d998227182ac38c2c51b876472755d650ff -r 924fad86026cb243c3110ad6279ad53842f7dcdd yt/analysis_modules/radmc3d_export/api.py
--- /dev/null
+++ b/yt/analysis_modules/radmc3d_export/api.py
@@ -0,0 +1,30 @@
+"""
+API for RadMC3D Export code
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Author: Andrew Myers <atmyers2 at gmail.com>
+Affiliation: UCB
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2010-2011 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+from .RadMC3DInterface import \
+ RadMC3DWriter
diff -r 34979d998227182ac38c2c51b876472755d650ff -r 924fad86026cb243c3110ad6279ad53842f7dcdd yt/analysis_modules/setup.py
--- a/yt/analysis_modules/setup.py
+++ b/yt/analysis_modules/setup.py
@@ -20,4 +20,5 @@
config.add_subpackage("spectral_integrator")
config.add_subpackage("star_analysis")
config.add_subpackage("two_point_functions")
+ config.add_subpackage("radmc3d_export")
return config
https://bitbucket.org/yt_analysis/yt/commits/ed10fa819095/
Changeset: ed10fa819095
Branch: yt
User: atmyers
Date: 2013-05-07 09:56:07
Summary: adding cython file IO routines
Affected #: 3 files
diff -r 924fad86026cb243c3110ad6279ad53842f7dcdd -r ed10fa819095703e9a8d1c9f431aff38a2d05f81 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -25,12 +25,13 @@
"""
from yt.mods import *
+from yt.utilities.lib.write_array import write_3D_array, write_3D_vector_array
class RadMC3DLayer:
'''
This class represents an AMR 'layer' of the style described in
- the radmc3d manual. Unlike grids, layers may not have more
+ the radmc3d manual. Unlike yt grids, layers may not have more
than one parent, so level L grids will need to be split up
if they straddle two or more level L - 1 grids.
@@ -74,7 +75,7 @@
readable by radmc3d. Examples:
from yt.mods import *
- from RadMC3DInterface import *
+ from yt.analysis_modules.radmc3d_export.api import *
pf = load('../data.0199.3d.hdf5')
writer = RadMC3DWriter(pf)
@@ -191,9 +192,6 @@
grid_file.close()
def _write_layer_data_to_file(self, fhandle, field, level, LE, dim):
- import pyximport; pyximport.install()
- from write_array import write_3D_array, write_3D_vector_array
-
cg = self.pf.h.covering_grid(level, LE, dim)
if type(field) == type([]):
data_x = cg[field[0]]
diff -r 924fad86026cb243c3110ad6279ad53842f7dcdd -r ed10fa819095703e9a8d1c9f431aff38a2d05f81 yt/utilities/lib/__init__.py
--- a/yt/utilities/lib/__init__.py
+++ b/yt/utilities/lib/__init__.py
@@ -39,3 +39,4 @@
from .grid_traversal import *
from .marching_cubes import *
from .GridTree import *
+from .write_array import *
diff -r 924fad86026cb243c3110ad6279ad53842f7dcdd -r ed10fa819095703e9a8d1c9f431aff38a2d05f81 yt/utilities/lib/setup.py
--- a/yt/utilities/lib/setup.py
+++ b/yt/utilities/lib/setup.py
@@ -204,6 +204,8 @@
"yt/utilities/lib/field_interpolation_tables.pxd",
]
)
+ config.add_extension("write_array",
+ ["yt/utilities/lib/write_array.pyx"])
config.add_extension("GridTree",
["yt/utilities/lib/GridTree.pyx"],
libraries=["m"], depends=["yt/utilities/lib/fp_utils.pxd"])
https://bitbucket.org/yt_analysis/yt/commits/31cb0a3745b9/
Changeset: 31cb0a3745b9
Branch: yt
User: atmyers
Date: 2013-05-07 09:58:18
Summary: forgot to actually add the file
Affected #: 1 file
diff -r ed10fa819095703e9a8d1c9f431aff38a2d05f81 -r 31cb0a3745b9cd89ef8741e5369a9b61468d75de yt/utilities/lib/write_array.pyx
--- /dev/null
+++ b/yt/utilities/lib/write_array.pyx
@@ -0,0 +1,66 @@
+"""
+Faster, cythonized file IO
+
+Author: Andrew Myers
+Affiliation: UCB
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2013 Andrew Myers. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import numpy as np
+cimport numpy as np
+cimport cython
+
+DTYPE = np.float64
+ctypedef np.float64_t DTYPE_t
+
+ at cython.boundscheck(False)
+def write_3D_array(np.ndarray[DTYPE_t, ndim=3] data, fhandle):
+ assert data.dtype == DTYPE
+ cdef int Nx, Ny, Nz
+ Nx = data.shape[0]
+ Ny = data.shape[1]
+ Nz = data.shape[2]
+ cdef unsigned int i, j, k
+
+ for i in np.arange(Nz):
+ for j in np.arange(Ny):
+ for k in np.arange(Nx):
+ fhandle.write(str(data[k, j, i]) + '\n')
+
+ at cython.boundscheck(False)
+def write_3D_vector_array(np.ndarray[DTYPE_t, ndim=3] data_x,
+ np.ndarray[DTYPE_t, ndim=3] data_y,
+ np.ndarray[DTYPE_t, ndim=3] data_z,
+ fhandle):
+
+ assert data_x.dtype == DTYPE
+ cdef int Nx, Ny, Nz
+ Nx = data_x.shape[0]
+ Ny = data_x.shape[1]
+ Nz = data_x.shape[2]
+ cdef unsigned int i, j, k
+
+ for i in np.arange(Nz):
+ for j in np.arange(Ny):
+ for k in np.arange(Nx):
+ fx = data_x[k, j, i]
+ fy = data_y[k, j, i]
+ fz = data_z[k, j, i]
+ fhandle.write('{} {} {} \n'.format(fx, fy, fz))
https://bitbucket.org/yt_analysis/yt/commits/1365195231df/
Changeset: 1365195231df
Branch: yt
User: atmyers
Date: 2013-05-07 19:12:19
Summary: Merged yt_analysis/yt into yt
Affected #: 1 file
diff -r 31cb0a3745b9cd89ef8741e5369a9b61468d75de -r 1365195231df34e5cb5def2d2e17780267c447f7 yt/analysis_modules/halo_merger_tree/merger_tree.py
--- a/yt/analysis_modules/halo_merger_tree/merger_tree.py
+++ b/yt/analysis_modules/halo_merger_tree/merger_tree.py
@@ -143,7 +143,7 @@
Note that this is not a string, so no quotes. Default = HaloFinder.
halo_finder_threshold : Float
If using HaloFinder or parallelHF, the value of the density threshold
- used when halo finding. Default = 80.0.
+ used when halo finding. Default = 160.0.
FOF_link_length : Float
If using FOFHaloFinder, the linking length between particles.
Default = 0.2.
@@ -169,7 +169,7 @@
... halo_finder_function=parallelHF)
"""
def __init__(self, restart_files=[], database='halos.db',
- halo_finder_function=HaloFinder, halo_finder_threshold=80.0,
+ halo_finder_function=HaloFinder, halo_finder_threshold=160.0,
FOF_link_length=0.2, dm_only=False, refresh=False,
index=True):
ParallelAnalysisInterface.__init__(self)
https://bitbucket.org/yt_analysis/yt/commits/506793d5d284/
Changeset: 506793d5d284
Branch: yt
User: atmyers
Date: 2013-05-07 19:38:42
Summary: update docstrings
Affected #: 1 file
diff -r 31cb0a3745b9cd89ef8741e5369a9b61468d75de -r 506793d5d2848007b898d9aeec24a039c6e63ff9 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -72,20 +72,64 @@
'''
This class provides a mechanism for writing out data files in a format
- readable by radmc3d. Examples:
+ readable by radmc3d. Currently, only the ASCII format, "Layer" style
+ file format is supported. For more information please see the radmc3d
+ manual.
+
+ Parameters
+ ----------
+
+ pf : `StaticOutput`
+ This is the parameter file object corresponding to the
+ simulation output to be written out.
+
+ max_level : int
+ An int corresponding to the maximum number of levels of refinement
+ to include in the output. Often, this does not need to be very large
+ as information on very high levels is frequently unobservable.
+ Default = 2.
+
+ Examples
+ --------
+
+ This will create a field called "DustDensity" and write it out to the
+ file "dust_data.inp" in a form readable by radmc3d:
+
+ >>> from yt.mods import *
+ >>> from yt.analysis_modules.radmc3d_export.api import *
+
+ >>> dust_to_gas = 0.01
+ >>> def _DustDensity(field, data):
+ >>> return dust_to_gas*data['Density']
+ >>> add_field("DustDensity", function=_DustDensity)
- from yt.mods import *
- from yt.analysis_modules.radmc3d_export.api import *
+ >>> pf = load("galaxy0030/galaxy0030")
+ >>> writer = RadMC3DWriter(pf)
- pf = load('../data.0199.3d.hdf5')
- writer = RadMC3DWriter(pf)
+ >>> writer.write_amr_grid()
+ >>> writer.write_dust_file("DustDensity", "dust_data.inp")
+
+ This will create a field called "NumberDensityCO and write it out to
+ the file "numberdens_co.inp". It will also write out information about
+ the gas velocity to "gas_velocity.inp" so that this broadening may be
+ included in the radiative transfer calculation by radmc3d:
+
+ >>> from yt.mods import *
+ >>> from yt.analysis_modules.radmc3d_export.api import *
+
+ >>> x_co = 1.0e-4
+ >>> mu_h = 2.34e-24
+ >>> def _NumberDensityCO(field, data):
+ >>> return (x_co/mu_h)*data['Density']
+ >>> add_field("NumberDensityCO", function=_NumberDensityCO)
- writer.write_amr_grid()
- writer.write_dust_data('dust-density', 'dust_data.inp')
- writer.write_dust_data('dust-temperature', 'dust_temperature.inp')
- writer.write_line_data('number-density-co', 'numberdens_co.inp')
- writer.write_line_data('gas-temperature', 'gas_temperature.inp')
- writer.write_line_data( ['x-velocity', 'y-velocity', 'z-velocity'], 'gas_velocity.inp')
+ >>> pf = load("galaxy0030/galaxy0030")
+ >>> writer = RadMC3DWriter(pf)
+
+ >>> writer.write_amr_grid()
+ >>> writer.write_line_file("NumberDensityCO", "numberdens_co.inp")
+ >>> writer.write_line_file(['x-velocity', 'y-velocity', 'z-velocity'], 'gas_velocity.inp')
+
'''
def __init__(self, pf, max_level=2):
@@ -206,7 +250,7 @@
'''
This method writes out fields in the format radmc3d needs to compute
thermal dust emission. In particular, if you have a field called
- "dust-density", you can write out a dust_density.inp file.
+ "DustDensity", you can write out a dust_density.inp file.
'''
fhandle = open(filename, 'w')
https://bitbucket.org/yt_analysis/yt/commits/92bcbe541132/
Changeset: 92bcbe541132
Branch: yt
User: atmyers
Date: 2013-05-07 19:39:40
Summary: merging
Affected #: 1 file
diff -r 506793d5d2848007b898d9aeec24a039c6e63ff9 -r 92bcbe541132f873c84966eae2f7ebab11c26456 yt/analysis_modules/halo_merger_tree/merger_tree.py
--- a/yt/analysis_modules/halo_merger_tree/merger_tree.py
+++ b/yt/analysis_modules/halo_merger_tree/merger_tree.py
@@ -143,7 +143,7 @@
Note that this is not a string, so no quotes. Default = HaloFinder.
halo_finder_threshold : Float
If using HaloFinder or parallelHF, the value of the density threshold
- used when halo finding. Default = 80.0.
+ used when halo finding. Default = 160.0.
FOF_link_length : Float
If using FOFHaloFinder, the linking length between particles.
Default = 0.2.
@@ -169,7 +169,7 @@
... halo_finder_function=parallelHF)
"""
def __init__(self, restart_files=[], database='halos.db',
- halo_finder_function=HaloFinder, halo_finder_threshold=80.0,
+ halo_finder_function=HaloFinder, halo_finder_threshold=160.0,
FOF_link_length=0.2, dm_only=False, refresh=False,
index=True):
ParallelAnalysisInterface.__init__(self)
https://bitbucket.org/yt_analysis/yt/commits/89843d4cf5ac/
Changeset: 89843d4cf5ac
Branch: yt
User: atmyers
Date: 2013-05-07 19:41:12
Summary: pointless formatting tweak
Affected #: 1 file
diff -r 92bcbe541132f873c84966eae2f7ebab11c26456 -r 89843d4cf5acf4a30b17dd2085f7d51d262d9c3c yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -72,9 +72,8 @@
'''
This class provides a mechanism for writing out data files in a format
- readable by radmc3d. Currently, only the ASCII format, "Layer" style
- file format is supported. For more information please see the radmc3d
- manual.
+ readable by radmc3d. Currently, only the ASCII, "Layer" style file format
+ is supported. For more information please see the radmc3d manual.
Parameters
----------
https://bitbucket.org/yt_analysis/yt/commits/510157e366b2/
Changeset: 510157e366b2
Branch: yt
User: atmyers
Date: 2013-05-07 19:52:02
Summary: breaking up some overlong lines
Affected #: 1 file
diff -r 89843d4cf5acf4a30b17dd2085f7d51d262d9c3c -r 510157e366b2d5020c375cab743389731ffe3638 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -25,7 +25,8 @@
"""
from yt.mods import *
-from yt.utilities.lib.write_array import write_3D_array, write_3D_vector_array
+from yt.utilities.lib.write_array import \
+ write_3D_array, write_3D_vector_array
class RadMC3DLayer:
'''
@@ -127,7 +128,8 @@
>>> writer.write_amr_grid()
>>> writer.write_line_file("NumberDensityCO", "numberdens_co.inp")
- >>> writer.write_line_file(['x-velocity', 'y-velocity', 'z-velocity'], 'gas_velocity.inp')
+ >>> velocity_fields = ['x-velocity', 'y-velocity', 'z-velocity']
+ >>> writer.write_line_file(velocity_fields, 'gas_velocity.inp')
'''
@@ -167,25 +169,26 @@
LE, RE = parent.get_overlap_with(grid)
N = (RE - LE) / grid.dds
N = np.array([int(n + 0.5) for n in N])
- new_layer = RadMC3DLayer(grid.Level, parent.id, len(self.layers), \
+ new_layer = RadMC3DLayer(grid.Level, parent.id, \
+ len(self.layers), \
LE, RE, N)
self.layers.append(new_layer)
self.cell_count += np.product(N)
def write_amr_grid(self):
'''
- This routine writes the 'amr_grid.inp' file that describes the mesh radmc3d
- will use.
+ This routine writes the 'amr_grid.inp' file that describes the mesh
+ radmc3d will use.
'''
dims = self.domain_dimensions
- left_edge = self.domain_left_edge
- right_edge = self.domain_right_edge
+ LE = self.domain_left_edge
+ RE = self.domain_right_edge
# calculate cell wall positions
- xs = [str(x) for x in np.linspace(left_edge[0], right_edge[0], dims[0]+1)]
- ys = [str(y) for y in np.linspace(left_edge[1], right_edge[1], dims[1]+1)]
- zs = [str(z) for z in np.linspace(left_edge[2], right_edge[2], dims[2]+1)]
+ xs = [str(x) for x in np.linspace(LE[0], RE[0], dims[0]+1)]
+ ys = [str(y) for y in np.linspace(LE[1], RE[1], dims[1]+1)]
+ zs = [str(z) for z in np.linspace(LE[2], RE[2], dims[2]+1)]
# writer file header
grid_file = open(self.grid_filename, 'w')
@@ -199,7 +202,8 @@
grid_file.write('{} {} {} \n'.format(1, 1, 1)) # assume 3D
grid_file.write('{} {} {} \n'.format(dims[0], dims[1], dims[2]))
if self.max_level != 0:
- grid_file.write(str(self.max_level) + ' ' + str(len(self.layers)) + '\n')
+ s = str(self.max_level) + ' ' + str(len(self.layers)) + '\n'
+ grid_file.write(s)
# write base grid cell wall positions
for x in xs:
@@ -219,7 +223,7 @@
p = layer.parent
dds = (layer.RightEdge - layer.LeftEdge) / (layer.ActiveDimensions)
if p == 0:
- ind = (layer.LeftEdge - left_edge) / (2.0*dds) + 1
+ ind = (layer.LeftEdge - LE) / (2.0*dds) + 1
else:
LE = np.zeros(3)
for potential_parent in self.layers:
@@ -230,7 +234,9 @@
iy = int(ind[1])
iz = int(ind[2])
nx, ny, nz = layer.ActiveDimensions / 2
- grid_file.write('{} {} {} {} {} {} {} \n'.format(p, ix, iy, iz, nx, ny, nz))
+ s = '{} {} {} {} {} {} {} \n'
+ s = s.format(p, ix, iy, iz, nx, ny, nz)
+ grid_file.write(s)
grid_file.close()
https://bitbucket.org/yt_analysis/yt/commits/ad099ba81366/
Changeset: ad099ba81366
Branch: yt
User: atmyers
Date: 2013-05-07 20:01:31
Summary: forgot one instance of chombo->pluto
Affected #: 1 file
diff -r 510157e366b2d5020c375cab743389731ffe3638 -r ad099ba81366508c14a6b26a37c8c2159759dcab yt/frontends/pluto/data_structures.py
--- a/yt/frontends/pluto/data_structures.py
+++ b/yt/frontends/pluto/data_structures.py
@@ -99,7 +99,7 @@
grid = PlutoGrid
- def __init__(self,pf,data_style='chombo_hdf5'):
+ def __init__(self,pf,data_style='pluto_hdf5'):
self.domain_left_edge = pf.domain_left_edge
self.domain_right_edge = pf.domain_right_edge
self.data_style = data_style
@@ -187,7 +187,7 @@
_fieldinfo_fallback = PlutoFieldInfo
_fieldinfo_known = KnownPlutoFields
- def __init__(self, filename, data_style='chombo_hdf5',
+ def __init__(self, filename, data_style='pluto_hdf5',
storage_filename = None, ini_filename = None):
self._handle = h5py.File(filename,'r')
self.current_time = self._handle.attrs['time']
https://bitbucket.org/yt_analysis/yt/commits/081a3a75722c/
Changeset: 081a3a75722c
Branch: yt
User: atmyers
Date: 2013-05-07 20:37:55
Summary: some more documentation
Affected #: 1 file
diff -r ad099ba81366508c14a6b26a37c8c2159759dcab -r 081a3a75722c9fc8e1d8ef5baa6d8472fb59ac2f yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -93,7 +93,8 @@
--------
This will create a field called "DustDensity" and write it out to the
- file "dust_data.inp" in a form readable by radmc3d:
+ file "dust_data.inp" in a form readable by radmc3d. It will also write
+ a "dust_temperature.inp" file with everything set to 10.0 K:
>>> from yt.mods import *
>>> from yt.analysis_modules.radmc3d_export.api import *
@@ -102,12 +103,17 @@
>>> def _DustDensity(field, data):
>>> return dust_to_gas*data['Density']
>>> add_field("DustDensity", function=_DustDensity)
+
+ >>> def _DustTemperature(field, data):
+ >>> return 10.0*data['Ones']
+ >>> add_field("DustTemperature", function=_DustTemperature)
>>> pf = load("galaxy0030/galaxy0030")
>>> writer = RadMC3DWriter(pf)
>>> writer.write_amr_grid()
>>> writer.write_dust_file("DustDensity", "dust_data.inp")
+ >>> writer.write_dust_file("DustTemperature", "dust_temperature.inp")
This will create a field called "NumberDensityCO and write it out to
the file "numberdens_co.inp". It will also write out information about
@@ -255,7 +261,17 @@
'''
This method writes out fields in the format radmc3d needs to compute
thermal dust emission. In particular, if you have a field called
- "DustDensity", you can write out a dust_density.inp file.
+ "DustDensity", you can write out a dust_density.inp file.
+
+ Parameters
+ ----------
+
+ field : string
+ The name of the field to be written out
+ filename : string
+ The name of the file to write the data to. The filenames radmc3d
+ expects for its various modes of operations are described in the
+ radmc3d manual.
'''
fhandle = open(filename, 'w')
@@ -284,6 +300,17 @@
This method writes out fields in the format radmc3d needs to compute
line emission.
+ Parameters
+ ----------
+
+ field : string or list of 3 strings
+ If a string, the name of the field to be written out. If a list,
+ three fields that will be written to the file as a vector quantity.
+ filename : string
+ The name of the file to write the data to. The filenames radmc3d
+ expects for its various modes of operations are described in the
+ radmc3d manual.
+
'''
fhandle = open(filename, 'w')
https://bitbucket.org/yt_analysis/yt/commits/50eaf1b67738/
Changeset: 50eaf1b67738
Branch: yt
User: atmyers
Date: 2013-05-07 20:40:25
Summary: add my email
Affected #: 2 files
diff -r 081a3a75722c9fc8e1d8ef5baa6d8472fb59ac2f -r 50eaf1b677384ec0236e23fee9cb57ab1e9a503c yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -1,7 +1,7 @@
"""
Code to export from yt to RadMC3D
-Author: Andrew Myers
+Author: Andrew Myers <atmyers2 at gmail.com>
Affiliation: UCB
Homepage: http://yt-project.org/
License:
diff -r 081a3a75722c9fc8e1d8ef5baa6d8472fb59ac2f -r 50eaf1b677384ec0236e23fee9cb57ab1e9a503c yt/utilities/lib/write_array.pyx
--- a/yt/utilities/lib/write_array.pyx
+++ b/yt/utilities/lib/write_array.pyx
@@ -1,7 +1,7 @@
"""
Faster, cythonized file IO
-Author: Andrew Myers
+Author: Andrew Myers <atmyers2 at gmail.com>
Affiliation: UCB
Homepage: http://yt-project.org/
License:
https://bitbucket.org/yt_analysis/yt/commits/1c1d77b43395/
Changeset: 1c1d77b43395
Branch: yt
User: atmyers
Date: 2013-05-07 20:56:14
Summary: forgot to port over these bug fixes
Affected #: 1 file
diff -r 50eaf1b677384ec0236e23fee9cb57ab1e9a503c -r 1c1d77b4339533b489c453963bab8d689a9b3c7c yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -208,7 +208,7 @@
grid_file.write('{} {} {} \n'.format(1, 1, 1)) # assume 3D
grid_file.write('{} {} {} \n'.format(dims[0], dims[1], dims[2]))
if self.max_level != 0:
- s = str(self.max_level) + ' ' + str(len(self.layers)) + '\n'
+ s = str(self.max_level) + ' ' + str(len(self.layers)-1) + '\n'
grid_file.write(s)
# write base grid cell wall positions
@@ -236,9 +236,9 @@
if potential_parent.id == p:
LE = potential_parent.LeftEdge
ind = (layer.LeftEdge - LE) / (2.0*dds) + 1
- ix = int(ind[0])
- iy = int(ind[1])
- iz = int(ind[2])
+ ix = int(ind[0]+0.5)
+ iy = int(ind[1]+0.5)
+ iz = int(ind[2]+0.5)
nx, ny, nz = layer.ActiveDimensions / 2
s = '{} {} {} {} {} {} {} \n'
s = s.format(p, ix, iy, iz, nx, ny, nz)
https://bitbucket.org/yt_analysis/yt/commits/a6c0381686a4/
Changeset: a6c0381686a4
Branch: yt
User: atmyers
Date: 2013-05-07 21:04:44
Summary: a few typos in the docs
Affected #: 1 file
diff -r 1c1d77b4339533b489c453963bab8d689a9b3c7c -r a6c0381686a43cbe59976be6015004406e2ac847 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -115,7 +115,7 @@
>>> writer.write_dust_file("DustDensity", "dust_data.inp")
>>> writer.write_dust_file("DustTemperature", "dust_temperature.inp")
- This will create a field called "NumberDensityCO and write it out to
+ This will create a field called "NumberDensityCO" and write it out to
the file "numberdens_co.inp". It will also write out information about
the gas velocity to "gas_velocity.inp" so that this broadening may be
included in the radiative transfer calculation by radmc3d:
@@ -308,7 +308,7 @@
three fields that will be written to the file as a vector quantity.
filename : string
The name of the file to write the data to. The filenames radmc3d
- expects for its various modes of operations are described in the
+ expects for its various modes of operation are described in the
radmc3d manual.
'''
https://bitbucket.org/yt_analysis/yt/commits/a863d2583159/
Changeset: a863d2583159
Branch: yt
User: atmyers
Date: 2013-05-07 21:26:45
Summary: fixing a bug in the code that writes vector quantities to disk, thanks to Kacper Kowalik
Affected #: 1 file
diff -r a6c0381686a43cbe59976be6015004406e2ac847 -r a863d25831599e3d07e2383915bf94dc07cbad00 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -252,7 +252,7 @@
data_x = cg[field[0]]
data_y = cg[field[1]]
data_z = cg[field[2]]
- write_3D_vector_array(data_x, data_y, data_x, fhandle)
+ write_3D_vector_array(data_x, data_y, data_z, fhandle)
else:
data = cg[field]
write_3D_array(data, fhandle)
https://bitbucket.org/yt_analysis/yt/commits/2731a478f0d0/
Changeset: 2731a478f0d0
Branch: yt
User: atmyers
Date: 2013-05-09 06:35:01
Summary: use one row of ghost zones so fields that need them can be written out as well
Affected #: 1 file
diff -r a863d25831599e3d07e2383915bf94dc07cbad00 -r 2731a478f0d0a5d21cc328ac75c5877f1eaa7fc4 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -31,7 +31,7 @@
class RadMC3DLayer:
'''
- This class represents an AMR 'layer' of the style described in
+ This class represents an AMR "layer" of the style described in
the radmc3d manual. Unlike yt grids, layers may not have more
than one parent, so level L grids will need to be split up
if they straddle two or more level L - 1 grids.
@@ -101,11 +101,11 @@
>>> dust_to_gas = 0.01
>>> def _DustDensity(field, data):
- >>> return dust_to_gas*data['Density']
+ >>> return dust_to_gas*data["Density"]
>>> add_field("DustDensity", function=_DustDensity)
>>> def _DustTemperature(field, data):
- >>> return 10.0*data['Ones']
+ >>> return 10.0*data["Ones"]
>>> add_field("DustTemperature", function=_DustTemperature)
>>> pf = load("galaxy0030/galaxy0030")
@@ -126,7 +126,7 @@
>>> x_co = 1.0e-4
>>> mu_h = 2.34e-24
>>> def _NumberDensityCO(field, data):
- >>> return (x_co/mu_h)*data['Density']
+ >>> return (x_co/mu_h)*data["Density"]
>>> add_field("NumberDensityCO", function=_NumberDensityCO)
>>> pf = load("galaxy0030/galaxy0030")
@@ -134,8 +134,8 @@
>>> writer.write_amr_grid()
>>> writer.write_line_file("NumberDensityCO", "numberdens_co.inp")
- >>> velocity_fields = ['x-velocity', 'y-velocity', 'z-velocity']
- >>> writer.write_line_file(velocity_fields, 'gas_velocity.inp')
+ >>> velocity_fields = ["x-velocity", "y-velocity", "z-velocity"]
+ >>> writer.write_line_file(velocity_fields, "gas_velocity.inp")
'''
@@ -146,7 +146,7 @@
self.domain_dimensions = pf.domain_dimensions
self.domain_left_edge = pf.domain_left_edge
self.domain_right_edge = pf.domain_right_edge
- self.grid_filename = 'amr_grid.inp'
+ self.grid_filename = "amr_grid.inp"
self.pf = pf
base_layer = RadMC3DLayer(0, None, 0, \
@@ -183,7 +183,7 @@
def write_amr_grid(self):
'''
- This routine writes the 'amr_grid.inp' file that describes the mesh
+ This routine writes the "amr_grid.inp" file that describes the mesh
radmc3d will use.
'''
@@ -247,7 +247,7 @@
grid_file.close()
def _write_layer_data_to_file(self, fhandle, field, level, LE, dim):
- cg = self.pf.h.covering_grid(level, LE, dim)
+ cg = self.pf.h.covering_grid(level, LE, dim, num_ghost_zones=1)
if type(field) == type([]):
data_x = cg[field[0]]
data_y = cg[field[1]]
https://bitbucket.org/yt_analysis/yt/commits/5eab37202a58/
Changeset: 5eab37202a58
Branch: yt
User: atmyers
Date: 2013-05-09 06:35:44
Summary: Merged yt_analysis/yt into yt
Affected #: 5 files
diff -r 2731a478f0d0a5d21cc328ac75c5877f1eaa7fc4 -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e yt/frontends/flash/fields.py
--- a/yt/frontends/flash/fields.py
+++ b/yt/frontends/flash/fields.py
@@ -64,7 +64,6 @@
translation_dict = {"x-velocity": "velx",
"y-velocity": "vely",
"z-velocity": "velz",
- "VelocityMagnitude": "velo",
"Density": "dens",
"Temperature": "temp",
"Pressure" : "pres",
diff -r 2731a478f0d0a5d21cc328ac75c5877f1eaa7fc4 -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e yt/gui/reason/widget_store.py
--- a/yt/gui/reason/widget_store.py
+++ b/yt/gui/reason/widget_store.py
@@ -76,7 +76,8 @@
sl = pf.h.slice(axis, coord, center = center, periodic = True)
xax, yax = x_dict[axis], y_dict[axis]
DLE, DRE = pf.domain_left_edge, pf.domain_right_edge
- pw = PWViewerExtJS(sl, (DLE[xax], DRE[xax], DLE[yax], DRE[yax]), setup = False)
+ pw = PWViewerExtJS(sl, (DLE[xax], DRE[xax], DLE[yax], DRE[yax]),
+ setup = False, plot_type='SlicePlot')
pw.set_current_field(field)
field_list = list(set(pf.h.field_list + pf.h.derived_field_list))
field_list = [dict(text = f) for f in sorted(field_list)]
@@ -96,7 +97,7 @@
xax, yax = x_dict[axis], y_dict[axis]
DLE, DRE = pf.domain_left_edge, pf.domain_right_edge
pw = PWViewerExtJS(proj, (DLE[xax], DRE[xax], DLE[yax], DRE[yax]),
- setup = False)
+ setup = False, plot_type='ProjectionPlot')
pw.set_current_field(field)
field_list = list(set(pf.h.field_list + pf.h.derived_field_list))
field_list = [dict(text = f) for f in sorted(field_list)]
diff -r 2731a478f0d0a5d21cc328ac75c5877f1eaa7fc4 -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e yt/utilities/linear_interpolators.py
--- a/yt/utilities/linear_interpolators.py
+++ b/yt/utilities/linear_interpolators.py
@@ -31,12 +31,44 @@
class UnilinearFieldInterpolator:
def __init__(self, table, boundaries, field_names, truncate=False):
+ r"""Initialize a 1D interpolator for field data.
+
+ table : array
+ The data table over which interpolation is performed.
+ boundaries: tuple or array
+ If a tuple, this should specify the upper and lower bounds
+ for the bins of the data table. This assumes the bins are
+ evenly spaced. If an array, this specifies the bins
+ explicitly.
+ field_names: str
+ Name of the field to be used as input data for interpolation.
+ truncate : bool
+ If False, an exception is raised if the input values are
+ outside the bounds of the table. If True, extrapolation is
+ performed.
+
+ Examples
+ --------
+
+ ad = pf.h.all_data()
+ table_data = np.random.random(64)
+ interp = UnilinearFieldInterpolator(table_data, (0.0, 1.0), "x",
+ truncate=True)
+ field_data = interp(ad)
+
+ """
self.table = table.astype('float64')
self.truncate = truncate
- x0, x1 = boundaries
self.x_name = field_names
- self.x_bins = np.linspace(x0, x1, table.shape[0]).astype('float64')
-
+ if isinstance(boundaries, np.ndarray):
+ if boundaries.size != table.shape[0]:
+ mylog.error("Bins array not the same length as the data.")
+ raise ValuesError
+ self.x_bins = boundaries
+ else:
+ x0, x1 = boundaries
+ self.x_bins = np.linspace(x0, x1, table.shape[0]).astype('float64')
+
def __call__(self, data_object):
orig_shape = data_object[self.x_name].shape
x_vals = data_object[self.x_name].ravel().astype('float64')
@@ -57,12 +89,51 @@
class BilinearFieldInterpolator:
def __init__(self, table, boundaries, field_names, truncate=False):
+ r"""Initialize a 2D interpolator for field data.
+
+ table : array
+ The data table over which interpolation is performed.
+ boundaries: tuple
+ Either a tuple of lower and upper bounds for the x and y bins
+ given as (x0, x1, y0, y1) or a tuple of two arrays containing the
+ x and y bins.
+ field_names: list
+ Names of the fields to be used as input data for interpolation.
+ truncate : bool
+ If False, an exception is raised if the input values are
+ outside the bounds of the table. If True, extrapolation is
+ performed.
+
+ Examples
+ --------
+
+ ad = pf.h.all_data()
+ table_data = np.random.random((64, 64))
+ interp = BilinearFieldInterpolator(table_data, (0.0, 1.0, 0.0, 1.0),
+ ["x", "y"],
+ truncate=True)
+ field_data = interp(ad)
+
+ """
self.table = table.astype('float64')
self.truncate = truncate
- x0, x1, y0, y1 = boundaries
self.x_name, self.y_name = field_names
- self.x_bins = np.linspace(x0, x1, table.shape[0]).astype('float64')
- self.y_bins = np.linspace(y0, y1, table.shape[1]).astype('float64')
+ if len(boundaries) == 4:
+ x0, x1, y0, y1 = boundaries
+ self.x_bins = np.linspace(x0, x1, table.shape[0]).astype('float64')
+ self.y_bins = np.linspace(y0, y1, table.shape[1]).astype('float64')
+ elif len(boundaries) == 2:
+ if boundaries[0].size != table.shape[0]:
+ mylog.error("X bins array not the same length as the data.")
+ raise ValueError
+ if boundaries[1].size != table.shape[1]:
+ mylog.error("Y bins array not the same length as the data.")
+ raise ValueError
+ self.x_bins = boundaries[0]
+ self.y_bins = boundaries[1]
+ else:
+ mylog.error("Boundaries must be given as (x0, x1, y0, y1) or as (x_bins, y_bins)")
+ raise ValueError
def __call__(self, data_object):
orig_shape = data_object[self.x_name].shape
@@ -90,14 +161,58 @@
class TrilinearFieldInterpolator:
def __init__(self, table, boundaries, field_names, truncate = False):
+ r"""Initialize a 3D interpolator for field data.
+
+ table : array
+ The data table over which interpolation is performed.
+ boundaries: tuple
+ Either a tuple of lower and upper bounds for the x, y, and z bins
+ given as (x0, x1, y0, y1, z0, z1) or a tuple of three arrays
+ containing the x, y, and z bins.
+ field_names: list
+ Names of the fields to be used as input data for interpolation.
+ truncate : bool
+ If False, an exception is raised if the input values are
+ outside the bounds of the table. If True, extrapolation is
+ performed.
+
+ Examples
+ --------
+
+ ad = pf.h.all_data()
+ table_data = np.random.random((64, 64, 64))
+ interp = BilinearFieldInterpolator(table_data,
+ (0.0, 1.0, 0.0, 1.0, 0.0, 1.0),
+ ["x", "y", "z"],
+ truncate=True)
+ field_data = interp(ad)
+
+ """
self.table = table.astype('float64')
self.truncate = truncate
- x0, x1, y0, y1, z0, z1 = boundaries
self.x_name, self.y_name, self.z_name = field_names
- self.x_bins = np.linspace(x0, x1, table.shape[0]).astype('float64')
- self.y_bins = np.linspace(y0, y1, table.shape[1]).astype('float64')
- self.z_bins = np.linspace(z0, z1, table.shape[2]).astype('float64')
-
+ if len(boundaries) == 6:
+ x0, x1, y0, y1, z0, z1 = boundaries
+ self.x_bins = np.linspace(x0, x1, table.shape[0]).astype('float64')
+ self.y_bins = np.linspace(y0, y1, table.shape[1]).astype('float64')
+ self.z_bins = np.linspace(z0, z1, table.shape[2]).astype('float64')
+ elif len(boundaries) == 3:
+ if boundaries[0].size != table.shape[0]:
+ mylog.error("X bins array not the same length as the data.")
+ raise ValueError
+ if boundaries[1].size != table.shape[1]:
+ mylog.error("Y bins array not the same length as the data.")
+ raise ValueError
+ if boundaries[2].size != table.shape[2]:
+ mylog.error("Z bins array not the same length as the data.")
+ raise ValueError
+ self.x_bins = boundaries[0]
+ self.y_bins = boundaries[1]
+ self.z_bins = boundaries[2]
+ else:
+ mylog.error("Boundaries must be given as (x0, x1, y0, y1, z0, z1) or as (x_bins, y_bins, z_bins)")
+ raise ValueError
+
def __call__(self, data_object):
orig_shape = data_object[self.x_name].shape
x_vals = data_object[self.x_name].ravel().astype('float64')
diff -r 2731a478f0d0a5d21cc328ac75c5877f1eaa7fc4 -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e yt/utilities/tests/test_interpolators.py
--- a/yt/utilities/tests/test_interpolators.py
+++ b/yt/utilities/tests/test_interpolators.py
@@ -7,21 +7,58 @@
def test_linear_interpolator_1d():
random_data = np.random.random(64)
fv = {'x': np.mgrid[0.0:1.0:64j]}
+ # evenly spaced bins
ufi = lin.UnilinearFieldInterpolator(random_data, (0.0, 1.0), "x", True)
- assert_array_equal(ufi(fv), random_data)
+ yield assert_array_equal, ufi(fv), random_data
+
+ # randomly spaced bins
+ size = 64
+ shift = (1. / size) * np.random.random(size) - (0.5 / size)
+ fv["x"] += shift
+ ufi = lin.UnilinearFieldInterpolator(random_data,
+ np.linspace(0.0, 1.0, size) + shift,
+ "x", True)
+ yield assert_array_almost_equal, ufi(fv), random_data, 15
def test_linear_interpolator_2d():
random_data = np.random.random((64, 64))
+ # evenly spaced bins
fv = dict((ax, v) for ax, v in zip("xyz",
np.mgrid[0.0:1.0:64j, 0.0:1.0:64j]))
bfi = lin.BilinearFieldInterpolator(random_data,
(0.0, 1.0, 0.0, 1.0), "xy", True)
- assert_array_equal(bfi(fv), random_data)
+ yield assert_array_equal, bfi(fv), random_data
+
+ # randomly spaced bins
+ size = 64
+ bins = np.linspace(0.0, 1.0, size)
+ shifts = dict((ax, (1. / size) * np.random.random(size) - (0.5 / size)) \
+ for ax in "xy")
+ fv["x"] += shifts["x"][:, np.newaxis]
+ fv["y"] += shifts["y"]
+ bfi = lin.BilinearFieldInterpolator(random_data,
+ (bins + shifts["x"], bins + shifts["y"]), "xy", True)
+ yield assert_array_almost_equal, bfi(fv), random_data, 15
def test_linear_interpolator_3d():
random_data = np.random.random((64, 64, 64))
+ # evenly spaced bins
fv = dict((ax, v) for ax, v in zip("xyz",
np.mgrid[0.0:1.0:64j, 0.0:1.0:64j, 0.0:1.0:64j]))
tfi = lin.TrilinearFieldInterpolator(random_data,
(0.0, 1.0, 0.0, 1.0, 0.0, 1.0), "xyz", True)
- assert_array_equal(tfi(fv), random_data)
+ yield assert_array_equal, tfi(fv), random_data
+
+ # randomly spaced bins
+ size = 64
+ bins = np.linspace(0.0, 1.0, size)
+ shifts = dict((ax, (1. / size) * np.random.random(size) - (0.5 / size)) \
+ for ax in "xyz")
+ fv["x"] += shifts["x"][:, np.newaxis, np.newaxis]
+ fv["y"] += shifts["y"][:, np.newaxis]
+ fv["z"] += shifts["z"]
+ tfi = lin.TrilinearFieldInterpolator(random_data,
+ (bins + shifts["x"], bins + shifts["y"],
+ bins + shifts["z"]), "xyz", True)
+ yield assert_array_almost_equal, tfi(fv), random_data, 15
+
diff -r 2731a478f0d0a5d21cc328ac75c5877f1eaa7fc4 -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -426,7 +426,7 @@
parameters
----------
- width : float, array of floats, (float, unit) tuple, or arry of (float, unit) tuples.
+ width : float, array of floats, (float, unit) tuple, or tuple of (float, unit) tuples.
Width can have four different formats to support windows with variable
x and y widths. They are:
@@ -551,8 +551,11 @@
"""A viewer for PlotWindows.
"""
+ _plot_type = None
def __init__(self, *args,**kwargs):
setup = kwargs.pop("setup", True)
+ if self._plot_type is None:
+ self._plot_type = kwargs.pop("plot_type")
PlotWindow.__init__(self, *args,**kwargs)
self._axes_unit_names = None
self._callbacks = []
@@ -635,7 +638,7 @@
Other Parameters
----------------
- dyanmic_range : float (default: None)
+ dynamic_range : float (default: None)
The dynamic range of the image.
If zmin == None, will set zmin = zmax / dynamic_range
If zmax == None, will set zmax = zmin * dynamic_range
https://bitbucket.org/yt_analysis/yt/commits/c8471258c0a1/
Changeset: c8471258c0a1
Branch: yt
User: atmyers
Date: 2013-05-09 18:37:28
Summary: Merged yt_analysis/yt into yt
Affected #: 2 files
diff -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e -r c8471258c0a1414170f046b56ecd2cfb141f9f45 yt/analysis_modules/halo_finding/halo_objects.py
--- a/yt/analysis_modules/halo_finding/halo_objects.py
+++ b/yt/analysis_modules/halo_finding/halo_objects.py
@@ -2010,8 +2010,9 @@
>>> halos.write_out("HopAnalysis.out")
"""
# if path denoted in filename, assure path exists
- if len(filename.split('/')) > 1:
- mkdir_rec('/'.join(filename.split('/')[:-1]))
+ my_dir = os.path.dirname(filename)
+ if not os.path.exists(my_dir):
+ only_on_root(os.makedirs, my_dir)
f = self.comm.write_on_root(filename)
HaloList.write_out(self, f, ellipsoid_data)
@@ -2033,8 +2034,9 @@
>>> halos.write_particle_lists_txt("halo-parts")
"""
# if path denoted in prefix, assure path exists
- if len(prefix.split('/')) > 1:
- mkdir_rec('/'.join(prefix.split('/')[:-1]))
+ my_dir = os.path.dirname(prefix)
+ if not os.path.exists(my_dir):
+ only_on_root(os.makedirs, my_dir)
f = self.comm.write_on_root("%s.txt" % prefix)
HaloList.write_particle_lists_txt(self, prefix, fp=f)
@@ -2060,8 +2062,9 @@
>>> halos.write_particle_lists("halo-parts")
"""
# if path denoted in prefix, assure path exists
- if len(prefix.split('/')) > 1:
- mkdir_rec('/'.join(prefix.split('/')[:-1]))
+ my_dir = os.path.dirname(prefix)
+ if not os.path.exists(my_dir):
+ only_on_root(os.makedirs, my_dir)
fn = "%s.h5" % self.comm.get_filename(prefix)
f = h5py.File(fn, "w")
@@ -2097,8 +2100,9 @@
>>> halos.dump("MyHalos")
"""
# if path denoted in basename, assure path exists
- if len(basename.split('/')) > 1:
- mkdir_rec('/'.join(basename.split('/')[:-1]))
+ my_dir = os.path.dirname(basename)
+ if not os.path.exists(my_dir):
+ only_on_root(os.makedirs, my_dir)
self.write_out("%s.out" % basename, ellipsoid_data)
self.write_particle_lists(basename)
diff -r 5eab37202a58ab91e76ad2d0de6e1878fd3c532e -r c8471258c0a1414170f046b56ecd2cfb141f9f45 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -602,18 +602,3 @@
def get_image_suffix(name):
suffix = os.path.splitext(name)[1]
return suffix if suffix in ['.png', '.eps', '.ps', '.pdf'] else ''
-
-def mkdir_rec(path):
- """
- Recursive mkdir, so that if you mkdir two levels deep and the first
- one doesn't exist, it creates the first, and then any subsequent dirs.
-
- Examples
- --------
- mkdir_rec("a/b/c")
- """
- dir_list = path.split("/")
- basedir = "."
- for dir in dir_list:
- basedir = "%s/%s" % (basedir, dir)
- if not os.path.isdir(basedir): os.mkdir(basedir)
https://bitbucket.org/yt_analysis/yt/commits/816702c2f14a/
Changeset: 816702c2f14a
Branch: yt
User: atmyers
Date: 2013-05-10 00:41:18
Summary: dust_data.inp -> dust_density.inp
Affected #: 1 file
diff -r c8471258c0a1414170f046b56ecd2cfb141f9f45 -r 816702c2f14a7923ef5b4d67d2af703558af5120 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -93,7 +93,7 @@
--------
This will create a field called "DustDensity" and write it out to the
- file "dust_data.inp" in a form readable by radmc3d. It will also write
+ file "dust_density.inp" in a form readable by radmc3d. It will also write
a "dust_temperature.inp" file with everything set to 10.0 K:
>>> from yt.mods import *
@@ -112,7 +112,7 @@
>>> writer = RadMC3DWriter(pf)
>>> writer.write_amr_grid()
- >>> writer.write_dust_file("DustDensity", "dust_data.inp")
+ >>> writer.write_dust_file("DustDensity", "dust_density.inp")
>>> writer.write_dust_file("DustTemperature", "dust_temperature.inp")
This will create a field called "NumberDensityCO" and write it out to
https://bitbucket.org/yt_analysis/yt/commits/66ab32b4e375/
Changeset: 66ab32b4e375
Branch: yt
User: atmyers
Date: 2013-05-10 00:42:20
Summary: id -> unique_id
Affected #: 1 file
diff -r 816702c2f14a7923ef5b4d67d2af703558af5120 -r 66ab32b4e375aff4299a3fb90496dbb4de3a111c yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -37,13 +37,13 @@
if they straddle two or more level L - 1 grids.
'''
- def __init__(self, level, parent, id, LE, RE, dim):
+ def __init__(self, level, parent, unique_id, LE, RE, dim):
self.level = level
self.parent = parent
self.LeftEdge = LE
self.RightEdge = RE
self.ActiveDimensions = dim
- self.id = id
+ self.id = unique_id
def get_overlap_with(self, grid):
'''
https://bitbucket.org/yt_analysis/yt/commits/13e2bc0d3cad/
Changeset: 13e2bc0d3cad
Branch: yt
User: atmyers
Date: 2013-05-10 00:44:37
Summary: add url for radmc3d homepage
Affected #: 1 file
diff -r 66ab32b4e375aff4299a3fb90496dbb4de3a111c -r 13e2bc0d3cadeb3f7588321066378ce25cbf34e3 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -74,7 +74,8 @@
This class provides a mechanism for writing out data files in a format
readable by radmc3d. Currently, only the ASCII, "Layer" style file format
- is supported. For more information please see the radmc3d manual.
+ is supported. For more information please see the radmc3d manual at:
+ http://www.ita.uni-heidelberg.de/~dullemond/software/radmc-3d
Parameters
----------
https://bitbucket.org/yt_analysis/yt/commits/9d19a96471a6/
Changeset: 9d19a96471a6
Branch: yt
User: atmyers
Date: 2013-05-10 00:47:05
Summary: >>> -> ... for multi-line inputs
Affected #: 1 file
diff -r 13e2bc0d3cadeb3f7588321066378ce25cbf34e3 -r 9d19a96471a6e1064140f603b1ed693881d542bb yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -102,11 +102,11 @@
>>> dust_to_gas = 0.01
>>> def _DustDensity(field, data):
- >>> return dust_to_gas*data["Density"]
+ ... return dust_to_gas*data["Density"]
>>> add_field("DustDensity", function=_DustDensity)
>>> def _DustTemperature(field, data):
- >>> return 10.0*data["Ones"]
+ ... return 10.0*data["Ones"]
>>> add_field("DustTemperature", function=_DustTemperature)
>>> pf = load("galaxy0030/galaxy0030")
@@ -127,7 +127,7 @@
>>> x_co = 1.0e-4
>>> mu_h = 2.34e-24
>>> def _NumberDensityCO(field, data):
- >>> return (x_co/mu_h)*data["Density"]
+ ... return (x_co/mu_h)*data["Density"]
>>> add_field("NumberDensityCO", function=_NumberDensityCO)
>>> pf = load("galaxy0030/galaxy0030")
https://bitbucket.org/yt_analysis/yt/commits/70ad437a12e2/
Changeset: 70ad437a12e2
Branch: yt
User: atmyers
Date: 2013-05-10 00:48:23
Summary: using isinstance() instead of type()
Affected #: 1 file
diff -r 9d19a96471a6e1064140f603b1ed693881d542bb -r 70ad437a12e2b7593a998f6c47ab3bb3e48cb4d0 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -249,7 +249,7 @@
def _write_layer_data_to_file(self, fhandle, field, level, LE, dim):
cg = self.pf.h.covering_grid(level, LE, dim, num_ghost_zones=1)
- if type(field) == type([]):
+ if isinstance(field, list):
data_x = cg[field[0]]
data_y = cg[field[1]]
data_z = cg[field[2]]
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list