[Yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Apr 15 13:00:09 PDT 2011
2 new changesets in yt:
http://bitbucket.org/yt_analysis/yt/changeset/cb1cc4f84a1b/
changeset: r4138:cb1cc4f84a1b
branch: yt
user: samskillman
date: 2011-04-15 21:58:30
summary: Adding the first bits of code for the OpenGL grid viewer. More work
to be done.
affected #: 1 file (5.7 KB)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/gui/reason/html/js/widget_gridviewer.js Fri Apr 15 15:58:30 2011 -0400
@@ -0,0 +1,203 @@
+/**********************************************************************
+The Plot Window Widget
+
+Author: Cameron Hummels <chummels at gmail.com>
+Affiliation: Columbia
+Author: Jeffrey S. Oishi <jsoishi at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Author: Britton Smith <brittonsmith at gmail.com>
+Affiliation: MSU
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: NSF / Columbia
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 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/>.
+***********************************************************************/
+
+
+
+var WidgetPlotWindow = function(python_varname, widget_data) {
+ this.id = python_varname;
+ this.widget_data = widget_data;
+
+ viewport.get("center-panel").add(
+ {
+ xtype: 'panel',
+ id: "pw_" + this.id,
+ title: "WebGL Grid Viewer",
+ iconCls: 'graph',
+ autoScroll: true,
+ layout:'absolute',
+ closable: true,
+
+ function webGLStart() {
+ this.curX = 0;
+ this.curY = 0;
+ this.dist = 0;
+ function updateBasedOnOffset(camera, offset){
+ camera.position.x = camera.target.x + offset.x;
+ camera.position.y = camera.target.y + offset.y;
+ camera.position.z = camera.target.z + offset.z;
+ }
+ function camGetOffset(camera){
+ return PhiloGL.Vec3.sub(camera.position, camera.target)
+ }
+ PhiloGL('lesson01-canvas', {
+ camera: {
+ position: {
+ x: 0.5, y: 0.5, z: 5
+ },
+ target: {
+ x: 0.5, y: 0.5, z: 0.5
+ },
+ },
+ program: {
+ from: 'ids',
+ vs: 'shader-vs',
+ fs: 'shader-fs'
+ },
+ events: {
+ onDragStart: function(e) {
+ pos = {
+ x: e.x,
+ y: e.y
+ };
+ this.curX = e.x;
+ this.curY = e.y;
+ this.dist = camGetOffset(this.camera).norm();
+ },
+ onDragEnd: function(e) {
+ pos = {
+ x: e.x,
+ y: e.y
+ };
+ },
+ onDragMove: function(e) {
+ var c = this.camera;
+ var off = camGetOffset(c);
+ // Get Horizontal vector
+ var horiz = PhiloGL.Vec3.cross(c.up,
+ camGetOffset(c))
+ horiz.$scale(1./horiz.norm());
+
+ if (e.event.button == 0){ // Rotation
+ // Do vertical rotation about horizontal vector
+ var vert_rot = new PhiloGL.Mat4();
+ vert_rot.id();
+ vert_rot.$rotateAxis((e.y-this.curY)/100., horiz);
+ PhiloGL.Mat4.$mulVec3(vert_rot, off);
+ PhiloGL.Mat4.$mulVec3(vert_rot, c.up);
+ c.up.$scale(1./c.up.norm());
+
+ // Do horizontal rotation about up vector
+ var side_rot = new PhiloGL.Mat4();
+ side_rot.id();
+ side_rot.$rotateAxis(-(e.x-this.curX)/100., c.up);
+ side_rot.$mulVec3(off);
+
+ // Update current positions
+ this.curX = e.x;
+ this.curY = e.y;
+ this.dist = off.norm();
+ updateBasedOnOffset(c, off);
+ c.update();
+ } else if (e.event.button = 2){ // Right click - transpose
+ var move_up = c.up.scale(-(e.y-this.curY)/200.);
+ var move_over = horiz.scale(-(e.x-this.curX)/200.);
+ c.position.$add(move_up);
+ c.position.$add(move_over);
+ c.target.$add(move_up);
+ c.target.$add(move_over);
+ // Update current positions
+ this.curX = e.x;
+ this.curY = e.y;
+ c.update();
+ }
+
+ },
+ onMouseWheel: function(e){
+ e.stop();
+ var offset = PhiloGL.Vec3.scale(camGetOffset(this.camera),
+ 1.0 - e.wheel/10.);
+ updateBasedOnOffset(this.camera, offset);
+ this.camera.update();
+ }
+ },
+ onError: function() {
+ alert("An error ocurred while loading the application");
+ },
+ onLoad: function(app) {
+ var gl = app.gl,
+ canvas = app.canvas,
+ program = app.program,
+ scene = app.scene,
+ camera = app.camera;
+
+ gl.viewport(0, 0, canvas.width, canvas.height);
+ gl.clearColor(0, 0, 0, 1);
+ gl.clearDepth(1);
+ gl.enable(gl.DEPTH_TEST);
+ gl.depthFunc(gl.LEQUAL);
+
+ program.setBuffers({
+ 'shapeset': {
+ attribute: 'aVertexPosition',
+ value: new Float32Array(vertex_positions),
+ size: 3
+ },
+
+ });
+ camera.modelView.id();
+ draw()
+
+ setInterval(draw, 100/60);
+ //Draw the scene
+ function draw() {
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+ //Draw Triangle
+ program.setUniform('uMVMatrix', camera.modelView);
+ program.setUniform('uPMatrix', camera.projection);
+ program.setBuffer('triangle');
+ gl.drawArrays(gl.LINES, 0, n_vertices);
+ examine = camera
+ }
+ }
+ });
+ }
+
+
+ }
+ );
+
+ viewport.get("center-panel").activate("pw_" + this.id);
+ viewport.doLayout();
+ this.panel = viewport.get("center-panel").get("pw_" + python_varname);
+ this.panel.doLayout();
+ this.image_panel = this.panel.get("image_panel_"+python_varname);
+ var image_dom = this.image_panel.el.dom;
+
+ this.accept_results = function(payload) {
+ this.image_panel.el.dom.src = "data:image/png;base64," + payload['image_data'];
+ }
+
+ yt_rpc.ExtDirectREPL.execute(
+ {code:python_varname + '.zoom(1.0)'},
+ cell_finished);
+}
+
+widget_types['plot_window'] = WidgetPlotWindow;
http://bitbucket.org/yt_analysis/yt/changeset/302967243b95/
changeset: r4139:302967243b95
branch: yt
user: samskillman
date: 2011-04-15 21:59:38
summary: Merging
affected #: 4 files (1.9 KB)
--- a/yt/analysis_modules/halo_profiler/centering_methods.py Fri Apr 15 15:58:30 2011 -0400
+++ b/yt/analysis_modules/halo_profiler/centering_methods.py Fri Apr 15 15:59:38 2011 -0400
@@ -40,104 +40,89 @@
#### Dark Matter Density ####
-def _MatterDensityXDMMass(field, data):
- return (data['Dark_Matter_Density'] * data['Dark_Matter_Density'] \
- * data["CellVolume"])
-def _Convert_MatterDensityXDMMass(data):
- return 1
-add_field("MatterDensityXDMMass", units=r"",
- function=_MatterDensityXDMMass,
- convert_function=_Convert_MatterDensityXDMMass)
-
@add_function("Min_Dark_Matter_Density")
def find_minimum_dm_density(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('MatterDensityXDMMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('Dark_Matter_Density',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("Max_Dark_Matter_Density")
def find_maximum_dm_density(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('MatterDensityXDMMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Dark_Matter_Density',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("CoM_Dark_Matter_Density")
def find_CoM_dm_density(data):
- dc_x = data.quantities['WeightedAverageQuantity']('x', 'MatterDensityXDMMass')
- dc_y = data.quantities['WeightedAverageQuantity']('y', 'MatterDensityXDMMass')
- dc_z = data.quantities['WeightedAverageQuantity']('z', 'MatterDensityXDMMass')
- return [dc_x, dc_y, dc_z]
+ dc_x, dc_y, dc_z = data.quantities['CenterOfMass'](use_cells=False,
+ use_particles=True,
+ lazy_reader=False,
+ preload=False)
+ return (dc_x, dc_y, dc_z)
#### Gas Density ####
-def _GasDensityXCellMass(field, data):
- return (data['Density'] * data['CellMassMsun'])
-def _Convert_GasDensityXCellMass(data):
- return 1
-add_field("GasDensityXCellMass", units=r"",
- function=_GasDensityXCellMass,
- convert_function=_Convert_GasDensityXCellMass)
-
@add_function("Min_Gas_Density")
def find_minimum_gas_density(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('GasDensityXCellMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('Density',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("Max_Gas_Density")
def find_maximum_gas_density(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('GasDensityXCellMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Density',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("CoM_Gas_Density")
def find_CoM_gas_density(data):
- dc_x = data.quantities['WeightedAverageQuantity']('x', 'GasDensityXCellMass')
- dc_y = data.quantities['WeightedAverageQuantity']('y', 'GasDensityXCellMass')
- dc_z = data.quantities['WeightedAverageQuantity']('z', 'GasDensityXCellMass')
- return [dc_x, dc_y, dc_z]
+ dc_x, dc_y, dc_z = data.quantities['CenterOfMass'](use_cells=True,
+ use_particles=False,
+ lazy_reader=False,
+ preload=False)
+ return (dc_x, dc_y, dc_z)
#### Total Density ####
-def _TotalDensityXTotalMass(field, data):
- return (data['Density'] + data['Dark_Matter_Density']) * \
- data['TotalMassMsun']
-def _Convert_TotalDensityXTotalMass(data):
- return 1
-add_field("TotalDensityXTotalMass", units=r"",
- function=_TotalDensityXTotalMass,
- convert_function=_Convert_TotalDensityXTotalMass)
-
@add_function("Min_Total_Density")
def find_minimum_total_density(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('TotalDensityXTotalMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('Matter_Density',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("Max_Total_Density")
def find_maximum_total_density(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('TotalDensityXTotalMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Matter_Density',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("CoM_Total_Density")
def find_CoM_total_density(data):
- dc_x = data.quantities['WeightedAverageQuantity']('x', 'TotalDensityXTotalMass')
- dc_y = data.quantities['WeightedAverageQuantity']('y', 'TotalDensityXTotalMass')
- dc_z = data.quantities['WeightedAverageQuantity']('z', 'TotalDensityXTotalMass')
- return [dc_x, dc_y, dc_z]
+ dc_x, dc_y, dc_z = data.quantities['CenterOfMass'](use_cells=True,
+ use_particles=True,
+ lazy_reader=False,
+ preload=False)
+ return (dc_x, dc_y, dc_z)
#### Temperature ####
-def _TemperatureXCellMass(field, data):
- return (data['Temperature'] * data['CellMassMsun'])
-def _Convert_TemperatureXCellMass(data):
- return 1
-add_field("TemperatureXCellMass", units=r"",
- function=_TemperatureXCellMass,
- convert_function=_Convert_TemperatureXCellMass)
-
@add_function("Min_Temperature")
def find_minimum_temperature(data):
- ma, mini, mx, my, mz, mg = data.quantities['MinLocation']('TemperatureXCellMass')
- return [mx,my,mz]
+ ma, mini, mx, my, mz, mg = data.quantities['MinLocation']('Temperature',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
@add_function("Max_Temperature")
def find_maximum_temperature(data):
- ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('TemperatureXCellMass')
- return [mx,my,mz]
+ ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Temperature',
+ lazy_reader=False,
+ preload=False)
+ return (mx, my, mz)
--- a/yt/analysis_modules/halo_profiler/halo_filters.py Fri Apr 15 15:58:30 2011 -0400
+++ b/yt/analysis_modules/halo_profiler/halo_filters.py Fri Apr 15 15:59:38 2011 -0400
@@ -28,11 +28,11 @@
from yt.funcs import *
-def VirialFilter(profile,overdensity_field='ActualOverdensity',
- virial_overdensity=200.,must_be_virialized=True,
- virial_filters=[['TotalMassMsun','>=','1e14']],
- virial_quantities=['TotalMassMsun','RadiusMpc'],
- virial_index=None):
+def VirialFilter(profile, overdensity_field='ActualOverdensity',
+ virial_overdensity=200., must_be_virialized=True,
+ virial_filters=[['TotalMassMsun', '>=','1e14']],
+ virial_quantities=['TotalMassMsun', 'RadiusMpc'],
+ virial_index=None, use_log=False):
"""
Filter halos by virial quantities.
Return values are a True or False whether the halo passed the filter,
@@ -40,6 +40,23 @@
the virial_quantities keyword. Thresholds for virial quantities are
given with the virial_filters keyword in the following way:
[field, condition, value].
+ :param: overdensity_field (str): the field used for interpolation with the
+ specified critical value given with 'virial_overdensity'.
+ Default: 'ActualOverdensity'.
+ :param: virial_overdensity (flt): the value used for interpolation.
+ Default: 200.[['TotalMassMsun', '>=','1e14']]
+ :param: must_be_virialized (bool): if no values in the profile are above the
+ value of virial_overdensity, the halo does not pass the filter.
+ Default: True.
+ :param: virial_filters (list): conditional filters based on virial quantities
+ given in the following way: [field, condition, value].
+ Default: [['TotalMassMsun', '>=','1e14']].
+ :param: virial_quantities (list): fields for which interpolated values should
+ be calculated and returned. Default: ['TotalMassMsun', 'RadiusMpc'].
+ :param: virial_index (list): if given as a list, the index of the radial profile
+ which is used for interpolation is placed here. Default: None.
+ :param: use_log (bool): if True, interpolation is done in log space.
+ Default: False.
"""
fields = deepcopy(virial_quantities)
@@ -49,9 +66,7 @@
fields.append(vfilter[0])
overDensity = []
- temp_profile = {}
- for field in fields:
- temp_profile[field] = []
+ temp_profile = dict((field, []) for field in fields)
for q in range(len(profile[overdensity_field])):
good = True
@@ -67,9 +82,11 @@
for field in fields:
temp_profile[field].append(profile[field][q])
- virial = {}
- for field in fields:
- virial[field] = 0.0
+ if use_log:
+ for field in temp_profile.keys():
+ temp_profile[field] = na.log10(temp_profile[field])
+
+ virial = dict((field, 0.0) for field in fields)
if (not (na.array(overDensity) >= virial_overdensity).any()) and \
must_be_virialized:
@@ -104,13 +121,20 @@
temp_profile[field][index]
virial[field] = value
+ if use_log:
+ for field in virial.keys():
+ virial[field] = na.power(10, virial[field])
+
for vfilter in virial_filters:
if eval("%s %s %s" % (virial[vfilter[0]],vfilter[1],vfilter[2])):
- mylog.debug("(%s %s %s) returned True for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
+ mylog.debug("(%s %s %s) returned True for %s." % \
+ (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
continue
else:
- mylog.debug("(%s %s %s) returned False for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
+ mylog.debug("(%s %s %s) returned False for %s." % \
+ (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
return [False, {}]
- return [True, dict((q,virial[q]) for q in virial_quantities)]
+ return [True, dict((("%s_%s" % (q, virial_overdensity)), virial[q])
+ for q in virial_quantities)]
--- a/yt/analysis_modules/halo_profiler/multi_halo_profiler.py Fri Apr 15 15:58:30 2011 -0400
+++ b/yt/analysis_modules/halo_profiler/multi_halo_profiler.py Fri Apr 15 15:59:38 2011 -0400
@@ -62,12 +62,12 @@
halo_finder_kwargs=dict(threshold=160.0, safety=1.5,
dm_only=False, resize=True,
fancy_padding=True, rearrange=True),
- use_density_center=False, density_center_exponent=1.0,
halo_radius=0.1, radius_units='1', n_profile_bins=50,
recenter = None,
profile_output_dir='radial_profiles', projection_output_dir='projections',
projection_width=8.0, projection_width_units='mpc', project_at_level='max',
- velocity_center=['bulk', 'halo'], filter_quantities=['id','center']):
+ velocity_center=['bulk', 'halo'], filter_quantities=['id','center'],
+ use_critical_density=False):
"""
Initialize a HaloProfiler object.
:param output_dir (str): if specified, all output will be put into this path instead of
@@ -114,6 +114,7 @@
specified (used only when halos set to single).
:param filter_quantities (list): quantities from the original halo list file to be written out in the
filtered list file. Default: ['id','center'].
+ :param use_critical_density (bool): if True, the definition of overdensity for virial quantities is calculated with respect to the critical density. If False, overdensity is with respect to mean matter density, which is lower by a factor of Omega_M. Default: False.
"""
self.dataset = dataset
@@ -126,6 +127,7 @@
self.project_at_level = project_at_level
self.filter_quantities = filter_quantities
if self.filter_quantities is None: self.filter_quantities = []
+ self.use_critical_density = use_critical_density
self.profile_fields = []
self.projection_fields = []
@@ -561,10 +563,10 @@
if 'ActualOverdensity' in profile.keys():
return
- rho_crit_now = 1.8788e-29 * self.pf.hubble_constant**2.0 * \
- self.pf.omega_matter # g cm^-3
+ rho_crit_now = 1.8788e-29 * self.pf.hubble_constant**2 # g cm^-3
Msun2g = 1.989e33
rho_crit = rho_crit_now * ((1.0 + self.pf.current_redshift)**3.0)
+ if not self.use_critical_density: rho_crit *= self.pf.omega_matter
profile['ActualOverdensity'] = (Msun2g * profile['TotalMassMsun']) / \
profile['CellVolume'] / rho_crit
--- a/yt/data_objects/derived_quantities.py Fri Apr 15 15:58:30 2011 -0400
+++ b/yt/data_objects/derived_quantities.py Fri Apr 15 15:59:38 2011 -0400
@@ -155,18 +155,21 @@
add_quantity("TotalMass", function=_TotalMass,
combine_function=_combTotalMass, n_ret = 2)
-def _CenterOfMass(data,use_particles=False):
+def _CenterOfMass(data, use_cells=True, use_particles=False):
"""
This function returns the location of the center
of mass. By default, it computes of the *non-particle* data in the object.
- :param use_particles: if True, will compute center of mass for
- *all data* in the object (default: False)
+ :param use_cells: if True, will include the cell mass (default: True)
+ :param use_particles: if True, will include the particles in the
+ object (default: False)
"""
- x = (data["x"] * data["CellMassMsun"]).sum()
- y = (data["y"] * data["CellMassMsun"]).sum()
- z = (data["z"] * data["CellMassMsun"]).sum()
- den = data["CellMassMsun"].sum()
+ x = y = z = den = 0
+ if use_cells:
+ x += (data["x"] * data["CellMassMsun"]).sum()
+ y += (data["y"] * data["CellMassMsun"]).sum()
+ z += (data["z"] * data["CellMassMsun"]).sum()
+ den += data["CellMassMsun"].sum()
if use_particles:
x += (data["particle_position_x"] * data["ParticleMassMsun"]).sum()
y += (data["particle_position_y"] * data["ParticleMassMsun"]).sum()
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