[yt-svn] commit/yt: xarthisius: Merged in jzuhone/yt (pull request #1326)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Dec 3 09:43:33 PST 2014
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/ee4276f9be71/
Changeset: ee4276f9be71
Branch: yt
User: xarthisius
Date: 2014-12-03 17:43:19+00:00
Summary: Merged in jzuhone/yt (pull request #1326)
[bugfix] Fixing problems in docs build, adding some keywords back to FITSImageBuffer
Affected #: 6 files
diff -r 02ef23fcc82e96c58e4786027e42534cc6d09be1 -r ee4276f9be712f57aa6dc829d7990fe6f8511f83 doc/source/analyzing/analysis_modules/PPVCube.ipynb
--- a/doc/source/analyzing/analysis_modules/PPVCube.ipynb
+++ b/doc/source/analyzing/analysis_modules/PPVCube.ipynb
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
- "signature": "sha256:b83e125278c2e58da4d99ac9d2ca2a136d01f1094e1b83497925e0f9b9b056c2"
+ "signature": "sha256:7ba601e381023e5b7c00a585ccaa55996316d2dfe7f8c96284b4539e1ee5b846"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -193,7 +193,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "cube = PPVCube(ds, L, \"density\", dims=(200,100,50), velocity_bounds=(-150.,150.,\"km/s\"))"
+ "cube = PPVCube(ds, L, \"density\", dims=(200,100,50), velocity_bounds=(-150.,150.,\"km/s\"), method=\"sum\")"
],
"language": "python",
"metadata": {},
@@ -335,7 +335,7 @@
"collapsed": false,
"input": [
"cube2 = PPVCube(ds, L, \"density\", dims=(200,100,50), velocity_bounds=(-150,150,\"km/s\"), thermal_broad=True, \n",
- " atomic_weight=12.0)\n",
+ " atomic_weight=12.0, method=\"sum\")\n",
"cube2.write_fits(\"cube2.fits\", clobber=True, length_unit=\"kpc\")"
],
"language": "python",
diff -r 02ef23fcc82e96c58e4786027e42534cc6d09be1 -r ee4276f9be712f57aa6dc829d7990fe6f8511f83 doc/source/cookbook/fits_xray_images.ipynb
--- a/doc/source/cookbook/fits_xray_images.ipynb
+++ b/doc/source/cookbook/fits_xray_images.ipynb
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
- "signature": "sha256:650e3fc7f66951a5fcdb18332bbc625f6f6e449fc919acd01da01e1fbbf92ee1"
+ "signature": "sha256:73eb48af6c5628619b5cab88840f6ac2b3eb278ae057c34d567f4a127181b8fb"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -74,15 +74,15 @@
"def _counts(field, data):\n",
" exposure_time = data.get_field_parameter(\"exposure_time\")\n",
" return data[\"flux\"]*data[\"pixel\"]*exposure_time\n",
- "ds.add_field(name=\"counts\", function=_counts, units=\"counts\", take_log=False)\n",
+ "ds.add_field((\"gas\",\"counts\"), function=_counts, units=\"counts\", take_log=False)\n",
"\n",
"def _pp(field, data):\n",
" return np.sqrt(data[\"counts\"])*data[\"projected_temperature\"]\n",
- "ds.add_field(name=\"pseudo_pressure\", function=_pp, units=\"sqrt(counts)*keV\", take_log=False)\n",
+ "ds.add_field((\"gas\",\"pseudo_pressure\"), function=_pp, units=\"sqrt(counts)*keV\", take_log=False)\n",
"\n",
"def _pe(field, data):\n",
" return data[\"projected_temperature\"]*data[\"counts\"]**(-1./3.)\n",
- "ds.add_field(name=\"pseudo_entropy\", function=_pe, units=\"keV*(counts)**(-1/3)\", take_log=False)"
+ "ds.add_field((\"gas\",\"pseudo_entropy\"), function=_pe, units=\"keV*(counts)**(-1/3)\", take_log=False)"
],
"language": "python",
"metadata": {},
@@ -180,10 +180,11 @@
"input": [
"radial_profile = yt.ProfilePlot(my_sphere, \"radius\", \n",
" [\"counts\",\"pseudo_pressure\",\"pseudo_entropy\"], \n",
- " n_bins=50, weight_field=\"ones\")\n",
+ " n_bins=30, weight_field=\"ones\")\n",
"radial_profile.set_log(\"counts\", True)\n",
"radial_profile.set_log(\"pseudo_pressure\", True)\n",
"radial_profile.set_log(\"pseudo_entropy\", True)\n",
+ "radial_profile.set_xlim(3,100.)\n",
"radial_profile.show()"
],
"language": "python",
@@ -401,4 +402,4 @@
"metadata": {}
}
]
-}
+}
\ No newline at end of file
diff -r 02ef23fcc82e96c58e4786027e42534cc6d09be1 -r ee4276f9be712f57aa6dc829d7990fe6f8511f83 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,7 +13,8 @@
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
+from yt.utilities.fits_image import FITSImageBuffer, sanitize_fits_unit, \
+ create_sky_wcs
from yt.visualization.volume_rendering.camera import off_axis_projection
from yt.funcs import get_pbar
from yt.utilities.physical_constants import clight, mh
@@ -188,6 +189,9 @@
else:
self.width = ds.quan(self.width, "code_length")
+ 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
@@ -245,57 +249,40 @@
Whether or not to clobber an existing file with the same name.
length_unit : string
The units to convert the coordinates to in the file.
- sky_scale : tuple or YTQuantity
+ sky_scale : tuple, optional
Conversion between an angle unit and a length unit, if sky
- coordinates are desired.
- Examples: (1.0, "arcsec/kpc"), YTQuantity(0.001, "deg/kpc")
+ coordinates are desired, e.g. (1.0, "arcsec/kpc")
sky_center : tuple, optional
- The (RA, Dec) coordinate in degrees of the central pixel if
- *sky_scale* has been specified.
+ The (RA, Dec) coordinate in degrees of the central pixel. Must
+ be specified with *sky_scale*.
Examples
--------
>>> cube.write_fits("my_cube.fits", clobber=False, sky_scale=(1.0,"arcsec/kpc"))
"""
- if sky_scale is None:
- center = (0.0,0.0)
- types = ["LINEAR","LINEAR"]
- else:
- if iterable(sky_scale):
- sky_scale = self.ds.quan(sky_scale[0], sky_scale[1])
- if sky_center is None:
- center = (30.,45.)
- else:
- center = sky_center
- types = ["RA---TAN","DEC--TAN"]
-
vunit = fits_info[self.axis_type][0]
vtype = fits_info[self.axis_type][1]
v_center = 0.5*(self.vbins[0]+self.vbins[-1]).in_units(vunit).value
- if sky_scale:
- dx = (self.width*sky_scale).in_units("deg").v/self.nx
- units = "deg"
+ if length_unit is None:
+ units = str(self.ds.get_smallest_appropriate_unit(self.width))
else:
- if length_unit is None:
- units = str(self.ds.get_smallest_appropriate_unit(self.width))
- else:
- units = length_unit
+ units = length_unit
units = sanitize_fits_unit(units)
dx = self.width.in_units(units).v/self.nx
- dy = dx
+ dy = self.width.in_units(units).v/self.ny
dv = self.dv.in_units(vunit).v
- if sky_scale:
- dx *= -1.
-
w = _astropy.pywcs.WCS(naxis=3)
w.wcs.crpix = [0.5*(self.nx+1), 0.5*(self.ny+1), 0.5*(self.nv+1)]
w.wcs.cdelt = [dx,dy,dv]
- w.wcs.crval = [center[0],center[1],v_center]
+ w.wcs.crval = [0.0,0.0,v_center]
w.wcs.cunit = [units,units,vunit]
- w.wcs.ctype = [types[0],types[1],vtype]
+ w.wcs.ctype = ["LINEAR","LINEAR",vtype]
+
+ 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(2,0,1), fields=self.field, wcs=w)
fib[0].header["bunit"] = re.sub('()', '', str(self.proj_units))
diff -r 02ef23fcc82e96c58e4786027e42534cc6d09be1 -r ee4276f9be712f57aa6dc829d7990fe6f8511f83 yt/analysis_modules/sunyaev_zeldovich/projection.py
--- a/yt/analysis_modules/sunyaev_zeldovich/projection.py
+++ b/yt/analysis_modules/sunyaev_zeldovich/projection.py
@@ -298,13 +298,12 @@
----------
filename : string
The name of the FITS file to be written.
- sky_scale : tuple or YTQuantity
+ sky_scale : tuple
Conversion between an angle unit and a length unit, if sky
- coordinates are desired.
- Examples: (1.0, "arcsec/kpc"), YTQuantity(0.001, "deg/kpc")
+ coordinates are desired, e.g. (1.0, "arcsec/kpc")
sky_center : tuple, optional
- The (RA, Dec) coordinate in degrees of the central pixel if
- *sky_scale* has been specified.
+ The (RA, Dec) coordinate in degrees of the central pixel. Must
+ be specified with *sky_scale*.
clobber : boolean, optional
If the file already exists, do we overwrite?
@@ -314,40 +313,23 @@
>>> szprj.write_fits("SZbullet.fits", clobber=False)
>>> # This example uses sky coords
>>> sky_scale = (1., "arcsec/kpc") # One arcsec per kpc
- >>> sky_center = (30., 45.) # In degrees
+ >>> 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, sanitize_fits_unit
+ from yt.utilities.fits_image import FITSImageBuffer, create_sky_wcs
- if sky_scale is None:
- center = (0.0,0.0)
- types = ["LINEAR","LINEAR"]
- else:
- if iterable(sky_scale):
- sky_scale = self.ds.quan(sky_scale[0], sky_scale[1])
- if sky_center is None:
- center = (30.,45.)
- else:
- center = sky_center
- types = ["RA---TAN","DEC--TAN"]
-
- units = self.ds.get_smallest_appropriate_unit(self.width)
- units = sanitize_fits_unit(units)
- # Hack because FITS is stupid and doesn't understand case
- dx = self.dx.in_units(units)
- if sky_scale:
- dx = (dx*sky_scale).in_units("deg")
- units = "deg"
+ dx = self.dx.in_units("kpc")
dy = dx
- if sky_scale:
- dx *= -1.
w = _astropy.pywcs.WCS(naxis=2)
w.wcs.crpix = [0.5*(self.nx+1)]*2
w.wcs.cdelt = [dx.v,dy.v]
- w.wcs.crval = center
- w.wcs.cunit = [units]*2
- w.wcs.ctype = types
+ w.wcs.crval = [0.0,0.0]
+ w.wcs.cunit = ["kpc"]*2
+ w.wcs.ctype = ["LINEAR"]*2
+
+ 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.writeto(filename, clobber=clobber)
diff -r 02ef23fcc82e96c58e4786027e42534cc6d09be1 -r ee4276f9be712f57aa6dc829d7990fe6f8511f83 yt/utilities/fits_image.py
--- a/yt/utilities/fits_image.py
+++ b/yt/utilities/fits_image.py
@@ -28,7 +28,7 @@
class FITSImageBuffer(HDUList):
- def __init__(self, data, fields=None, units="cm", wcs=None):
+ def __init__(self, data, fields=None, units=None, pixel_scale=None, wcs=None):
r""" Initialize a FITSImageBuffer object.
FITSImageBuffer contains a list of FITS ImageHDU instances, and
@@ -49,8 +49,11 @@
keys, it will use these for the fields. If *data* is just a
single array one field name must be specified.
units : string
- The units of the WCS coordinates. Only applies
- to FixedResolutionBuffers or YTCoveringGrids. Defaults to "cm".
+ The units of the WCS coordinates. Defaults to "cm".
+ pixel_scale : float
+ The scale of the pixel, in *units*. Either a single float or
+ iterable of floats. Only used if this information is not already
+ provided by *data*.
wcs : `astropy.wcs.WCS` instance, optional
Supply an AstroPy WCS instance. Will override automatic WCS
creation from FixedResolutionBuffers and YTCoveringGrids.
@@ -77,7 +80,10 @@
>>> f_deg = FITSImageBuffer(frb, fields="kT", wcs=w)
>>> f_deg.writeto("temp.fits")
"""
-
+
+ if units is None: units = "cm"
+ if pixel_scale is None: pixel_scale = 1.0
+
super(FITSImageBuffer, self).__init__()
if isinstance(fields, basestring): fields = [fields]
@@ -91,13 +97,13 @@
img_data = {}
if fields is None:
mylog.error("Please specify a field name for this array.")
- raise KeyError
+ raise KeyError("Please specify a field name for this array.")
img_data[fields[0]] = data
if fields is None: fields = img_data.keys()
if len(fields) == 0:
mylog.error("Please specify one or more fields to write.")
- raise KeyError
+ raise KeyError("Please specify one or more fields to write.")
first = True
@@ -128,12 +134,8 @@
elif self.dimensionality == 3:
self.nx, self.ny, self.nz = self[0].data.shape
- has_coords = (isinstance(img_data, FixedResolutionBuffer) or
- isinstance(img_data, YTCoveringGridBase))
-
if wcs is None:
w = pywcs.WCS(header=self[0].header, naxis=self.dimensionality)
- w.wcs.crpix = 0.5*(np.array(self.shape)+1)
if isinstance(img_data, FixedResolutionBuffer):
# FRBs are a special case where we have coordinate
# information, so we take advantage of this and
@@ -143,26 +145,28 @@
xctr = 0.5*(img_data.bounds[1]+img_data.bounds[0]).in_units(units)
yctr = 0.5*(img_data.bounds[3]+img_data.bounds[2]).in_units(units)
center = [xctr, yctr]
+ cdelt = [dx,dy]
elif isinstance(img_data, YTCoveringGridBase):
- dx, dy, dz = img_data.dds.in_units(units)
+ cdelt = img_data.dds.in_units(units).v
center = 0.5*(img_data.left_edge+img_data.right_edge).in_units(units)
else:
- # We default to pixel coordinates if nothing is provided
- dx, dy, dz = 1.0, 1.0, 1.0
- center = 0.5*(np.array(self.shape)+1)
+ # If img_data is just an array, we assume the center is the origin
+ # and use *pixel_scale* to determine the cell widths
+ if iterable(pixel_scale):
+ cdelt = pixel_scale
+ else:
+ cdelt = [pixel_scale]*self.dimensionality
+ center = [0.0]*self.dimensionality
+ w.wcs.crpix = 0.5*(np.array(self.shape)+1)
w.wcs.crval = center
- if has_coords:
- w.wcs.cunit = [units]*self.dimensionality
- if self.dimensionality == 2:
- w.wcs.cdelt = [dx,dy]
- elif self.dimensionality == 3:
- w.wcs.cdelt = [dx,dy,dz]
+ w.wcs.cdelt = cdelt
w.wcs.ctype = ["linear"]*self.dimensionality
- self._set_wcs(w)
+ w.wcs.cunit = [units]*self.dimensionality
+ self.set_wcs(w)
else:
- self._set_wcs(wcs)
+ self.set_wcs(wcs)
- def _set_wcs(self, wcs):
+ def set_wcs(self, wcs):
"""
Set the WCS coordinate information for all images
with a WCS object *wcs*.
@@ -250,6 +254,50 @@
axis_wcs = [[1,2],[0,2],[0,1]]
+def create_sky_wcs(old_wcs, sky_center, sky_scale,
+ ctype=["RA---TAN","DEC--TAN"], crota=None):
+ """
+ Takes an astropy.wcs.WCS instance created in yt from a
+ simulation that has a Cartesian coordinate system and
+ converts it to one in a celestial coordinate system.
+
+ Parameters
+ ----------
+ old_wcs : astropy.wcs.WCS
+ The original WCS to be converted.
+ sky_center : tuple
+ Reference coordinates of the WCS in degrees.
+ sky_scale : tuple
+ Conversion between an angle unit and a length unit,
+ e.g. (3.0, "arcsec/kpc")
+ ctype : list of strings, optional
+ The type of the coordinate system to create.
+ crota : list of floats, optional
+ Rotation angles between cartesian coordinates and
+ the celestial coordinates.
+ """
+ naxis = old_wcs.naxis
+ crval = [sky_center[0], sky_center[1]]
+ scaleq = YTQuantity(sky_scale[0],sky_scale[1])
+ deltas = old_wcs.wcs.cdelt
+ units = [str(unit) for unit in old_wcs.wcs.cunit]
+ new_dx = (YTQuantity(-deltas[0], units[0])*scaleq).in_units("deg")
+ new_dy = (YTQuantity(deltas[1], units[1])*scaleq).in_units("deg")
+ new_wcs = pywcs.WCS(naxis=naxis)
+ cdelt = [new_dx.v, new_dy.v]
+ if naxis == 3:
+ crval.append(old_wcs.wcs.crval[2])
+ cdelt.append(old_wcs.wcs.cdelt[2])
+ ctype.append(old_wcs.wcs.ctype[2])
+ new_wcs.wcs.crpix = old_wcs.wcs.crpix
+ new_wcs.wcs.cdelt = cdelt
+ new_wcs.wcs.crval = crval
+ new_wcs.wcs.cunit = ["deg"]*naxis
+ new_wcs.wcs.ctype = ctype
+ if crota is not None:
+ new_wcs.wcs.crota = crota
+ return new_wcs
+
def sanitize_fits_unit(unit):
if unit == "Mpc":
mylog.info("Changing FITS file unit to kpc.")
diff -r 02ef23fcc82e96c58e4786027e42534cc6d09be1 -r ee4276f9be712f57aa6dc829d7990fe6f8511f83 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -775,7 +775,7 @@
"%s_axis" % ("xy"[i]))[axis_index]
unn = self.ds.coordinates.default_unit_label.get(axax, "")
if unn != "":
- axes_unit_labels[i] = '\/\/\left('+unn+'\right)'
+ axes_unit_labels[i] = r'\/\/\left('+unn+r'\right)'
continue
# Use sympy to factor h out of the unit. In this context 'un'
# is a string, so we call the Unit constructor.
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