[yt-svn] commit/yt: ngoldbaum: Merged in chummels/yt (pull request #1332)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Dec 9 11:08:50 PST 2014
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/9799455919d2/
Changeset: 9799455919d2
Branch: yt
User: ngoldbaum
Date: 2014-12-09 19:08:40+00:00
Summary: Merged in chummels/yt (pull request #1332)
Updating RadMC3D exporter analysis module
Affected #: 3 files
diff -r c49dbb18e2f0cbc1357be61e77a1757bf4aa47d2 -r 9799455919d22c5c6d6168287bb69439a9fd1962 doc/source/analyzing/analysis_modules/radmc3d_export.rst
--- a/doc/source/analyzing/analysis_modules/radmc3d_export.rst
+++ b/doc/source/analyzing/analysis_modules/radmc3d_export.rst
@@ -6,17 +6,11 @@
.. sectionauthor:: Andrew Myers <atmyers2 at gmail.com>
.. versionadded:: 2.6
-.. note::
-
- As of :code:`yt-3.0`, the radial column density analysis module is not
- currently functional. This functionality is still available in
- :code:`yt-2.x`. If you would like to use these features in :code:`yt-3.x`,
- help is needed to port them over. Contact the yt-users mailing list if you
- are interested in doing this.
-
`RADMC-3D
-<http://www.ita.uni-heidelberg.de/~dullemond/software/radmc-3d/>`_ is a three-dimensional Monte-Carlo radiative transfer code
-that is capable of handling both line and continuum emission. The :class:`~yt.analysis_modules.radmc3d_export.RadMC3DInterface.RadMC3DWriter`
+<http://www.ita.uni-heidelberg.de/~dullemond/software/radmc-3d/>`_ is a
+three-dimensional Monte-Carlo radiative transfer code that is capable of
+handling both line and continuum emission. The
+:class:`~yt.analysis_modules.radmc3d_export.RadMC3DInterface.RadMC3DWriter`
class saves AMR data to disk in an ACSII format that RADMC-3D can read.
In principle, this allows one to use RADMC-3D to make synthetic observations
from any simulation data format that yt recognizes.
@@ -31,74 +25,77 @@
.. code-block:: python
- from yt.mods import *
- from yt.analysis_modules.radmc3d_export.api import *
+ import yt
+ from yt.analysis_modules.radmc3d_export.api import RadMC3DWriter
-Then, define a field that calculates the dust density in each cell. Here, we assume
-a constant dust-to-gas mass ratio of 0.01:
+Then, define a field that calculates the dust density in each cell. Here, we
+assume a constant dust-to-gas mass ratio of 0.01:
.. code-block:: python
dust_to_gas = 0.01
def _DustDensity(field, data):
- return dust_to_gas*data["density"]
- add_field("DustDensity", function=_DustDensity)
+ return dust_to_gas * data["density"]
+ yt.add_field(("gas", "dust_density"), function=_DustDensity, units="g/cm**3")
Now load up a dataset and call the
:class:`~yt.analysis_modules.radmc3d_export.RadMC3DInterface.RadMC3DWriter`:
.. code-block:: python
- ds = load("galaxy0030/galaxy0030")
+ ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
writer = RadMC3DWriter(ds)
writer.write_amr_grid()
- writer.write_dust_file("DustDensity", "dust_density.inp")
+ writer.write_dust_file(("gas", "dust_density"), "dust_density.inp")
-The method write_amr_grid() creates an "amr_grid.inp" file that tells RADMC-3D how
-to interpret the rest of the data, while "dust_density.inp" contains the actual data field.
+The method write_amr_grid() creates an "amr_grid.inp" file that tells RADMC-3D
+how to interpret the rest of the data, while "dust_density.inp" contains the
+actual data field.
-We can also supply temperature information. The following code creates a "DustTemperature"
-field that is constant at 10 K, and saves it into a file called "dust_temperature.inp"
+We can also supply temperature information. The following code creates a
+"dust_temperature" field that is constant at 10 K, and saves it into a file
+called "dust_temperature.inp"
.. code-block:: python
def _DustTemperature(field, data):
- return 10.0*data["Ones"]
- add_field("DustTemperature", function=_DustTemperature)
+ return 0. * data["temperature"] + data.ds.quan(10, 'K')
+ yt.add_field(("gas", "dust_temperature"), function=_DustTemperature, units="K")
- writer.write_dust_file("DustTemperature", "dust_temperature.inp")
+ writer.write_dust_file(("gas", "dust_temperature"), "dust_temperature.inp")
-With the "amr_grid.inp", "dust_density.inp", and "dust_temperature.inp" files, RADMC-3D
-has everything it needs to compute the thermal dust emission (you may also have to include
-the location and spectra of any sources, which currently must be done manually).
-The result is something that looks like this:
+With the "amr_grid.inp", "dust_density.inp", and "dust_temperature.inp" files,
+RADMC-3D has everything it needs to compute the thermal dust emission (you may
+also have to include the location and spectra of any sources, which currently
+must be done manually). The result is something that looks like this:
.. image:: _images/31micron.png
Line Emission
-------------
-The file format required for line emission is slightly different. The following script will generate
-two files, one called "numderdens_co.inp", which contains the number density of CO molecules
-for every cell in the index, and another called "gas-velocity.inp", which is useful if you want
-to include doppler broadening.
+The file format required for line emission is slightly different. The
+following script will generate two files, one called "numderdens_co.inp",
+which contains the number density of CO molecules for every cell in the index,
+and another called "gas-velocity.inp", which is useful if you want to include
+doppler broadening.
.. code-block:: python
- from yt.mods import *
- from yt.analysis_modules.radmc3d_export.api import *
+ import yt
+ from yt.analysis_modules.radmc3d_export.api import RadMC3DWriter
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)
+ yt.add_field(("gas", "number_density_CO"), function=_NumberDensityCO, units="cm**-3")
- ds = load("galaxy0030/galaxy0030")
+ ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
writer = RadMC3DWriter(ds)
writer.write_amr_grid()
- writer.write_line_file("NumberDensityCO", "numberdens_co.inp")
+ writer.write_line_file(("gas", "number_density_CO"), "numberdens_co.inp")
velocity_fields = ["velocity_x", "velocity_y", "velocity_z"]
writer.write_line_file(velocity_fields, "gas_velocity.inp")
diff -r c49dbb18e2f0cbc1357be61e77a1757bf4aa47d2 -r 9799455919d22c5c6d6168287bb69439a9fd1962 yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
--- a/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
+++ b/yt/analysis_modules/radmc3d_export/RadMC3DInterface.py
@@ -13,7 +13,8 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
-from yt.mods import *
+import yt
+import numpy as np
from yt.utilities.lib.write_array import \
write_3D_array, write_3D_vector_array
@@ -86,40 +87,42 @@
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 *
- >>> from yt.analysis_modules.radmc3d_export.api import *
+ >>> import yt
+ >>> from yt.analysis_modules.radmc3d_export.api import RadMC3DWriter
>>> dust_to_gas = 0.01
>>> def _DustDensity(field, data):
... return dust_to_gas*data["Density"]
- >>> add_field("DustDensity", function=_DustDensity)
+ >>> yt.add_field("DustDensity", function=_DustDensity)
>>> def _DustTemperature(field, data):
... return 10.0*data["Ones"]
- >>> add_field("DustTemperature", function=_DustTemperature)
+ >>> yt.add_field("DustTemperature", function=_DustTemperature)
- >>> ds = load("galaxy0030/galaxy0030")
+ >>> ds = yt.load("galaxy0030/galaxy0030")
>>> writer = RadMC3DWriter(ds)
>>> writer.write_amr_grid()
>>> 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
+ ---
+
+ This example 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 *
+ >>> import yt
+ >>> from yt.analysis_modules.radmc3d_export.api import RadMC3DWriter
>>> 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)
+ >>> yt.add_field("NumberDensityCO", function=_NumberDensityCO)
- >>> ds = load("galaxy0030/galaxy0030")
+ >>> ds = yt.load("galaxy0030/galaxy0030")
>>> writer = RadMC3DWriter(ds)
>>> writer.write_amr_grid()
@@ -183,8 +186,8 @@
RE = self.domain_right_edge
# Radmc3D wants the cell wall positions in cgs. Convert here:
- LE_cgs = LE * self.ds.units['cm']
- RE_cgs = RE * self.ds.units['cm']
+ LE_cgs = LE.in_units('cm')
+ RE_cgs = RE.in_units('cm')
# calculate cell wall positions
xs = [str(x) for x in np.linspace(LE_cgs[0], RE_cgs[0], dims[0]+1)]
diff -r c49dbb18e2f0cbc1357be61e77a1757bf4aa47d2 -r 9799455919d22c5c6d6168287bb69439a9fd1962 yt/analysis_modules/radmc3d_export/tests/test_radmc3d_exporter.py
--- /dev/null
+++ b/yt/analysis_modules/radmc3d_export/tests/test_radmc3d_exporter.py
@@ -0,0 +1,56 @@
+"""
+Unit test for the RADMC3D Exporter analysis module
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2014, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+import yt
+from yt.testing import *
+from yt.analysis_modules.radmc3d_export.api import RadMC3DWriter
+from yt.config import ytcfg
+import tempfile
+import os
+import shutil
+
+ISO_GAL = "IsolatedGalaxy/galaxy0030/galaxy0030"
+
+ at requires_file(ISO_GAL)
+def test_radmc3d_exporter_continuum():
+ """
+ This test is simply following the description in the docs for how to
+ generate the necessary output files to run a continuum emission map from
+ dust for one of our sample datasets.
+ """
+
+ # Set up in a temp dir
+ tmpdir = tempfile.mkdtemp()
+ curdir = os.getcwd()
+ os.chdir(tmpdir)
+
+ # Make up a dust density field where dust density is 1% of gas density
+ dust_to_gas = 0.01
+ def _DustDensity(field, data):
+ return dust_to_gas * data["density"]
+
+ # Make up a dust temperature field where temp = 10K everywhere
+ def _DustTemperature(field, data):
+ return 0.*data["temperature"] + data.ds.quan(10,'K')
+
+ ds = yt.load(ISO_GAL)
+ ds.add_field(("gas", "dust_density"), function=_DustDensity, units="g/cm**3")
+ ds.add_field(("gas", "dust_temperature"), function=_DustTemperature, units="K")
+ writer = RadMC3DWriter(ds)
+
+ writer.write_amr_grid()
+ writer.write_dust_file(("gas", "dust_density"), "dust_density.inp")
+ writer.write_dust_file(("gas", "dust_temperature"), "dust_temperature.inp")
+
+ # clean up
+ os.chdir(curdir)
+ shutil.rmtree(tmpdir)
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