[yt-svn] commit/yt: 4 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Jun 29 13:44:54 PDT 2015
4 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/4d53180140fe/
Changeset: 4d53180140fe
Branch: yt
User: alrosen
Date: 2015-06-05 17:57:38+00:00
Summary: Allow more than 10 fields from an orion data file be read in correctly.
Affected #: 1 file
diff -r ab1bd145878fe53d71c4d000422c9b7723af8c99 -r 4d53180140fe304dd0f336617b34305c6f378d30 yt/frontends/chombo/io.py
--- a/yt/frontends/chombo/io.py
+++ b/yt/frontends/chombo/io.py
@@ -75,7 +75,7 @@
field_dict = {}
for key, val in self._handle.attrs.items():
if key.startswith('component_'):
- comp_number = int(re.match('component_(\d)', key).groups()[0])
+ comp_number = int(re.match('component_(\d+)', key).groups()[0])
field_dict[val] = comp_number
self._field_dict = field_dict
return self._field_dict
https://bitbucket.org/yt_analysis/yt/commits/ad1c905fde64/
Changeset: ad1c905fde64
Branch: yt
User: alrosen
Date: 2015-06-05 18:01:22+00:00
Summary: Added direct radiation fields.
Affected #: 1 file
diff -r 4d53180140fe304dd0f336617b34305c6f378d30 -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -21,6 +21,11 @@
particle_vector_functions, \
standard_particle_fields
+from yt.frontends.boxlib.fields import \
+ rho_units, \
+ mom_units, \
+ eden_units
+
from yt.utilities.exceptions import YTFieldNotFound
rho_units = "code_mass / code_length**3"
@@ -48,19 +53,22 @@
("Y-momentum", (mom_units, ["momentum_y"], None)),
("Z-momentum", (mom_units, ["momentum_z"], None)),
("temperature", ("K", ["temperature"], None)),
- ("X-magnfield", (b_units, ["magnetic_field_x"], None)),
- ("Y-magnfield", (b_units, ["magnetic_field_y"], None)),
- ("Z-magnfield", (b_units, ["magnetic_field_z"], None)),
- )
-
+ ("X-magnfield", ("gauss", ["magnetic_field_x"], None)),
+ ("Y-magnfield", ("gauss", ["magnetic_field_y"], None)),
+ ("Z-magnfield", ("gauss", ["magnetic_field_z"], None)),
+ ("directrad-dedt-density", (eden_units, ["directrad-dedt-density"], None)),
+ ("directrad-dpxdt-density", (mom_units, ["directrad-dpxdt-density"], None)),
+ ("directrad-dpydt-density", (mom_units, ["directrad-dpydt-density"], None)),
+ ("directrad-dpzdt-density", (mom_units, ["directrad-dpzdt-density"], None)),
+ )
known_particle_fields = (
("particle_mass", ("code_mass", [], None)),
("particle_position_x", ("code_length", [], None)),
("particle_position_y", ("code_length", [], None)),
("particle_position_z", ("code_length", [], None)),
- ("particle_momentum_x", ("code_mass*code_length/code_time", [], None)),
- ("particle_momentum_y", ("code_mass*code_length/code_time", [], None)),
- ("particle_momentum_z", ("code_mass*code_length/code_time", [], None)),
+ ("particle_momentum_x", (mom_units, [], None)),
+ ("particle_momentum_y", (mom_units, [], None)),
+ ("particle_momentum_z", (mom_units, [], None)),
# Note that these are *internal* agmomen
("particle_angmomen_x", ("code_length**2/code_time", [], None)),
("particle_angmomen_y", ("code_length**2/code_time", [], None)),
https://bitbucket.org/yt_analysis/yt/commits/049b989a5f23/
Changeset: 049b989a5f23
Branch: yt
User: atmyers
Date: 2015-06-29 20:38:49+00:00
Summary: merging
Affected #: 38 files
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/helper_scripts/run_recipes.py
--- a/doc/helper_scripts/run_recipes.py
+++ b/doc/helper_scripts/run_recipes.py
@@ -13,7 +13,7 @@
from yt.config import ytcfg
FPATTERNS = ['*.png', '*.txt', '*.h5', '*.dat']
-DPATTERNS = ['LC*', 'LR', 'DD0046', 'halo_analysis']
+DPATTERNS = ['LC*', 'LR', 'DD0046']
BADF = ['cloudy_emissivity.h5', 'apec_emissivity.h5',
'xray_emissivity.h5', 'AMRGridData_Slice_x_density.png']
CWD = os.getcwd()
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/analyzing/fields.rst
--- a/doc/source/analyzing/fields.rst
+++ b/doc/source/analyzing/fields.rst
@@ -271,6 +271,29 @@
For a practical application of this, see :ref:`cookbook-radial-velocity`.
+Gradient Fields
+---------------
+
+yt provides a way to compute gradients of spatial fields using the
+:meth:`~yt.frontends.flash.data_structures.FLASHDataset.add_gradient_fields`
+method. If you have a spatially-based field such as density or temperature,
+and want to calculate the gradient of that field, you can do it like so:
+
+.. code-block:: python
+
+ ds = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150")
+ grad_fields = ds.add_gradient_fields(("gas","temperature"))
+
+where the ``grad_fields`` list will now have a list of new field names that can be used
+in calculations, representing the 3 different components of the field and the magnitude
+of the gradient, e.g., ``"temperature_gradient_x"``, ``"temperature_gradient_y"``,
+``"temperature_gradient_z"``, and ``"temperature_gradient_magnitude"``. To see an example
+of how to create and use these fields, see :ref:`cookbook-complicated-derived-fields`.
+
+.. note::
+
+ ``add_gradient_fields`` currently only supports Cartesian geometries!
+
General Particle Fields
-----------------------
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/cookbook/calculating_information.rst
--- a/doc/source/cookbook/calculating_information.rst
+++ b/doc/source/cookbook/calculating_information.rst
@@ -82,6 +82,17 @@
.. yt_cookbook:: derived_field.py
+.. _cookbook-complicated-derived-fields:
+
+Complicated Derived Fields
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This recipe demonstrates how to use the
+:meth:`~yt.frontends.flash.data_structures.FLASHDataset.add_gradient_fields` method
+to generate gradient fields and use them in a more complex derived field.
+
+.. yt_cookbook:: hse_field.py
+
Using Particle Filters to Calculate Star Formation Rates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/cookbook/hse_field.py
--- a/doc/source/cookbook/hse_field.py
+++ b/doc/source/cookbook/hse_field.py
@@ -1,44 +1,32 @@
import numpy as np
import yt
-from yt.fields.field_plugin_registry import \
- register_field_plugin
-from yt.fields.fluid_fields import \
- setup_gradient_fields
-
-
-# Define the components of the gravitational acceleration vector field by
-# taking the gradient of the gravitational potential
- at register_field_plugin
-def setup_my_fields(registry, ftype="gas", slice_info=None):
- setup_gradient_fields(registry, (ftype, "gravitational_potential"),
- "cm ** 2 / s ** 2", slice_info)
-
-# Define the "degree of hydrostatic equilibrium" field
-
-
- at yt.derived_field(name='HSE', units=None, take_log=False,
- display_name='Hydrostatic Equilibrium')
-def HSE(field, data):
-
- gx = data["density"] * data["gravitational_potential_gradient_x"]
- gy = data["density"] * data["gravitational_potential_gradient_y"]
- gz = data["density"] * data["gravitational_potential_gradient_z"]
-
- hx = data["pressure_gradient_x"] - gx
- hy = data["pressure_gradient_y"] - gy
- hz = data["pressure_gradient_z"] - gz
-
- h = np.sqrt((hx * hx + hy * hy + hz * hz) / (gx * gx + gy * gy + gz * gz))
-
- return h
-
-
# Open a dataset from when there's a lot of sloshing going on.
ds = yt.load("GasSloshingLowRes/sloshing_low_res_hdf5_plt_cnt_0350")
-# gradient operator requires periodic boundaries. This dataset has
+# Define the components of the gravitational acceleration vector field by
+# taking the gradient of the gravitational potential
+grad_fields = ds.add_gradient_fields(("gas","gravitational_potential"))
+
+# We don't need to do the same for the pressure field because yt already
+# has pressure gradient fields. Now, define the "degree of hydrostatic
+# equilibrium" field.
+
+def _hse(field, data):
+ # Remember that g is the negative of the potential gradient
+ gx = -data["density"] * data["gravitational_potential_gradient_x"]
+ gy = -data["density"] * data["gravitational_potential_gradient_y"]
+ gz = -data["density"] * data["gravitational_potential_gradient_z"]
+ hx = data["pressure_gradient_x"] - gx
+ hy = data["pressure_gradient_y"] - gy
+ hz = data["pressure_gradient_z"] - gz
+ h = np.sqrt((hx * hx + hy * hy + hz * hz) / (gx * gx + gy * gy + gz * gz))
+ return h
+ds.add_field(('gas','HSE'), function=_hse, units="", take_log=False,
+ display_name='Hydrostatic Equilibrium')
+
+# The gradient operator requires periodic boundaries. This dataset has
# open boundary conditions. We need to hack it for now (this will be fixed
# in future version of yt)
ds.periodicity = (True, True, True)
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/visualizing/FITSImageBuffer.ipynb
--- a/doc/source/visualizing/FITSImageBuffer.ipynb
+++ /dev/null
@@ -1,205 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:872f7525edd3c1ee09c67f6ecdd8552218df05ebe5ab73bcab55654edf0ac2bb"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "yt has capabilities for writing 2D and 3D uniformly gridded data generated from datasets to FITS files. This is via the `FITSImageBuffer` class, which has subclasses `FITSSlice` and `FITSProjection` to write slices and projections directly to FITS. We'll test this out on an Athena dataset."
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "%matplotlib inline\n",
- "import yt\n",
- "from yt.utilities.fits_image import FITSImageBuffer, FITSSlice, FITSProjection"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "ds = yt.load(\"MHDSloshing/virgo_low_res.0054.vtk\", parameters={\"length_unit\":(1.0,\"Mpc\"),\n",
- " \"mass_unit\":(1.0e14,\"Msun\"),\n",
- " \"time_unit\":(1.0,\"Myr\")})"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "To demonstrate a useful example of creating a FITS file, let's first make a `ProjectionPlot`:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "prj = yt.ProjectionPlot(ds, \"z\", [\"temperature\"], weight_field=\"density\", width=(500.,\"kpc\"))\n",
- "prj.show()"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Suppose that we wanted to write this projection to a FITS file for analysis and visualization in other programs, such as ds9. We can do that using `FITSProjection`:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "prj_fits = FITSProjection(ds, \"z\", [\"temperature\"], weight_field=\"density\")"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "which took the same parameters as `ProjectionPlot` except the width, because `FITSProjection` and `FITSSlice` always make slices and projections of the width of the domain size, at the finest resolution available in the simulation, in a unit determined to be appropriate for the physical size of the dataset. `prj_fits` is a full-fledged FITS file in memory, specifically an [AstroPy `HDUList`](http://astropy.readthedocs.org/en/latest/io/fits/api/hdulists.html) object. This means that we can use all of the methods inherited from `HDUList`:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "prj_fits.info()"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "`info` shows us the contents of the virtual FITS file. We can also look at the header for the `\"temperature\"` image, like so:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "prj_fits[\"temperature\"].header"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "where we can see that the temperature units are in Kelvin and the cell widths are in kiloparsecs. The projection can be written to disk using the `writeto` method:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "prj_fits.writeto(\"sloshing.fits\", clobber=True)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Since yt can read FITS image files, it can be loaded up just like any other dataset:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "ds2 = yt.load(\"sloshing.fits\")"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "and we can make a `SlicePlot` of the 2D image, which shows the same data as the previous image:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "slc2 = yt.SlicePlot(ds2, \"z\", [\"temperature\"], width=(500.,\"kpc\"))\n",
- "slc2.set_log(\"temperature\", True)\n",
- "slc2.show()"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "If you want more fine-grained control over what goes into the FITS file, you can call `FITSImageBuffer` directly, with various kinds of inputs. For example, you could use a `FixedResolutionBuffer`, and specify you want the units in parsecs instead:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "slc3 = ds.slice(0, 0.0)\n",
- "frb = slc3.to_frb((500.,\"kpc\"), 800)\n",
- "fib = FITSImageBuffer(frb, fields=[\"density\",\"temperature\"], units=\"pc\")"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Finally, a 3D FITS cube can be created from a covering grid:"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "cvg = ds.covering_grid(ds.index.max_level, [-0.5,-0.5,-0.5], [64, 64, 64], fields=[\"density\",\"temperature\"])\n",
- "fib = FITSImageBuffer(cvg, fields=[\"density\",\"temperature\"], units=\"Mpc\")"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-}
\ No newline at end of file
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/visualizing/FITSImageData.ipynb
--- /dev/null
+++ b/doc/source/visualizing/FITSImageData.ipynb
@@ -0,0 +1,409 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c7de5ef190feaa2289595aec7eaa05db02fd535e408e0d04aa54088b0bd3ebae"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "yt has capabilities for writing 2D and 3D uniformly gridded data generated from datasets to FITS files. This is via the `FITSImageData` class. We'll test these capabilities out on an Athena dataset."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import yt\n",
+ "from yt.utilities.fits_image import FITSImageData, FITSProjection"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ds = yt.load(\"MHDSloshing/virgo_low_res.0054.vtk\", parameters={\"length_unit\":(1.0,\"Mpc\"),\n",
+ " \"mass_unit\":(1.0e14,\"Msun\"),\n",
+ " \"time_unit\":(1.0,\"Myr\")})"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Creating FITS images from Slices and Projections"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are several ways to make a `FITSImageData` instance. The most intuitive ways are to use the `FITSSlice`, `FITSProjection`, `FITSOffAxisSlice`, and `FITSOffAxisProjection` classes to write slices and projections directly to FITS. To demonstrate a useful example of creating a FITS file, let's first make a `ProjectionPlot`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj = yt.ProjectionPlot(ds, \"z\", [\"temperature\"], weight_field=\"density\", width=(500.,\"kpc\"))\n",
+ "prj.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Suppose that we wanted to write this projection to a FITS file for analysis and visualization in other programs, such as ds9. We can do that using `FITSProjection`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits = FITSProjection(ds, \"z\", [\"temperature\"], weight_field=\"density\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "which took the same parameters as `ProjectionPlot` except the width, because `FITSProjection` and `FITSSlice` always make slices and projections of the width of the domain size, at the finest resolution available in the simulation, in a unit determined to be appropriate for the physical size of the dataset."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Because `FITSImageData` inherits from the [AstroPy `HDUList`](http://astropy.readthedocs.org/en/latest/io/fits/api/hdulists.html) class, we can call its methods. For example, `info` shows us the contents of the virtual FITS file:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits.info()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can also look at the header for a particular field:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits[\"temperature\"].header"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "where we can see that the temperature units are in Kelvin and the cell widths are in kiloparsecs. If we want the raw image data with units, we can call `get_data`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits.get_data(\"temperature\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can use the `set_unit` method to change the units of a particular field:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits.set_unit(\"temperature\",\"R\")\n",
+ "prj_fits.get_data(\"temperature\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The image can be written to disk using the `writeto` method:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits.writeto(\"sloshing.fits\", clobber=True)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Since yt can read FITS image files, it can be loaded up just like any other dataset:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ds2 = yt.load(\"sloshing.fits\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "and we can make a `SlicePlot` of the 2D image, which shows the same data as the previous image:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "slc2 = yt.SlicePlot(ds2, \"z\", [\"temperature\"], width=(500.,\"kpc\"))\n",
+ "slc2.set_log(\"temperature\", True)\n",
+ "slc2.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Using `FITSImageData` directly"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If you want more fine-grained control over what goes into the FITS file, you can call `FITSImageData` directly, with various kinds of inputs. For example, you could use a `FixedResolutionBuffer`, and specify you want the units in parsecs instead:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "slc3 = ds.slice(0, 0.0)\n",
+ "frb = slc3.to_frb((500.,\"kpc\"), 800)\n",
+ "fid_frb = FITSImageData(frb, fields=[\"density\",\"temperature\"], units=\"pc\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "A 3D FITS cube can also be created from a covering grid:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "cvg = ds.covering_grid(ds.index.max_level, [-0.5,-0.5,-0.5], [64, 64, 64], fields=[\"density\",\"temperature\"])\n",
+ "fid_cvg = FITSImageData(cvg, fields=[\"density\",\"temperature\"], units=\"Mpc\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Other `FITSImageData` Methods"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "A `FITSImageData` instance can be generated from one previously written to disk using the `from_file` classmethod:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fid = FITSImageData.from_file(\"sloshing.fits\")\n",
+ "fid.info()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Multiple `FITSImageData` can be combined to create a new one, provided that the coordinate information is the same:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits2 = FITSProjection(ds, \"z\", [\"density\"])\n",
+ "prj_fits3 = FITSImageData.from_images([prj_fits, prj_fits2])\n",
+ "prj_fits3.info()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Alternatively, individual fields can be popped as well:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dens_fits = prj_fits3.pop(\"density\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dens_fits.info()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits3.info()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "So far, the FITS images we have shown have linear spatial coordinates. One may want to take a projection of an object and make a crude mock observation out of it, with celestial coordinates. For this, we can use the `create_sky_wcs` method. Specify a center (RA, Dec) coordinate in degrees, as well as a linear scale in terms of angle per distance:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sky_center = [30.,45.] # in degrees\n",
+ "sky_scale = (2.5, \"arcsec/kpc\") # could also use a YTQuantity\n",
+ "prj_fits.create_sky_wcs(sky_center, sky_scale, ctype=[\"RA---TAN\",\"DEC--TAN\"])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "By the default, a tangent RA/Dec projection is used, but one could also use another projection using the `ctype` keyword. We can now look at the header and see it has the appropriate WCS:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "prj_fits[\"temperature\"].header"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Finally, we can add header keywords to a single field or for all fields in the FITS image using `update_header`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fid_frb.update_header(\"all\", \"time\", 0.1) # Update all the fields\n",
+ "fid_frb.update_header(\"temperature\", \"scale\", \"Rankine\") # Update just one field"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print fid_frb[\"density\"].header[\"time\"]\n",
+ "print fid_frb[\"temperature\"].header[\"scale\"]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/visualizing/manual_plotting.rst
--- a/doc/source/visualizing/manual_plotting.rst
+++ b/doc/source/visualizing/manual_plotting.rst
@@ -66,6 +66,57 @@
setting up multiple axes with colorbars easier than it would be using only
matplotlib can be found in the :ref:`advanced-multi-panel` cookbook recipe.
+.. _frb-filters:
+
+Fixed Resolution Buffer Filters
+-------------------------------
+
+The FRB can be modified by using set of predefined filters in order to e.g.
+create realistically looking, mock observation images out of simulation data.
+Applying filter is an irreversible operation, hence the order in which you are
+using them matters.
+
+.. python-script::
+
+ import matplotlib
+ matplotlib.use('Agg')
+ from matplotlib import pyplot as plt
+
+ import yt
+
+ ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+ slc = ds.slice('z', 0.5)
+ frb = slc.to_frb((20, 'kpc'), 512)
+ frb.apply_gauss_beam(nbeam=30, sigma=2.0)
+ frb.apply_white_noise(5e-23)
+ plt.imshow(frb['density'].d)
+ plt.savefig('frb_filters.png')
+
+Currently available filters:
+
+Gaussian Smoothing
+~~~~~~~~~~~~~~~~~~
+
+.. function:: apply_gauss_beam(self, nbeam=30, sigma=2.0)
+
+ (This is a proxy for
+ :class:`~yt.visualization.fixed_resolution_filters.FixedResolutionBufferGaussBeamFilter`.)
+
+ This filter convolves the FRB with 2d Gaussian that is "nbeam" pixel wide
+ and has standard deviation "sigma".
+
+White Noise
+~~~~~~~~~~~
+
+.. function:: apply_white_noise(self, bg_lvl=None)
+
+ (This is a proxy for
+ :class:`~yt.visualization.fixed_resolution_filters.FixedResolutionBufferWhiteNoiseFilter`.)
+
+ This filter adds white noise with the amplitude "bg_lvl" to the FRB.
+ If "bg_lvl" is not present, 10th percentile of the FRB's values is used
+ instead.
+
.. _manual-line-plots:
Line Plots
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 doc/source/visualizing/writing_fits_images.rst
--- a/doc/source/visualizing/writing_fits_images.rst
+++ b/doc/source/visualizing/writing_fits_images.rst
@@ -3,4 +3,4 @@
Writing FITS Images
==========================
-.. notebook:: FITSImageBuffer.ipynb
\ No newline at end of file
+.. notebook:: FITSImageData.ipynb
\ No newline at end of file
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 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
@@ -274,8 +274,8 @@
'b_thermal': thermal_b[lixel],
'redshift': field_data['redshift'][lixel],
'v_pec': peculiar_velocity})
- pbar.update(i)
- pbar.finish()
+ pbar.update(i)
+ pbar.finish()
del column_density, delta_lambda, thermal_b, \
center_bins, width_ratio, left_index, right_index
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/analysis_modules/halo_analysis/halo_callbacks.py
--- a/yt/analysis_modules/halo_analysis/halo_callbacks.py
+++ b/yt/analysis_modules/halo_analysis/halo_callbacks.py
@@ -400,7 +400,7 @@
The field used as the overdensity from which interpolation is done to
calculate virial quantities.
Default: ("gas", "overdensity")
- critical_density : float
+ critical_overdensity : float
The value of the overdensity at which to evaulate the virial quantities.
Overdensity is with respect to the critical density.
Default: 200
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/analysis_modules/ppv_cube/ppv_cube.py
--- a/yt/analysis_modules/ppv_cube/ppv_cube.py
+++ b/yt/analysis_modules/ppv_cube/ppv_cube.py
@@ -13,8 +13,7 @@
import numpy as np
from yt.utilities.on_demand_imports import _astropy
from yt.utilities.orientation import Orientation
-from yt.utilities.fits_image import FITSImageBuffer, sanitize_fits_unit, \
- create_sky_wcs
+from yt.utilities.fits_image import FITSImageData, sanitize_fits_unit
from yt.visualization.volume_rendering.camera import off_axis_projection
from yt.funcs import get_pbar
from yt.utilities.physical_constants import clight, mh
@@ -89,6 +88,8 @@
dims : integer, optional
The spatial resolution of the cube. Implies nx = ny, e.g. the
aspect ratio of the PPVCube's spatial dimensions is 1.
+ thermal_broad : boolean, optional
+ Whether or not to broaden the line using the gas temperature. Default: False.
atomic_weight : float, optional
Set this value to the atomic weight of the particle that is emitting the line
if *thermal_broad* is True. Defaults to 56 (Fe).
@@ -152,9 +153,7 @@
"methods are supported in PPVCube.")
dd = ds.all_data()
-
fd = dd._determine_fields(field)[0]
-
self.field_units = ds._get_field_info(fd).units
self.vbins = ds.arr(np.linspace(velocity_bounds[0],
@@ -172,7 +171,7 @@
_vlos = create_vlos(normal, self.no_shifting)
self.ds.add_field(("gas","v_los"), function=_vlos, units="cm/s")
- _intensity = self.create_intensity()
+ _intensity = self._create_intensity()
self.ds.add_field(("gas","intensity"), function=_intensity, units=self.field_units)
if method == "integrate" and weight_field is None:
@@ -214,16 +213,6 @@
self.ds.field_info.pop(("gas","intensity"))
self.ds.field_info.pop(("gas","v_los"))
- def create_intensity(self):
- def _intensity(field, data):
- v = self.current_v-data["v_los"].v
- T = data["temperature"].v
- w = ppv_utils.compute_weight(self.thermal_broad, self.dv_cgs,
- self.particle_mass, v.flatten(), T.flatten())
- w[np.isnan(w)] = 0.0
- return data[self.field]*w.reshape(v.shape)
- return _intensity
-
def transform_spectral_axis(self, rest_value, units):
"""
Change the units of the spectral axis to some equivalent unit, such
@@ -259,17 +248,18 @@
self.dv = self.vbins[1]-self.vbins[0]
@parallel_root_only
- def write_fits(self, filename, clobber=True, length_unit=None,
+ def write_fits(self, filename, clobber=False, length_unit=None,
sky_scale=None, sky_center=None):
r""" Write the PPVCube to a FITS file.
Parameters
----------
filename : string
- The name of the file to write.
- clobber : boolean
- Whether or not to clobber an existing file with the same name.
- length_unit : string
+ The name of the file to write to.
+ clobber : boolean, optional
+ Whether to overwrite a file with the same name that already
+ exists. Default False.
+ length_unit : string, optional
The units to convert the coordinates to in the file.
sky_scale : tuple, optional
Conversion between an angle unit and a length unit, if sky
@@ -280,7 +270,8 @@
Examples
--------
- >>> cube.write_fits("my_cube.fits", clobber=False, sky_scale=(1.0,"arcsec/kpc"))
+ >>> cube.write_fits("my_cube.fits", clobber=False,
+ ... sky_scale=(1.0,"arcsec/kpc"), sky_center=(30.,45.))
"""
vunit = fits_info[self.axis_type][0]
vtype = fits_info[self.axis_type][1]
@@ -303,13 +294,11 @@
w.wcs.cunit = [units,units,vunit]
w.wcs.ctype = ["LINEAR","LINEAR",vtype]
+ fib = FITSImageData(self.data.transpose(), fields=self.field, wcs=w)
+ fib.update_all_headers("bunit", re.sub('()', '', str(self.proj_units)))
+ fib.update_all_headers("btype", self.field)
if sky_scale is not None and sky_center is not None:
- w = create_sky_wcs(w, sky_center, sky_scale)
-
- fib = FITSImageBuffer(self.data.transpose(), fields=self.field, wcs=w)
- fib[0].header["bunit"] = re.sub('()', '', str(self.proj_units))
- fib[0].header["btype"] = self.field
-
+ fib.create_sky_wcs(sky_center, sky_scale)
fib.writeto(filename, clobber=clobber)
def __repr__(self):
@@ -320,3 +309,13 @@
def __getitem__(self, item):
return self.data[item]
+
+ def _create_intensity(self):
+ def _intensity(field, data):
+ v = self.current_v-data["v_los"].in_cgs().v
+ T = (data["temperature"]).in_cgs().v
+ w = ppv_utils.compute_weight(self.thermal_broad, self.dv_cgs,
+ self.particle_mass, v.flatten(), T.flatten())
+ w[np.isnan(w)] = 0.0
+ return data[self.field]*w.reshape(v.shape)
+ return _intensity
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/analysis_modules/ppv_cube/tests/test_ppv.py
--- a/yt/analysis_modules/ppv_cube/tests/test_ppv.py
+++ b/yt/analysis_modules/ppv_cube/tests/test_ppv.py
@@ -1,5 +1,5 @@
"""
-Unit test the sunyaev_zeldovich analysis module.
+Unit test the PPVCube analysis module.
"""
#-----------------------------------------------------------------------------
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/analysis_modules/sunyaev_zeldovich/projection.py
--- a/yt/analysis_modules/sunyaev_zeldovich/projection.py
+++ b/yt/analysis_modules/sunyaev_zeldovich/projection.py
@@ -316,7 +316,7 @@
>>> sky_center = (30., 45., "deg")
>>> szprj.write_fits("SZbullet.fits", sky_center=sky_center, sky_scale=sky_scale)
"""
- from yt.utilities.fits_image import FITSImageBuffer, create_sky_wcs
+ from yt.utilities.fits_image import FITSImageData
dx = self.dx.in_units("kpc")
dy = dx
@@ -328,10 +328,9 @@
w.wcs.cunit = ["kpc"]*2
w.wcs.ctype = ["LINEAR"]*2
+ fib = FITSImageData(self.data, fields=self.data.keys(), wcs=w)
if sky_scale is not None and sky_center is not None:
- w = create_sky_wcs(w, sky_center, sky_scale)
-
- fib = FITSImageBuffer(self.data, fields=self.data.keys(), wcs=w)
+ fib.create_sky_wcs(sky_center, sky_scale)
fib.writeto(filename, clobber=clobber)
@parallel_root_only
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -92,7 +92,7 @@
>>> streamlines = Streamlines(ds, [0.5]*3)
>>> streamlines.integrate_through_volume()
>>> stream = streamlines.path(0)
- >>> matplotlib.pylab.semilogy(stream['t'], stream['Density'], '-x')
+ >>> matplotlib.pylab.semilogy(stream['t'], stream['density'], '-x')
"""
_type_name = "streamline"
@@ -991,12 +991,13 @@
This will create a data object, find a nice value in the center, and
output the vertices to "triangles.obj" after rescaling them.
+ >>> from yt.units import kpc
>>> sp = ds.sphere("max", (10, "kpc")
- >>> surf = ds.surface(sp, "Density", 5e-27)
- >>> print surf["Temperature"]
+ >>> surf = ds.surface(sp, "density", 5e-27)
+ >>> print surf["temperature"]
>>> print surf.vertices
- >>> bounds = [(sp.center[i] - 5.0/ds['kpc'],
- ... sp.center[i] + 5.0/ds['kpc']) for i in range(3)]
+ >>> bounds = [(sp.center[i] - 5.0*kpc,
+ ... sp.center[i] + 5.0*kpc) for i in range(3)]
>>> surf.export_ply("my_galaxy.ply", bounds = bounds)
"""
_type_name = "surface"
@@ -1117,9 +1118,9 @@
calculate the metal flux over it.
>>> sp = ds.sphere("max", (10, "kpc")
- >>> surf = ds.surface(sp, "Density", 5e-27)
+ >>> surf = ds.surface(sp, "density", 5e-27)
>>> flux = surf.calculate_flux(
- ... "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
+ ... "velocity_x", "velocity_y", "velocity_z", "metal_density")
"""
flux = 0.0
mylog.info("Fluxing %s", fluxing_field)
@@ -1204,18 +1205,18 @@
>>> sp = ds.sphere("max", (10, "kpc"))
>>> trans = 1.0
>>> distf = 3.1e18*1e3 # distances into kpc
- >>> surf = ds.surface(sp, "Density", 5e-27)
+ >>> surf = ds.surface(sp, "density", 5e-27)
>>> surf.export_obj("my_galaxy", transparency=trans, dist_fac = distf)
>>> sp = ds.sphere("max", (10, "kpc"))
- >>> mi, ma = sp.quantities['Extrema']('Temperature')[0]
+ >>> mi, ma = sp.quantities.extrema('temperature')[0]
>>> rhos = [1e-24, 1e-25]
>>> trans = [0.5, 1.0]
>>> distf = 3.1e18*1e3 # distances into kpc
>>> for i, r in enumerate(rhos):
- ... surf = ds.surface(sp,'Density',r)
+ ... surf = ds.surface(sp,'density',r)
... surf.export_obj("my_galaxy", transparency=trans[i],
- ... color_field='Temperature', dist_fac = distf,
+ ... color_field='temperature', dist_fac = distf,
... plot_index = i, color_field_max = ma,
... color_field_min = mi)
@@ -1224,12 +1225,12 @@
>>> trans = [0.5, 1.0]
>>> distf = 3.1e18*1e3 # distances into kpc
>>> def _Emissivity(field, data):
- ... return (data['Density']*data['Density']*np.sqrt(data['Temperature']))
- >>> add_field("Emissivity", function=_Emissivity, units=r"\rm{g K}/\rm{cm}^{6}")
+ ... return (data['density']*data['density']*np.sqrt(data['temperature']))
+ >>> ds.add_field("emissivity", function=_Emissivity, units=r"g*K/cm**6")
>>> for i, r in enumerate(rhos):
- ... surf = ds.surface(sp,'Density',r)
- ... surf.export_obj("my_galaxy", transparency=trans[i],
- ... color_field='Temperature', emit_field = 'Emissivity',
+ ... surf = ds.surface(sp,'density',r)
+ ... surf.export_obj("my_galaxy", transparency=trans[i],
+ ... color_field='temperature', emit_field = 'emissivity',
... dist_fac = distf, plot_index = i)
"""
@@ -1459,18 +1460,18 @@
>>> sp = ds.sphere("max", (10, "kpc"))
>>> trans = 1.0
>>> distf = 3.1e18*1e3 # distances into kpc
- >>> surf = ds.surface(sp, "Density", 5e-27)
+ >>> surf = ds.surface(sp, "density", 5e-27)
>>> surf.export_obj("my_galaxy", transparency=trans, dist_fac = distf)
>>> sp = ds.sphere("max", (10, "kpc"))
- >>> mi, ma = sp.quantities['Extrema']('Temperature')[0]
+ >>> mi, ma = sp.quantities.extrema('temperature')[0]
>>> rhos = [1e-24, 1e-25]
>>> trans = [0.5, 1.0]
>>> distf = 3.1e18*1e3 # distances into kpc
>>> for i, r in enumerate(rhos):
- ... surf = ds.surface(sp,'Density',r)
+ ... surf = ds.surface(sp,'density',r)
... surf.export_obj("my_galaxy", transparency=trans[i],
- ... color_field='Temperature', dist_fac = distf,
+ ... color_field='temperature', dist_fac = distf,
... plot_index = i, color_field_max = ma,
... color_field_min = mi)
@@ -1479,12 +1480,12 @@
>>> trans = [0.5, 1.0]
>>> distf = 3.1e18*1e3 # distances into kpc
>>> def _Emissivity(field, data):
- ... return (data['Density']*data['Density']*np.sqrt(data['Temperature']))
- >>> add_field("Emissivity", function=_Emissivity, units=r"\rm{g K}/\rm{cm}^{6}")
+ ... return (data['density']*data['density']*np.sqrt(data['temperature']))
+ >>> ds.add_field("emissivity", function=_Emissivity, units="g / cm**6")
>>> for i, r in enumerate(rhos):
- ... surf = ds.surface(sp,'Density',r)
+ ... surf = ds.surface(sp,'density',r)
... surf.export_obj("my_galaxy", transparency=trans[i],
- ... color_field='Temperature', emit_field = 'Emissivity',
+ ... color_field='temperature', emit_field = 'emissivity',
... dist_fac = distf, plot_index = i)
"""
@@ -1581,12 +1582,13 @@
Examples
--------
+ >>> from yt.units import kpc
>>> sp = ds.sphere("max", (10, "kpc")
- >>> surf = ds.surface(sp, "Density", 5e-27)
- >>> print surf["Temperature"]
+ >>> surf = ds.surface(sp, "density", 5e-27)
+ >>> print surf["temperature"]
>>> print surf.vertices
- >>> bounds = [(sp.center[i] - 5.0/ds['kpc'],
- ... sp.center[i] + 5.0/ds['kpc']) for i in range(3)]
+ >>> bounds = [(sp.center[i] - 5.0*kpc,
+ ... sp.center[i] + 5.0*kpc) for i in range(3)]
>>> surf.export_ply("my_galaxy.ply", bounds = bounds)
"""
if self.vertices is None:
@@ -1716,18 +1718,17 @@
Examples
--------
- >>> from yt.mods import *
- >>> ds = load("redshift0058")
+ >>> from yt.units import kpc
>>> dd = ds.sphere("max", (200, "kpc"))
>>> rho = 5e-27
- >>> bounds = [(dd.center[i] - 100.0/ds['kpc'],
- ... dd.center[i] + 100.0/ds['kpc']) for i in range(3)]
+ >>> bounds = [(dd.center[i] - 100.0*kpc,
+ ... dd.center[i] + 100.0*kpc) for i in range(3)]
...
- >>> surf = ds.surface(dd, "Density", rho)
+ >>> surf = ds.surface(dd, "density", rho)
>>> rv = surf.export_sketchfab(
... title = "Testing Upload",
... description = "A simple test of the uploader",
- ... color_field = "Temperature",
+ ... color_field = "temperature",
... color_map = "hot",
... color_log = True,
... bounds = bounds)
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -937,6 +937,9 @@
def items(self):
return [(k,self[k]) for k in self.field_data.keys()]
+ def keys(self):
+ return self.field_data.keys()
+
def __iter__(self):
return sorted(self.items())
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -35,6 +35,8 @@
ValidateSpatial
from yt.fields.field_info_container import \
FieldInfoContainer, NullFunc
+from yt.fields.fluid_fields import \
+ setup_gradient_fields
from yt.data_objects.particle_filters import \
filter_registry
from yt.data_objects.particle_unions import \
@@ -965,6 +967,50 @@
validators=[ValidateSpatial()])
return ("deposit", field_name)
+ def add_gradient_fields(self, input_field):
+ """Add gradient fields.
+
+ Creates four new grid-based fields that represent the components of
+ the gradient of an existing field, plus an extra field for the magnitude
+ of the gradient. Currently only supported in Cartesian geometries. The
+ gradient is computed using second-order centered differences.
+
+ Parameters
+ ----------
+ input_field : tuple
+ The field name tuple of the particle field the deposited field will
+ be created from. This must be a field name tuple so yt can
+ appropriately infer the correct field type.
+
+ Returns
+ -------
+ A list of field name tuples for the newly created fields.
+
+ Examples
+ --------
+ >>> grad_fields = ds.add_gradient_fields(("gas","temperature"))
+ >>> print(grad_fields)
+ [('gas', 'temperature_gradient_x'),
+ ('gas', 'temperature_gradient_y'),
+ ('gas', 'temperature_gradient_z'),
+ ('gas', 'temperature_gradient_magnitude')]
+ """
+ self.index
+ if isinstance(input_field, tuple):
+ ftype, input_field = input_field[0], input_field[1]
+ else:
+ raise RuntimeError
+ units = self.field_info[ftype, input_field].units
+ setup_gradient_fields(self.field_info, (ftype, input_field), units)
+ # Now we make a list of the fields that were just made, to check them
+ # and to return them
+ grad_fields = [(ftype,input_field+"_gradient_%s" % suffix)
+ for suffix in "xyz"]
+ grad_fields.append((ftype,input_field+"_gradient_magnitude"))
+ deps, _ = self.field_info.check_derived_fields(grad_fields)
+ self.field_dependencies.update(deps)
+ return grad_fields
+
def _reconstruct_ds(*args, **kwargs):
datasets = ParameterFileStore()
ds = datasets.get_ds_hash(*args)
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/fields/field_detector.py
--- a/yt/fields/field_detector.py
+++ b/yt/fields/field_detector.py
@@ -136,6 +136,11 @@
self[item] = \
YTArray(np.ones((self.NumberOfParticles, 3)),
finfo.units, registry=self.ds.unit_registry)
+ elif "FourMetalFractions" in (item, item[1]):
+ self[item] = \
+ YTArray(np.ones((self.NumberOfParticles, 4)),
+ finfo.units, registry=self.ds.unit_registry)
+
else:
# Not a vector
self[item] = \
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -61,6 +61,10 @@
'Mg_fraction',
'Si_fraction',
'Fe_fraction',
+ 'C_density',
+ 'O_density',
+ 'Si_density',
+ 'Fe_density'
)
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -194,6 +194,18 @@
ret = ad[fn]
assert_equal(ret.sum(), ad['particle_ones'].sum())
+def test_add_gradient_fields():
+ gfields = base_ds.add_gradient_fields(("gas","density"))
+ field_list = [('gas', 'density_gradient_x'),
+ ('gas', 'density_gradient_y'),
+ ('gas', 'density_gradient_z'),
+ ('gas', 'density_gradient_magnitude')]
+ assert_equal(gfields, field_list)
+ ad = base_ds.all_data()
+ for field in field_list:
+ ret = ad[field]
+ assert str(ret.units) == "g/cm**4"
+
def get_data(ds, field_name):
# Need to create a new data object otherwise the errors we are
# intentionally raising lead to spurious GenerationInProgress errors
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/chombo/api.py
--- a/yt/frontends/chombo/api.py
+++ b/yt/frontends/chombo/api.py
@@ -33,7 +33,6 @@
PlutoFieldInfo
from .io import \
- IOHandlerChomboHDF5,\
- IOHandlerPlutoHDF5
+ IOHandlerChomboHDF5
from . import tests
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -47,6 +47,7 @@
class ChomboGrid(AMRGridPatch):
_id_offset = 0
__slots__ = ["_level_id", "stop_index"]
+
def __init__(self, id, index, level, start, stop):
AMRGridPatch.__init__(self, id, filename = index.index_filename,
index = index)
@@ -99,12 +100,6 @@
self.domain_left_edge = ds.domain_left_edge
self.domain_right_edge = ds.domain_right_edge
self.dataset_type = dataset_type
-
- if ds.dimensionality == 1:
- self.dataset_type = "chombo1d_hdf5"
- if ds.dimensionality == 2:
- self.dataset_type = "chombo2d_hdf5"
-
self.field_indexes = {}
self.dataset = weakref.proxy(ds)
# for now, the index file is the dataset!
@@ -114,7 +109,7 @@
self._handle = ds._handle
tr = self._handle['Chombo_global'].attrs.get("testReal", "float32")
-
+
self._levels = [key for key in self._handle.keys() if key.startswith('level')]
GridIndex.__init__(self, ds, dataset_type)
@@ -256,17 +251,10 @@
self._handle = HDF5FileHandler(filename)
self.dataset_type = dataset_type
- # look up the dimensionality of the dataset
- D = self._handle['Chombo_global/'].attrs['SpaceDim']
- if D == 1:
- self.dataset_type = 'chombo1d_hdf5'
- if D == 2:
- self.dataset_type = 'chombo2d_hdf5'
-
self.geometry = "cartesian"
self.ini_filename = ini_filename
self.fullplotdir = os.path.abspath(filename)
- Dataset.__init__(self,filename, self.dataset_type,
+ Dataset.__init__(self, filename, self.dataset_type,
units_override=units_override)
self.storage_filename = storage_filename
self.cosmological_simulation = False
@@ -398,7 +386,7 @@
class PlutoHierarchy(ChomboHierarchy):
- def __init__(self, ds, dataset_type="pluto_chombo_native"):
+ def __init__(self, ds, dataset_type="chombo_hdf5"):
ChomboHierarchy.__init__(self, ds, dataset_type)
def _parse_index(self):
@@ -456,7 +444,7 @@
_index_class = PlutoHierarchy
_field_info_class = PlutoFieldInfo
- def __init__(self, filename, dataset_type='pluto_chombo_native',
+ def __init__(self, filename, dataset_type='chombo_hdf5',
storage_filename = None, ini_filename = None,
units_override=None):
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/chombo/io.py
--- a/yt/frontends/chombo/io.py
+++ b/yt/frontends/chombo/io.py
@@ -93,15 +93,11 @@
self._particle_field_index = field_dict
return self._particle_field_index
- def _read_field_names(self, grid):
- ncomp = int(self._handle.attrs['num_components'])
- fns = [c[1] for c in f.attrs.items()[-ncomp-1:-1]]
-
def _read_data(self, grid, field):
lstring = 'level_%i' % grid.Level
lev = self._handle[lstring]
dims = grid.ActiveDimensions
- shape = grid.ActiveDimensions + 2*self.ghost
+ shape = dims + 2*self.ghost
boxsize = shape.prod()
if self._offsets is not None:
@@ -112,7 +108,7 @@
stop = start + boxsize
data = lev[self._data_string][start:stop]
data_no_ghost = data.reshape(shape, order='F')
- ghost_slice = [slice(g, d-g, None) for g, d in zip(self.ghost, grid.ActiveDimensions)]
+ ghost_slice = [slice(g, d-g, None) for g, d in zip(self.ghost, dims)]
ghost_slice = ghost_slice[0:self.dim]
return data_no_ghost[ghost_slice]
@@ -201,43 +197,6 @@
return np.asarray(data[field_index::items_per_particle], dtype=np.float64, order='F')
-class IOHandlerChombo2DHDF5(IOHandlerChomboHDF5):
- _dataset_type = "chombo2d_hdf5"
- _offset_string = 'data:offsets=0'
- _data_string = 'data:datatype=0'
-
- def __init__(self, ds, *args, **kwargs):
- BaseIOHandler.__init__(self, ds, *args, **kwargs)
- self.ds = ds
- self._handle = ds._handle
- self.dim = 2
- self._read_ghost_info()
-
-
-class IOHandlerChombo1DHDF5(IOHandlerChomboHDF5):
- _dataset_type = "chombo1d_hdf5"
- _offset_string = 'data:offsets=0'
- _data_string = 'data:datatype=0'
-
- def __init__(self, ds, *args, **kwargs):
- BaseIOHandler.__init__(self, ds, *args, **kwargs)
- self.ds = ds
- self.dim = 1
- self._handle = ds._handle
- self._read_ghost_info()
-
-
-class IOHandlerPlutoHDF5(IOHandlerChomboHDF5):
- _dataset_type = "pluto_chombo_native"
- _offset_string = 'data:offsets=0'
- _data_string = 'data:datatype=0'
-
- def __init__(self, ds, *args, **kwargs):
- BaseIOHandler.__init__(self, ds, *args, **kwargs)
- self.ds = ds
- self._handle = ds._handle
-
-
def parse_orion_sinks(fn):
'''
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/enzo/data_structures.py
--- a/yt/frontends/enzo/data_structures.py
+++ b/yt/frontends/enzo/data_structures.py
@@ -452,9 +452,16 @@
if "AppendActiveParticleType" in self.dataset.parameters:
ap_fields = self._detect_active_particle_fields()
field_list = list(set(field_list).union(ap_fields))
+ ptypes = self.dataset.particle_types
+ ptypes_raw = self.dataset.particle_types_raw
else:
field_list = None
+ ptypes = None
+ ptypes_raw = None
self.field_list = list(self.comm.mpi_bcast(field_list))
+ self.dataset.particle_types = list(self.comm.mpi_bcast(ptypes))
+ self.dataset.particle_types_raw = list(self.comm.mpi_bcast(ptypes_raw))
+
def _generate_random_grids(self):
if self.num_grids > 40:
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/fits/data_structures.py
--- a/yt/frontends/fits/data_structures.py
+++ b/yt/frontends/fits/data_structures.py
@@ -159,7 +159,7 @@
naxis4 = 1
for i, fits_file in enumerate(self.dataset._handle._fits_files):
for j, hdu in enumerate(fits_file):
- if isinstance(hdu, _astropy.pyfits.BinTableHDU):
+ if isinstance(hdu, _astropy.pyfits.BinTableHDU) or hdu.header["naxis"] == 0:
continue
if self._ensure_same_dims(hdu):
units = self._determine_image_units(hdu.header, known_units)
@@ -386,14 +386,17 @@
(self.events_info["y"][1]-self.events_info["y"][0])/self.reblock]
else:
self.events_data = False
- self.first_image = 0
+ # Sometimes the primary hdu doesn't have an image
+ if len(self._handle) > 1 and self._handle[0].header["naxis"] == 0:
+ self.first_image = 1
+ else:
+ self.first_image = 0
self.primary_header = self._handle[self.first_image].header
self.naxis = self.primary_header["naxis"]
- self.axis_names = [self.primary_header["ctype%d" % (i+1)]
+ self.axis_names = [self.primary_header.get("ctype%d" % (i+1),"LINEAR")
for i in range(self.naxis)]
self.dims = [self.primary_header["naxis%d" % (i+1)]
for i in range(self.naxis)]
-
wcs = _astropy.pywcs.WCS(header=self.primary_header)
if self.naxis == 4:
self.wcs = _astropy.pywcs.WCS(naxis=3)
@@ -515,12 +518,20 @@
# Check to see if this data is in some kind of (Lat,Lon,Vel) format
self.spec_cube = False
+ self.wcs_2d = None
x = 0
for p in lon_prefixes+lat_prefixes+list(spec_names.keys()):
y = np_char.startswith(self.axis_names[:self.dimensionality], p)
x += np.any(y)
- if x == self.dimensionality and self.axis_names != ['LINEAR','LINEAR']:
- self._setup_spec_cube()
+ if x == self.dimensionality:
+ if self.axis_names == ['LINEAR','LINEAR']:
+ self.wcs_2d = self.wcs
+ self.lat_axis = 1
+ self.lon_axis = 0
+ self.lat_name = "Y"
+ self.lon_name = "X"
+ else:
+ self._setup_spec_cube()
def _setup_spec_cube(self):
@@ -587,7 +598,7 @@
self.spectral_factor*Dz
self._dz /= self.spectral_factor
self._p0 = (self._p0-0.5)*self.spectral_factor + 0.5
-
+
else:
self.wcs_2d = self.wcs
@@ -620,8 +631,8 @@
warnings.filterwarnings('ignore', category=UserWarning, append=True)
fileh = _astropy.pyfits.open(args[0])
valid = fileh[0].header["naxis"] >= 2
- if len(fileh) > 1 and fileh[1].name == "EVENTS":
- valid = fileh[1].header["naxis"] >= 2
+ if len(fileh) > 1:
+ valid = fileh[1].header["naxis"] >= 2 or valid
fileh.close()
return valid
except:
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/fits/misc.py
--- a/yt/frontends/fits/misc.py
+++ b/yt/frontends/fits/misc.py
@@ -18,7 +18,7 @@
from yt.funcs import mylog, get_image_suffix
from yt.visualization._mpl_imports import FigureCanvasAgg
from yt.units.yt_array import YTQuantity, YTArray
-from yt.utilities.fits_image import FITSImageBuffer
+from yt.utilities.fits_image import FITSImageData
import os
@@ -127,7 +127,7 @@
w = subcube.wcs.copy()
w.wcs.crpix[-1] = 0.5
w.wcs.crval[-1] = -0.5*width
- fid = FITSImageBuffer(slab_data, wcs=w)
+ fid = FITSImageData(slab_data, wcs=w)
for hdu in fid:
hdu.header.pop("RESTFREQ", None)
hdu.header.pop("RESTFRQ", None)
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/gadget/definitions.py
--- a/yt/frontends/gadget/definitions.py
+++ b/yt/frontends/gadget/definitions.py
@@ -65,5 +65,22 @@
("Electron_Number_Density", "Gas"),
("HI_NumberDensity", "Gas"),
("SmoothingLength", "Gas"),
- )
+ ),
+ group0000 = ( "Coordinates",
+ "Velocities",
+ "ParticleIDs",
+ "Mass",
+ "Potential",
+ ("Temperature", "Gas"),
+ ("Density", "Gas"),
+ ("ElectronNumberDensity", "Gas"),
+ ("HI_NumberDensity", "Gas"),
+ ("SmoothingLength", "Gas"),
+ ("StarFormationRate", "Gas"),
+ ("DelayTime", "Gas"),
+ ("FourMetalFractions", ("Gas", "Stars")),
+ ("MaxTemperature", ("Gas", "Stars")),
+ ("NStarsSpawned", ("Gas", "Stars")),
+ ("StellarAge", "Stars")
+ ),
)
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/gadget/fields.py
--- a/yt/frontends/gadget/fields.py
+++ b/yt/frontends/gadget/fields.py
@@ -21,13 +21,53 @@
class GadgetFieldInfo(SPHFieldInfo):
def setup_particle_fields(self, ptype, *args, **kwargs):
+
+ # setup some special fields that only make sense for SPH particles
+
+ if (ptype, "FourMetalFractions") in self.ds.field_list:
+ self._setup_four_metal_fractions(ptype)
+
super(GadgetFieldInfo, self).setup_particle_fields(
ptype, *args, **kwargs)
- # setup some special fields that only make sense for SPH particles
if ptype in ("PartType0", "Gas"):
self.setup_gas_particle_fields(ptype)
+ def _setup_four_metal_fractions(self, ptype):
+ """
+ This function breaks the FourMetalFractions field (if present)
+ into its four component metal fraction fields and adds
+ corresponding metal density fields which will later get smoothed
+
+ This gets used with the Gadget group0000 format
+ as defined in the gadget_field_specs in frontends/gadget/definitions.py
+ """
+ metal_names = ['C', 'O', 'Si', 'Fe']
+ for i, metal_name in enumerate(metal_names):
+
+ # add the metal fraction fields
+ def _Fraction_wrap(i):
+ def _Fraction(field, data):
+ return data[(ptype, 'FourMetalFractions')][:,i]
+ return _Fraction
+
+ self.add_field( (ptype, metal_name+"_fraction"),
+ function=_Fraction_wrap(i),
+ particle_type=True,
+ units="")
+
+ # add the metal density fields
+ def _Density_wrap(i):
+ def _Metal_density(field, data):
+ return data[(ptype, 'FourMetalFractions')][:,i] * \
+ data[(ptype, 'density')]
+ return _Metal_density
+
+ self.add_field( (ptype, metal_name+"_density"),
+ function=_Density_wrap(i),
+ particle_type=True,
+ units="g/cm**3")
+
def setup_gas_particle_fields(self, ptype):
if (ptype, "ElectronAbundance") in self.ds.field_list:
def _temperature(field, data):
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/frontends/gadget/io.py
--- a/yt/frontends/gadget/io.py
+++ b/yt/frontends/gadget/io.py
@@ -33,7 +33,10 @@
class IOHandlerGadgetBinary(BaseIOHandler):
_dataset_type = "gadget_binary"
- _vector_fields = ("Coordinates", "Velocity", "Velocities")
+ _vector_fields = (("Coordinates", 3),
+ ("Velocity", 3),
+ ("Velocities", 3),
+ ("FourMetalFractions", 4))
# Particle types (Table 3 in GADGET-2 user guide)
#
@@ -54,6 +57,7 @@
_var_mass = None
def __init__(self, ds, *args, **kwargs):
+ self._vector_fields = dict(self._vector_fields)
self._fields = ds._field_spec
self._ptypes = ds._ptype_spec
super(IOHandlerGadgetBinary, self).__init__(ds, *args, **kwargs)
@@ -126,10 +130,11 @@
else:
dt = "float32"
if name in self._vector_fields:
- count *= 3
+ count *= self._vector_fields[name]
arr = np.fromfile(f, dtype=dt, count = count)
if name in self._vector_fields:
- arr = arr.reshape((count/3, 3), order="C")
+ factor = self._vector_fields[name]
+ arr = arr.reshape((count/factor, factor), order="C")
return arr.astype("float64")
def _initialize_index(self, data_file, regions):
@@ -177,7 +182,7 @@
offsets[(ptype, field)] = pos
any_ptypes = True
if field in self._vector_fields:
- pos += 3 * pcount[ptype] * fs
+ pos += self._vector_fields[field] * pcount[ptype] * fs
else:
pos += pcount[ptype] * fs
pos += 4
@@ -203,6 +208,8 @@
field, req = field
if req is ZeroMass:
if m > 0.0 : continue
+ elif isinstance(req, tuple) and ptype in req:
+ pass
elif req != ptype:
continue
field_list.append((ptype, field))
diff -r ad1c905fde6444e7e4c4021b60ed66c642aa6e67 -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 yt/geometry/grid_geometry_handler.py
--- a/yt/geometry/grid_geometry_handler.py
+++ b/yt/geometry/grid_geometry_handler.py
@@ -286,7 +286,7 @@
return g.filename
if dobj._type_name == "grid":
dobj._chunk_info = np.empty(1, dtype='object')
- dobj._chunk_info[0] = dobj
+ dobj._chunk_info[0] = weakref.proxy(dobj)
elif getattr(dobj, "_grids", None) is None:
gi = dobj.selector.select_grids(self.grid_left_edge,
self.grid_right_edge,
This diff is so big that we needed to truncate the remainder.
https://bitbucket.org/yt_analysis/yt/commits/b641ebb30958/
Changeset: b641ebb30958
Branch: yt
User: atmyers
Date: 2015-06-29 20:41:12+00:00
Summary: restoring some changes that got lost somehow
Affected #: 1 file
diff -r 049b989a5f23b59b672f0f50f804ce70d84b26b8 -r b641ebb3095886b0452d2e5cb2692879fec3391a yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -21,11 +21,6 @@
particle_vector_functions, \
standard_particle_fields
-from yt.frontends.boxlib.fields import \
- rho_units, \
- mom_units, \
- eden_units
-
from yt.utilities.exceptions import YTFieldNotFound
rho_units = "code_mass / code_length**3"
@@ -53,9 +48,9 @@
("Y-momentum", (mom_units, ["momentum_y"], None)),
("Z-momentum", (mom_units, ["momentum_z"], None)),
("temperature", ("K", ["temperature"], None)),
- ("X-magnfield", ("gauss", ["magnetic_field_x"], None)),
- ("Y-magnfield", ("gauss", ["magnetic_field_y"], None)),
- ("Z-magnfield", ("gauss", ["magnetic_field_z"], None)),
+ ("X-magnfield", (b_units, ["magnetic_field_x"], None)),
+ ("Y-magnfield", (b_units, ["magnetic_field_y"], None)),
+ ("Z-magnfield", (b_units, ["magnetic_field_z"], None)),
("directrad-dedt-density", (eden_units, ["directrad-dedt-density"], None)),
("directrad-dpxdt-density", (mom_units, ["directrad-dpxdt-density"], None)),
("directrad-dpydt-density", (mom_units, ["directrad-dpydt-density"], None)),
@@ -66,9 +61,9 @@
("particle_position_x", ("code_length", [], None)),
("particle_position_y", ("code_length", [], None)),
("particle_position_z", ("code_length", [], None)),
- ("particle_momentum_x", (mom_units, [], None)),
- ("particle_momentum_y", (mom_units, [], None)),
- ("particle_momentum_z", (mom_units, [], None)),
+ ("particle_momentum_x", ("code_mass*code_length/code_time", [], None)),
+ ("particle_momentum_y", ("code_mass*code_length/code_time", [], None)),
+ ("particle_momentum_z", ("code_mass*code_length/code_time", [], None)),
# Note that these are *internal* agmomen
("particle_angmomen_x", ("code_length**2/code_time", [], None)),
("particle_angmomen_y", ("code_length**2/code_time", [], None)),
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